g2o
Classes | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
g2o::EstimatePropagator Class Reference

propagation of an initial guess More...

#include <estimate_propagator.h>

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

Classes

class  AdjacencyMapEntry
 data structure for loopuk during Dijkstra More...
 
class  PriorityQueue
 priority queue for AdjacencyMapEntry More...
 
struct  PropagateAction
 Applying the action for propagating. More...
 
class  VertexIDHashFunction
 hash function for a vertex More...
 

Public Types

typedef EstimatePropagatorCost PropagateCost
 
typedef std::unordered_map< OptimizableGraph::Vertex *, AdjacencyMapEntry, VertexIDHashFunctionAdjacencyMap
 

Public Member Functions

 EstimatePropagator (OptimizableGraph *g)
 
OptimizableGraph::VertexSetvisited ()
 
AdjacencyMapadjacencyMap ()
 
OptimizableGraphgraph ()
 
void propagate (OptimizableGraph::Vertex *v, const EstimatePropagator::PropagateCost &cost, const EstimatePropagator::PropagateAction &action=PropagateAction(), double maxDistance=std::numeric_limits< double >::max(), double maxEdgeCost=std::numeric_limits< double >::max())
 
void propagate (OptimizableGraph::VertexSet &vset, const EstimatePropagator::PropagateCost &cost, const EstimatePropagator::PropagateAction &action=PropagateAction(), double maxDistance=std::numeric_limits< double >::max(), double maxEdgeCost=std::numeric_limits< double >::max())
 

Protected Member Functions

void reset ()
 

Protected Attributes

AdjacencyMap _adjacencyMap
 
OptimizableGraph::VertexSet _visited
 
OptimizableGraph_graph
 

Detailed Description

propagation of an initial guess

Definition at line 72 of file estimate_propagator.h.

Member Typedef Documentation

Definition at line 135 of file estimate_propagator.h.

Definition at line 88 of file estimate_propagator.h.

Constructor & Destructor Documentation

g2o::EstimatePropagator::EstimatePropagator ( OptimizableGraph g)

Definition at line 66 of file estimate_propagator.cpp.

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

66  : _graph(g)
67  {
68  for (OptimizableGraph::VertexIDMap::const_iterator it=_graph->vertices().begin(); it!=_graph->vertices().end(); ++it){
69  AdjacencyMapEntry entry;
70  entry._child = static_cast<OptimizableGraph::Vertex*>(it->second);
71  _adjacencyMap.insert(make_pair(entry.child(), entry));
72  }
73  }
const VertexIDMap & vertices() const
Definition: hyper_graph.h:225
class G2O_CORE_API Vertex

Member Function Documentation

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

Definition at line 140 of file estimate_propagator.h.

140 {return _adjacencyMap; }
OptimizableGraph* g2o::EstimatePropagator::graph ( )
inline

Definition at line 141 of file estimate_propagator.h.

141 {return _graph;}
void g2o::EstimatePropagator::propagate ( OptimizableGraph::Vertex v,
const EstimatePropagator::PropagateCost cost,
const EstimatePropagator::PropagateAction action = PropagateAction(),
double  maxDistance = std::numeric_limits<double>::max(),
double  maxEdgeCost = std::numeric_limits<double>::max() 
)

propagate an initial guess starting from v. The function computes a spanning tree whereas the cost for each edge is determined by calling cost() and the action applied to each vertex is action().

Definition at line 86 of file estimate_propagator.cpp.

Referenced by g2o::SparseOptimizer::computeInitialGuess().

91  {
93  vset.insert(v);
94  propagate(vset, cost, action, maxDistance, maxEdgeCost);
95  }
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
void propagate(OptimizableGraph::Vertex *v, const EstimatePropagator::PropagateCost &cost, const EstimatePropagator::PropagateAction &action=PropagateAction(), double maxDistance=std::numeric_limits< double >::max(), double maxEdgeCost=std::numeric_limits< double >::max())
void g2o::EstimatePropagator::propagate ( OptimizableGraph::VertexSet vset,
const EstimatePropagator::PropagateCost cost,
const EstimatePropagator::PropagateAction action = PropagateAction(),
double  maxDistance = std::numeric_limits<double>::max(),
double  maxEdgeCost = std::numeric_limits<double>::max() 
)

