g2o
Loading...
Searching...
No Matches
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)
 

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

◆ AdjacencyMap

Definition at line 73 of file hyper_dijkstra.h.

Constructor & Destructor Documentation

◆ HyperDijkstra()

g2o::HyperDijkstra::HyperDijkstra ( HyperGraph g)

Definition at line 65 of file hyper_dijkstra.cpp.

65 : _graph(g) {
66 for (HyperGraph::VertexIDMap::const_iterator it = _graph->vertices().begin();
67 it != _graph->vertices().end(); ++it) {
68 AdjacencyMapEntry entry(it->second, 0, 0,
69 std::numeric_limits<double>::max());
70 _adjacencyMap.insert(make_pair(entry.child(), entry));
71 }
72}
const VertexIDMap & vertices() const
HyperGraph * _graph
AdjacencyMap _adjacencyMap

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

Member Function Documentation

◆ adjacencyMap()

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

Definition at line 76 of file hyper_dijkstra.h.

76{ return _adjacencyMap; }

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

◆ computeTree()

void g2o::HyperDijkstra::computeTree ( AdjacencyMap amap)
static

Definition at line 170 of file hyper_dijkstra.cpp.

170 {
171 for (AdjacencyMap::iterator it = amap.begin(); it != amap.end(); ++it) {
172 AdjacencyMapEntry& entry(it->second);
173 entry._children.clear();
174 }
175 for (AdjacencyMap::iterator it = amap.begin(); it != amap.end(); ++it) {
176 AdjacencyMapEntry& entry(it->second);
177 HyperGraph::Vertex* parent = entry.parent();
178 if (!parent) {
179 continue;
180 }
181 HyperGraph::Vertex* v = entry.child();
182 assert(v == it->first);
183
184 AdjacencyMap::iterator pt = amap.find(parent);
185 assert(pt != amap.end());
186 pt->second._children.insert(v);
187 }
188}

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

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

◆ graph()

HyperGraph * g2o::HyperDijkstra::graph ( )
inline

Definition at line 77 of file hyper_dijkstra.h.

77{ return _graph; }

◆ reset()

void g2o::HyperDijkstra::reset ( )
protected

Definition at line 74 of file hyper_dijkstra.cpp.

74 {
75 for (HyperGraph::VertexSet::iterator it = _visited.begin();
76 it != _visited.end(); ++it) {
77 AdjacencyMap::iterator at = _adjacencyMap.find(*it);
78 assert(at != _adjacencyMap.end());
79 at->second =
80 AdjacencyMapEntry(at->first, 0, 0, std::numeric_limits<double>::max());
81 }
82 _visited.clear();
83}
HyperGraph::VertexSet _visited

References _adjacencyMap, and _visited.

Referenced by shortestPaths().

◆ shortestPaths() [1/2]

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 159 of file hyper_dijkstra.cpp.

163 {
165 vset.insert(v);
166 shortestPaths(vset, cost, maxDistance, comparisonConditioner, directed,
167 maxEdgeCost);
168}
std::set< Vertex * > VertexSet
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())

References shortestPaths().

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

◆ shortestPaths() [2/2]

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 90 of file hyper_dijkstra.cpp.

94 {
95 reset();
96 std::priority_queue<AdjacencyMapEntry> frontier;
97 for (HyperGraph::VertexSet::iterator vit = vset.begin(); vit != vset.end();
98 ++vit) {
99 HyperGraph::Vertex* v = *vit;
100 assert(v != 0);
101 AdjacencyMap::iterator it = _adjacencyMap.find(v);
102 if (it == _adjacencyMap.end()) {
103 G2O_WARN("{} Vertex {} is not in the adjacency map", __PRETTY_FUNCTION__,
104 v->id());
105 }
106 assert(it != _adjacencyMap.end());
107 it->second._distance = 0.;
108 it->second._parent = 0;
109 frontier.push(it->second);
110 }
111
112 while (!frontier.empty()) {
113 AdjacencyMapEntry entry = frontier.top();
114 frontier.pop();
115 HyperGraph::Vertex* u = entry.child();
116 AdjacencyMap::iterator ut = _adjacencyMap.find(u);
117 if (ut == _adjacencyMap.end()) {
118 G2O_WARN("{} Vertex {} is not in the adjacency map", __PRETTY_FUNCTION__,
119 u->id());
120 }
121 assert(ut != _adjacencyMap.end());
122 double uDistance = ut->second.distance();
123
124 std::pair<HyperGraph::VertexSet::iterator, bool> insertResult =
125 _visited.insert(u);
126 (void)insertResult;
127 HyperGraph::EdgeSet::iterator et = u->edges().begin();
128 while (et != u->edges().end()) {
129 HyperGraph::Edge* edge = *et;
130 ++et;
131
132 if (directed && edge->vertex(0) != u) continue;
133
134 for (size_t i = 0; i < edge->vertices().size(); ++i) {
135 HyperGraph::Vertex* z = edge->vertex(i);
136 if (z == u) continue;
137
138 double edgeDistance = (*cost)(edge, u, z);
139 if (edgeDistance == std::numeric_limits<double>::max() ||
140 edgeDistance > maxEdgeCost)
141 continue;
142 double zDistance = uDistance + edgeDistance;
143
144 AdjacencyMap::iterator ot = _adjacencyMap.find(z);
145 assert(ot != _adjacencyMap.end());
146
147 if (zDistance + comparisonConditioner < ot->second.distance() &&
148 zDistance < maxDistance) {
149 ot->second._distance = zDistance;
150 ot->second._parent = u;
151 ot->second._edge = edge;
152 frontier.push(ot->second);
153 }
154 }
155 }
156 }
157}
#define G2O_WARN(...)
Definition logger.h:88
#define __PRETTY_FUNCTION__
Definition macros.h:90

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

◆ visitAdjacencyMap()

void g2o::HyperDijkstra::visitAdjacencyMap ( AdjacencyMap amap,
TreeAction action,
bool  useDistance = false 
)
static

Definition at line 190 of file hyper_dijkstra.cpp.

191 {
192 typedef std::deque<HyperGraph::Vertex*> Deque;
193 Deque q;
194 // scans for the vertices without the parent (which are the roots of the
195 // trees) and applies the action to them.
196 for (AdjacencyMap::iterator it = amap.begin(); it != amap.end(); ++it) {
197 AdjacencyMapEntry& entry(it->second);
198 if (!entry.parent()) {
199 action->perform(it->first, 0, 0);
200 q.push_back(it->first);
201 }
202 }
203
204 while (!q.empty()) {
205 HyperGraph::Vertex* parent = q.front();
206 q.pop_front();
207 AdjacencyMap::iterator parentIt = amap.find(parent);
208 if (parentIt == amap.end()) {
209 continue;
210 }
211 HyperGraph::VertexSet& childs(parentIt->second.children());
212 for (HyperGraph::VertexSet::iterator childsIt = childs.begin();
213 childsIt != childs.end(); ++childsIt) {
214 HyperGraph::Vertex* child = *childsIt;
215 AdjacencyMap::iterator adjacencyIt = amap.find(child);
216 assert(adjacencyIt != amap.end());
217 HyperGraph::Edge* edge = adjacencyIt->second.edge();
218
219 assert(adjacencyIt->first == child);
220 assert(adjacencyIt->second.child() == child);
221 assert(adjacencyIt->second.parent() == parent);
222 if (!useDistance) {
223 action->perform(child, parent, edge);
224 } else {
225 action->perform(child, parent, edge, adjacencyIt->second.distance());
226 }
227 q.push_back(child);
228 }
229 }
230}

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

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

◆ visited()

HyperGraph::VertexSet & g2o::HyperDijkstra::visited ( )
inline

Definition at line 75 of file hyper_dijkstra.h.

75{ return _visited; }

Referenced by main().

Member Data Documentation

◆ _adjacencyMap

AdjacencyMap g2o::HyperDijkstra::_adjacencyMap
protected

Definition at line 97 of file hyper_dijkstra.h.

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

◆ _graph

HyperGraph* g2o::HyperDijkstra::_graph
protected

Definition at line 99 of file hyper_dijkstra.h.

Referenced by HyperDijkstra().

◆ _visited

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

Definition at line 98 of file hyper_dijkstra.h.

Referenced by reset(), and shortestPaths().


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