9 #ifndef GlobeEngine_ReducableUndirectedGraph_h
10 #define GlobeEngine_ReducableUndirectedGraph_h
12 #include "OpenGL_Includes.h"
34 for (
unsigned int i=0; i < this->
nodes.size();i++)
36 if (this->
nodes[i].isEndpoint()) {
39 if (this->
nodes[i].isCrossing()) {
50 unsigned int tmpEdgeID = this->
nodes[_nodeID].getNeighbors()[0];
51 unsigned int tmpNodeID = this->
edges[tmpEdgeID].getOppositeNode(_nodeID);
53 float weight = this->
edges[tmpEdgeID].getWeight();
55 if(this->
edges[tmpEdgeID].isMarked()) {
58 std::vector< U > markedEdges;
59 while (this->
nodes[tmpNodeID].isConnector())
61 this->
edges[tmpEdgeID].mark();
62 markedEdges.push_back(tmpEdgeID);
63 tmpEdgeID = this->
nodes[tmpNodeID].getOppositeEdge(tmpEdgeID);
64 tmpNodeID = this->
edges[tmpEdgeID].getOppositeNode(tmpNodeID);
66 weight += this->
edges[tmpEdgeID].getWeight();
69 this->
edges[tmpEdgeID].mark();
70 markedEdges.push_back(tmpEdgeID);
72 EDGETYPE newUEdge(tmpEdgeID, _nodeID, tmpNodeID, weight);
73 unsigned int tmpRedEdgeID = this->reducedEdges.size();
74 reducedEdgeToGraphEdge.insert(std::pair< U , std::vector< U > >(tmpRedEdgeID, markedEdges));
75 this->reducedEdges.push_back(newUEdge);
78 std::vector< U > edgesAssociatedToNode;
79 edgesAssociatedToNode.push_back(tmpRedEdgeID);
80 nodeIDToReducedEdge.insert(std::pair< U , std::vector< U > >(_nodeID, edgesAssociatedToNode));
83 typename std::map< U, std::vector< U > >::iterator nodeCheckItr = nodeIDToReducedEdge.find(tmpNodeID);
84 if(nodeCheckItr != nodeIDToReducedEdge.end()) {
85 nodeCheckItr->second.push_back(tmpRedEdgeID);
87 nodeIDToReducedEdge.insert(std::pair< U , std::vector< U > >(tmpNodeID, edgesAssociatedToNode));
93 std::vector< U > edgesAssociatedToNode;
94 for (
unsigned int i=0;i<this->
nodes[_nodeID].getNeighborCount();i++)
96 unsigned int tmpEdgeID = this->
nodes[_nodeID].getNeighbors()[i];
97 unsigned int tmpNodeID = this->
edges[tmpEdgeID].getOppositeNode(_nodeID);
98 float weight = this->
edges[tmpEdgeID].getWeight();
100 if(this->
edges[tmpEdgeID].isMarked()) {
103 std::vector< U > markedEdges;
104 while (this->
nodes[tmpNodeID].isConnector())
106 this->
edges[tmpEdgeID].mark();
107 markedEdges.push_back(tmpEdgeID);
108 tmpEdgeID = this->
nodes[tmpNodeID].getOppositeEdge(tmpEdgeID);
109 tmpNodeID = this->
edges[tmpEdgeID].getOppositeNode(tmpNodeID);
111 weight += this->
edges[tmpEdgeID].getWeight();
113 this->
edges[tmpEdgeID].mark();
114 markedEdges.push_back(tmpEdgeID);
115 unsigned int tmpRedEdgeID = this->reducedEdges.size();
116 EDGETYPE newUEdge(tmpEdgeID, _nodeID, tmpNodeID, weight);
117 this->reducedEdges.push_back(newUEdge);
118 reducedEdgeToGraphEdge.insert(std::pair< U , std::vector< U > >(tmpRedEdgeID, markedEdges));
119 edgesAssociatedToNode.push_back(tmpRedEdgeID);
122 typename std::map< U, std::vector< U > >::iterator nodeCheckItr = nodeIDToReducedEdge.find(tmpNodeID);
123 if(nodeCheckItr != nodeIDToReducedEdge.end()) {
124 nodeCheckItr->second.push_back(tmpRedEdgeID);
126 nodeIDToReducedEdge.insert(std::pair< U , std::vector< U > >(tmpNodeID, edgesAssociatedToNode));
131 typename std::map< U, std::vector< U > >::iterator nodeCheckItr = nodeIDToReducedEdge.find(_nodeID);
132 if(nodeCheckItr != nodeIDToReducedEdge.end()) {
133 for(
int i=0;i < edgesAssociatedToNode.size();i++) {
134 nodeCheckItr->second.push_back(edgesAssociatedToNode[i]);
137 nodeIDToReducedEdge.insert(std::pair< U , std::vector< U > >(_nodeID, edgesAssociatedToNode));
142 typename std::map< U, std::vector< U > >::const_iterator edgesByIDItr = reducedEdgeToGraphEdge.find(_redEdgeID);
143 if(edgesByIDItr != reducedEdgeToGraphEdge.end()) {
144 return edgesByIDItr->second;
147 return std::vector<U>();
151 typename std::map< U, std::vector< U > >::const_iterator edgesByIDItr = nodeIDToReducedEdge.find(_nodeID);
152 if(edgesByIDItr != nodeIDToReducedEdge.end()) {
153 return edgesByIDItr->second;
156 return std::vector<U>();
160 std::vector< U > nodeIDs;
161 typename std::map< U, std::vector< U > >::const_iterator edgeByIDItr = nodeIDToReducedEdge.find(_startNodeID);
162 if(edgeByIDItr != nodeIDToReducedEdge.end()) {
163 if(edgeByIDItr->second.size() == 0){
167 if(edgeByIDItr->second.size() == 1){
171 for (
unsigned int i = 0; i < edgeByIDItr->second.size();i++)
174 if (_endNodeID == this->reducedEdges[edgeByIDItr->second[i]].getOppositeNode(_startNodeID) || _startNodeID == this->reducedEdges[edgeByIDItr->second[i]].getOppositeNode(_endNodeID))
179 std::cout <<
"Error: EndNode not found." << std::endl;
183 std::cout <<
"No reduced edge found." << std::endl;
189 std::vector< U > redNodeIds;
191 if (edgeIds.size() > 0)
193 unsigned int prevNodeID = this->
edges[edgeIds[0]].getNodes()[0];
194 if (this->
nodes[prevNodeID].isConnector()) {
195 prevNodeID = this->
edges[edgeIds[0]].getNodes()[1];
198 redNodeIds.push_back(prevNodeID);
199 for (
unsigned int i = 0; i < edgeIds.size();i++)
201 unsigned int tmpNodeID = this->
edges[edgeIds[i]].getOppositeNode(prevNodeID);
202 redNodeIds.push_back(tmpNodeID);
203 prevNodeID = tmpNodeID;
210 return &reducedEdges[_redEdgeID];
215 return reducedEdges.size();
219 std::vector< EDGETYPE > reducedEdges;
220 std::map< U, std::vector< U > > reducedEdgeToGraphEdge;
221 std::map< U, std::vector< U > > nodeIDToReducedEdge;
239 this->reducedEdges[_redEdgeID].setWeight(_weight);
unsigned int getReducedEdgesCount()
Definition: ReducableUndirectedGraph.h:213
std::vector< U > getReducedEdgesForNodeID(unsigned int _nodeID)
Definition: ReducableUndirectedGraph.h:150
ReducableWeightedUndirectedGraph()
Definition: ReducableUndirectedGraph.h:235
std::vector< U > getEdgesForReducedEdge(unsigned int _redEdgeID)
Definition: ReducableUndirectedGraph.h:141
void reduceEdges()
Definition: ReducableUndirectedGraph.h:32
ReducableWeightedUndirectedGraph< ge::Vertex3d, WeightedUndirectedEdgeui, unsigned int > ReducableWeightedUndirectedGraph3Dd
Definition: ReducableUndirectedGraph.h:252
ReducableWeightedUndirectedGraph< ge::Vertex3d, WeightedUndirectedPolylineEdgeui, unsigned int > ReducableWeightedUndirectedPolylineGraph3Dd
Definition: ReducableUndirectedGraph.h:255
ReducableUndirectedGraph< ge::Vertex3d, UndirectedEdgeui, unsigned int > ReducableGraph3Dd
Definition: ReducableUndirectedGraph.h:226
std::vector< U > getReducedNodeIDsForReducedEdge(unsigned int _redEdgeID)
Definition: ReducableUndirectedGraph.h:188
void setReducedEdgeWheight(unsigned int _redEdgeID, float _weight)
Definition: ReducableUndirectedGraph.h:237
ReducableWeightedUndirectedGraph< ge::Vertex2d, WeightedUndirectedEdgeui, unsigned int > ReducableWeightedGraph2Dd
Definition: ReducableUndirectedGraph.h:248
Definition: ReducableUndirectedGraph.h:232
ReducableWeightedUndirectedGraph< ge::Vertex3d, WeightedUndirectedEdgeui, unsigned int > ReducableWeightedGraph3Dd
Definition: ReducableUndirectedGraph.h:249
std::vector< U > getReducedNodesForNodeID(unsigned int _startNodeID, unsigned int _endNodeID)
Definition: ReducableUndirectedGraph.h:159
ReducableUndirectedGraph< ge::Vertex3d, UndirectedEdgeui, unsigned int > ReducableUndirectedGraph3Dd
Definition: ReducableUndirectedGraph.h:229
ReducableWeightedUndirectedGraph< ge::Vertex2d, WeightedUndirectedPolylineEdgeui, unsigned int > ReducableWeightedUndirectedPolylineGraph2Dd
Definition: ReducableUndirectedGraph.h:254
Definition: DirectedEdge.h:16
ReducableUndirectedGraph()
Definition: ReducableUndirectedGraph.h:27
std::vector< EDGETYPE > edges
Definition: Graph.h:147
void reduceFromEndpoint(unsigned int _nodeID)
Definition: ReducableUndirectedGraph.h:49
std::vector< GraphNode< U > > nodes
Definition: Graph.h:145
Definition: UndirectedGraph.h:21
void setReducedEdgeWheightByID(unsigned int _nodeID, float _weight)
Definition: ReducableUndirectedGraph.h:242
Definition: ReducableUndirectedGraph.h:24
ReducableUndirectedGraph< ge::Vertex2d, UndirectedEdgeui, unsigned int > ReducableGraph2Dd
Definition: ReducableUndirectedGraph.h:225
ReducableWeightedUndirectedGraph< ge::Vertex2d, WeightedUndirectedEdgeui, unsigned int > ReducableWeightedUndirectedGraph2Dd
Definition: ReducableUndirectedGraph.h:251
EDGETYPE * getReducedEdge(unsigned int _redEdgeID)
Definition: ReducableUndirectedGraph.h:209
ReducableUndirectedGraph< ge::Vertex2d, UndirectedEdgeui, unsigned int > ReducableUndirectedGraph2Dd
Definition: ReducableUndirectedGraph.h:228
void reduceFromCrossing(unsigned int _nodeID)
Definition: ReducableUndirectedGraph.h:91