trajopt
 All Classes Namespaces Files Functions Variables Typedefs Pages
modeling_utils.hpp
Go to the documentation of this file.
1 #pragma once
2 #include "modeling.hpp"
3 #include "num_diff.hpp"
4 #include "sco_common.hpp"
15 namespace sco {
16 
17 enum PenaltyType {
18  SQUARED,
19  ABS,
20  HINGE
21 };
22 
23 using Eigen::VectorXd;
24 using Eigen::MatrixXd;
25 
31 VectorXd getVec(const vector<double>& x, const VarVector& vars);
35 DblVec getDblVec(const vector<double>& x, const VarVector& vars);
36 
37 AffExpr affFromValGrad(double y, const VectorXd& x, const VectorXd& dydx, const VarVector& vars);
38 
39 class CostFromFunc : public Cost {
40 public:
42  CostFromFunc(ScalarOfVectorPtr f, const VarVector& vars, const string& name, bool full_hessian=false);
43  double value(const vector<double>& x);
44  ConvexObjectivePtr convex(const vector<double>& x, Model* model);
45 protected:
46  ScalarOfVectorPtr f_;
47  VarVector vars_;
48  bool full_hessian_;
49  double epsilon_;
50 };
51 
52 class CostFromErrFunc : public Cost {
53 public:
55  CostFromErrFunc(VectorOfVectorPtr f, const VarVector& vars, const VectorXd& coeffs, PenaltyType pen_type, const string& name);
57  CostFromErrFunc(VectorOfVectorPtr f, MatrixOfVectorPtr dfdx, const VarVector& vars, const VectorXd& coeffs, PenaltyType pen_type, const string& name);
58  double value(const vector<double>& x);
59  ConvexObjectivePtr convex(const vector<double>& x, Model* model);
60 protected:
61  VectorOfVectorPtr f_;
62  MatrixOfVectorPtr dfdx_;
63  VarVector vars_;
64  VectorXd coeffs_;
65  PenaltyType pen_type_;
66  double epsilon_;
67 };
68 
70 public:
72  ConstraintFromFunc(VectorOfVectorPtr f, const VarVector& vars, const VectorXd& coeffs, ConstraintType type, const std::string& name);
74  ConstraintFromFunc(VectorOfVectorPtr f, MatrixOfVectorPtr dfdx, const VarVector& vars, const VectorXd& coeffs, ConstraintType type, const std::string& name);
75  vector<double> value(const vector<double>& x);
76  ConvexConstraintsPtr convex(const vector<double>& x, Model* model);
77  ConstraintType type() {return type_;}
78 protected:
79  VectorOfVectorPtr f_;
80  MatrixOfVectorPtr dfdx_;
81  VarVector vars_;
82  VectorXd coeffs_;
83  ConstraintType type_;
84  double epsilon_;
85  VectorXd scaling_;
86 };
87 
88 
89 }