g2o
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
g2o::HyperDijkstra Struct Reference

#include <hyper_dijkstra.h>

Collaboration diagram for g2o::HyperDijkstra:
Collaboration graph
[legend]

Classes

struct  AdjacencyMapEntry
 
struct  CostFunction
 
struct  TreeAction
 

Public Types

typedef std::map< HyperGraph::Vertex *, AdjacencyMapEntryAdjacencyMap
 

Public Member Functions

 HyperDijkstra (HyperGraph *g)
 
HyperGraph::VertexSetvisited ()
 
AdjacencyMapadjacencyMap ()
 
HyperGraphgraph ()
 
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())
 
void shortestPaths (HyperGraph::VertexSet &vset, HyperDijkstra::CostFunction *cost, double maxDistance=std::numeric_limits< double >::max(), double comparisonConditioner=1e-3, bool directed=false, double maxEdgeCost=std::numeric_limits< double >::max())
 

Static Public Member Functions

static void computeTree (AdjacencyMap &amap)
 
static void visitAdjacencyMap (AdjacencyMap &amap, TreeAction *action, bool useDistance=false)
 
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())
 

Protected Member Functions

void reset ()
 

Protected Attributes

AdjacencyMap _adjacencyMap
 
HyperGraph::VertexSet _visited
 
HyperGraph_graph
 

Detailed Description

Definition at line 38 of file hyper_dijkstra.h.

Member Typedef Documentation

Definition at line 70 of file hyper_dijkstra.h.

Constructor & Destructor Documentation

g2o::HyperDijkstra::HyperDijkstra ( HyperGraph g)

Definition at line 61 of file hyper_dijkstra.cpp.

References _adjacencyMap, _graph, g2o::HyperDijkstra::AdjacencyMapEntry::child(), and g2o::HyperGraph::vertices().

61  : _graph(g)
62  {
63  for (HyperGraph::VertexIDMap::const_iterator it=_graph->vertices().begin(); it!=_graph->vertices().end(); it++){
64  AdjacencyMapEntry entry(it->second, 0,0,std::numeric_limits< double >::max());
65  _adjacencyMap.insert(make_pair(entry.child(), entry));
66  }
67  }
const VertexIDMap & vertices() const
Definition: hyper_graph.h:225
HyperGraph * _graph
AdjacencyMap _adjacencyMap

Member Function Documentation

AdjacencyMap& g2o::HyperDijkstra::adjacencyMap ( )
inline

Definition at line 73 of file hyper_dijkstra.h.

Referenced by g2o::computeSimpleStars(), and g2o::SolverSLAM2DLinear::solveOrientation().

73 {return _adjacencyMap; }
AdjacencyMap _adjacencyMap
void g2o::HyperDijkstra::computeTree ( AdjacencyMap amap)
static

Definition at line 157 of file hyper_dijkstra.cpp.

References g2o::HyperDijkstra::AdjacencyMapEntry::_children, g2o::HyperDijkstra::AdjacencyMapEntry::child(), and g2o::HyperDijkstra::AdjacencyMapEntry::parent().

Referenced by g2o::computeSimpleStars(), and g2o::SolverSLAM2DLinear::solveOrientation().

158  {
159  for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it){
160  AdjacencyMapEntry& entry(it->second);
161  entry._children.clear();
162  }
163  for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it){
164  AdjacencyMapEntry& entry(it->second);
165  HyperGraph::Vertex* parent=entry.parent();
166  if (!parent){
167  continue;
168  }
169  HyperGraph::Vertex* v=entry.child();
170  assert (v==it->first);
171 
172  AdjacencyMap::iterator pt=amap.find(parent);
173  assert(pt!=amap.end());
174  pt->second._children.insert(v);
175  }
176  }
class G2O_CORE_API Vertex
Definition: hyper_graph.h:78
void g2o::HyperDijkstra::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

Definition at line 227 of file hyper_dijkstra.cpp.

References shortestPaths(), and visited().

