6 namespace pt = boost::property_tree;
11 Optimizer::Optimizer(std::shared_ptr<ModPiece>
const& cost,
12 pt::ptree
const& pt) :
15 std::vector<std::string>({
typeid(Eigen::VectorXd).
name(),
typeid(double).
name()})),
16 opt(ConvertModPiece(cost)),
17 ftol_rel(pt.get(
"Ftol.RelativeTolerance", 1.0e-8)),
18 ftol_abs(pt.get(
"Ftol.AbsoluteTolerance", 1.0e-8)),
19 xtol_rel(pt.get(
"Xtol.RelativeTolerance", 1.0e-8)),
20 xtol_abs(pt.get(
"Xtol.AbsoluteTolerance", 1.0e-8)),
21 constraint_tol(pt.get(
"ConstraintTolerance", 1.0e-8)),
22 maxEvals(pt.get(
"MaxEvaluations", 100)) {}
28 auto cast = std::dynamic_pointer_cast<CostFunction>(modCost);
32 return std::make_shared<ModPieceCostFunction>(modCost);
39 std::vector<Eigen::VectorXd> inVec(1);
75 std::cout << prefix << pair.first << std::endl;
79 boost::property_tree::ptree
const& options) {
81 std::string method = options.get<std::string>(
"Algorithm");
83 auto iter = map.find(method);
84 if(iter != map.end()) {
85 return iter->second(cost,options);
87 std::stringstream msg;
88 msg <<
"Invalid \"Algorithm\" passed to Optimizer::Construct. A value of \"" << method <<
"\" was used, but valid options are:\n";
90 msg <<
" " << part.first <<
"\n";
91 throw std::invalid_argument(msg.str());
97 static std::shared_ptr<Optimizer::OptimizerMap> map;
100 map = std::make_shared<Optimizer::OptimizerMap>();
Base class for MUQ's modelling envronment.
std::vector< boost::any > outputs
The outputs.
std::string name
A unique name for this WorkPiece. Defaults to <ClassName>_<id>
std::vector< std::shared_ptr< muq::Modeling::ModPiece > > ineqConstraints
Inequality constraints.
void ClearEqualityConstraint()
Clear all equality constraints.
virtual void AddInequalityConstraint(std::vector< std::shared_ptr< muq::Modeling::ModPiece >> const &ineq)
Add an inequality constraint to the optimization.
static std::shared_ptr< Optimizer > Construct(std::shared_ptr< muq::Modeling::ModPiece > const &cost, boost::property_tree::ptree const &options)
static std::shared_ptr< CostFunction > ConvertModPiece(std::shared_ptr< muq::Modeling::ModPiece > const &modCost)
virtual void AddEqualityConstraint(std::vector< std::shared_ptr< muq::Modeling::ModPiece >> const &eq)
Add an equality constraint to the optimization.
std::vector< std::shared_ptr< muq::Modeling::ModPiece > > eqConstraints
Equality constraints.
virtual void EvaluateImpl(muq::Modeling::ref_vector< boost::any > const &inputs) override
User-implemented function that determines the behavior of this muq::Modeling::WorkPiece.
virtual std::pair< Eigen::VectorXd, double > Solve(std::vector< Eigen::VectorXd > const &inputs)=0
Solve the optimization problem.
std::map< std::string, OptimizerConstructor > OptimizerMap
void ClearInequalityConstraint()
Clear all inequality constraints.
static void ListMethods(std::string prefix="")
static std::shared_ptr< OptimizerMap > GetOptimizerMap()
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...