Program Listing for File marginalize_variables.hpp

Return to documentation for file (/tmp/ws/src/fuse/fuse_constraints/include/fuse_constraints/marginalize_variables.hpp)

/*
 * Software License Agreement (BSD License)
 *
 *  Copyright (c) 2019, Locus Robotics
 *  All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions
 *  are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   * Redistributions in binary form must reproduce the above
 *     copyright notice, this list of conditions and the following
 *     disclaimer in the documentation and/or other materials provided
 *     with the distribution.
 *   * Neither the name of the copyright holder nor the names of its
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 *  COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 *  POSSIBILITY OF SUCH DAMAGE.
 */
#ifndef FUSE_CONSTRAINTS__MARGINALIZE_VARIABLES_HPP_
#define FUSE_CONSTRAINTS__MARGINALIZE_VARIABLES_HPP_

#include <ceres/cost_function.h>

#include <algorithm>
#include <cassert>
#include <iterator>
#include <ostream>
#include <string>
#include <vector>

#include <fuse_constraints/marginal_constraint.hpp>
#include <fuse_constraints/uuid_ordering.hpp>
#include <fuse_core/constraint.hpp>
#include <fuse_core/eigen.hpp>
#include <fuse_core/graph.hpp>
#include <fuse_core/local_parameterization.hpp>
#include <fuse_core/fuse_macros.hpp>
#include <fuse_core/transaction.hpp>
#include <fuse_core/variable.hpp>

#include <boost/iterator/transform_iterator.hpp>


namespace fuse_constraints
{

UuidOrdering computeEliminationOrder(
  const std::vector<fuse_core::UUID> & marginalized_variables,
  const fuse_core::Graph & graph);

fuse_core::Transaction marginalizeVariables(
  const std::string & source,
  const std::vector<fuse_core::UUID> & marginalized_variables,
  const fuse_core::Graph & graph);

fuse_core::Transaction marginalizeVariables(
  const std::string & source,
  const std::vector<fuse_core::UUID> & marginalized_variables,
  const fuse_core::Graph & graph,
  const fuse_constraints::UuidOrdering & elimination_order);

namespace detail
{

struct LinearTerm
{
  std::vector<unsigned int> variables;
  std::vector<fuse_core::MatrixXd> A;
  fuse_core::VectorXd b;
};

LinearTerm linearize(
  const fuse_core::Constraint & constraint,
  const fuse_core::Graph & graph,
  const UuidOrdering & elimination_order);

LinearTerm marginalizeNext(const std::vector<LinearTerm> & linear_terms);

MarginalConstraint::SharedPtr createMarginalConstraint(
  const std::string & source,
  const LinearTerm & linear_term,
  const fuse_core::Graph & graph,
  const UuidOrdering & elimination_order);
}  // namespace detail

}  // namespace fuse_constraints

#endif  // FUSE_CONSTRAINTS__MARGINALIZE_VARIABLES_HPP_