class mrpt::graphs::ScalarFactorGraph

Sparse solver for GMRF (Gaussian Markov Random Fields) graphical models.

The design of this class is optimized for large problems (e.g. >1e3 nodes, >1e4 constrainst) by leaving to the user/caller the responsibility of allocating all “nodes” and constraints. This class can be seen as an intermediary solution between current methods in mrpt::graphslam and the well-known G2O library:


  • Linear error functions (for now).

  • Scalar (1-dim) error functions.

  • Gaussian factors.

  • Solver: Eigen SparseQR.


  • Call initialize() to set the number of nodes.

  • Call addConstraints() to insert constraints. This may be called more than once.

  • Call updateEstimation() to run one step of the linear SparseQR solver.

[New in MRPT 1.5.0] Requires Eigen>=3.1

#include <mrpt/graphs/ScalarFactorGraph.h>

class ScalarFactorGraph: public mrpt::system::COutputLogger
    // structs

    struct BinaryFactorVirtualBase;
    struct FactorBase;
    struct UnaryFactorVirtualBase;


    bool isLoggingLevelVisible(VerbosityLevel level) const;
    void logRegisterCallback(output_logger_callback_t userFunc);
    void clear();
    void initialize(const size_t nodeCount);
    void addConstraint(const UnaryFactorVirtualBase& listOfConstraints);
    void addConstraint(const BinaryFactorVirtualBase& listOfConstraints);
    bool eraseConstraint(const FactorBase& c);
    void clearAllConstraintsByType_Unary();
    void clearAllConstraintsByType_Binary();

    void updateEstimation(
        mrpt::math::CVectorDouble& solved_x_inc,
        mrpt::math::CVectorDouble* solved_variances = nullptr

    bool isProfilerEnabled() const;
    void enableProfiler(bool enable = true);

Inherited Members

    // structs

    struct TMsg;


void clear()

Reset state: remove all constraints and nodes.

void initialize(const size_t nodeCount)

Initialize the GMRF internal state and copy the prior factors.

void addConstraint(const UnaryFactorVirtualBase& listOfConstraints)

Insert constraints into the GMRF problem.



List of user-implemented constraints. A pointer to the passed object is kept, but memory ownship REMAINS being responsability of the caller. This is done such that arrays/vectors of constraints can be more efficiently allocated if their type is known at build time.

bool eraseConstraint(const FactorBase& c)

Removes a constraint.

Return true if found and deleted correctly.