Workaround for conflict between boost variant and graph in boost < 1.47
parent
ffcbcb703d
commit
e0988ade11
|
|
@ -0,0 +1,95 @@
|
||||||
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
* GTSAM Copyright 2010, Georgia Tech Research Corporation,
|
||||||
|
* Atlanta, Georgia 30332-0415
|
||||||
|
* All Rights Reserved
|
||||||
|
* Authors: Frank Dellaert, et al. (see THANKS for the full author list)
|
||||||
|
|
||||||
|
* See LICENSE for the license information
|
||||||
|
|
||||||
|
* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file boost_variant_with_workaround.h
|
||||||
|
* @brief Includes boost/variant.hpp with a workaround for a variant/boost graph conflict, by defining the variant 'get' function in a new variant_workaround namespace.
|
||||||
|
* @author Richard Roberts
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <boost/variant.hpp>
|
||||||
|
#include <boost/version.hpp>
|
||||||
|
|
||||||
|
namespace variant_workaround {
|
||||||
|
|
||||||
|
/* ************************************************************************* */
|
||||||
|
// The following functions are pasted from boost/variant/get.hpp, but with
|
||||||
|
// explicit argument types to avoid a conflict with 'get' in the boost graph
|
||||||
|
// library that exists in boost < 1.47.
|
||||||
|
#if BOOST_VERSION >= 104700
|
||||||
|
using boost::get;
|
||||||
|
#else
|
||||||
|
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
|
||||||
|
inline
|
||||||
|
typename boost::add_pointer<U>::type
|
||||||
|
get(
|
||||||
|
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
|
||||||
|
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef typename boost::add_pointer<U>::type U_ptr;
|
||||||
|
if (!operand) return static_cast<U_ptr>(0);
|
||||||
|
|
||||||
|
boost::detail::variant::get_visitor<U> v;
|
||||||
|
return operand->apply_visitor(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
|
||||||
|
inline
|
||||||
|
typename boost::add_pointer<const U>::type
|
||||||
|
get(
|
||||||
|
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
|
||||||
|
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef typename boost::add_pointer<const U>::type U_ptr;
|
||||||
|
if (!operand) return static_cast<U_ptr>(0);
|
||||||
|
|
||||||
|
boost::detail::variant::get_visitor<const U> v;
|
||||||
|
return operand->apply_visitor(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
|
||||||
|
inline
|
||||||
|
typename boost::add_reference<U>::type
|
||||||
|
get(
|
||||||
|
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
|
||||||
|
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef typename boost::add_pointer<U>::type U_ptr;
|
||||||
|
U_ptr result = variant_workaround::get<U>(&operand);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
throw boost::bad_get();
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
|
||||||
|
inline
|
||||||
|
typename boost::add_reference<const U>::type
|
||||||
|
get(
|
||||||
|
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
|
||||||
|
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
typedef typename boost::add_pointer<const U>::type U_ptr;
|
||||||
|
U_ptr result = variant_workaround::get<const U>(&operand);
|
||||||
|
|
||||||
|
if (!result)
|
||||||
|
throw boost::bad_get();
|
||||||
|
return *result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ using namespace boost::assign;
|
||||||
#include <gtsam/nonlinear/ISAM2-impl-inl.h>
|
#include <gtsam/nonlinear/ISAM2-impl-inl.h>
|
||||||
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
|
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
|
||||||
|
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
@ -43,16 +44,18 @@ static const bool structuralLast = false;
|
||||||
template<class CONDITIONAL, class VALUES, class GRAPH>
|
template<class CONDITIONAL, class VALUES, class GRAPH>
|
||||||
ISAM2<CONDITIONAL, VALUES, GRAPH>::ISAM2(const ISAM2Params& params):
|
ISAM2<CONDITIONAL, VALUES, GRAPH>::ISAM2(const ISAM2Params& params):
|
||||||
delta_(Permutation(), deltaUnpermuted_), params_(params) {
|
delta_(Permutation(), deltaUnpermuted_), params_(params) {
|
||||||
|
// See note in gtsam/base/boost_variant_with_workaround.h
|
||||||
if(params_.optimizationParams.type() == typeid(ISAM2DoglegParams))
|
if(params_.optimizationParams.type() == typeid(ISAM2DoglegParams))
|
||||||
doglegDelta_ = boost::get<ISAM2DoglegParams>(params_.optimizationParams).initialDelta;
|
doglegDelta_ = variant_workaround::get<ISAM2DoglegParams>(params_.optimizationParams).initialDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
template<class CONDITIONAL, class VALUES, class GRAPH>
|
template<class CONDITIONAL, class VALUES, class GRAPH>
|
||||||
ISAM2<CONDITIONAL, VALUES, GRAPH>::ISAM2():
|
ISAM2<CONDITIONAL, VALUES, GRAPH>::ISAM2():
|
||||||
delta_(Permutation(), deltaUnpermuted_) {
|
delta_(Permutation(), deltaUnpermuted_) {
|
||||||
|
// See note in gtsam/base/boost_variant_with_workaround.h
|
||||||
if(params_.optimizationParams.type() == typeid(ISAM2DoglegParams))
|
if(params_.optimizationParams.type() == typeid(ISAM2DoglegParams))
|
||||||
doglegDelta_ = boost::get<ISAM2DoglegParams>(params_.optimizationParams).initialDelta;
|
doglegDelta_ = variant_workaround::get<ISAM2DoglegParams>(params_.optimizationParams).initialDelta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
|
|
@ -528,7 +531,9 @@ ISAM2Result ISAM2<CONDITIONAL, VALUES, GRAPH>::update(
|
||||||
tic(9,"solve");
|
tic(9,"solve");
|
||||||
// 9. Solve
|
// 9. Solve
|
||||||
if(params_.optimizationParams.type() == typeid(ISAM2GaussNewtonParams)) {
|
if(params_.optimizationParams.type() == typeid(ISAM2GaussNewtonParams)) {
|
||||||
const ISAM2GaussNewtonParams& gaussNewtonParams = boost::get<ISAM2GaussNewtonParams>(params_.optimizationParams);
|
// See note in gtsam/base/boost_variant_with_workaround.h
|
||||||
|
const ISAM2GaussNewtonParams& gaussNewtonParams =
|
||||||
|
variant_workaround::get<ISAM2GaussNewtonParams>(params_.optimizationParams);
|
||||||
if (gaussNewtonParams.wildfireThreshold <= 0.0 || disableReordering) {
|
if (gaussNewtonParams.wildfireThreshold <= 0.0 || disableReordering) {
|
||||||
VectorValues newDelta(theta_.dims(ordering_));
|
VectorValues newDelta(theta_.dims(ordering_));
|
||||||
optimize2(this->root(), newDelta);
|
optimize2(this->root(), newDelta);
|
||||||
|
|
@ -550,7 +555,9 @@ ISAM2Result ISAM2<CONDITIONAL, VALUES, GRAPH>::update(
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
} else if(params_.optimizationParams.type() == typeid(ISAM2DoglegParams)) {
|
} else if(params_.optimizationParams.type() == typeid(ISAM2DoglegParams)) {
|
||||||
const ISAM2DoglegParams& doglegParams = boost::get<ISAM2DoglegParams>(params_.optimizationParams);
|
// See note in gtsam/base/boost_variant_with_workaround.h
|
||||||
|
const ISAM2DoglegParams& doglegParams =
|
||||||
|
variant_workaround::get<ISAM2DoglegParams>(params_.optimizationParams);
|
||||||
// Do one Dogleg iteration
|
// Do one Dogleg iteration
|
||||||
DoglegOptimizerImpl::IterationResult doglegResult = DoglegOptimizerImpl::Iterate(
|
DoglegOptimizerImpl::IterationResult doglegResult = DoglegOptimizerImpl::Iterate(
|
||||||
*doglegDelta_, doglegParams.adaptationMode, *this, nonlinearFactors_, theta_, ordering_, nonlinearFactors_.error(theta_), doglegParams.verbose);
|
*doglegDelta_, doglegParams.adaptationMode, *this, nonlinearFactors_, theta_, ordering_, nonlinearFactors_.error(theta_), doglegParams.verbose);
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
|
#include <gtsam/nonlinear/DoglegOptimizerImpl.h>
|
||||||
#include <gtsam/inference/BayesTree.h>
|
#include <gtsam/inference/BayesTree.h>
|
||||||
|
|
||||||
#include <boost/variant.hpp>
|
// Workaround for boost < 1.47, see note in file
|
||||||
|
#include <gtsam/base/boost_variant_with_workaround.h>
|
||||||
|
|
||||||
namespace gtsam {
|
namespace gtsam {
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue