9 #ifndef GlobeEngine_UndirectedGraph_h
10 #define GlobeEngine_UndirectedGraph_h
12 #include "OpenGL_Includes.h"
21 template <
class NODETYPE,
class EDGETYPE,
class U>
class UndirectedGraph :
public Graph < NODETYPE, EDGETYPE, U>
34 unsigned int newEdgeID = this->
edges.size();
35 std::pair<U , U > fwcomb(_nodeIdx1, _nodeIdx2);
36 std::pair<U , U > bwcomb(_nodeIdx2, _nodeIdx1);
38 typename std::map< std::pair < U , U >, U >::const_iterator edgeFWItr = this->
forwardEdges.find(fwcomb);
43 typename std::map< std::pair < U , U >, U >::const_iterator edgeBWItr = this->
forwardEdges.find(bwcomb);
49 EDGETYPE newUEdge(newEdgeID, _nodeIdx1, _nodeIdx2, _weight);
50 this->
edges.push_back(newUEdge);
51 this->
nodes[_nodeIdx1].addEdge(newEdgeID);
52 this->
nodes[_nodeIdx2].addEdge(newEdgeID);
54 this->
forwardEdges.insert(std::pair< std::pair< U , U > , U >(fwcomb, newEdgeID));
55 this->
backwardEdges.insert(std::pair< std::pair< U , U >, U >(bwcomb, newEdgeID));
63 std::pair<U , U > edgeToSearch(_nodeIdx1, _nodeIdx2);
64 typename std::map< std::pair < U , U >, U >::const_iterator edgeItr = this->
forwardEdges.find(edgeToSearch);
66 return edgeItr->second;
69 typename std::map< std::pair < U , U >, U >::const_iterator edgeBWItr = this->
backwardEdges.find(edgeToSearch);
71 return edgeBWItr->second;
73 std::cout <<
"No edge for NodeIDs found." << std::endl;
79 friend std::ostream& operator<< (std::ostream &out, const UndirectedGraph< NODETYPE, EDGETYPE, U> &graph) {
80 out <<
"graph has "<< graph.nodes.size() <<
" nodes: " << std::endl;
81 for (
int i = 0; i < graph.nodes.size(); i++)
83 out << graph.nodes[i] << std::endl;
UndirectedGraph< ge::Vertex2d, UndirectedEdgeui, unsigned int > UndirectedGraph2Dd
Definition: UndirectedGraph.h:93
UndirectedGraph()
Definition: UndirectedGraph.h:24
U getEdgeByNodeIDs(unsigned int _nodeIdx1, unsigned int _nodeIdx2)
Definition: UndirectedGraph.h:62
UndirectedGraph< ge::Vertex3d, UndirectedEdgeui, unsigned int > Graph3Dd
Definition: UndirectedGraph.h:91
std::map< std::pair< U, U >, U > forwardEdges
Definition: Graph.h:148
unsigned int addUndirectedEdge(unsigned int _nodeIdx1, unsigned int _nodeIdx2)
Definition: UndirectedGraph.h:29
Definition: DirectedEdge.h:16
std::vector< EDGETYPE > edges
Definition: Graph.h:147
std::vector< GraphNode< U > > nodes
Definition: Graph.h:145
unsigned int addWeightedUndirectedEdge(unsigned int _nodeIdx1, unsigned int _nodeIdx2, float _weight)
Definition: UndirectedGraph.h:33
Definition: UndirectedGraph.h:21
UndirectedGraph< ge::Vertex2d, UndirectedEdgeui, unsigned int > Graph2Dd
Definition: UndirectedGraph.h:90
std::map< std::pair< U, U >, U > backwardEdges
Definition: Graph.h:149
UndirectedGraph< ge::Vertex3d, UndirectedEdgeui, unsigned int > UndirectedGraph3Dd
Definition: UndirectedGraph.h:94