Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _AIS_GENERAL_DIJKSTRA_HH
00018 #define _AIS_GENERAL_DIJKSTRA_HH
00019
00020 #include <map>
00021 #include <set>
00022 #include <limits>
00023 #include "hyper_graph.h"
00024
00025 namespace g2o{
00026
00027 struct HyperDijkstra{
00028 struct CostFunction {
00029 virtual double operator() (HyperGraph::Edge* e, HyperGraph::Vertex* from, HyperGraph::Vertex* to)=0;
00030 };
00031
00032 struct TreeAction {
00033 virtual double perform(HyperGraph::Vertex* v, HyperGraph::Vertex* vParent, HyperGraph::Edge* e);
00034 virtual double perform(HyperGraph::Vertex* v, HyperGraph::Vertex* vParent, HyperGraph::Edge* e, double distance);
00035 };
00036
00037
00038 struct AdjacencyMapEntry{
00039 friend struct HyperDijkstra;
00040 AdjacencyMapEntry(HyperGraph::Vertex* _child=0,
00041 HyperGraph::Vertex* _parent=0,
00042 HyperGraph::Edge* _edge=0,
00043 double _distance=std::numeric_limits<double>::max());
00044 HyperGraph::Vertex* child() const {return _child;}
00045 HyperGraph::Vertex* parent() const {return _parent;}
00046 HyperGraph::Edge* edge() const {return _edge;}
00047 double distance() const {return _distance;}
00048 HyperGraph::VertexSet& children() {return _children;}
00049 const HyperGraph::VertexSet& children() const {return _children;}
00050 protected:
00051 HyperGraph::Vertex* _child;
00052 HyperGraph::Vertex* _parent;
00053 HyperGraph::Edge* _edge;
00054 double _distance;
00055 HyperGraph::VertexSet _children;
00056 };
00057
00058 typedef std::map<HyperGraph::Vertex*, AdjacencyMapEntry> AdjacencyMap;
00059 HyperDijkstra(HyperGraph* g);
00060 HyperGraph::VertexSet& visited() {return _visited; }
00061 AdjacencyMap& adjacencyMap() {return _adjacencyMap; }
00062 HyperGraph* graph() {return _graph;}
00063
00064 void shortestPaths(HyperGraph::Vertex* v,
00065 HyperDijkstra::CostFunction* cost,
00066 double maxDistance=std::numeric_limits< double >::max(),
00067 double comparisonConditioner=1e-3,
00068 bool directed=false,
00069 double maxEdgeCost=std::numeric_limits< double >::max());
00070
00071 void shortestPaths(HyperGraph::VertexSet& vset,
00072 HyperDijkstra::CostFunction* cost,
00073 double maxDistance=std::numeric_limits< double >::max(),
00074 double comparisonConditioner=1e-3,
00075 bool directed=false,
00076 double maxEdgeCost=std::numeric_limits< double >::max());
00077
00078
00079 static void computeTree(AdjacencyMap& amap);
00080 static void visitAdjacencyMap(AdjacencyMap& amap, TreeAction* action, bool useDistance=false);
00081
00082 protected:
00083 void reset();
00084
00085 AdjacencyMap _adjacencyMap;
00086 HyperGraph::VertexSet _visited;
00087 HyperGraph* _graph;
00088 };
00089
00090 void connectedSubset(HyperGraph::VertexSet& connected, HyperGraph::VertexSet& visited,
00091 HyperGraph::VertexSet& startingSet,
00092 HyperGraph* g, HyperGraph::Vertex* v,
00093 HyperDijkstra::CostFunction* cost, double distance, double comparisonConditioner,
00094 double maxEdgeCost=std::numeric_limits< double >::max() );
00095
00096
00097
00098 struct UniformCostFunction: public HyperDijkstra::CostFunction {
00099 virtual double operator ()(HyperGraph::Edge* edge, HyperGraph::Vertex* from, HyperGraph::Vertex* to);
00100 };
00101
00102
00103
00104 }
00105 #endif