Epigraph
Convex Optimization in C++
problem.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "constraint.hpp"
9 
10 namespace cvx
11 {
12 
14  {
15  public:
16  OptimizationProblem() = default;
17 
24  Scalar addVariable(const std::string &name);
25 
33  VectorX addVariable(const std::string &name,
34  size_t rows);
35 
44  MatrixX addVariable(const std::string &name,
45  size_t rows,
46  size_t cols);
47 
53  void addConstraint(const Constraint &constraint);
54 
60  void addConstraint(const std::vector<Constraint> &constraints);
61 
67  void addCostTerm(const Scalar &term);
68 
75  void getVariableValue(const std::string &name, double &var);
76 
83  void getVariableValue(const std::string &name, Eigen::VectorXd &var);
84 
91  void getVariableValue(const std::string &name, Eigen::MatrixXd &var);
92 
99  void getVariable(const std::string &name, Scalar &var);
100 
107  void getVariable(const std::string &name, VectorX &var);
108 
115  void getVariable(const std::string &name, MatrixX &var);
116 
124  double getOptimalValue() const;
125 
131  size_t getNumVariables() const;
132 
133  friend std::ostream &operator<<(std::ostream &os, const OptimizationProblem &socp);
134  friend internal::SOCPWrapperBase;
135  friend internal::QPWrapperBase;
136 
137  private:
139 
140  Scalar costFunction;
141 
142  std::vector<internal::EqualityConstraint> equality_constraints;
143  std::vector<internal::PositiveConstraint> positive_constraints;
144  std::vector<internal::BoxConstraint> box_constraints;
145  std::vector<internal::SecondOrderConeConstraint> second_order_cone_constraints;
146 
147  std::map<std::string, Scalar> scalar_variables;
148  std::map<std::string, VectorX> vector_variables;
149  std::map<std::string, MatrixX> matrix_variables;
150  };
151 
152 } // namespace cvx
cvx::OptimizationProblem::addConstraint
void addConstraint(const std::vector< Constraint > &constraints)
Add multiple constraints to the problem.
cvx::OptimizationProblem::getVariable
void getVariable(const std::string &name, Scalar &var)
Get a scalar variable that exists in the problem.
cvx::OptimizationProblem::getVariable
void getVariable(const std::string &name, MatrixX &var)
Get a matrix variable that exists in the problem.
cvx::OptimizationProblem::addVariable
VectorX addVariable(const std::string &name, size_t rows)
Creates and returns a vector of variables.
cvx::OptimizationProblem::getVariableValue
void getVariableValue(const std::string &name, Eigen::MatrixXd &var)
Get the value of a matrix variable.
cvx::OptimizationProblem::getOptimalValue
double getOptimalValue() const
Returns the evaluated cost function. Only call this after the problem has been solved.
cvx::Constraint
Definition: constraint.hpp:47
cvx::OptimizationProblem::getVariableValue
void getVariableValue(const std::string &name, Eigen::VectorXd &var)
Get the value of a vector variable.
cvx::OptimizationProblem
Definition: problem.hpp:14
cvx::OptimizationProblem::getNumVariables
size_t getNumVariables() const
Returns the number of used variables in the problem.
cvx::OptimizationProblem::addCostTerm
void addCostTerm(const Scalar &term)
Add a cost term to the problem's cost function. This has to be a scalar.
constraint.hpp
cvx::Scalar
Definition: expressions.hpp:117
cvx::OptimizationProblem::addVariable
MatrixX addVariable(const std::string &name, size_t rows, size_t cols)
Creates and returns a matrix of variables.
cvx::OptimizationProblem::getVariableValue
void getVariableValue(const std::string &name, double &var)
Get the value of a scalar variable.
cvx::OptimizationProblem::addConstraint
void addConstraint(const Constraint &constraint)
Add a single constraint to the problem. found.
cvx::OptimizationProblem::addVariable
Scalar addVariable(const std::string &name)
Creates and returns a variable.
cvx::OptimizationProblem::getVariable
void getVariable(const std::string &name, VectorX &var)
Get a vector variable that exists in the problem.