g2o
Loading...
Searching...
No Matches
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 78 of file estimate_propagator.h.

Member Typedef Documentation

◆ AdjacencyMap

Definition at line 146 of file estimate_propagator.h.

◆ PropagateCost

Definition at line 94 of file estimate_propagator.h.

Constructor & Destructor Documentation

◆ EstimatePropagator()

g2o::EstimatePropagator::EstimatePropagator ( OptimizableGraph g)

Definition at line 65 of file estimate_propagator.cpp.

65 : _graph(g) {
66 for (OptimizableGraph::VertexIDMap::const_iterator it =
67 _graph->vertices().begin();
68 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

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

Member Function Documentation

◆ adjacencyMap()

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

Definition at line 151 of file estimate_propagator.h.

151{ return _adjacencyMap; }

◆ graph()

OptimizableGraph * g2o::EstimatePropagator::graph ( )
inline

Definition at line 152 of file estimate_propagator.h.

152{ return _graph; }

◆ propagate() [1/2]

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.

89 {
91 vset.insert(v);
92 propagate(vset, cost, action, maxDistance, maxEdgeCost);
93}
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())
std::set< Vertex * > VertexSet

References propagate().

Referenced by g2o::SparseOptimizer::computeInitialGuess(), and propagate().

◆ propagate() [2/2]

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 95 of file estimate_propagator.cpp.

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

References _adjacencyMap, g2o::EstimatePropagator::AdjacencyMapEntry::_frontierLevel, _visited, g2o::EstimatePropagator::AdjacencyMapEntry::child(), g2o::EstimatePropagator::AdjacencyMapEntry::distance(), g2o::EstimatePropagator::AdjacencyMapEntry::edge(), g2o::HyperGraph::Vertex::edges(), G2O_DEBUG, 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().

◆ reset()

void g2o::EstimatePropagator::reset ( )
protected

Definition at line 75 of file estimate_propagator.cpp.

75 {
76 for (OptimizableGraph::VertexSet::iterator it = _visited.begin();
77 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}

References _adjacencyMap, and _visited.

Referenced by propagate().

◆ visited()

OptimizableGraph::VertexSet & g2o::EstimatePropagator::visited ( )
inline

Definition at line 150 of file estimate_propagator.h.

150{ return _visited; }

Member Data Documentation

◆ _adjacencyMap

AdjacencyMap g2o::EstimatePropagator::_adjacencyMap
protected

Definition at line 180 of file estimate_propagator.h.

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

◆ _graph

OptimizableGraph* g2o::EstimatePropagator::_graph
protected

Definition at line 182 of file estimate_propagator.h.

Referenced by EstimatePropagator().

◆ _visited

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

Definition at line 181 of file estimate_propagator.h.

Referenced by propagate(), and reset().


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