void HyperDijkstra::visitAdjacencyMap(AdjacencyMap& amap, TreeAction* action, bool useDistance) { typedef std::deque<HyperGraph::Vertex*> Deque; Deque q; // scans for the vertices without the parent (whcih are the roots of the trees) and applies the action to them. for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it) { AdjacencyMapEntry& entry(it->second); if (! entry.parent()) { action->perform(it->first,0,0); q.push_back(it->first); } } //std::cerr << "q.size()" << q.size() << endl; int count=0; while (! q.empty()) { HyperGraph::Vertex* parent=q.front(); q.pop_front(); ++count; AdjacencyMap::iterator parentIt=amap.find(parent); if (parentIt==amap.end()) { continue; } //cerr << "parent= " << parent << " parent id= " << parent->id() << "\t children id ="; HyperGraph::VertexSet& childs(parentIt->second.children()); for (HyperGraph::VertexSet::iterator childsIt=childs.begin(); childsIt!=childs.end(); ++childsIt) { HyperGraph::Vertex* child=*childsIt; //cerr << child->id(); AdjacencyMap::iterator adjacencyIt=amap.find(child); assert (adjacencyIt!=amap.end()); HyperGraph::Edge* edge=adjacencyIt->second.edge(); assert(adjacencyIt->first==child); assert(adjacencyIt->second.child()==child); assert(adjacencyIt->second.parent()==parent); if (! useDistance) { action->perform(child, parent, edge); } else { action->perform(child, parent, edge, adjacencyIt->second.distance()); } q.push_back(child); } //cerr << endl; } }
void HyperDijkstra::computeTree(AdjacencyMap& amap) { for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it) { AdjacencyMapEntry& entry(it->second); entry._children.clear(); } for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it) { AdjacencyMapEntry& entry(it->second); HyperGraph::Vertex* parent=entry.parent(); if (!parent) { continue; } HyperGraph::Vertex* v=entry.child(); assert (v==it->first); AdjacencyMap::iterator pt=amap.find(parent); assert(pt!=amap.end()); pt->second._children.insert(v); } }