232  {
233  typedef std::queue<HyperGraph::Vertex*> VertexDeque;
234  visited.clear();
235  connected.clear();
236  VertexDeque frontier;
237  HyperDijkstra dv(g);
238  connected.insert(v);
239  frontier.push(v);
240  while (! frontier.empty()){
241  HyperGraph::Vertex* v0=frontier.front();
242  frontier.pop();
243  dv.shortestPaths(v0, cost, distance, comparisonConditioner, false, maxEdgeCost);
244  for (HyperGraph::VertexSet::iterator it=dv.visited().begin(); it!=dv.visited().end(); ++it){
245  visited.insert(*it);
246  if (startingSet.find(*it)==startingSet.end())
247  continue;
248  std::pair<HyperGraph::VertexSet::iterator, bool> insertOutcome=connected.insert(*it);
249  if (insertOutcome.second){ // the node was not in the connectedSet;
250  frontier.push(dynamic_cast<HyperGraph::Vertex*>(*it));
251  }
252  }
253  }
254  }
HyperGraph::VertexSet & visited()
HyperDijkstra(HyperGraph *g)
class G2O_CORE_API Vertex
Definition: hyper_graph.h:78
HyperGraph* g2o::HyperDijkstra::graph ( )
inline

Definition at line 74 of file hyper_dijkstra.h.

74 {return _graph;}
HyperGraph * _graph
void g2o::HyperDijkstra::reset ( )
protected

Definition at line 69 of file hyper_dijkstra.cpp.

References _adjacencyMap, and _visited.

Referenced by shortestPaths().

70  {
71  for (HyperGraph::VertexSet::iterator it=_visited.begin(); it!=_visited.end(); it++){
72  AdjacencyMap::iterator at=_adjacencyMap.find(*it);
73  assert(at!=_adjacencyMap.end());
74  at->second=AdjacencyMapEntry(at->first,0,0,std::numeric_limits< double >::max());
75  }
76  _visited.clear();
77  }
HyperGraph::VertexSet _visited
AdjacencyMap _adjacencyMap
void g2o::HyperDijkstra::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() 
)

Definition at line 149 of file hyper_dijkstra.cpp.

Referenced by g2o::computeSimpleStars(), connectedSubset(), main(), and g2o::SolverSLAM2DLinear::solveOrientation().

151  {
153  vset.insert(v);
154  shortestPaths(vset, cost, maxDistance, comparisonConditioner, directed, maxEdgeCost);
155  }
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
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())
void g2o::HyperDijkstra::shortestPaths ( HyperGraph::VertexSet vset,
HyperDijkstra::CostFunction cost,
double  maxDistance = std::numeric_limits< double >::max(),
double  comparisonConditioner = 1e-3,
bool  directed = false,
double  maxEdgeCost = std::numeric_limits< double >::max() 
)

Definition at line 86 of file hyper_dijkstra.cpp.

References __PRETTY_FUNCTION__, _adjacencyMap, _visited, g2o::HyperDijkstra::AdjacencyMapEntry::child(), g2o::HyperGraph::Vertex::edges(), g2o::HyperGraph::Vertex::id(), reset(), g2o::HyperGraph::Edge::vertex(), and g2o::HyperGraph::Edge::vertices().

88  {
89  reset();
90  std::priority_queue< AdjacencyMapEntry > frontier;
91  for (HyperGraph::VertexSet::iterator vit=vset.begin(); vit!=vset.end(); ++vit){
92  HyperGraph::Vertex* v=*vit;
93  assert(v!=0);
94  AdjacencyMap::iterator it=_adjacencyMap.find(v);
95  if (it == _adjacencyMap.end()) {
96  cerr << __PRETTY_FUNCTION__ << "Vertex " << v->id() << " is not in the adjacency map" << endl;
97  }
98  assert(it!=_adjacencyMap.end());
99  it->second._distance=0.;
100  it->second._parent=0;
101  frontier.push(it->second);
102  }
103 
104  while(! frontier.empty()){
105  AdjacencyMapEntry entry=frontier.top();
106  frontier.pop();
107  HyperGraph::Vertex* u=entry.child();
108  AdjacencyMap::iterator ut=_adjacencyMap.find(u);
109  if (ut == _adjacencyMap.end()) {
110  cerr << __PRETTY_FUNCTION__ << "Vertex " << u->id() << " is not in the adjacency map" << endl;
111  }
112  assert(ut!=_adjacencyMap.end());
113  double uDistance=ut->second.distance();
114 
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()){
118  HyperGraph::Edge* edge=*et;
119  ++et;
120 
121  if (directed && edge->vertex(0) != u)
122  continue;
123 
124  for (size_t i = 0; i < edge->vertices().size(); ++i) {
125  HyperGraph::Vertex* z = edge->vertex(i);
126  if (z == u)
127  continue;
128 
129  double edgeDistance=(*cost)(edge, u, z);
130  if (edgeDistance==std::numeric_limits< double >::max() || edgeDistance > maxEdgeCost)
131  continue;
132  double zDistance=uDistance+edgeDistance;
133  //cerr << z->id() << " " << zDistance << endl;
134 
135  AdjacencyMap::iterator ot=_adjacencyMap.find(z);
136  assert(ot!=_adjacencyMap.end());
137 
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);
143  }
144  }
145  }
146  }
147  }
#define __PRETTY_FUNCTION__
Definition: macros.h:89
HyperGraph::VertexSet _visited
class G2O_CORE_API Vertex
Definition: hyper_graph.h:78
AdjacencyMap _adjacencyMap
class G2O_CORE_API Edge
Definition: hyper_graph.h:79
void g2o::HyperDijkstra::visitAdjacencyMap ( AdjacencyMap amap,
TreeAction action,
bool  useDistance = false 
)
static

