27#ifndef G2O_AIS_OPTIMIZABLE_GRAPH_HH_
28#define G2O_AIS_OPTIMIZABLE_GRAPH_HH_
80 return v1->
id() < v2->
id();
95 static_cast<const Edge*
>(e2));
123 virtual const double&
hessian(
int i,
int j)
const = 0;
135 virtual int copyB(
double* b_)
const = 0;
138 virtual const double&
b(
int i)
const = 0;
139 virtual double&
b(
int i) = 0;
168 if ((dim == -1) || (estimate.size() != std::size_t(dim)))
return false;
177 template <
typename Derived>
180 if ((dim == -1) || (estimate.size() != dim))
return false;
188 virtual bool getEstimateData(
double* estimate)
const;
196 if (dim < 0)
return false;
197 estimate.resize(dim);
205 template <
typename Derived>
209 if (dim < 0)
return false;
213 if (estimate.size() != dim) {
214 if ((estimate.RowsAtCompileTime == Eigen::Dynamic) ||
215 (estimate.ColsAtCompileTime == Eigen::Dynamic))
216 estimate.derived().resize(dim);
227 virtual int estimateDimension()
const;
234 bool setMinimalEstimateData(
const double* estimate);
243 if ((dim == -1) || (estimate.size() != std::size_t(dim)))
return false;
252 template <
typename Derived>
255 if ((dim == -1) || (estimate.size() != dim))
return false;
263 virtual bool getMinimalEstimateData(
double* estimate)
const;
271 if (dim < 0)
return false;
272 estimate.resize(dim);
280 template <
typename Derived>
284 if (dim < 0)
return false;
288 if (estimate.size() != dim) {
289 if ((estimate.RowsAtCompileTime == Eigen::Dynamic) ||
290 (estimate.ColsAtCompileTime == Eigen::Dynamic))
291 estimate.derived().resize(dim);
302 virtual int minimalEstimateDimension()
const;
374 virtual bool read(std::istream& is) = 0;
376 virtual bool write(std::ostream& os)
const = 0;
467 virtual double chi2()
const = 0;
525 virtual bool read(std::istream& is) = 0;
527 virtual bool write(std::ostream& os)
const = 0;
535 bool setParameterId(
int argNum,
int paramId);
553 template <
typename ParameterType>
562 template <
typename CacheType>
564 const std::string& _type,
567 bool resolveParameters();
568 virtual bool resolveCaches();
622 int maxDimension()
const;
634 std::set<int> dimensions()
const;
640 virtual int optimize(
int iterations,
bool online =
false);
644 virtual void preIteration(
int);
647 virtual void postIteration(
int);
665 virtual void discardTop();
669 virtual bool load(std::istream& is);
670 bool load(
const char* filename);
672 virtual bool save(std::ostream& os,
int level = 0)
const;
674 bool save(
const char* filename,
int level = 0)
const;
708 const std::set<int>& vertDims = std::set<int>())
const;
725 bool verifyInformationMatrices(
bool verbose =
false)
const;
728 bool saveVertex(std::ostream& os, Vertex* v)
const;
731 bool saveParameter(std::ostream& os,
Parameter* v)
const;
734 bool saveEdge(std::ostream& os, Edge* e)
const;
751 static bool initMultiThreading();
Abstract action that operates on an entire graph.
Container class that implements an interface for adding/removing Data elements in a linked list.
data packet for a vertex. Extend this class to store in the vertices the potential additional informa...
abstract Vertex, your types must derive from that one
int id() const
returns the id
std::set< Edge * > EdgeSet
std::set< Vertex * > VertexSet
HyperGraph()
constructs an empty hyper graph
provide memory workspace for computing the Jacobians
std::vector< std::string > _parameterTypes
int dimension() const
returns the dimensions of the error function
virtual void linearizeOplus(JacobianWorkspace &jacobianWorkspace)=0
const Parameter * parameter(int argNo) const
virtual double chi2() const =0
virtual double initialEstimatePossible(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)
virtual void computeError()=0
bool installParameter(ParameterType *&p, size_t argNo, int paramId=-1)
int level() const
returns the level of the edge
G2O_ATTRIBUTE_DEPRECATED(virtual Vertex *createFrom())
virtual bool setMeasurementFromState()
virtual bool read(std::istream &is)=0
read the vertex from a stream, i.e., the internal state of the vertex
std::vector< int > _parameterIds
virtual int measurementDimension() const
virtual void mapHessianMemory(double *d, int i, int j, bool rowMajor)=0
long long internalId() const
the internal ID of the edge
G2O_ATTRIBUTE_DEPRECATED(virtual Vertex *createTo())
virtual bool allVerticesFixed() const =0
std::vector< Parameter ** > _parameters
friend struct OptimizableGraph
RobustKernel * robustKernel() const
if NOT NULL, error of this edge will be robustifed with the kernel
virtual double * informationData()=0
std::vector< int > _cacheIds
virtual void constructQuadraticForm()=0
RobustKernel * _robustKernel
virtual bool write(std::ostream &os) const =0
write the vertex to a stream
virtual const double * errorData() const =0
returns the error vector cached after calling the computeError;
virtual void initialEstimate(const OptimizableGraph::VertexSet &from, OptimizableGraph::Vertex *to)=0
void setLevel(int l)
sets the level of the edge
virtual double * errorData()=0
virtual bool getMeasurementData(double *m) const
void resizeParameters(size_t newSize)
virtual const double * informationData() const =0
virtual Vertex * createVertex(int)
size_t numParameters() const
virtual bool setMeasurementData(const double *m)
A general case Vertex for optimization.
virtual bool setMinimalEstimateDataImpl(const double *)
virtual const double & hessian(int i, int j) const =0
get the element from the hessian matrix
virtual int stackSize() const =0
return the stack size
virtual void mapHessianMemory(double *d)=0
bool setEstimateData(const std::vector< double > &estimate)
virtual double & hessian(int i, int j)=0
bool marginalized() const
true => this node is marginalized out during the optimization
virtual bool read(std::istream &is)=0
read the vertex from a stream, i.e., the internal state of the vertex
virtual bool setEstimateDataImpl(const double *)
void setHessianIndex(int ti)
set the temporary index of the vertex in the parameter blocks
virtual void oplusImpl(const double *v)=0
friend struct OptimizableGraph
virtual bool write(std::ostream &os) const =0
write the vertex to a stream
int colInHessian() const
get the row of this vertex in the Hessian
bool setMinimalEstimateData(const double *estimate)
void unlockQuadraticForm()
virtual double solveDirect(double lambda=0)=0
virtual double & b(int i)=0
OptimizableGraph * _graph
CacheContainer * _cacheContainer
bool getEstimateData(Eigen::MatrixBase< Derived > &estimate) const
virtual bool getEstimateData(double *estimate) const
virtual void clearQuadraticForm()=0
virtual const double & b(int i) const =0
get the b vector element
int dimension() const
dimension of the estimated state belonging to this node
bool setMinimalEstimateData(const Eigen::MatrixBase< Derived > &estimate)
int G2O_ATTRIBUTE_DEPRECATED(tempIndex() const)
virtual void discardTop()=0
bool fixed() const
true => this node is fixed during the optimization
virtual void push()=0
backup the position of the vertex to a stack
void setColInHessian(int c)
set the row of this vertex in the Hessian
void setToOrigin()
sets the node to the origin (used in the multilevel stuff)
CacheContainer * cacheContainer()
virtual void updateCache()
OpenMPMutex _quadraticFormMutex
OptimizableGraph * graph()
virtual void setToOriginImpl()=0
sets the node to the origin (used in the multilevel stuff)
void G2O_ATTRIBUTE_DEPRECATED(setTempIndex(int ti))
bool setMinimalEstimateData(const std::vector< double > &estimate)
virtual void setId(int id)
virtual bool getMinimalEstimateData(double *estimate) const
virtual bool getEstimateData(std::vector< double > &estimate) const
bool setEstimateData(const double *estimate)
virtual double hessianDeterminant() const =0
const OptimizableGraph * graph() const
bool getMinimalEstimateData(Eigen::MatrixBase< Derived > &estimate) const
virtual int minimalEstimateDimension() const
virtual double * hessianData()=0
virtual int estimateDimension() const
virtual double * bData()=0
return a pointer to the b vector associated with this vertex
void oplus(const double *v)
virtual int copyB(double *b_) const =0
bool setEstimateData(const Eigen::MatrixBase< Derived > &estimate)
virtual bool getMinimalEstimateData(std::vector< double > &estimate) const
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
base for all robust cost functions
std::vector< Parameter * > ParameterVector
order edges based on the internal ID, which is assigned to the edge in addEdge()
bool operator()(const HyperGraph::Edge *e1, const HyperGraph::Edge *e2) const
bool operator()(const Edge *e1, const Edge *e2) const
order vertices based on their ID
bool operator()(const Vertex *v1, const Vertex *v2) const
JacobianWorkspace & jacobianWorkspace()
the workspace for storing the Jacobians of the graph
virtual void setFixed(HyperGraph::VertexSet &vset, bool fixed)
fixes/releases a set of vertices
virtual void clearParameters()
JacobianWorkspace _jacobianWorkspace
ParameterContainer & parameters()
bool saveSubset(std::ostream &os, HyperGraph::EdgeSet &eset)
save a subgraph to a stream. Again uses the Factory system.
std::vector< OptimizableGraph::Edge * > EdgeContainer
vector container for edges
virtual void discardTop()
ParameterContainer _parameters
virtual void push()
push the estimate of all variables onto a stack
const JacobianWorkspace & jacobianWorkspace() const
std::vector< OptimizableGraph::Vertex * > VertexContainer
vector container for vertices
bool addVertex(OptimizableGraph::Vertex *v)
bool isSolverSuitable(const OptimizationAlgorithmProperty &solverProperty, const std::set< int > &vertDims=std::set< int >()) const
std::vector< HyperGraphActionSet > _graphActions
std::map< std::string, std::string > _renamedTypesLookup
void recomputeJacobianWorkspaceSize()
virtual void pop()
pop (restore) the estimate of all variables from the stack
void performActions(int iter, HyperGraphActionSet &actions)
Parameter * parameter(int id)
std::set< HyperGraphAction * > HyperGraphActionSet
const Vertex * vertex(int id) const
returns the vertex number id appropriately casted
virtual bool save(std::ostream &os, int level=0) const
save the graph to a stream. Again uses the Factory system.
virtual bool addVertex(HyperGraph::Vertex *v)
OptimizableGraph()
empty constructor
const ParameterContainer & parameters() const
bool addParameter(Parameter *p)
bool saveSubset(std::ostream &os, HyperGraph::VertexSet &vset, int level=0)
save a subgraph to a stream. Again uses the Factory system.
virtual bool load(std::istream &is)
Vertex * vertex(int id)
returns the vertex number id appropriately casted
void setRenamedTypesFromString(const std::string &types)
describe the properties of a solver