33 #include "../stuff/macros.h" 43 return std::numeric_limits<double>::max();
48 return perform (v,vParent,e);
49 return std::numeric_limits<double>::max();
71 for (HyperGraph::VertexSet::iterator it=
_visited.begin(); it!=
_visited.end(); it++){
87 double maxDistance,
double comparisonConditioner,
bool directed,
double maxEdgeCost)
90 std::priority_queue< AdjacencyMapEntry > frontier;
91 for (HyperGraph::VertexSet::iterator vit=vset.begin(); vit!=vset.end(); ++vit){
99 it->second._distance=0.;
100 it->second._parent=0;
101 frontier.push(it->second);
104 while(! frontier.empty()){
113 double uDistance=ut->second.distance();
115 std::pair< HyperGraph::VertexSet::iterator, bool> insertResult=
_visited.insert(u); (void) insertResult;
116 HyperGraph::EdgeSet::iterator et=u->
edges().begin();
117 while (et != u->
edges().end()){
121 if (directed && edge->
vertex(0) != u)
124 for (
size_t i = 0; i < edge->
vertices().size(); ++i) {
129 double edgeDistance=(*cost)(edge, u, z);
130 if (edgeDistance==std::numeric_limits< double >::max() || edgeDistance > maxEdgeCost)
132 double zDistance=uDistance+edgeDistance;
138 if (zDistance+comparisonConditioner<ot->second.distance() && zDistance<maxDistance){
139 ot->second._distance=zDistance;
140 ot->second._parent=u;
141 ot->second._edge=edge;
142 frontier.push(ot->second);
150 double comparisonConditioner,
bool directed,
double maxEdgeCost)
154 shortestPaths(vset, cost, maxDistance, comparisonConditioner, directed, maxEdgeCost);
159 for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it){
163 for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it){
170 assert (v==it->first);
172 AdjacencyMap::iterator pt=amap.find(parent);
173 assert(pt!=amap.end());
174 pt->second._children.insert(v);
182 typedef std::deque<HyperGraph::Vertex*> Deque;
185 for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it){
188 action->
perform(it->first,0,0);
189 q.push_back(it->first);
199 AdjacencyMap::iterator parentIt=amap.find(parent);
200 if (parentIt==amap.end()) {
205 for (HyperGraph::VertexSet::iterator childsIt=childs.begin(); childsIt!=childs.end(); ++childsIt){
208 AdjacencyMap::iterator adjacencyIt=amap.find(child);
209 assert (adjacencyIt!=amap.end());
212 assert(adjacencyIt->first==child);
213 assert(adjacencyIt->second.child()==child);
214 assert(adjacencyIt->second.parent()==parent);
216 action->
perform(child, parent, edge);
218 action->
perform(child, parent, edge, adjacencyIt->second.distance());
231 double comparisonConditioner,
double maxEdgeCost)
233 typedef std::queue<HyperGraph::Vertex*> VertexDeque;
236 VertexDeque frontier;
240 while (! frontier.empty()){
243 dv.
shortestPaths(v0, cost, distance, comparisonConditioner,
false, maxEdgeCost);
244 for (HyperGraph::VertexSet::iterator it=dv.
visited().begin(); it!=dv.
visited().end(); ++it){
246 if (startingSet.find(*it)==startingSet.end())
248 std::pair<HyperGraph::VertexSet::iterator, bool> insertOutcome=connected.insert(*it);
249 if (insertOutcome.second){
250 frontier.push(dynamic_cast<HyperGraph::Vertex*>(*it));
AdjacencyMapEntry(HyperGraph::Vertex *_child=0, HyperGraph::Vertex *_parent=0, HyperGraph::Edge *_edge=0, double _distance=std::numeric_limits< double >::max())
int id() const
returns the id
const Vertex * vertex(size_t i) const
#define __PRETTY_FUNCTION__
HyperGraph::VertexSet & visited()
static void computeTree(AdjacencyMap &amap)
HyperGraph::Vertex * parent() const
HyperGraph::VertexSet _children
std::set< Vertex * > VertexSet
HyperDijkstra(HyperGraph *g)
const VertexIDMap & vertices() const
HyperGraph::VertexSet _visited
static void connectedSubset(HyperGraph::VertexSet &connected, HyperGraph::VertexSet &visited, HyperGraph::VertexSet &startingSet, HyperGraph *g, HyperGraph::Vertex *v, HyperDijkstra::CostFunction *cost, double distance, double comparisonConditioner, double maxEdgeCost=std::numeric_limits< double >::max())
static void visitAdjacencyMap(AdjacencyMap &amap, TreeAction *action, bool useDistance=false)
const VertexContainer & vertices() const
const EdgeSet & edges() const
returns the set of hyper-edges that are leaving/entering in this vertex
void shortestPaths(HyperGraph::Vertex *v, HyperDijkstra::CostFunction *cost, double maxDistance=std::numeric_limits< double >::max(), double comparisonConditioner=1e-3, bool directed=false, double maxEdgeCost=std::numeric_limits< double >::max())
std::map< HyperGraph::Vertex *, AdjacencyMapEntry > AdjacencyMap
TFSIMD_FORCE_INLINE const tfScalar & z() const
abstract Vertex, your types must derive from that one
bool operator<(const HyperDijkstra::AdjacencyMapEntry &a, const HyperDijkstra::AdjacencyMapEntry &b)
virtual double perform(HyperGraph::Vertex *v, HyperGraph::Vertex *vParent, HyperGraph::Edge *e)
AdjacencyMap _adjacencyMap
HyperGraph::Vertex * child() const