Definition at line 179 of file hyper_dijkstra.cpp.

References g2o::HyperDijkstra::AdjacencyMapEntry::parent(), and g2o::HyperDijkstra::TreeAction::perform().

Referenced by g2o::computeSimpleStars(), and g2o::SolverSLAM2DLinear::solveOrientation().

180  {
181 
182  typedef std::deque<HyperGraph::Vertex*> Deque;
183  Deque q;
184  // scans for the vertices without the parent (whcih are the roots of the trees) and applies the action to them.
185  for (AdjacencyMap::iterator it=amap.begin(); it!=amap.end(); ++it){
186  AdjacencyMapEntry& entry(it->second);
187  if (! entry.parent()) {
188  action->perform(it->first,0,0);
189  q.push_back(it->first);
190  }
191  }
192 
193  //std::cerr << "q.size()" << q.size() << endl;
194  int count=0;
195  while (! q.empty()){
196  HyperGraph::Vertex* parent=q.front();
197  q.pop_front();
198  ++count;
199  AdjacencyMap::iterator parentIt=amap.find(parent);
200  if (parentIt==amap.end()) {
201  continue;
202  }
203  //cerr << "parent= " << parent << " parent id= " << parent->id() << "\t children id =";
204  HyperGraph::VertexSet& childs(parentIt->second.children());
205  for (HyperGraph::VertexSet::iterator childsIt=childs.begin(); childsIt!=childs.end(); ++childsIt){
206  HyperGraph::Vertex* child=*childsIt;
207  //cerr << child->id();
208  AdjacencyMap::iterator adjacencyIt=amap.find(child);
209  assert (adjacencyIt!=amap.end());
210  HyperGraph::Edge* edge=adjacencyIt->second.edge();
211 
212  assert(adjacencyIt->first==child);
213  assert(adjacencyIt->second.child()==child);
214  assert(adjacencyIt->second.parent()==parent);
215  if (! useDistance) {
216  action->perform(child, parent, edge);
217  } else {
218  action->perform(child, parent, edge, adjacencyIt->second.distance());
219  }
220  q.push_back(child);
221  }
222  //cerr << endl;
223  }
224 
225  }
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
class G2O_CORE_API Vertex
Definition: hyper_graph.h:78
class G2O_CORE_API Edge
Definition: hyper_graph.h:79
HyperGraph::VertexSet& g2o::HyperDijkstra::visited ( )
inline

Definition at line 72 of file hyper_dijkstra.h.

Referenced by connectedSubset(), and main().

72 {return _visited; }
HyperGraph::VertexSet _visited

Member Data Documentation

AdjacencyMap g2o::HyperDijkstra::_adjacencyMap
protected

Definition at line 102 of file hyper_dijkstra.h.

Referenced by HyperDijkstra(), reset(), and shortestPaths().

HyperGraph* g2o::HyperDijkstra::_graph
protected

Definition at line 104 of file hyper_dijkstra.h.

Referenced by HyperDijkstra().

HyperGraph::VertexSet g2o::HyperDijkstra::_visited
protected

Definition at line 103 of file hyper_dijkstra.h.

Referenced by reset(), and shortestPaths().


The documentation for this struct was generated from the following files: