7 #include <Eigen/Cholesky> 8 #include <Eigen/Eigenvalues> 14 using namespace Eigen;
21 for (HyperGraph::EdgeSet::iterator it = v->
edges().begin(); it!=v->
edges().end(); it++){
37 for (StarSet::iterator it=stars.begin(); it!=stars.end(); it++){
40 for (HyperGraph::EdgeSet::iterator it = s->
lowLevelEdges().begin();
43 esmap.insert(make_pair(e,s));
46 for (HyperGraph::EdgeSet::iterator it = s->
starEdges().begin();
49 esmap.insert(make_pair(e,s));
57 for (HyperGraph::EdgeSet::iterator it=v->
edges().begin(); it!=v->
edges().end(); it++){
59 EdgeStarMap::iterator eit=esmap.find(e);
60 if (eit!=esmap.end() && eit->second == s)
67 for (HyperGraph::EdgeSet::iterator it=v->
edges().begin(); it!=v->
edges().end(); it++){
69 EdgeStarMap::iterator eit=esmap.find(e);
71 stars.insert(eit->second);
76 for (
size_t i=0; i<e->
vertices().size(); i++){
78 if (gauge.find(v)==gauge.end())
86 for (StarSet::iterator it=stars.begin(); it!=stars.end(); it++){
87 cerr <<
"STAR# " << starNum << endl;
89 std::vector<OptimizableGraph::Vertex*>
vertices(2);
91 cerr <<
"eIs" << endl;
108 cerr <<
"THERE" << endl;
109 cerr <<
"FATAL, cannot create edge" << endl;
116 for (HyperGraph::EdgeSet::iterator it=eInSt.begin(); it!=eInSt.end(); it++){
124 cerr <<
"gauge: " << (*s->
_gauge.begin())->
id()
128 const bool debug =
false;
130 char starLowName[100];
131 sprintf(starLowName,
"star-%04d-low.g2o", starNum);
132 ofstream starLowStream(starLowName);
138 char starHighName[100];
139 sprintf(starHighName,
"star-%04d-high.g2o", starNum);
140 ofstream starHighStream(starHighName);
144 cerr <<
"FAILURE" << endl;
151 cerr <<
"computing edges on the border" << endl;
152 for (StarSet::iterator it=stars.begin(); it!=stars.end(); it++){
173 std::string vertexTag,
176 int backboneIterations,
178 double rejectionThreshold,
181 cerr <<
"preforming the tree actions" << endl;
187 std::numeric_limits< double >::max(),
190 std::numeric_limits< double >::max()/2);
198 cerr <<
"free edges size " << bact.freeEdges().size() << endl;
204 for (VertexStarMultimap::iterator it=bact.vertexStarMultiMap().begin();
205 it!=bact.vertexStarMultiMap().end(); it++){
206 stars.insert(it->second);
208 cerr <<
"stars.size: " << stars.size() << endl;
209 cerr <<
"size: " << bact.vertexStarMultiMap().size() << endl;
243 for (StarSet::iterator it=stars.begin(); it!=stars.end(); it++){
247 if (backboneEdges.empty())
254 gauge.insert(*backboneVertices.begin());
266 std::multimap<HyperGraph::Vertex*, HyperGraph::Edge*> vemap;
267 for (HyperGraph::VertexSet::iterator bit=backboneVertices.begin(); bit!=backboneVertices.end(); bit++){
269 for (HyperGraph::EdgeSet::iterator eit=v->
edges().begin(); eit!=v->
edges().end(); eit++){
271 HyperGraph::EdgeSet::iterator feit=bact.freeEdges().find(e);
272 if (feit!=bact.freeEdges().end()){
273 otherEdges.insert(e);
274 bact.freeEdges().erase(feit);
275 for (
size_t i=0; i<e->
vertices().size(); i++){
277 if (backboneVertices.find(ve)==backboneVertices.end()){
278 otherVertices.insert(ve);
279 vemap.insert(make_pair(ve,e));
288 if (solverWithHessian) {
300 cerr <<
"FATAL: failure while building linear structure" << endl;
307 cerr <<
"FATAL: hierarchical thing cannot be used with a solver that does not support the system structure construction" << endl;
312 for (HyperGraph::VertexSet::iterator vit=otherVertices.begin(); vit!=otherVertices.end(); vit++){
319 for (HyperGraph::EdgeSet::iterator eit=v->
edges().begin(); eit!=v->
edges().end(); eit++){
321 if (otherEdges.find(e)!=otherEdges.end())
341 cerr <<
"computing star: " << starNum << endl;
343 int vKept=0, vDropped=0;
344 if (!starIterations || starOptResult > 0 ){
355 for (HyperGraph::VertexSet::iterator vit=otherVertices.begin(); vit!=otherVertices.end(); vit++){
366 EigenSolver<Eigen::MatrixXd> esolver;
368 VectorXcd ev= esolver.eigenvalues();
369 double emin = std::numeric_limits<double>::max();
370 double emax = -std::numeric_limits<double>::max();
371 for (
int i=0; i<ev.size(); i++){
372 emin = ev(i).real()>emin ? emin : ev(i).real();
373 emax = ev(i).real()<emax ? emax : ev(i).real();
380 if (d>rejectionThreshold){
383 prunedStarVertices.insert(v);
384 for (HyperGraph::EdgeSet::iterator eit=v->
edges().begin(); eit!=v->
edges().end(); eit++){
386 if (otherEdges.find(e)!=otherEdges.end())
387 prunedStarEdges.insert(e);
402 std::vector<OptimizableGraph::Vertex*>
vertices(2);
417 cerr <<
"HERE" << endl;
418 cerr <<
"FATAL, cannot create edge" << endl;
423 cerr <<
" gauge: " << (*s->
_gauge.begin())->
id()
424 <<
" kept: " << vKept
425 <<
" dropped: " << vDropped
428 <<
" initial chi " << initialChi
429 <<
" final chi " << finalchi << endl;
432 char starLowName[100];
433 sprintf(starLowName,
"star-%04d-low.g2o", starNum);
434 ofstream starLowStream(starLowName);
438 if (!starIterations || starOptResult > 0)
442 char starHighName[100];
443 sprintf(starHighName,
"star-%04d-high.g2o", starNum);
444 ofstream starHighStream(starHighName);
449 cerr <<
"FAILURE: " << starOptResult << endl;
462 for (StarSet::iterator it=stars.begin(); it!=stars.end(); it++){
virtual void computeInitialGuess()
const OptimizableGraph * graph() const
static Factory * instance()
return the instance
SparseOptimizer * optimizer()
returns the optimizer
virtual double solveDirect(double lambda=0)=0
HyperGraph::EdgeSet _lowLevelEdges
edges in the lower level
virtual const double & hessian(int i, int j) const =0
get the element from the hessian matrix
void assignHierarchicalEdges(StarSet &stars, EdgeStarMap &esmap, EdgeLabeler *labeler, EdgeCreator *creator, SparseOptimizer *optimizer, int minNumEdges, int maxIterations)
double activeVertexChi(const OptimizableGraph::Vertex *v)
static void computeTree(AdjacencyMap &amap)
void constructEdgeStarMap(EdgeStarMap &esmap, StarSet &stars, bool low)
std::set< Vertex * > VertexSet
HyperGraph::EdgeSet & starFrontierEdges()
edges in the high level that lead to some node owned by a different star
void pop(SparseOptimizer::VertexContainer &vlist)
pop (restore) the estimate a subset of the variables from the stack
virtual double chi2() const =0
computes the chi2 based on the cached error value, only valid after computeError has been called...
int optimize(int iterations, bool online=false)
HyperGraph::EdgeSet & starEdges()
high level edge set
virtual bool init(bool online=false)=0
OptimizationAlgorithm * solver()
const EdgeContainer & activeEdges() const
the edges active in the current optimization
void computeActiveErrors()
Base for solvers operating on the approximated Hessian, e.g., Gauss-Newton, Levenberg.
void computeBorder(StarSet &stars, EdgeStarMap &hesmap)
bool labelStarEdges(int iterations, EdgeLabeler *labeler)
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
std::set< Edge * > EdgeSet
static void visitAdjacencyMap(AdjacencyMap &amap, TreeAction *action, bool useDistance=false)
int dimension() const
dimension of the estimated state belonging to this node
Protocol The SLAM executable accepts such as solving the and retrieving or vertices in the explicitly state the reprensentation poses are represented by poses by VERTEX_XYZRPY In the Quaternions and other representations could be but note that it is up to the SLAM algorithm to choose the internal representation of the angles The keyword is followed by a unique vertex ID and an optional initialization of the or edges in the explicitly state the type of the constraint pose constraints are given by pose constraints by EDGE_XYZRPY The keyword is followed by a unique edge the IDs of the referenced vertices
HyperGraph::EdgeSet _starEdges
edges in the star
const VertexContainer & vertices() const
const EdgeSet & edges() const
returns the set of hyper-edges that are leaving/entering in this vertex
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())
bool saveSubset(std::ostream &os, HyperGraph::VertexSet &vset, int level=0)
save a subgraph to a stream. Again uses the Factory system.
HyperGraph::VertexSet _lowLevelVertices
vertices that are fixed (center of the star)
std::set< Star * > StarSet
HyperGraph::VertexSet _gauge
vertices that are fixed (center of the star)
void starsInEdge(StarSet &stars, HyperGraph::Edge *e, EdgeStarMap &esmap, HyperGraph::VertexSet &gauge)
OptimizableGraph::Edge * createEdge(std::vector< OptimizableGraph::Vertex * > &vertices)
std::map< HyperGraph::Edge *, Star * > EdgeStarMap
void starsInVertex(StarSet &stars, HyperGraph::Vertex *v, EdgeStarMap &esmap)
virtual bool buildLinearStructure()
A general case Vertex for optimization.
abstract Vertex, your types must derive from that one
HyperGraph::EdgeSet & lowLevelEdges()
low level edge set
EdgeContainer::const_iterator findActiveEdge(const OptimizableGraph::Edge *e) const
AdjacencyMap & adjacencyMap()
size_t vertexEdgesInStar(HyperGraph::EdgeSet &eset, HyperGraph::Vertex *v, Star *s, EdgeStarMap &esmap)
virtual void setFixed(HyperGraph::VertexSet &vset, bool fixed)
fixes/releases a set of vertices
void computeSimpleStars(StarSet &stars, SparseOptimizer *optimizer, EdgeLabeler *labeler, EdgeCreator *creator, OptimizableGraph::Vertex *gauge_, std::string edgeTag, std::string vertexTag, int level, int step, int backboneIterations, int starIterations, double rejectionThreshold, bool debug)
HyperGraph::VertexSet & gauge()
set of nodes to keep fixed in the optimization
void setLevel(int l)
sets the level of the edge
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
void push(SparseOptimizer::VertexContainer &vlist)
push the estimate of a subset of the variables onto a stack
virtual bool addEdge(HyperGraph::Edge *e)
virtual void updateLinearSystem()
HyperGraph::VertexSet & lowLevelVertices()
set of all vertices in the low level
double activeChi2() const