same as above but starting to propagate from a set of vertices instead of just a single one.

Definition at line 97 of file estimate_propagator.cpp.

References _adjacencyMap, g2o::EstimatePropagator::AdjacencyMapEntry::_frontierLevel, _visited, g2o::EstimatePropagator::AdjacencyMapEntry::child(), g2o::EstimatePropagator::AdjacencyMapEntry::distance(), g2o::EstimatePropagator::AdjacencyMapEntry::edge(), g2o::HyperGraph::Vertex::edges(), g2o::HyperGraph::Vertex::id(), g2o::EstimatePropagator::AdjacencyMapEntry::parent(), g2o::EstimatePropagator::PriorityQueue::pop(), g2o::EstimatePropagator::PriorityQueue::push(), reset(), g2o::HyperGraph::Edge::vertex(), and g2o::HyperGraph::Edge::vertices().

102  {
103  reset();
104 
105  PriorityQueue frontier;
106  for (OptimizableGraph::VertexSet::iterator vit=vset.begin(); vit!=vset.end(); ++vit){
107  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*vit);
108  AdjacencyMap::iterator it = _adjacencyMap.find(v);
109  assert(it != _adjacencyMap.end());
110  it->second._distance = 0.;
111  it->second._parent.clear();
112  it->second._frontierLevel = 0;
113  frontier.push(&it->second);
114  }
115 
116  while(! frontier.empty()){
117  AdjacencyMapEntry* entry = frontier.pop();
118  OptimizableGraph::Vertex* u = entry->child();
119  double uDistance = entry->distance();
120  //cerr << "uDistance " << uDistance << endl;
121 
122  // initialize the vertex
123  if (entry->_frontierLevel > 0) {
124  action(entry->edge(), entry->parent(), u);
125  }
126 
127  /* std::pair< OptimizableGraph::VertexSet::iterator, bool> insertResult = */ _visited.insert(u);
128  OptimizableGraph::EdgeSet::iterator et = u->edges().begin();
129  while (et != u->edges().end()){
130  OptimizableGraph::Edge* edge = static_cast<OptimizableGraph::Edge*>(*et);
131  ++et;
132 
133  int maxFrontier = -1;
134  OptimizableGraph::VertexSet initializedVertices;
135  for (size_t i = 0; i < edge->vertices().size(); ++i) {
136  OptimizableGraph::Vertex* z = static_cast<OptimizableGraph::Vertex*>(edge->vertex(i));
137  if (! z)
138  continue;
139  AdjacencyMap::iterator ot = _adjacencyMap.find(z);
140  if (ot->second._distance != numeric_limits<double>::max()) {
141  initializedVertices.insert(z);
142  maxFrontier = (max)(maxFrontier, ot->second._frontierLevel);
143  }
144  }
145  assert(maxFrontier >= 0);
146 
147  for (size_t i = 0; i < edge->vertices().size(); ++i) {
148  OptimizableGraph::Vertex* z = static_cast<OptimizableGraph::Vertex*>(edge->vertex(i));
149  if (! z)
150  continue;
151  if (z == u)
152  continue;
153  size_t wasInitialized = initializedVertices.erase(z);
154 
155  double edgeDistance = cost(edge, initializedVertices, z);
156  if (edgeDistance > 0. && edgeDistance != std::numeric_limits<double>::max() && edgeDistance < maxEdgeCost) {
157  double zDistance = uDistance + edgeDistance;
158  //cerr << z->id() << " " << zDistance << endl;
159 
160  AdjacencyMap::iterator ot = _adjacencyMap.find(z);
161  assert(ot!=_adjacencyMap.end());
162 
163  if (zDistance < ot->second.distance() && zDistance < maxDistance){
164  //if (ot->second.inQueue)
165  //cerr << "Updating" << endl;
166  ot->second._distance = zDistance;
167  ot->second._parent = initializedVertices;
168  ot->second._edge = edge;
169  ot->second._frontierLevel = maxFrontier + 1;
170  frontier.push(&ot->second);
171  }
172  }
173 
174  if (wasInitialized > 0)
175  initializedVertices.insert(z);
176 
177  }
178  }
179  }
180 
181  // writing debug information like cost for reaching each vertex and the parent used to initialize
182 #ifdef DEBUG_ESTIMATE_PROPAGATOR
183  cerr << "Writing cost.dat" << endl;
184  ofstream costStream("cost.dat");
185  for (AdjacencyMap::const_iterator it = _adjacencyMap.begin(); it != _adjacencyMap.end(); ++it) {
186  HyperGraph::Vertex* u = it->second.child();
187  costStream << "vertex " << u->id() << " cost " << it->second._distance << endl;
188  }
189  cerr << "Writing init.dat" << endl;
190  ofstream initStream("init.dat");
191  vector<AdjacencyMapEntry*> frontierLevels;
192  for (AdjacencyMap::iterator it = _adjacencyMap.begin(); it != _adjacencyMap.end(); ++it) {
193  if (it->second._frontierLevel > 0)
194  frontierLevels.push_back(&it->second);
195  }
196  sort(frontierLevels.begin(), frontierLevels.end(), FrontierLevelCmp());
197  for (vector<AdjacencyMapEntry*>::const_iterator it = frontierLevels.begin(); it != frontierLevels.end(); ++it) {
198  AdjacencyMapEntry* entry = *it;
199  OptimizableGraph::Vertex* to = entry->child();
200 
201  initStream << "calling init level = " << entry->_frontierLevel << "\t (";
202  for (OptimizableGraph::VertexSet::iterator pit = entry->parent().begin(); pit != entry->parent().end(); ++pit) {
203  initStream << " " << (*pit)->id();
204  }
205  initStream << " ) -> " << to->id() << endl;
206  }
207 #endif
208 
209  }
std::set< Vertex * > VertexSet
Definition: hyper_graph.h:136
OptimizableGraph::VertexSet _visited
class G2O_CORE_API Vertex
class G2O_CORE_API Edge
class G2O_CORE_API Vertex
Definition: hyper_graph.h:78
void g2o::EstimatePropagator::reset ( )
protected

