10 #include <boost/property_tree/ptree.hpp> 11 #include <boost/property_tree/info_parser.hpp> 15 #include "../CostFunction.hpp" 20 template <
typename SCALAR>
22 const std::string& scalarName,
24 const std::string& termName =
"")
26 boost::property_tree::ptree pt;
27 boost::property_tree::read_info(filename, pt);
29 scalar = pt.get<
SCALAR>(termName +
".weights." + scalarName);
32 template <
typename SCALAR>
34 const std::string& scalarName,
36 const std::string& termName,
37 const SCALAR& defaultValue)
39 boost::property_tree::ptree pt;
40 boost::property_tree::read_info(filename, pt);
42 scalar = pt.get<
SCALAR>(termName +
".weights." + scalarName, defaultValue);
45 template <
typename SCALAR,
int ROW,
int COL>
47 const std::string& matrixName,
48 Eigen::Matrix<SCALAR, ROW, COL>& matrix,
49 const std::string& termName =
"")
51 size_t rows = matrix.rows();
52 size_t cols = matrix.cols();
54 boost::property_tree::ptree pt;
55 boost::property_tree::read_info(filename, pt);
57 double scaling = pt.get<
double>(termName +
".weights." + matrixName +
".scaling", 1);
59 for (
size_t i = 0;
i < rows;
i++)
61 for (
size_t j = 0; j < cols; j++)
67 pt.get<
double>(matrixName +
"." +
"(" + std::to_string(
i) +
"," + std::to_string(j) +
")", 0.0);
71 matrix(
i, j) = scaling *
72 pt.get<
double>(termName +
".weights." + matrixName +
"." +
"(" + std::to_string(
i) +
73 "," + std::to_string(j) +
")",
80 template <
typename TERM_PTR,
typename costFuncType>
82 std::string& currentTerm,
85 costFuncType* costFunc,
88 switch (currentTermType)
91 costFunc->addIntermediateTerm(term,
verbose);
94 costFunc->addFinalTerm(term,
verbose);
99 std::cout <<
"error code 1 => term type other than term0 and term1 encountered" << std::endl;
101 BOOST_PROPERTY_TREE_THROW(boost::property_tree::info_parser::info_parser_error(
102 "read error code = ",
"", 1));
105 term->loadTimeActivation(filename, currentTerm,
verbose);
106 term->loadConfigFile(filename, currentTerm,
verbose);
109 std::cout <<
"Successfully loaded term " + currentTerm << std::endl;
112 template <
typename TERM_PTR,
typename costFuncType>
114 std::string& currentTerm,
117 costFuncType* costFunc,
120 switch (currentTermType)
123 costFunc->addIntermediateADTerm(term,
verbose);
126 costFunc->addFinalADTerm(term,
verbose);
131 std::cout <<
"error code 1 => term type other than term0 and term1 encountered" << std::endl;
133 BOOST_PROPERTY_TREE_THROW(boost::property_tree::info_parser::info_parser_error(
134 "read error code = ",
"", 1));
137 term->loadTimeActivation(filename, currentTerm,
verbose);
138 term->loadConfigFile(filename, currentTerm,
verbose);
141 std::cout <<
"Successfully loaded term " + currentTerm << std::endl;
CppAD::AD< CppAD::cg::CG< double > > SCALAR
void addADTerm(const std::string &filename, std::string ¤tTerm, int currentTermType, TERM_PTR term, costFuncType *costFunc, bool verbose=false)
Definition: utilities.hpp:113
void addTerm(const std::string &filename, std::string ¤tTerm, int currentTermType, TERM_PTR term, costFuncType *costFunc, bool verbose=false)
Definition: utilities.hpp:81
for i
Definition: mpc_unittest_plotting.m:14
void loadScalarCF(const std::string &filename, const std::string &scalarName, SCALAR &scalar, const std::string &termName="")
Definition: utilities.hpp:21
const bool verbose
Definition: ConstraintComparison.h:18
void loadMatrixCF(const std::string &filename, const std::string &matrixName, Eigen::Matrix< SCALAR, ROW, COL > &matrix, const std::string &termName="")
Definition: utilities.hpp:46
void loadScalarOptionalCF(const std::string &filename, const std::string &scalarName, SCALAR &scalar, const std::string &termName, const SCALAR &defaultValue)
Definition: utilities.hpp:33