Definition at line 75 of file estimate_propagator.cpp.

References _adjacencyMap, and _visited.

Referenced by propagate().

76  {
77  for (OptimizableGraph::VertexSet::iterator it=_visited.begin(); it!=_visited.end(); ++it){
78  OptimizableGraph::Vertex* v = static_cast<OptimizableGraph::Vertex*>(*it);
79  AdjacencyMap::iterator at = _adjacencyMap.find(v);
80  assert(at != _adjacencyMap.end());
81  at->second.reset();
82  }
83  _visited.clear();
84  }
OptimizableGraph::VertexSet _visited
class G2O_CORE_API Vertex
OptimizableGraph::VertexSet& g2o::EstimatePropagator::visited ( )
inline

Definition at line 139 of file estimate_propagator.h.

139 {return _visited; }
OptimizableGraph::VertexSet _visited

Member Data Documentation

AdjacencyMap g2o::EstimatePropagator::_adjacencyMap
protected

Definition at line 166 of file estimate_propagator.h.

Referenced by EstimatePropagator(), propagate(), and reset().

OptimizableGraph* g2o::EstimatePropagator::_graph
protected

Definition at line 168 of file estimate_propagator.h.

Referenced by EstimatePropagator().

OptimizableGraph::VertexSet g2o::EstimatePropagator::_visited
protected

Definition at line 167 of file estimate_propagator.h.

Referenced by propagate(), and reset().


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