MathematicalProgram stores the decision variables, the constraints and costs of an optimization problem.
The user can solve the problem by calling solvers::Solve() function, and obtain the results of the optimization.
#include <drake/solvers/mathematical_program.h>
Public Types | |
enum | NonnegativePolynomial { kSos = 1, kSdsos, kDsos } |
Types of non-negative polynomial that can be found through conic optimization. More... | |
using | VarType = symbolic::Variable::Type |
Public Member Functions | |||||
MathematicalProgram () | |||||
virtual | ~MathematicalProgram () | ||||
std::unique_ptr< MathematicalProgram > | Clone () const | ||||
Clones an optimization program. More... | |||||
std::string | to_string () const | ||||
Returns string representation of this program, listing the decision variables, costs, and constraints. More... | |||||
bool | IsThreadSafe () const | ||||
Returns whether it is safe to solve this mathematical program concurrently. More... | |||||
std::string | ToLatex (int precision=3) | ||||
Returns a string representation of this program in LaTeX. More... | |||||
VectorXDecisionVariable | NewContinuousVariables (int rows, const std::string &name="x") | ||||
Adds continuous variables, appending them to an internal vector of any existing vars. More... | |||||
template<int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic> | |||||
MatrixDecisionVariable< Rows, Cols > | NewContinuousVariables (int rows, int cols, const std::string &name="X") | ||||
Adds continuous variables, appending them to an internal vector of any existing vars. More... | |||||
template<int Rows, int Cols = 1> | |||||
MatrixDecisionVariable< Rows, Cols > | NewContinuousVariables (const std::string &name="X") | ||||
Adds continuous variables, appending them to an internal vector of any existing vars. More... | |||||
template<int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic> | |||||
MatrixDecisionVariable< Rows, Cols > | NewBinaryVariables (int rows, int cols, const std::string &name) | ||||
Adds binary variables, appending them to an internal vector of any existing vars. More... | |||||
template<int Rows, int Cols = 1> | |||||
MatrixDecisionVariable< Rows, Cols > | NewBinaryVariables (const std::string &name="b") | ||||
Adds a matrix of binary variables into the optimization program. More... | |||||
VectorXDecisionVariable | NewBinaryVariables (int rows, const std::string &name="b") | ||||
Adds binary variables to this MathematicalProgram. More... | |||||
MatrixXDecisionVariable | NewSymmetricContinuousVariables (int rows, const std::string &name="Symmetric") | ||||
Adds a runtime sized symmetric matrix as decision variables to this MathematicalProgram. More... | |||||
template<int rows> | |||||
MatrixDecisionVariable< rows, rows > | NewSymmetricContinuousVariables (const std::string &name="Symmetric") | ||||
Adds a static sized symmetric matrix as decision variables to this MathematicalProgram. More... | |||||
void | AddDecisionVariables (const Eigen::Ref< const MatrixXDecisionVariable > &decision_variables) | ||||
Appends new variables to the end of the existing variables. More... | |||||
symbolic::Polynomial | NewFreePolynomial (const symbolic::Variables &indeterminates, int degree, const std::string &coeff_name="a") | ||||
Returns a free polynomial in a monomial basis over indeterminates of a given degree . More... | |||||
symbolic::Polynomial | NewEvenDegreeFreePolynomial (const symbolic::Variables &indeterminates, int degree, const std::string &coeff_name="a") | ||||
Returns a free polynomial that only contains even degree monomials. More... | |||||
symbolic::Polynomial | NewOddDegreeFreePolynomial (const symbolic::Variables &indeterminates, int degree, const std::string &coeff_name="a") | ||||
Returns a free polynomial that only contains odd degree monomials. More... | |||||
std::pair< symbolic::Polynomial, MatrixXDecisionVariable > | NewSosPolynomial (const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis, NonnegativePolynomial type=NonnegativePolynomial::kSos, const std::string &gram_name="S") | ||||
Returns a pair of a SOS polynomial p = mᵀQm and the Gramian matrix Q, where m is the monomial basis. More... | |||||
symbolic::Polynomial | NewSosPolynomial (const Eigen::Ref< const MatrixX< symbolic::Variable >> &gramian, const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis, NonnegativePolynomial type=NonnegativePolynomial::kSos) | ||||
Overloads NewSosPolynomial, except the Gramian matrix Q is an input instead of an output. More... | |||||
std::pair< symbolic::Polynomial, MatrixXDecisionVariable > | NewSosPolynomial (const symbolic::Variables &indeterminates, int degree, NonnegativePolynomial type=NonnegativePolynomial::kSos, const std::string &gram_name="S") | ||||
Overloads NewSosPolynomial. More... | |||||
symbolic::Polynomial | MakePolynomial (const symbolic::Expression &e) const | ||||
Creates a symbolic polynomial from the given expression e . More... | |||||
void | Reparse (symbolic::Polynomial *p) const | ||||
Reparses the polynomial p using this MathematicalProgram's indeterminates. More... | |||||
template<int rows, int cols> | |||||
MatrixIndeterminate< rows, cols > | NewIndeterminates (const std::array< std::string, rows *cols > &names) | ||||
Adds indeterminates, appending them to an internal vector of any existing indeterminates. More... | |||||
template<int rows> | |||||
VectorIndeterminate< rows > | NewIndeterminates (const std::array< std::string, rows > &names) | ||||
Adds indeterminates, appending them to an internal vector of any existing indeterminates. More... | |||||
template<int rows, int cols> | |||||
MatrixIndeterminate< rows, cols > | NewIndeterminates (const std::string &name="X") | ||||
Adds indeterminates, appending them to an internal vector of any existing indeterminates. More... | |||||
template<int rows> | |||||
VectorIndeterminate< rows > | NewIndeterminates (const std::string &name="x") | ||||
Adds indeterminates to the program. More... | |||||
VectorXIndeterminate | NewIndeterminates (int rows, const std::vector< std::string > &names) | ||||
Adds indeterminates to this MathematicalProgram. More... | |||||
VectorXIndeterminate | NewIndeterminates (int rows, const std::string &name="x") | ||||
Adds indeterminates to this MathematicalProgram, with default name "x". More... | |||||
MatrixXIndeterminate | NewIndeterminates (int rows, int cols, const std::vector< std::string > &names) | ||||
Adds indeterminates, appending them to an internal vector of any existing vars. More... | |||||
MatrixXIndeterminate | NewIndeterminates (int rows, int cols, const std::string &name="X") | ||||
Adds indeterminates to this MathematicalProgram, with default name "X". More... | |||||
int | AddIndeterminate (const symbolic::Variable &new_indeterminate) | ||||
Adds indeterminate. More... | |||||
void | AddIndeterminates (const Eigen::Ref< const MatrixXIndeterminate > &new_indeterminates) | ||||
Adds indeterminates. More... | |||||
void | AddIndeterminates (const symbolic::Variables &new_indeterminates) | ||||
Adds indeterminates. More... | |||||
Binding< VisualizationCallback > | AddVisualizationCallback (const VisualizationCallback::CallbackFunction &callback, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a callback method to visualize intermediate results of the optimization. More... | |||||
Binding< VisualizationCallback > | AddVisualizationCallback (const VisualizationCallback::CallbackFunction &callback, const VariableRefList &vars) | ||||
Adds a callback method to visualize intermediate results of the optimization. More... | |||||
Binding< Cost > | AddCost (const Binding< Cost > &binding) | ||||
Adds a generic cost to the optimization program. More... | |||||
template<typename C > | |||||
auto | AddCost (const std::shared_ptr< C > &obj, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a cost type to the optimization program. More... | |||||
template<typename C > | |||||
auto | AddCost (const std::shared_ptr< C > &obj, const VariableRefList &vars) | ||||
Adds a generic cost to the optimization program. More... | |||||
template<typename F > | |||||
std::enable_if_t< internal::is_cost_functor_candidate< F >::value, Binding< Cost > > | AddCost (F &&f, const VariableRefList &vars) | ||||
Adds a cost to the optimization program on a list of variables. More... | |||||
template<typename F > | |||||
std::enable_if_t< internal::is_cost_functor_candidate< F >::value, Binding< Cost > > | AddCost (F &&f, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a cost to the optimization program on an Eigen::Vector containing decision variables. More... | |||||
template<typename F , typename Vars > | |||||
std::enable_if_t< internal::assert_if_is_constraint< F >::value, Binding< Cost > > | AddCost (F &&, Vars &&) | ||||
Statically assert if a user inadvertently passes a binding-compatible Constraint. More... | |||||
Binding< LinearCost > | AddCost (const Binding< LinearCost > &binding) | ||||
Adds a cost term of the form c'*x. More... | |||||
Binding< LinearCost > | AddLinearCost (const symbolic::Expression &e) | ||||
Adds a linear cost term of the form a'*x + b. More... | |||||
Binding< LinearCost > | AddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, double b, const VariableRefList &vars) | ||||
Adds a linear cost term of the form a'*x + b. More... | |||||
Binding< LinearCost > | AddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, double b, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a linear cost term of the form a'*x + b. More... | |||||
template<typename VarType > | |||||
Binding< LinearCost > | AddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, const VarType &vars) | ||||
Adds a linear cost term of the form a'*x. More... | |||||
Binding< QuadraticCost > | AddCost (const Binding< QuadraticCost > &binding) | ||||
Adds a cost term of the form 0.5*x'*Q*x + b'x. More... | |||||
Binding< QuadraticCost > | AddQuadraticCost (const symbolic::Expression &e, std::optional< bool > is_convex=std::nullopt) | ||||
Add a quadratic cost term of the form 0.5*x'*Q*x + b'*x + c. More... | |||||
Binding< QuadraticCost > | AddQuadraticCost (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars, std::optional< bool > is_convex=std::nullopt) | ||||
Adds a cost term of the form 0.5*x'*Q*x + b'x. More... | |||||
Binding< QuadraticCost > | AddQuadraticCost (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, double c, const Eigen::Ref< const VectorXDecisionVariable > &vars, std::optional< bool > is_convex=std::nullopt) | ||||
Adds a cost term of the form 0.5*x'*Q*x + b'x + c Applied to subset of the variables. More... | |||||
Binding< QuadraticCost > | AddQuadraticCost (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars, std::optional< bool > is_convex=std::nullopt) | ||||
Adds a cost term of the form 0.5*x'*Q*x + b'x Applied to subset of the variables. More... | |||||
Binding< QuadraticCost > | AddQuadraticErrorCost (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &x_desired, const VariableRefList &vars) | ||||
Adds a cost term of the form (x-x_desired)'Q(x-x_desired). More... | |||||
Binding< QuadraticCost > | AddQuadraticErrorCost (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &x_desired, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a cost term of the form (x-x_desired)'Q(x-x_desired). More... | |||||
Binding< QuadraticCost > | Add2NormSquaredCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars) | ||||
Adds a quadratic cost of the form |Ax-b|²=(Ax-b)ᵀ(Ax-b) More... | |||||
Binding< QuadraticCost > | Add2NormSquaredCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a quadratic cost of the form |Ax-b|²=(Ax-b)ᵀ(Ax-b) More... | |||||
Binding< L2NormCost > | AddCost (const Binding< L2NormCost > &binding) | ||||
Adds an L2 norm cost |Ax+b|₂ (notice this cost is not quadratic since we don't take the square of the L2 norm). More... | |||||
Binding< L2NormCost > | AddL2NormCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds an L2 norm cost |Ax+b|₂ (notice this cost is not quadratic since we don't take the square of the L2 norm). More... | |||||
Binding< L2NormCost > | AddL2NormCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars) | ||||
Adds an L2 norm cost |Ax+b|₂ (notice this cost is not quadratic since we don't take the square of the L2 norm) More... | |||||
Binding< L2NormCost > | AddL2NormCost (const symbolic::Expression &e, double psd_tol=1e-8, double coefficient_tol=1e-8) | ||||
Adds an L2 norm cost |Ax+b|₂ from a symbolic expression which can be decomposed into sqrt((Ax+b)'(Ax+b)). More... | |||||
std::tuple< symbolic::Variable, Binding< LinearCost >, Binding< LorentzConeConstraint > > | AddL2NormCostUsingConicConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds an L2 norm cost min |Ax+b|₂ as a linear cost min s on the slack variable s, together with a Lorentz cone constraint s ≥ |Ax+b|₂ Many conic optimization solvers (Gurobi, MOSEK™, SCS, etc) natively prefers this form of linear cost + conic constraints. More... | |||||
Binding< PolynomialCost > | AddPolynomialCost (const symbolic::Expression &e) | ||||
Adds a cost term in the polynomial form. More... | |||||
Binding< Cost > | AddCost (const symbolic::Expression &e) | ||||
Adds a cost in the symbolic form. More... | |||||
Binding< Constraint > | AddConstraint (const Binding< Constraint > &binding) | ||||
Adds a generic constraint to the program. More... | |||||
Binding< Constraint > | AddConstraint (const symbolic::Expression &e, double lb, double ub) | ||||
Adds one row of constraint lb <= e <= ub where e is a symbolic expression. More... | |||||
Binding< Constraint > | AddConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &v, const Eigen::Ref< const Eigen::MatrixXd > &lb, const Eigen::Ref< const Eigen::MatrixXd > &ub) | ||||
Binding< Constraint > | AddConstraint (const symbolic::Formula &f) | ||||
Add a constraint represented by a symbolic formula to the program. More... | |||||
template<typename Derived > | |||||
std::enable_if_t< is_eigen_scalar_same< Derived, symbolic::Formula >::value, Binding< Constraint > > | AddConstraint (const Eigen::DenseBase< Derived > &formulas) | ||||
template<typename C > | |||||
auto | AddConstraint (std::shared_ptr< C > con, const VariableRefList &vars) | ||||
Adds a generic constraint to the program. More... | |||||
template<typename C > | |||||
auto | AddConstraint (std::shared_ptr< C > con, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a generic constraint to the program. More... | |||||
Binding< LinearConstraint > | AddConstraint (const Binding< LinearConstraint > &binding) | ||||
Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const VariableRefList &vars) | ||||
Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::SparseMatrix< double > &A, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const VariableRefList &vars) | ||||
Adds sparse linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::SparseMatrix< double > &A, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds sparse linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::Ref< const Eigen::RowVectorXd > &a, double lb, double ub, const VariableRefList &vars) | ||||
Adds one row of linear constraint referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::Ref< const Eigen::RowVectorXd > &a, double lb, double ub, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds one row of linear constraint referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const symbolic::Expression &e, double lb, double ub) | ||||
Adds one row of linear constraint lb <= e <= ub where e is a symbolic expression. More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &v, const Eigen::Ref< const Eigen::MatrixXd > &lb, const Eigen::Ref< const Eigen::MatrixXd > &ub) | ||||
Adds linear constraints represented by symbolic expressions to the program. More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const symbolic::Formula &f) | ||||
Add a linear constraint represented by a symbolic formula to the program. More... | |||||
Binding< LinearConstraint > | AddLinearConstraint (const Eigen::Ref< const Eigen::Array< symbolic::Formula, Eigen::Dynamic, Eigen::Dynamic >> &formulas) | ||||
Add a linear constraint represented by an Eigen::Array<symbolic::Formula> to the program. More... | |||||
Binding< LinearEqualityConstraint > | AddConstraint (const Binding< LinearEqualityConstraint > &binding) | ||||
Adds linear equality constraints referencing potentially a subset of the decision variables. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const symbolic::Expression &e, double b) | ||||
Adds one row of linear constraint e = b where e is a symbolic expression. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const symbolic::Formula &f) | ||||
Adds a linear equality constraint represented by a symbolic formula to the program. More... | |||||
template<typename DerivedV , typename DerivedB > | |||||
std::enable_if_t< is_eigen_vector_expression_double_pair< DerivedV, DerivedB >::value, Binding< LinearEqualityConstraint > > | AddLinearEqualityConstraint (const Eigen::MatrixBase< DerivedV > &v, const Eigen::MatrixBase< DerivedB > &b) | ||||
Adds linear equality constraints \( v = b \), where v(i) is a symbolic linear expression. More... | |||||
template<typename DerivedV , typename DerivedB > | |||||
std::enable_if_t< is_eigen_nonvector_expression_double_pair< DerivedV, DerivedB >::value, Binding< LinearEqualityConstraint > > | AddLinearEqualityConstraint (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedB > &B, bool lower_triangle=false) | ||||
Adds a linear equality constraint for a matrix of linear expression V , such that V(i, j) = B(i, j). More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const VariableRefList &vars) | ||||
AddLinearEqualityConstraint. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const Eigen::SparseMatrix< double > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const VariableRefList &vars) | ||||
AddLinearEqualityConstraint. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
AddLinearEqualityConstraint. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const Eigen::SparseMatrix< double > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
AddLinearEqualityConstraint. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const Eigen::Ref< const Eigen::RowVectorXd > &a, double beq, const VariableRefList &vars) | ||||
Adds one row of linear equality constraint referencing potentially a subset of decision variables. More... | |||||
Binding< LinearEqualityConstraint > | AddLinearEqualityConstraint (const Eigen::Ref< const Eigen::RowVectorXd > &a, double beq, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds one row of linear equality constraint referencing potentially a subset of decision variables. More... | |||||
Binding< BoundingBoxConstraint > | AddConstraint (const Binding< BoundingBoxConstraint > &binding) | ||||
Adds bounding box constraints referencing potentially a subest of the decision variables. More... | |||||
Binding< BoundingBoxConstraint > | AddBoundingBoxConstraint (const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const VariableRefList &vars) | ||||
AddBoundingBoxConstraint. More... | |||||
Binding< BoundingBoxConstraint > | AddBoundingBoxConstraint (const Eigen::Ref< const Eigen::MatrixXd > &lb, const Eigen::Ref< const Eigen::MatrixXd > &ub, const Eigen::Ref< const MatrixXDecisionVariable > &vars) | ||||
Adds bounding box constraints referencing potentially a subset of the decision variables. More... | |||||
Binding< BoundingBoxConstraint > | AddBoundingBoxConstraint (double lb, double ub, const symbolic::Variable &var) | ||||
Adds bounds for a single variable. More... | |||||
Binding< BoundingBoxConstraint > | AddBoundingBoxConstraint (double lb, double ub, const VariableRefList &vars) | ||||
Adds the same scalar lower and upper bound to every variable in the list. More... | |||||
template<typename Derived > | |||||
std::enable_if_t< std::is_same_v< typename Derived::Scalar, symbolic::Variable > &&Derived::ColsAtCompileTime==1, Binding< BoundingBoxConstraint > > | AddBoundingBoxConstraint (double lb, double ub, const Eigen::MatrixBase< Derived > &vars) | ||||
Adds the same scalar lower and upper bound to every variable in vars . More... | |||||
template<typename Derived > | |||||
std::enable_if_t< std::is_same_v< typename Derived::Scalar, symbolic::Variable > &&Derived::ColsAtCompileTime !=1, Binding< BoundingBoxConstraint > > | AddBoundingBoxConstraint (double lb, double ub, const Eigen::MatrixBase< Derived > &vars) | ||||
Adds the same scalar lower and upper bound to every variable in vars . More... | |||||
Binding< QuadraticConstraint > | AddConstraint (const Binding< QuadraticConstraint > &binding) | ||||
Adds quadratic constraint. More... | |||||
Binding< QuadraticConstraint > | AddQuadraticConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, double lb, double ub, const Eigen::Ref< const VectorXDecisionVariable > &vars, std::optional< QuadraticConstraint::HessianType > hessian_type=std::nullopt) | ||||
Adds quadratic constraint lb ≤ .5 xᵀQx + bᵀx ≤ ub Notice that if your quadratic constraint is convex, and you intend to solve the problem with a convex solver (like Mosek), then it is better to reformulate it with a second order cone constraint. More... | |||||
Binding< QuadraticConstraint > | AddQuadraticConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, double lb, double ub, const VariableRefList &vars, std::optional< QuadraticConstraint::HessianType > hessian_type=std::nullopt) | ||||
Adds quadratic constraint lb ≤ .5 xᵀQx + bᵀx ≤ ub Notice that if your quadratic constraint is convex, and you intend to solve the problem with a convex solver (like Mosek), then it is better to reformulate it with a second order cone constraint. More... | |||||
Binding< QuadraticConstraint > | AddQuadraticConstraint (const symbolic::Expression &e, double lb, double ub, std::optional< QuadraticConstraint::HessianType > hessian_type=std::nullopt) | ||||
Overloads AddQuadraticConstraint, impose lb <= e <= ub where e is a quadratic expression. More... | |||||
Binding< LorentzConeConstraint > | AddConstraint (const Binding< LorentzConeConstraint > &binding) | ||||
Adds Lorentz cone constraint referencing potentially a subset of the decision variables. More... | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const symbolic::Formula &f, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth, double psd_tol=1e-8, double coefficient_tol=1e-8) | ||||
Adds a Lorentz cone constraint of the form Ax+b >= |Cx+d|₂ from a symbolic formula with one side which can be decomposed into sqrt((Cx+d)'(Cx+d)). More... | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const Eigen::Ref< const VectorX< symbolic::Expression >> &v, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth) | ||||
Adds Lorentz cone constraint referencing potentially a subset of the decision variables. More... | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const symbolic::Expression &linear_expression, const symbolic::Expression &quadratic_expression, double tol=0, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth) | ||||
Adds Lorentz cone constraint on the linear expression v1 and quadratic expression v2, such that v1 >= sqrt(v2) More... | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth) | ||||
Adds Lorentz cone constraint referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth) | ||||
Adds Lorentz cone constraint referencing potentially a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const VariableRefList &vars, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth) | ||||
Imposes that a vector \( x\in\mathbb{R}^m \) lies in Lorentz cone. More... | |||||
template<int rows> | |||||
Binding< LorentzConeConstraint > | AddLorentzConeConstraint (const Eigen::MatrixBase< VectorDecisionVariable< rows >> &vars, LorentzConeConstraint::EvalType eval_type=LorentzConeConstraint::EvalType::kConvexSmooth) | ||||
Imposes that a vector \( x\in\mathbb{R}^m \) lies in Lorentz cone. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddConstraint (const Binding< RotatedLorentzConeConstraint > &binding) | ||||
Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddRotatedLorentzConeConstraint (const symbolic::Expression &linear_expression1, const symbolic::Expression &linear_expression2, const symbolic::Expression &quadratic_expression, double tol=0) | ||||
Adds rotated Lorentz cone constraint on the linear expression v1, v2 and quadratic expression u, such that v1 * v2 >= u, v1 >= 0, v2 >= 0. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddRotatedLorentzConeConstraint (const Eigen::Ref< const VectorX< symbolic::Expression >> &v) | ||||
Adds a constraint that a symbolic expression. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddRotatedLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars) | ||||
Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddRotatedLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddRotatedLorentzConeConstraint (const VariableRefList &vars) | ||||
Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone. More... | |||||
template<int rows> | |||||
Binding< RotatedLorentzConeConstraint > | AddRotatedLorentzConeConstraint (const Eigen::MatrixBase< VectorDecisionVariable< rows >> &vars) | ||||
Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone. More... | |||||
Binding< RotatedLorentzConeConstraint > | AddQuadraticAsRotatedLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, double c, const Eigen::Ref< const VectorX< symbolic::Variable >> &vars, double psd_tol=0.) | ||||
Add the convex quadratic constraint 0.5xᵀQx + bᵀx + c <= 0 as a rotated Lorentz cone constraint [rᵀx+s, 1, Px+q] is in the rotated Lorentz cone. More... | |||||
Binding< LinearComplementarityConstraint > | AddConstraint (const Binding< LinearComplementarityConstraint > &binding) | ||||
Adds a linear complementarity constraints referencing a subset of the decision variables. More... | |||||
Binding< LinearComplementarityConstraint > | AddLinearComplementarityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &M, const Eigen::Ref< const Eigen::VectorXd > &q, const VariableRefList &vars) | ||||
Adds a linear complementarity constraints referencing a subset of the decision variables. More... | |||||
Binding< LinearComplementarityConstraint > | AddLinearComplementarityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &M, const Eigen::Ref< const Eigen::VectorXd > &q, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a linear complementarity constraints referencing a subset of the decision variables. More... | |||||
Binding< Constraint > | AddPolynomialConstraint (const Eigen::Ref< const MatrixX< Polynomiald >> &polynomials, const std::vector< Polynomiald::VarType > &poly_vars, const Eigen::Ref< const Eigen::MatrixXd > &lb, const Eigen::Ref< const Eigen::MatrixXd > &ub, const VariableRefList &vars) | ||||
Adds a polynomial constraint to the program referencing a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< Constraint > | AddPolynomialConstraint (const Eigen::Ref< const MatrixX< Polynomiald >> &polynomials, const std::vector< Polynomiald::VarType > &poly_vars, const Eigen::Ref< const Eigen::MatrixXd > &lb, const Eigen::Ref< const Eigen::MatrixXd > &ub, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a polynomial constraint to the program referencing a subset of the decision variables (defined in the vars parameter). More... | |||||
Binding< PositiveSemidefiniteConstraint > | AddConstraint (const Binding< PositiveSemidefiniteConstraint > &binding) | ||||
Adds a positive semidefinite constraint on a symmetric matrix. More... | |||||
Binding< PositiveSemidefiniteConstraint > | AddConstraint (std::shared_ptr< PositiveSemidefiniteConstraint > con, const Eigen::Ref< const MatrixXDecisionVariable > &symmetric_matrix_var) | ||||
Adds a positive semidefinite constraint on a symmetric matrix. More... | |||||
Binding< PositiveSemidefiniteConstraint > | AddPositiveSemidefiniteConstraint (const Eigen::Ref< const MatrixXDecisionVariable > &symmetric_matrix_var) | ||||
Adds a positive semidefinite constraint on a symmetric matrix. More... | |||||
Binding< PositiveSemidefiniteConstraint > | AddPositiveSemidefiniteConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &e) | ||||
Adds a positive semidefinite constraint on a symmetric matrix of symbolic expressions e . More... | |||||
Binding< PositiveSemidefiniteConstraint > | AddPrincipalSubmatrixIsPsdConstraint (const Eigen::Ref< const MatrixXDecisionVariable > &symmetric_matrix_var, const std::set< int > &minor_indices) | ||||
Adds a constraint that the principal submatrix of a symmetric matrix composed of the indices in minor_indices is positive semidefinite. More... | |||||
Binding< PositiveSemidefiniteConstraint > | AddPrincipalSubmatrixIsPsdConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &e, const std::set< int > &minor_indices) | ||||
Adds a constraint the that the principal submatrix of a symmetric matrix of expressions composed of the indices in minor_indices is positive semidefinite. More... | |||||
Binding< LinearMatrixInequalityConstraint > | AddConstraint (const Binding< LinearMatrixInequalityConstraint > &binding) | ||||
Adds a linear matrix inequality constraint to the program. More... | |||||
Binding< LinearMatrixInequalityConstraint > | AddLinearMatrixInequalityConstraint (std::vector< Eigen::MatrixXd > F, const VariableRefList &vars) | ||||
Adds a linear matrix inequality constraint to the program. More... | |||||
Binding< LinearMatrixInequalityConstraint > | AddLinearMatrixInequalityConstraint (std::vector< Eigen::MatrixXd > F, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds a linear matrix inequality constraint to the program. More... | |||||
MatrixX< symbolic::Expression > | AddPositiveDiagonallyDominantMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X) | ||||
Adds the constraint that a symmetric matrix is diagonally dominant with non-negative diagonal entries. More... | |||||
MatrixX< symbolic::Expression > | TightenPsdConstraintToDd (const Binding< PositiveSemidefiniteConstraint > &constraint) | ||||
Binding< LinearConstraint > | RelaxPsdConstraintToDdDualCone (const Binding< PositiveSemidefiniteConstraint > &constraint) | ||||
std::vector< std::vector< Matrix2< symbolic::Variable > > > | TightenPsdConstraintToSdd (const Binding< PositiveSemidefiniteConstraint > &constraint) | ||||
std::vector< Binding< RotatedLorentzConeConstraint > > | RelaxPsdConstraintToSddDualCone (const Binding< PositiveSemidefiniteConstraint > &constraint) | ||||
MatrixXDecisionVariable | AddSosConstraint (const symbolic::Polynomial &p, const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis, NonnegativePolynomial type=NonnegativePolynomial::kSos, const std::string &gram_name="S") | ||||
Adds constraints that a given polynomial p is a sums-of-squares (SOS), that is, p can be decomposed into mᵀQm , where m is the monomial_basis . More... | |||||
std::pair< MatrixXDecisionVariable, VectorX< symbolic::Monomial > > | AddSosConstraint (const symbolic::Polynomial &p, NonnegativePolynomial type=NonnegativePolynomial::kSos, const std::string &gram_name="S") | ||||
Adds constraints that a given polynomial p is a sums-of-squares (SOS), that is, p can be decomposed into mᵀQm , where m is a monomial basis selected from the sparsity of p . More... | |||||
MatrixXDecisionVariable | AddSosConstraint (const symbolic::Expression &e, const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis, NonnegativePolynomial type=NonnegativePolynomial::kSos, const std::string &gram_name="S") | ||||
Adds constraints that a given symbolic expression e is a sums-of-squares (SOS), that is, p can be decomposed into mᵀQm , where m is the monomial_basis . More... | |||||
std::pair< MatrixXDecisionVariable, VectorX< symbolic::Monomial > > | AddSosConstraint (const symbolic::Expression &e, NonnegativePolynomial type=NonnegativePolynomial::kSos, const std::string &gram_name="S") | ||||
Adds constraints that a given symbolic expression e is a sums-of-squares (SOS), that is, e can be decomposed into mᵀQm . More... | |||||
std::vector< Binding< LinearEqualityConstraint > > | AddEqualityConstraintBetweenPolynomials (const symbolic::Polynomial &p1, const symbolic::Polynomial &p2) | ||||
Constraining that two polynomials are the same (i.e., they have the same coefficients for each monomial). More... | |||||
Binding< ExponentialConeConstraint > | AddConstraint (const Binding< ExponentialConeConstraint > &binding) | ||||
Adds the exponential cone constraint that z = binding.evaluator()->A() * binding.variables() + binding.evaluator()->b() should be in the exponential cone. More... | |||||
Binding< ExponentialConeConstraint > | AddExponentialConeConstraint (const Eigen::Ref< const Eigen::SparseMatrix< double >> &A, const Eigen::Ref< const Eigen::Vector3d > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars) | ||||
Adds an exponential cone constraint, that z = A * vars + b should be in the exponential cone. More... | |||||
Binding< ExponentialConeConstraint > | AddExponentialConeConstraint (const Eigen::Ref< const Vector3< symbolic::Expression >> &z) | ||||
Add the constraint that z is in the exponential cone. More... | |||||
double | GetInitialGuess (const symbolic::Variable &decision_variable) const | ||||
Gets the initial guess for a single variable. More... | |||||
template<typename Derived > | |||||
std::enable_if_t< std::is_same_v< typename Derived::Scalar, symbolic::Variable >, MatrixLikewise< double, Derived > > | GetInitialGuess (const Eigen::MatrixBase< Derived > &decision_variable_mat) const | ||||
Gets the initial guess for some variables. More... | |||||
void | SetInitialGuess (const symbolic::Variable &decision_variable, double variable_guess_value) | ||||
Sets the initial guess for a single variable decision_variable . More... | |||||
template<typename DerivedA , typename DerivedB > | |||||
void | SetInitialGuess (const Eigen::MatrixBase< DerivedA > &decision_variable_mat, const Eigen::MatrixBase< DerivedB > &x0) | ||||
Sets the initial guess for the decision variables stored in decision_variable_mat to be x0 . More... | |||||
template<typename Derived > | |||||
void | SetInitialGuessForAllVariables (const Eigen::MatrixBase< Derived > &x0) | ||||
Set the initial guess for ALL decision variables. More... | |||||
void | SetDecisionVariableValueInVector (const symbolic::Variable &decision_variable, double decision_variable_new_value, EigenPtr< Eigen::VectorXd > values) const | ||||
Updates the value of a single decision_variable inside the values vector to be decision_variable_new_value . More... | |||||
void | SetDecisionVariableValueInVector (const Eigen::Ref< const MatrixXDecisionVariable > &decision_variables, const Eigen::Ref< const Eigen::MatrixXd > &decision_variables_new_values, EigenPtr< Eigen::VectorXd > values) const | ||||
Updates the values of some decision_variables inside the values vector to be decision_variables_new_values . More... | |||||
const SolverOptions & | solver_options () const | ||||
Returns the solver options stored inside MathematicalProgram. More... | |||||
const std::unordered_map< std::string, double > & | GetSolverOptionsDouble (const SolverId &solver_id) const | ||||
const std::unordered_map< std::string, int > & | GetSolverOptionsInt (const SolverId &solver_id) const | ||||
const std::unordered_map< std::string, std::string > & | GetSolverOptionsStr (const SolverId &solver_id) const | ||||
const std::vector< Binding< VisualizationCallback > > & | visualization_callbacks () const | ||||
Getter for all callbacks. More... | |||||
const std::vector< Binding< Cost > > & | generic_costs () const | ||||
Getter for all generic costs. More... | |||||
const std::vector< Binding< Constraint > > & | generic_constraints () const | ||||
Getter for all generic constraints. More... | |||||
const std::vector< Binding< LinearEqualityConstraint > > & | linear_equality_constraints () const | ||||
Getter for linear equality constraints. More... | |||||
const std::vector< Binding< LinearCost > > & | linear_costs () const | ||||
Getter for linear costs. More... | |||||
const std::vector< Binding< QuadraticCost > > & | quadratic_costs () const | ||||
Getter for quadratic costs. More... | |||||
const std::vector< Binding< L2NormCost > > & | l2norm_costs () const | ||||
Getter for l2norm costs. More... | |||||
const std::vector< Binding< LinearConstraint > > & | linear_constraints () const | ||||
Getter for linear inequality constraints. More... | |||||
const std::vector< Binding< QuadraticConstraint > > & | quadratic_constraints () const | ||||
Getter for quadratic constraints. More... | |||||
const std::vector< Binding< LorentzConeConstraint > > & | lorentz_cone_constraints () const | ||||
Getter for Lorentz cone constraints. More... | |||||
const std::vector< Binding< RotatedLorentzConeConstraint > > & | rotated_lorentz_cone_constraints () const | ||||
Getter for rotated Lorentz cone constraints. More... | |||||
const std::vector< Binding< PositiveSemidefiniteConstraint > > & | positive_semidefinite_constraints () const | ||||
Getter for positive semidefinite constraints. More... | |||||
const std::vector< Binding< LinearMatrixInequalityConstraint > > & | linear_matrix_inequality_constraints () const | ||||
Getter for linear matrix inequality constraints. More... | |||||
const std::vector< Binding< ExponentialConeConstraint > > & | exponential_cone_constraints () const | ||||
Getter for exponential cone constraints. More... | |||||
const std::vector< Binding< BoundingBoxConstraint > > & | bounding_box_constraints () const | ||||
Getter for all bounding box constraints. More... | |||||
const std::vector< Binding< LinearComplementarityConstraint > > & | linear_complementarity_constraints () const | ||||
Getter for all linear complementarity constraints. More... | |||||
std::vector< Binding< Cost > > | GetAllCosts () const | ||||
Getter returning all costs. More... | |||||
std::vector< Binding< LinearConstraint > > | GetAllLinearConstraints () const | ||||
Getter returning all linear constraints (both linear equality and inequality constraints). More... | |||||
std::vector< Binding< Constraint > > | GetAllConstraints () const | ||||
Getter for returning all constraints. More... | |||||
int | num_vars () const | ||||
Getter for number of variables in the optimization program. More... | |||||
int | num_indeterminates () const | ||||
Gets the number of indeterminates in the optimization program. More... | |||||
const Eigen::VectorXd & | initial_guess () const | ||||
Getter for the initial guess. More... | |||||
int | FindDecisionVariableIndex (const symbolic::Variable &var) const | ||||
Returns the index of the decision variable. More... | |||||
std::vector< int > | FindDecisionVariableIndices (const Eigen::Ref< const VectorXDecisionVariable > &vars) const | ||||
Returns the indices of the decision variables. More... | |||||
size_t | FindIndeterminateIndex (const symbolic::Variable &var) const | ||||
Returns the index of the indeterminate. More... | |||||
template<typename C , typename DerivedX > | |||||
std::enable_if_t< is_eigen_vector< DerivedX >::value, VectorX< typename DerivedX::Scalar > > | EvalBinding (const Binding< C > &binding, const Eigen::MatrixBase< DerivedX > &prog_var_vals) const | ||||
Evaluates the value of some binding, for some input value for all decision variables. More... | |||||
template<typename C , typename DerivedX > | |||||
std::enable_if_t< is_eigen_vector< DerivedX >::value, VectorX< typename DerivedX::Scalar > > | EvalBindings (const std::vector< Binding< C >> &bindings, const Eigen::MatrixBase< DerivedX > &prog_var_vals) const | ||||
Evaluates a set of bindings (plural version of EvalBinding ). More... | |||||
template<typename C , typename DerivedX > | |||||
std::enable_if_t< is_eigen_vector< DerivedX >::value, VectorX< typename DerivedX::Scalar > > | GetBindingVariableValues (const Binding< C > &binding, const Eigen::MatrixBase< DerivedX > &prog_var_vals) const | ||||
Given the value of all decision variables, namely this.decision_variable(i) takes the value prog_var_vals(i), returns the vector that contains the value of the variables in binding.variables(). More... | |||||
void | EvalVisualizationCallbacks (const Eigen::Ref< const Eigen::VectorXd > &prog_var_vals) const | ||||
Evaluates all visualization callbacks registered with the MathematicalProgram. More... | |||||
template<typename C > | |||||
Eigen::VectorXd | EvalBindingAtInitialGuess (const Binding< C > &binding) const | ||||
Evaluates the evaluator in binding at the initial guess. More... | |||||
bool | CheckSatisfied (const Binding< Constraint > &binding, const Eigen::Ref< const Eigen::VectorXd > &prog_var_vals, double tol=1e-6) const | ||||
Evaluates CheckSatisfied for the constraint in binding using the value of ALL of the decision variables in this program. More... | |||||
bool | CheckSatisfied (const std::vector< Binding< Constraint >> &bindings, const Eigen::Ref< const Eigen::VectorXd > &prog_var_vals, double tol=1e-6) const | ||||
Evaluates CheckSatisfied for the all of the constraints in binding using the value of ALL of the decision variables in this program. More... | |||||
bool | CheckSatisfiedAtInitialGuess (const Binding< Constraint > &binding, double tol=1e-6) const | ||||
Evaluates CheckSatisfied for the constraint in binding at the initial guess. More... | |||||
bool | CheckSatisfiedAtInitialGuess (const std::vector< Binding< Constraint >> &bindings, double tol=1e-6) const | ||||
Evaluates CheckSatisfied for the all of the constraints in bindings at the initial guess. More... | |||||
Eigen::Map< const VectorX< symbolic::Variable > > | decision_variables () const | ||||
Getter for all decision variables in the program. More... | |||||
const symbolic::Variable & | decision_variable (int i) const | ||||
Getter for the decision variable with index i in the program. More... | |||||
Eigen::Map< const VectorX< symbolic::Variable > > | indeterminates () const | ||||
Getter for all indeterminates in the program. More... | |||||
const symbolic::Variable & | indeterminate (int i) const | ||||
Getter for the indeterminate with index i in the program. More... | |||||
const ProgramAttributes & | required_capabilities () const | ||||
Getter for the required capability on the solver, given the cost/constraint/variable types in the program. More... | |||||
const std::unordered_map< symbolic::Variable::Id, int > & | decision_variable_index () const | ||||
Returns the mapping from a decision variable ID to its index in the vector containing all the decision variables in the mathematical program. More... | |||||
const std::unordered_map< symbolic::Variable::Id, int > & | indeterminates_index () const | ||||
Returns the mapping from an indeterminate ID to its index in the vector containing all the indeterminates in the mathematical program. More... | |||||
int | RemoveDecisionVariable (const symbolic::Variable &var) | ||||
Remove var from this program's decision variable. More... | |||||
Does not allow copy, move, or assignment. | |||||
MathematicalProgram (const MathematicalProgram &)=delete | |||||
MathematicalProgram & | operator= (const MathematicalProgram &)=delete | ||||
MathematicalProgram (MathematicalProgram &&)=delete | |||||
MathematicalProgram & | operator= (MathematicalProgram &&)=delete | ||||
Creating even-degree nonnegative polynomials | |||||
Creates a nonnegative polynomial p = m(x)ᵀQm(x) of a given degree, and p only contains even-degree monomials. If we partition the monomials m(x) to odd degree monomials m_o(x) and even degree monomials m_e(x), then we can write p(x) as ⌈m_o(x)⌉ᵀ * ⌈Q_oo Q_oeᵀ⌉ * ⌈m_o(x)⌉ ⌊m_e(x)⌋ ⌊Q_oe Q_ee ⌋ ⌊m_e(x)⌋ Since p(x) doesn't contain any odd degree monomials, and p(x) contains terms m_e(x)ᵀ*Q_oe * m_o(x) which has odd degree, we know that the off-diagonal block Q_oe has to be zero. So the constraint that Q is psd can be simplified as Q_oo and Q_ee has to be psd. Since both Q_oo and Q_ee have smaller size than Q, these PSD constraints are easier to solve than requiring Q to be PSD. One use case for even-degree polynomial, is for polynomials that are even functions, namely p(x) = p(-x).
| |||||
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable > | NewEvenDegreeNonnegativePolynomial (const symbolic::Variables &indeterminates, int degree, NonnegativePolynomial type) | ||||
See even_degree_nonnegative_polynomial for more details. More... | |||||
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable > | NewEvenDegreeSosPolynomial (const symbolic::Variables &indeterminates, int degree) | ||||
See even_degree_nonnegative_polynomial for more details. More... | |||||
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable > | NewEvenDegreeSdsosPolynomial (const symbolic::Variables &indeterminates, int degree) | ||||
see even_degree_nonnegative_polynomial for details. More... | |||||
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable > | NewEvenDegreeDsosPolynomial (const symbolic::Variables &indeterminates, int degree) | ||||
see even_degree_nonnegative_polynomial for details. More... | |||||
Matrix log determinant | |||||
Represents the log-determinant of ⌈X Z⌉ is positive semidifinite. ⌊Zᵀ diag(Z)⌋ log(Z(i, i)) >= t(i) Since log(det(X)) is a concave function of X, we can either lower bound it's value by imposing the constraint
already implies that X is positive semidefinite. The user DO NOT need to separately impose the constraint that X being psd. Refer to https://docs.mosek.com/modeling-cookbook/sdo.html#log-determinant for more details. | |||||
std::tuple< Binding< LinearCost >, VectorX< symbolic::Variable >, MatrixX< symbolic::Expression > > | AddMaximizeLogDeterminantCost (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X) | ||||
Maximize the log determinant. More... | |||||
std::tuple< Binding< LinearConstraint >, VectorX< symbolic::Variable >, MatrixX< symbolic::Expression > > | AddLogDeterminantLowerBoundConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X, double lower) | ||||
Impose the constraint log(det(X)) >= lower. More... | |||||
Maximize geometric mean | |||||
Adds the cost to maximize the geometric mean of z = Ax+b, i.e. power(∏ᵢz(i), 1/n), where z ∈ ℝⁿ, z(i) >= 0. Mathematically, the cost we add is -power(∏ᵢz(i), 1/r), where r = power(2, ceil(log₂n)), namely r is the smallest power of 2 that is no smaller than the size of z. For example, if z ∈ ℝ², then the added cost is -power(z(0)*z(1), 1/2) if z ∈ ℝ³, then the added cost is -power(z(0)*z(1)*z(2), 1/4). In order to add this cost, we need to introduce a set of second-order cone constraints. For example, to maximize power(z(0) * z(1), 1/2), we introduce the slack variable w(0), together with the second order cone constraint w(0)² ≤ z(0) * z(1), z(0) ≥ 0, z(1) ≥ 0, and we maximize w(0). To maximize power(z(0) * z(1) * z(2), 1/ 4), we introduce the slack variable w(0), w(1), w(2), together with the second order cone constraints w(0)² ≤ z(0) * z(1), z(0) ≥ 0, z(1) ≥ 0 w(1)² ≤ z(2), z(2) ≥ 0 w(2)² ≤ w(0) * w(1), w(0) ≥ 0, w(1) ≥ 0 and we maximize w(2). | |||||
Binding< LinearCost > | AddMaximizeGeometricMeanCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorX< symbolic::Variable >> &x) | ||||
An overloaded version of maximize_geometric_mean. More... | |||||
Binding< LinearCost > | AddMaximizeGeometricMeanCost (const Eigen::Ref< const VectorX< symbolic::Variable >> &x, double c=1.0) | ||||
An overloaded version of maximize_geometric_mean. More... | |||||
Diagonally dominant dual cone constraint | |||||
Adds the constraint that a symmetric matrix is in the dual cone of the diagonally dominant matrices which is denoted DD*. This set is a polyhedral (linear) outer approximation to the PSD cone. This follows from the fact that since DD ⊆ PSD, then PSD* ⊆ DD*, and since PSD is self-dual, we have that PSD = PSD* and so DD ⊆ PSD = PSD* ⊆ DD*. A symmetric matrix X is in DD* if and only if vᵢᵀXvᵢ ≥ 0 for all vᵢ, where vᵢ is a non-zero vector with at most two entries set to ±1 and all other entries set to 0. There are 4 * (n choose 2) + 2 * n of these vectors, but notice that vᵢᵀXvᵢ = (-vᵢ)ᵀX(vᵢ) and so we only need to add all choices with different partities of which there are 2 * (n choose 2) + n = n². Therefore, if X is a matrix of size n x n, this function adds exactly n² linear constraints. This is a consequence of the characterization of DD given in "Cones of diagonally dominant matrices" by Barker and Carlson which can be found at https://msp.org/pjm/1975/57-1/p03.xhtml. | |||||
Binding< LinearConstraint > | AddPositiveDiagonallyDominantDualConeMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X) | ||||
This is an overloaded variant of diagonally dominant dual cone constraint. More... | |||||
Binding< LinearConstraint > | AddPositiveDiagonallyDominantDualConeMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Variable >> &X) | ||||
This is an overloaded variant of diagonally dominant dual cone constraint. More... | |||||
Scaled diagonally dominant matrix constraint | |||||
Adds the constraint that a symmetric matrix is scaled diagonally dominant (sdd). A matrix X is sdd if there exists a diagonal matrix D, such that the product DXD is diagonally dominant with non-negative diagonal entries, namely d(i)X(i, i) ≥ ∑ⱼ |d(j)X(i, j)| ∀ j ≠ i where d(i) = D(i, i). X being sdd is equivalent to the existence of symmetric matrices Mⁱʲ∈ ℝⁿˣⁿ, i < j, such that all entries in Mⁱʲ are 0, except Mⁱʲ(i, i), Mⁱʲ(i, j), Mⁱʲ(j, j). (Mⁱʲ(i, i), Mⁱʲ(j, j), Mⁱʲ(i, j)) is in the rotated Lorentz cone, and X = ∑ᵢⱼ Mⁱʲ. The users can refer to "DSOS and SDSOS Optimization: More Tractable Alternatives to Sum of Squares and Semidefinite Optimization" by Amir Ali Ahmadi and Anirudha Majumdar, with arXiv link https://arxiv.org/abs/1706.02586. | |||||
std::vector< std::vector< Matrix2< symbolic::Expression > > > | AddScaledDiagonallyDominantMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X) | ||||
This is an overloaded variant of scaled diagonally dominant matrix constraint. More... | |||||
std::vector< std::vector< Matrix2< symbolic::Variable > > > | AddScaledDiagonallyDominantMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Variable >> &X) | ||||
This is an overloaded variant of scaled diagonally dominant matrix constraint. More... | |||||
Scaled diagonally dominant dual cone constraint | |||||
Adds the constraint that a symmetric matrix is in the dual cone of the scaled diagonally dominant matrices which is denoted SDD*. The set SDD* is an SOCP outer approximation to the PSD cone that is tighter than DD*. This follows from the fact that DD ⊆ SDD ⊆ PSD = PSD* ⊆ SDD* ⊆ DD*. A symmetric matrix X is in SDD* if and only if all 2 x 2 principal minors of X are psd. This can be encoded by ensuring that VᵢⱼᵀXVᵢⱼ is psd for all Vᵢⱼ, where Vᵢⱼ is the n x 2 matrix such that Vᵢⱼ(i, 0) = 1, V(j, 1) = 1, namely Vᵢⱼ = [eᵢ eⱼ]. This can be encoded using 1/2 * n * (n-1) RotatedLorentzCone constraints which we return in this function. This can be seen by noting that VᵢⱼᵀXVᵢⱼ = ⌈ Xᵢᵢ Xᵢⱼ⌉ ⌊ Xⱼᵢ Xⱼⱼ⌋ is psd if and only if VⱼᵢᵀXVⱼᵢ as they are simply permutations of each other. Therefore, it suffices to only add the constraint for i ≥ j. Moreover, notice that VᵢᵢᵀXVᵢᵢ = ⌈ Xᵢᵢ 0⌉ ⌊ 0 0⌋ is psd if and only if Xᵢᵢ ≥ 0. This linear constraint is already implied by VᵢⱼᵀXVᵢⱼ is psd for every i ≠ j and so is redundant. Therefore, we only add RotatedLorentzConeConstraints for i > j. This characterization can be found in Section 3.3 of "Sum of Squares Basis Pursuit with Linear and Second Order Cone Programming" by Ahmadi and Hall with arXiv link https://arxiv.org/abs/1510.01597 | |||||
std::vector< Binding< RotatedLorentzConeConstraint > > | AddScaledDiagonallyDominantDualConeMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X) | ||||
This is an overloaded variant of scaled diagonally dominant dual cone constraint. More... | |||||
std::vector< Binding< RotatedLorentzConeConstraint > > | AddScaledDiagonallyDominantDualConeMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Variable >> &X) | ||||
This is an overloaded variant of scaled diagonally dominant dual cone constraint. More... | |||||
Set solver options | |||||
Set the options (parameters) for a specific solver. Refer to SolverOptions class for more details on the supported options of each solver. | |||||
void | SetSolverOption (const SolverId &solver_id, const std::string &solver_option, double option_value) | ||||
See set_solver_option for more details. More... | |||||
void | SetSolverOption (const SolverId &solver_id, const std::string &solver_option, int option_value) | ||||
See set_solver_option for more details. More... | |||||
void | SetSolverOption (const SolverId &solver_id, const std::string &solver_option, const std::string &option_value) | ||||
See set_solver_option for more details. More... | |||||
void | SetSolverOptions (const SolverOptions &solver_options) | ||||
Overwrite the stored solver options inside MathematicalProgram with the provided solver options. More... | |||||
Variable scaling | |||||
Some solvers (e.g. SNOPT) work better if the decision variables values are on the same scale. Hence, internally we scale the variable as snopt_var_value = var_value / scaling_factor. This scaling factor is only used inside the solve, so users don't need to manually scale the variables every time they appears in cost and constraints. When the users set the initial guess, or getting the result from MathematicalProgramResult::GetSolution(), the values are unscaled. Namely, MathematicalProgramResult::GetSolution(var) returns the value of var, not var_value / scaling_factor. The feature of variable scaling is currently only implemented for SNOPT and OSQP. | |||||
const std::unordered_map< int, double > & | GetVariableScaling () const | ||||
Returns the mapping from a decision variable index to its scaling factor. More... | |||||
void | SetVariableScaling (const symbolic::Variable &var, double s) | ||||
Setter for the scaling s of decision variable var . More... | |||||
void | ClearVariableScaling () | ||||
Clears the scaling factors for decision variables. More... | |||||
Remove costs, constraints or callbacks. | |||||
Removes costs, constraints or visualization callbacks from this program. If this program contains multiple costs/constraints/callbacks objects matching the given argument, then all of these costs/constraints/callbacks are removed. If this program doesn't contain the specified cost/constraint/callback, then the code does nothing. We regard two costs/constraints/callbacks being equal, if their evaluators point to the same object, and the associated variables are also the same.
| |||||
int | RemoveCost (const Binding< Cost > &cost) | ||||
Removes cost from this mathematical program. More... | |||||
int | RemoveConstraint (const Binding< Constraint > &constraint) | ||||
Removes constraint from this mathematical program. More... | |||||
int | RemoveVisualizationCallback (const Binding< VisualizationCallback > &callback) | ||||
Removes callback from this mathematical program. More... | |||||
Static Public Member Functions | |
template<typename F > | |
static std::shared_ptr< Cost > | MakeCost (F &&f) |
Convert an input of type F to a FunctionCost object. More... | |
Static Public Attributes | |
static constexpr double | kGlobalInfeasibleCost |
The optimal cost is +∞ when the problem is globally infeasible. More... | |
static constexpr double | kUnboundedCost |
The optimal cost is -∞ when the problem is unbounded. More... | |
using VarType = symbolic::Variable::Type |
|
strong |
Types of non-negative polynomial that can be found through conic optimization.
We currently support SOS, SDSOS and DSOS. For more information about these polynomial types, please refer to "DSOS and SDSOS Optimization: More Tractable Alternatives to Sum of Squares and Semidefinite Optimization" by Amir Ali Ahmadi and Anirudha Majumdar, with arXiv link https://arxiv.org/abs/1706.02586
Enumerator | |
---|---|
kSos | A sum-of-squares polynomial. |
kSdsos | A scaled-diagonally dominant sum-of-squares polynomial. |
kDsos | A diagonally dominant sum-of-squares polynomial. |
|
delete |
|
delete |
|
virtual |
Binding<QuadraticCost> Add2NormSquaredCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const VariableRefList & | vars | ||
) |
Adds a quadratic cost of the form |Ax-b|²=(Ax-b)ᵀ(Ax-b)
Binding<QuadraticCost> Add2NormSquaredCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a quadratic cost of the form |Ax-b|²=(Ax-b)ᵀ(Ax-b)
Binding<BoundingBoxConstraint> AddBoundingBoxConstraint | ( | const Eigen::Ref< const Eigen::VectorXd > & | lb, |
const Eigen::Ref< const Eigen::VectorXd > & | ub, | ||
const VariableRefList & | vars | ||
) |
AddBoundingBoxConstraint.
Adds bounding box constraints referencing potentially a subset of the decision variables (defined in the vars parameter). Example
Binding<BoundingBoxConstraint> AddBoundingBoxConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | lb, |
const Eigen::Ref< const Eigen::MatrixXd > & | ub, | ||
const Eigen::Ref< const MatrixXDecisionVariable > & | vars | ||
) |
Adds bounding box constraints referencing potentially a subset of the decision variables.
lb | The lower bound. |
ub | The upper bound. |
vars | Will imposes constraint lb(i, j) <= vars(i, j) <= ub(i, j). |
Binding<BoundingBoxConstraint> AddBoundingBoxConstraint | ( | double | lb, |
double | ub, | ||
const symbolic::Variable & | var | ||
) |
Adds bounds for a single variable.
lb | Lower bound. |
ub | Upper bound. |
var | The decision variable. |
Binding<BoundingBoxConstraint> AddBoundingBoxConstraint | ( | double | lb, |
double | ub, | ||
const VariableRefList & | vars | ||
) |
Adds the same scalar lower and upper bound to every variable in the list.
lb | Lower bound. |
ub | Upper bound. |
vars | The decision variables. |
std::enable_if_t< std::is_same_v<typename Derived::Scalar, symbolic::Variable> && Derived::ColsAtCompileTime == 1, Binding<BoundingBoxConstraint> > AddBoundingBoxConstraint | ( | double | lb, |
double | ub, | ||
const Eigen::MatrixBase< Derived > & | vars | ||
) |
Adds the same scalar lower and upper bound to every variable in vars
.
Derived | An Eigen Vector type with Variable as the scalar type. |
lb | Lower bound. |
ub | Upper bound. |
vars | The decision variables. |
std::enable_if_t< std::is_same_v<typename Derived::Scalar, symbolic::Variable> && Derived::ColsAtCompileTime != 1, Binding<BoundingBoxConstraint> > AddBoundingBoxConstraint | ( | double | lb, |
double | ub, | ||
const Eigen::MatrixBase< Derived > & | vars | ||
) |
Adds the same scalar lower and upper bound to every variable in vars
.
Derived | An Eigen::Matrix with Variable as the scalar type. The matrix has unknown number of columns at compile time, or has more than one column. |
lb | Lower bound. |
ub | Upper bound. |
vars | The decision variables. |
Binding<Constraint> AddConstraint | ( | const Binding< Constraint > & | binding | ) |
Adds a generic constraint to the program.
This should only be used if a more specific type of constraint is not available, as it may require the use of a significantly more expensive solver.
binding.evaluator()->num_constraints()
== 0, then this constraint is not added into the MathematicalProgram. We return binding
directly. Binding<Constraint> AddConstraint | ( | const symbolic::Expression & | e, |
double | lb, | ||
double | ub | ||
) |
Adds one row of constraint lb <= e <= ub where e
is a symbolic expression.
std::exception | if
|
e | A symbolic expression of the decision variables. |
lb | A scalar, the lower bound. |
ub | A scalar, the upper bound. |
The resulting constraint may be a BoundingBoxConstraint, LinearConstraint, LinearEqualityConstraint, QuadraticConstraint, or ExpressionConstraint, depending on the arguments. Constraints of the form x == 1 (which could be created as a BoundingBoxConstraint or LinearEqualityConstraint) will be constructed as a LinearEqualityConstraint.
Binding<Constraint> AddConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | v, |
const Eigen::Ref< const Eigen::MatrixXd > & | lb, | ||
const Eigen::Ref< const Eigen::MatrixXd > & | ub | ||
) |
Binding< Constraint > AddConstraint | ( | const symbolic::Formula & | f | ) |
Add a constraint represented by a symbolic formula to the program.
The input formula f
can be of the following forms:
Note that first two cases might return an object of Binding<BoundingBoxConstraint>, Binding<LinearConstraint>, or Binding<ExpressionConstraint>, depending on f
. Also the third case might return an object of Binding<LinearEqualityConstraint> or Binding<ExpressionConstraint>.
It throws an exception if
f
is not matched with one of the above patterns. Especially, strict inequalities (<, >) are not allowed.f
is either a trivial constraint such as "1 <= 2" or an unsatisfiable constraint such as "2 <= 1".e1
and e2
where f
= e1 ≃ e2. We allow e1
and e2
to be infinite but only if there are no other terms. For example, x <= ∞
is allowed. However, x - ∞ <= 0
is not allowed because x ↦ ∞
introduces nan
in the evaluation.This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
A common use-case of this function is to add a constraint with the element-wise comparison between two Eigen matrices, using A.array() <= B.array()
. See the following example.
A formula in formulas
can be of the following forms:
It throws an exception if AddConstraint(const symbolic::Formula& f) throws an exception for f ∈ formulas
.
Derived | Eigen::Matrix or Eigen::Array with Formula as the Scalar. |
std::enable_if_t< is_eigen_scalar_same<Derived, symbolic::Formula>::value, Binding<Constraint> > AddConstraint | ( | const Eigen::DenseBase< Derived > & | formulas | ) |
auto AddConstraint | ( | std::shared_ptr< C > | con, |
const VariableRefList & | vars | ||
) |
Adds a generic constraint to the program.
This should only be used if a more specific type of constraint is not available, as it may require the use of a significantly more expensive solver.
auto AddConstraint | ( | std::shared_ptr< C > | con, |
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a generic constraint to the program.
This should only be used if a more specific type of constraint is not available, as it may require the use of a significantly more expensive solver.
Binding<LinearConstraint> AddConstraint | ( | const Binding< LinearConstraint > & | binding | ) |
Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter).
Binding<LinearEqualityConstraint> AddConstraint | ( | const Binding< LinearEqualityConstraint > & | binding | ) |
Adds linear equality constraints referencing potentially a subset of the decision variables.
Binding<BoundingBoxConstraint> AddConstraint | ( | const Binding< BoundingBoxConstraint > & | binding | ) |
Adds bounding box constraints referencing potentially a subest of the decision variables.
binding | Binds a BoundingBoxConstraint with some decision variables, such that binding.evaluator()->lower_bound()(i) <= binding.variables()(i) <= binding.evaluator().upper_bound()(i) |
Binding<QuadraticConstraint> AddConstraint | ( | const Binding< QuadraticConstraint > & | binding | ) |
Adds quadratic constraint.
The quadratic constraint is of the form lb ≤ .5 xᵀQx + bᵀx ≤ ub where x
might be a subset of the decision variables in this MathematicalProgram. Notice that if your quadratic constraint is convex, and you intend to solve the problem with a convex solver (like Mosek), then it is better to reformulate it with a second order cone constraint. See https://docs.mosek.com/10.1/capi/prob-def-quadratic.html#a-recommendation for an explanation.
Binding<LorentzConeConstraint> AddConstraint | ( | const Binding< LorentzConeConstraint > & | binding | ) |
Adds Lorentz cone constraint referencing potentially a subset of the decision variables.
The linear expression \( z=Ax+b \) is in the Lorentz cone. A vector \( z \in\mathbb{R}^n \) is in the Lorentz cone, if
\[ z_0 \ge \sqrt{z_1^2 + ... + z_{n-1}^2} \]
Binding<RotatedLorentzConeConstraint> AddConstraint | ( | const Binding< RotatedLorentzConeConstraint > & | binding | ) |
Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables.
The linear expression \( z=Ax+b \) is in rotated Lorentz cone. A vector \( z \in\mathbb{R}^n \) is in the rotated Lorentz cone, if
\[ z_0z_1 \ge z_2^2 + ... + z_{n-1}^2 \]
Binding<LinearComplementarityConstraint> AddConstraint | ( | const Binding< LinearComplementarityConstraint > & | binding | ) |
Adds a linear complementarity constraints referencing a subset of the decision variables.
Binding<PositiveSemidefiniteConstraint> AddConstraint | ( | const Binding< PositiveSemidefiniteConstraint > & | binding | ) |
Adds a positive semidefinite constraint on a symmetric matrix.
Binding<PositiveSemidefiniteConstraint> AddConstraint | ( | std::shared_ptr< PositiveSemidefiniteConstraint > | con, |
const Eigen::Ref< const MatrixXDecisionVariable > & | symmetric_matrix_var | ||
) |
Adds a positive semidefinite constraint on a symmetric matrix.
Binding<LinearMatrixInequalityConstraint> AddConstraint | ( | const Binding< LinearMatrixInequalityConstraint > & | binding | ) |
Adds a linear matrix inequality constraint to the program.
Binding<ExponentialConeConstraint> AddConstraint | ( | const Binding< ExponentialConeConstraint > & | binding | ) |
Adds the exponential cone constraint that z = binding.evaluator()->A() * binding.variables() + binding.evaluator()->b() should be in the exponential cone.
Namely {(z₀, z₁, z₂) | z₀ ≥ z₁ * exp(z₂ / z₁), z₁ > 0}.
binding | The binding of ExponentialConeConstraint and its bound variables. |
Adds a generic cost to the optimization program.
auto AddCost | ( | const std::shared_ptr< C > & | obj, |
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a cost type to the optimization program.
obj | The added objective. |
vars | The decision variables on which the cost depend. |
auto AddCost | ( | const std::shared_ptr< C > & | obj, |
const VariableRefList & | vars | ||
) |
Adds a generic cost to the optimization program.
obj | The added objective. |
vars | The decision variables on which the cost depend. |
std::enable_if_t<internal::is_cost_functor_candidate<F>::value, Binding<Cost> > AddCost | ( | F && | f, |
const VariableRefList & | vars | ||
) |
Adds a cost to the optimization program on a list of variables.
F | it should define functions numInputs, numOutputs and eval. Check |
std::enable_if_t<internal::is_cost_functor_candidate<F>::value, Binding<Cost> > AddCost | ( | F && | f, |
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a cost to the optimization program on an Eigen::Vector containing decision variables.
F | Type that defines functions numInputs, numOutputs and eval. |
std::enable_if_t<internal::assert_if_is_constraint<F>::value, Binding<Cost> > AddCost | ( | F && | , |
Vars && | |||
) |
Statically assert if a user inadvertently passes a binding-compatible Constraint.
F | The type to check. |
Binding<LinearCost> AddCost | ( | const Binding< LinearCost > & | binding | ) |
Adds a cost term of the form c'*x.
Applied to a subset of the variables and pushes onto the linear cost data structure.
Binding<QuadraticCost> AddCost | ( | const Binding< QuadraticCost > & | binding | ) |
Adds a cost term of the form 0.5*x'*Q*x + b'x.
Applied to subset of the variables and pushes onto the quadratic cost data structure.
Binding<L2NormCost> AddCost | ( | const Binding< L2NormCost > & | binding | ) |
Adds an L2 norm cost |Ax+b|₂ (notice this cost is not quadratic since we don't take the square of the L2 norm).
Refer to AddL2NormCost for more details.
Binding<Cost> AddCost | ( | const symbolic::Expression & | e | ) |
Adds a cost in the symbolic form.
void AddDecisionVariables | ( | const Eigen::Ref< const MatrixXDecisionVariable > & | decision_variables | ) |
Appends new variables to the end of the existing variables.
decision_variables | The newly added decision_variables. |
decision_variables
should not intersect with the existing indeterminates in the optimization program. std::exception | if the preconditions are not satisfied. |
std::vector<Binding<LinearEqualityConstraint> > AddEqualityConstraintBetweenPolynomials | ( | const symbolic::Polynomial & | p1, |
const symbolic::Polynomial & | p2 | ||
) |
Constraining that two polynomials are the same (i.e., they have the same coefficients for each monomial).
This function is often used in sum-of-squares optimization. We will impose the linear equality constraint that the coefficient of a monomial in p1
is the same as the coefficient of the same monomial in p2
.
p1 | Note that p1's indeterminates should have been registered as indeterminates in this MathematicalProgram object, and p1's coefficients are affine functions of decision variables in this MathematicalProgram object. |
p2 | Note that p2's indeterminates should have been registered as indeterminates in this MathematicalProgram object, and p2's coefficients are affine functions of decision variables in this MathematicalProgram object. |
Reparse
to enforce p1
and p2
to have this MathematicalProgram's indeterminates. Binding<ExponentialConeConstraint> AddExponentialConeConstraint | ( | const Eigen::Ref< const Eigen::SparseMatrix< double >> & | A, |
const Eigen::Ref< const Eigen::Vector3d > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds an exponential cone constraint, that z = A * vars + b should be in the exponential cone.
Namely {z₀, z₁, z₂ | z₀ ≥ z₁ * exp(z₂ / z₁), z₁ > 0}.
A | The A matrix in the documentation above. A must have 3 rows. |
b | The b vector in the documentation above. |
vars | The variables bound with this constraint. |
Binding<ExponentialConeConstraint> AddExponentialConeConstraint | ( | const Eigen::Ref< const Vector3< symbolic::Expression >> & | z | ) |
Add the constraint that z is in the exponential cone.
z | The expression in the exponential cone. |
z
is a linear expression of the decision variables. int AddIndeterminate | ( | const symbolic::Variable & | new_indeterminate | ) |
Adds indeterminate.
This method appends an indeterminate to the end of the program's old indeterminates, if new_indeterminate
is not already in the program's old indeterminates.
new_indeterminate | The indeterminate to be appended to the program's old indeterminates. |
new_indeterminate
should not intersect with the program's decision variables. void AddIndeterminates | ( | const Eigen::Ref< const MatrixXIndeterminate > & | new_indeterminates | ) |
Adds indeterminates.
This method appends some indeterminates to the end of the program's old indeterminates.
new_indeterminates | The indeterminates to be appended to the program's old indeterminates. |
new_indeterminates
should not intersect with the program's old decision variables. void AddIndeterminates | ( | const symbolic::Variables & | new_indeterminates | ) |
Adds indeterminates.
This method appends some indeterminates to the end of the program's old indeterminates.
new_indeterminates | The indeterminates to be appended to the program's old indeterminates. |
new_indeterminates
should not intersect with the program's old decision variables. Binding<L2NormCost> AddL2NormCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds an L2 norm cost |Ax+b|₂ (notice this cost is not quadratic since we don't take the square of the L2 norm).
Binding<L2NormCost> AddL2NormCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const VariableRefList & | vars | ||
) |
Adds an L2 norm cost |Ax+b|₂ (notice this cost is not quadratic since we don't take the square of the L2 norm)
Binding<L2NormCost> AddL2NormCost | ( | const symbolic::Expression & | e, |
double | psd_tol = 1e-8 , |
||
double | coefficient_tol = 1e-8 |
||
) |
Adds an L2 norm cost |Ax+b|₂ from a symbolic expression which can be decomposed into sqrt((Ax+b)'(Ax+b)).
See symbolic::DecomposeL2NormExpression for details on the tolerance parameters.
std::exception | if e cannot be decomposed into an L2 norm. |
std::tuple<symbolic::Variable, Binding<LinearCost>, Binding<LorentzConeConstraint> > AddL2NormCostUsingConicConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds an L2 norm cost min |Ax+b|₂ as a linear cost min s on the slack variable s, together with a Lorentz cone constraint s ≥ |Ax+b|₂ Many conic optimization solvers (Gurobi, MOSEK™, SCS, etc) natively prefers this form of linear cost + conic constraints.
So if you are going to use one of these conic solvers, then add the L2 norm cost using this function instead of AddL2NormCost().
s
is the slack variable (with variable name string as "slack"), linear_cost
is the cost on s
, and lorentz_cone_constraint
is the constraint s≥|Ax+b|₂ Binding<LinearComplementarityConstraint> AddLinearComplementarityConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | M, |
const Eigen::Ref< const Eigen::VectorXd > & | q, | ||
const VariableRefList & | vars | ||
) |
Adds a linear complementarity constraints referencing a subset of the decision variables.
Binding<LinearComplementarityConstraint> AddLinearComplementarityConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | M, |
const Eigen::Ref< const Eigen::VectorXd > & | q, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a linear complementarity constraints referencing a subset of the decision variables.
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | lb, | ||
const Eigen::Ref< const Eigen::VectorXd > & | ub, | ||
const VariableRefList & | vars | ||
) |
Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter).
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::SparseMatrix< double > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | lb, | ||
const Eigen::Ref< const Eigen::VectorXd > & | ub, | ||
const VariableRefList & | vars | ||
) |
Adds sparse linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter).
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | lb, | ||
const Eigen::Ref< const Eigen::VectorXd > & | ub, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter).
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::SparseMatrix< double > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | lb, | ||
const Eigen::Ref< const Eigen::VectorXd > & | ub, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds sparse linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter).
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::Ref< const Eigen::RowVectorXd > & | a, |
double | lb, | ||
double | ub, | ||
const VariableRefList & | vars | ||
) |
Adds one row of linear constraint referencing potentially a subset of the decision variables (defined in the vars parameter).
lb <= a*vars <= ub
a | A row vector. |
lb | A scalar, the lower bound. |
ub | A scalar, the upper bound. |
vars | The decision variables on which to impose the linear constraint. |
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::Ref< const Eigen::RowVectorXd > & | a, |
double | lb, | ||
double | ub, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds one row of linear constraint referencing potentially a subset of the decision variables (defined in the vars parameter).
lb <= a*vars <= ub
a | A row vector. |
lb | A scalar, the lower bound. |
ub | A scalar, the upper bound. |
vars | The decision variables on which to impose the linear constraint. |
Binding<LinearConstraint> AddLinearConstraint | ( | const symbolic::Expression & | e, |
double | lb, | ||
double | ub | ||
) |
Adds one row of linear constraint lb <= e <= ub where e
is a symbolic expression.
std::exception | if
|
e | A linear symbolic expression in the form of c0 + c1 * v1 + ... + cn * vn where c_i is a constant and @v_i is a variable. |
lb | A scalar, the lower bound. |
ub | A scalar, the upper bound. |
Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | v, |
const Eigen::Ref< const Eigen::MatrixXd > & | lb, | ||
const Eigen::Ref< const Eigen::MatrixXd > & | ub | ||
) |
Adds linear constraints represented by symbolic expressions to the program.
It throws if @v includes a non-linear expression or lb <= v <= ub
includes trivial/unsatisfiable constraints.
Binding<LinearConstraint> AddLinearConstraint | ( | const symbolic::Formula & | f | ) |
Add a linear constraint represented by a symbolic formula to the program.
The input formula f
can be of the following forms:
Note that first two cases might return an object of Binding<BoundingBoxConstraint> depending on f
. Also the third case returns an object of Binding<LinearEqualityConstraint>.
It throws an exception if
f
is not matched with one of the above patterns. Especially, strict inequalities (<, >) are not allowed.f
includes a non-linear expression.f
is either a trivial constraint such as "1 <= 2" or an unsatisfiable constraint such as "2 <= 1".e1
and e2
where f
= e1 ≃ e2. We allow e1
and e2
to be infinite but only if there are no other terms. For example, x <= ∞
is allowed. However, x - ∞ <= 0
is not allowed because x ↦ ∞
introduces nan
in the evaluation. Binding<LinearConstraint> AddLinearConstraint | ( | const Eigen::Ref< const Eigen::Array< symbolic::Formula, Eigen::Dynamic, Eigen::Dynamic >> & | formulas | ) |
Add a linear constraint represented by an Eigen::Array<symbolic::Formula> to the program.
A common use-case of this function is to add a linear constraint with the element-wise comparison between two Eigen matrices, using A.array() <= B.array()
. See the following example.
A formula in formulas
can be of the following forms:
It throws an exception if AddLinearConstraint(const symbolic::Formula& f) throws an exception for f ∈ formulas
.
Derived | An Eigen Array type of Formula. |
Binding<LinearCost> AddLinearCost | ( | const symbolic::Expression & | e | ) |
Adds a linear cost term of the form a'*x + b.
e | A linear symbolic expression. |
Binding<LinearCost> AddLinearCost | ( | const Eigen::Ref< const Eigen::VectorXd > & | a, |
double | b, | ||
const VariableRefList & | vars | ||
) |
Adds a linear cost term of the form a'*x + b.
Applied to a subset of the variables and pushes onto the linear cost data structure.
Binding<LinearCost> AddLinearCost | ( | const Eigen::Ref< const Eigen::VectorXd > & | a, |
double | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a linear cost term of the form a'*x + b.
Applied to a subset of the variables and pushes onto the linear cost data structure.
Binding<LinearCost> AddLinearCost | ( | const Eigen::Ref< const Eigen::VectorXd > & | a, |
const VarType & | vars | ||
) |
Adds a linear cost term of the form a'*x.
Applied to a subset of the variables and pushes onto the linear cost data structure.
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const symbolic::Expression & | e, |
double | b | ||
) |
Adds one row of linear constraint e = b where e
is a symbolic expression.
std::exception | if
|
e | A linear symbolic expression in the form of c0 + c1 * x1 + ... + cn * xn where c_i is a constant and @x_i is a variable. |
b | A scalar. |
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const symbolic::Formula & | f | ) |
Adds a linear equality constraint represented by a symbolic formula to the program.
The input formula f
is either an equality formula (e1 == e2
) or a conjunction of equality formulas.
It throws an exception if
f
is neither an equality formula nor a conjunction of equalities.f
includes a non-linear expression. std::enable_if_t< is_eigen_vector_expression_double_pair<DerivedV, DerivedB>::value, Binding<LinearEqualityConstraint> > AddLinearEqualityConstraint | ( | const Eigen::MatrixBase< DerivedV > & | v, |
const Eigen::MatrixBase< DerivedB > & | b | ||
) |
Adds linear equality constraints \( v = b \), where v(i)
is a symbolic linear expression.
std::exception | if
|
DerivedV | An Eigen Matrix type of Expression. A column vector. |
DerivedB | An Eigen Matrix type of double. A column vector. |
v | v(i) is a linear symbolic expression in the form of c0 + c1 * x1 + ... + cn * xn where ci is a constant and @xi is a variable. |
b | A vector of doubles. |
std::enable_if_t< is_eigen_nonvector_expression_double_pair<DerivedV, DerivedB>::value, Binding<LinearEqualityConstraint> > AddLinearEqualityConstraint | ( | const Eigen::MatrixBase< DerivedV > & | V, |
const Eigen::MatrixBase< DerivedB > & | B, | ||
bool | lower_triangle = false |
||
) |
Adds a linear equality constraint for a matrix of linear expression V
, such that V(i, j) = B(i, j).
If V is a symmetric matrix, then the user may only want to constrain the lower triangular part of V. This function is meant to provide convenience to the user, it incurs additional copy and memory allocation. For faster speed, add each column of the matrix equality in a for loop.
DerivedV | An Eigen Matrix type of Expression. The number of columns at compile time should not be 1. |
DerivedB | An Eigen Matrix type of double. |
V | An Eigen Matrix of symbolic expressions. V(i, j) should be a linear expression. |
B | An Eigen Matrix of doubles. |
lower_triangle | If true, then only the lower triangular part of V is constrained, otherwise the whole matrix V is constrained. Default: is false. |
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Aeq, |
const Eigen::Ref< const Eigen::VectorXd > & | beq, | ||
const VariableRefList & | vars | ||
) |
AddLinearEqualityConstraint.
Adds linear equality constraints referencing potentially a subset of the decision variables.
Example: to add two equality constraints which only depend on two of the elements of x, you could use
The code above imposes constraints
\[-x(2) + 2x(5) = 1 \]
\[ x(2) + x(5) = 3 \]
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const Eigen::SparseMatrix< double > & | Aeq, |
const Eigen::Ref< const Eigen::VectorXd > & | beq, | ||
const VariableRefList & | vars | ||
) |
AddLinearEqualityConstraint.
Adds linear equality constraints referencing potentially a subset of the decision variables using a sparse A matrix.
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Aeq, |
const Eigen::Ref< const Eigen::VectorXd > & | beq, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
AddLinearEqualityConstraint.
Adds linear equality constraints referencing potentially a subset of the decision variables.
Example: to add two equality constraints which only depend on two of the elements of x, you could use
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const Eigen::SparseMatrix< double > & | Aeq, |
const Eigen::Ref< const Eigen::VectorXd > & | beq, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
AddLinearEqualityConstraint.
Adds linear equality constraints referencing potentially a subset of the decision variables using a sparse A matrix.
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const Eigen::Ref< const Eigen::RowVectorXd > & | a, |
double | beq, | ||
const VariableRefList & | vars | ||
) |
Adds one row of linear equality constraint referencing potentially a subset of decision variables.
\[ ax = beq \]
a | A row vector. |
beq | A scalar. |
vars | The decision variables on which the constraint is imposed. |
Binding<LinearEqualityConstraint> AddLinearEqualityConstraint | ( | const Eigen::Ref< const Eigen::RowVectorXd > & | a, |
double | beq, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds one row of linear equality constraint referencing potentially a subset of decision variables.
\[ ax = beq \]
a | A row vector. |
beq | A scalar. |
vars | The decision variables on which the constraint is imposed. |
Binding<LinearMatrixInequalityConstraint> AddLinearMatrixInequalityConstraint | ( | std::vector< Eigen::MatrixXd > | F, |
const VariableRefList & | vars | ||
) |
Adds a linear matrix inequality constraint to the program.
Binding<LinearMatrixInequalityConstraint> AddLinearMatrixInequalityConstraint | ( | std::vector< Eigen::MatrixXd > | F, |
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a linear matrix inequality constraint to the program.
std::tuple<Binding<LinearConstraint>, VectorX<symbolic::Variable>, MatrixX<symbolic::Expression> > AddLogDeterminantLowerBoundConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | X, |
double | lower | ||
) |
Impose the constraint log(det(X)) >= lower.
See log_determinant for more details.
X | A symmetric positive semidefinite matrix X. |
lower | The lower bound of log(det(X)) |
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const symbolic::Formula & | f, |
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth , |
||
double | psd_tol = 1e-8 , |
||
double | coefficient_tol = 1e-8 |
||
) |
Adds a Lorentz cone constraint of the form Ax+b >= |Cx+d|₂ from a symbolic formula with one side which can be decomposed into sqrt((Cx+d)'(Cx+d)).
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
See symbolic::DecomposeL2NormExpression for details on the tolerance parameters, psd_tol
and coefficient_tol
. Consider using the overload which takes a vector of expressions to avoid the numerical decomposition.
std::exception | if f cannot be decomposed into a Lorentz cone. |
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const Eigen::Ref< const VectorX< symbolic::Expression >> & | v, |
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth |
||
) |
Adds Lorentz cone constraint referencing potentially a subset of the decision variables.
v | An Eigen::Vector of symbolic::Expression. Constraining that \[ v_0 \ge \sqrt{v_1^2 + ... + v_{n-1}^2} \] |
x+1 >= sqrt(y² + 2y + x² + 5), = sqrt((y+1)²+x²+2²)The user could call
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const symbolic::Expression & | linear_expression, |
const symbolic::Expression & | quadratic_expression, | ||
double | tol = 0 , |
||
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth |
||
) |
Adds Lorentz cone constraint on the linear expression v1 and quadratic expression v2, such that v1 >= sqrt(v2)
linear_expression | The linear expression v1. |
quadratic_expression | The quadratic expression v2. |
tol | The tolerance to determine if the matrix in v2 is positive semidefinite or not. |
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
binding | The newly added Lorentz cone constraint, together with the bound variables. |
v1
is a linear expression, in the form of c'*x + d.v2
is a quadratic expression, in the form of x'*Q*x + b'x + aAlso the quadratic expression has to be convex, namely Q is a positive semidefinite matrix, and the quadratic expression needs to be non-negative for any x.
std::exception | if the preconditions are not satisfied. |
Notice this constraint is equivalent to the vector [z;y] is within a Lorentz cone, where
z = v1 y = R * x + d
while (R, d) satisfies y'*y = x'*Q*x + b'*x + a For example, to add the Lorentz cone constraint
x+1 >= sqrt(y² + 2y + x² + 4),
the user could call
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const VariableRefList & | vars, | ||
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth |
||
) |
Adds Lorentz cone constraint referencing potentially a subset of the decision variables (defined in the vars parameter).
The linear expression \( z=Ax+b \) is in the Lorentz cone. A vector \( z \in\mathbb{R}^n \) is in the Lorentz cone, if
\[ z_0 \ge \sqrt{z_1^2 + ... + z_{n-1}^2} \]
A | A \(\mathbb{R}^{n\times m}\) matrix, whose number of columns equals to the size of the decision variables. |
b | A \(\mathbb{R}^n\) vector, whose number of rows equals to the size of the decision variables. |
vars | The list of \( m \) decision variables. |
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars, | ||
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth |
||
) |
Adds Lorentz cone constraint referencing potentially a subset of the decision variables (defined in the vars parameter).
The linear expression \( z=Ax+b \) is in the Lorentz cone. A vector \( z \in\mathbb{R}^n \) is in the Lorentz cone, if
\[ z_0 \ge \sqrt{z_1^2 + ... + z_{n-1}^2} \]
A | A \(\mathbb{R}^{n\times m}\) matrix, whose number of columns equals to the size of the decision variables. |
b | A \(\mathbb{R}^n\) vector, whose number of rows equals to the size of the decision variables. |
vars | The Eigen vector of \( m \) decision variables. |
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
For example, to add the Lorentz cone constraint
x+1 >= sqrt(y² + 2y + x² + 5) = sqrt((y+1)² + x² + 2²),
the user could call
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const VariableRefList & | vars, |
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth |
||
) |
Imposes that a vector \( x\in\mathbb{R}^m \) lies in Lorentz cone.
Namely
\[ x_0 \ge \sqrt{x_1^2 + .. + x_{m-1}^2} \]
vars | The stacked column of vars should lie within the Lorentz cone. |
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
Binding<LorentzConeConstraint> AddLorentzConeConstraint | ( | const Eigen::MatrixBase< VectorDecisionVariable< rows >> & | vars, |
LorentzConeConstraint::EvalType | eval_type = LorentzConeConstraint::EvalType::kConvexSmooth |
||
) |
Imposes that a vector \( x\in\mathbb{R}^m \) lies in Lorentz cone.
Namely
\[ x_0 \ge \sqrt{x_1^2 + .. + x_{m-1}^2} \]
vars | The stacked column of vars should lie within the Lorentz cone. |
eval_type | The evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details. |
Binding<LinearCost> AddMaximizeGeometricMeanCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorX< symbolic::Variable >> & | x | ||
) |
An overloaded version of maximize_geometric_mean.
Binding<LinearCost> AddMaximizeGeometricMeanCost | ( | const Eigen::Ref< const VectorX< symbolic::Variable >> & | x, |
double | c = 1.0 |
||
) |
An overloaded version of maximize_geometric_mean.
We add the cost to maximize the geometric mean of x, i.e., c*power(∏ᵢx(i), 1/n).
c | The positive coefficient of the geometric mean cost, Default: is 1. |
std::tuple<Binding<LinearCost>, VectorX<symbolic::Variable>, MatrixX<symbolic::Expression> > AddMaximizeLogDeterminantCost | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | X | ) |
Maximize the log determinant.
See log_determinant for more details.
X | A symmetric positive semidefinite matrix X, whose log(det(X)) will be maximized. |
Binding<Constraint> AddPolynomialConstraint | ( | const Eigen::Ref< const MatrixX< Polynomiald >> & | polynomials, |
const std::vector< Polynomiald::VarType > & | poly_vars, | ||
const Eigen::Ref< const Eigen::MatrixXd > & | lb, | ||
const Eigen::Ref< const Eigen::MatrixXd > & | ub, | ||
const VariableRefList & | vars | ||
) |
Adds a polynomial constraint to the program referencing a subset of the decision variables (defined in the vars parameter).
Binding<Constraint> AddPolynomialConstraint | ( | const Eigen::Ref< const MatrixX< Polynomiald >> & | polynomials, |
const std::vector< Polynomiald::VarType > & | poly_vars, | ||
const Eigen::Ref< const Eigen::MatrixXd > & | lb, | ||
const Eigen::Ref< const Eigen::MatrixXd > & | ub, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a polynomial constraint to the program referencing a subset of the decision variables (defined in the vars parameter).
Binding<PolynomialCost> AddPolynomialCost | ( | const symbolic::Expression & | e | ) |
Adds a cost term in the polynomial form.
e | A symbolic expression in the polynomial form. |
Binding<LinearConstraint> AddPositiveDiagonallyDominantDualConeMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | X | ) |
This is an overloaded variant of diagonally dominant dual cone constraint.
X | The matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X. |
Binding<LinearConstraint> AddPositiveDiagonallyDominantDualConeMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Variable >> & | X | ) |
This is an overloaded variant of diagonally dominant dual cone constraint.
X | The matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X. |
MatrixX<symbolic::Expression> AddPositiveDiagonallyDominantMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | X | ) |
Adds the constraint that a symmetric matrix is diagonally dominant with non-negative diagonal entries.
A symmetric matrix X is diagonally dominant with non-negative diagonal entries if X(i, i) >= ∑ⱼ |X(i, j)| ∀ j ≠ i namely in each row, the diagonal entry is larger than the sum of the absolute values of all other entries in the same row. A matrix being diagonally dominant with non-negative diagonals is a sufficient (but not necessary) condition of a matrix being positive semidefinite. Internally we will create a matrix Y as slack variables, such that Y(i, j) represents the absolute value |X(i, j)| ∀ j ≠ i. The diagonal entries Y(i, i) = X(i, i) The users can refer to "DSOS and SDSOS Optimization: More Tractable Alternatives to Sum of Squares and Semidefinite Optimization" by Amir Ali Ahmadi and Anirudha Majumdar, with arXiv link https://arxiv.org/abs/1706.02586
X | The matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X. |
Binding<PositiveSemidefiniteConstraint> AddPositiveSemidefiniteConstraint | ( | const Eigen::Ref< const MatrixXDecisionVariable > & | symmetric_matrix_var | ) |
Adds a positive semidefinite constraint on a symmetric matrix.
std::exception | in Debug mode if symmetric_matrix_var is not symmetric. |
symmetric_matrix_var | A symmetric MatrixDecisionVariable object. |
Binding<PositiveSemidefiniteConstraint> AddPositiveSemidefiniteConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | e | ) |
Adds a positive semidefinite constraint on a symmetric matrix of symbolic expressions e
.
We create a new symmetric matrix of variables M being positive semidefinite, with the linear equality constraint e == M.
e | Imposes constraint "e is positive semidefinite". |
For example, to add a constraint that
⌈x + 1 2x + 3 x+y⌉ |2x+ 3 2 0| is positive semidefinite ⌊x + y 0 x⌋
The user could call
Binding<PositiveSemidefiniteConstraint> AddPrincipalSubmatrixIsPsdConstraint | ( | const Eigen::Ref< const MatrixXDecisionVariable > & | symmetric_matrix_var, |
const std::set< int > & | minor_indices | ||
) |
Adds a constraint that the principal submatrix of a symmetric matrix composed of the indices in minor_indices is positive semidefinite.
symmetric_matrix_var
is a symmetric matrix. minor_indices
lie in the range [0, symmetric_matrix_var.rows() - 1]. symmetric_matrix_var | A symmetric MatrixDecisionVariable object. |
Binding<PositiveSemidefiniteConstraint> AddPrincipalSubmatrixIsPsdConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | e, |
const std::set< int > & | minor_indices | ||
) |
Adds a constraint the that the principal submatrix of a symmetric matrix of expressions composed of the indices in minor_indices is positive semidefinite.
symmetric_matrix_var
is a symmetric matrix. minor_indices
lie in the range [0, symmetric_matrix_var.rows() - 1]. e | Imposes constraint "e is positive semidefinite". |
Binding<RotatedLorentzConeConstraint> AddQuadraticAsRotatedLorentzConeConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
double | c, | ||
const Eigen::Ref< const VectorX< symbolic::Variable >> & | vars, | ||
double | psd_tol = 0. |
||
) |
Add the convex quadratic constraint 0.5xᵀQx + bᵀx + c <= 0 as a rotated Lorentz cone constraint [rᵀx+s, 1, Px+q] is in the rotated Lorentz cone.
When solving the optimization problem using conic solvers (like Mosek, Gurobi, SCS, etc), it is numerically preferable to impose the convex quadratic constraint as rotated Lorentz cone constraint. See https://docs.mosek.com/latest/capi/prob-def-quadratic.html#a-recommendation
exception | if this quadratic constraint is not convex (Q is not positive semidefinite) |
Q | The Hessian of the quadratic constraint. Should be positive semidefinite. |
b | The linear coefficient of the quadratic constraint. |
c | The constant term of the quadratic constraint. |
vars | x in the documentation above. |
psd_tol | If the minimal eigenvalue of Q is smaller than -psd_tol, then throw an exception. Default: = 0. |
Binding<QuadraticConstraint> AddQuadraticConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
double | lb, | ||
double | ub, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars, | ||
std::optional< QuadraticConstraint::HessianType > | hessian_type = std::nullopt |
||
) |
Adds quadratic constraint lb ≤ .5 xᵀQx + bᵀx ≤ ub Notice that if your quadratic constraint is convex, and you intend to solve the problem with a convex solver (like Mosek), then it is better to reformulate it with a second order cone constraint.
See https://docs.mosek.com/10.1/capi/prob-def-quadratic.html#a-recommendation for an explanation.
vars | x in the documentation above. |
hessian_type | Whether the Hessian is positive semidefinite, negative semidefinite or indefinite. Drake will check the type if hessian_type=std::nullopt. Specifying the hessian type will speed this method up. |
Binding<QuadraticConstraint> AddQuadraticConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
double | lb, | ||
double | ub, | ||
const VariableRefList & | vars, | ||
std::optional< QuadraticConstraint::HessianType > | hessian_type = std::nullopt |
||
) |
Adds quadratic constraint lb ≤ .5 xᵀQx + bᵀx ≤ ub Notice that if your quadratic constraint is convex, and you intend to solve the problem with a convex solver (like Mosek), then it is better to reformulate it with a second order cone constraint.
See https://docs.mosek.com/10.1/capi/prob-def-quadratic.html#a-recommendation for an explanation.
vars | x in the documentation above. |
hessian_type | Whether the Hessian is positive semidefinite, negative semidefinite or indefinite. Drake will check the type if hessian_type=std::nullopt. Specifying the hessian type will speed this method up. |
Binding<QuadraticConstraint> AddQuadraticConstraint | ( | const symbolic::Expression & | e, |
double | lb, | ||
double | ub, | ||
std::optional< QuadraticConstraint::HessianType > | hessian_type = std::nullopt |
||
) |
Overloads AddQuadraticConstraint, impose lb <= e <= ub where e
is a quadratic expression.
Notice that if your quadratic constraint is convex, and you intend to solve the problem with a convex solver (like Mosek), then it is better to reformulate it with a second order cone constraint. See https://docs.mosek.com/10.1/capi/prob-def-quadratic.html#a-recommendation for an explanation.
Binding<QuadraticCost> AddQuadraticCost | ( | const symbolic::Expression & | e, |
std::optional< bool > | is_convex = std::nullopt |
||
) |
Add a quadratic cost term of the form 0.5*x'*Q*x + b'*x + c.
e | A quadratic symbolic expression. |
is_convex | Whether the cost is already known to be convex. If is_convex=nullopt (the default), then Drake will determine if e is a convex quadratic cost or not. To improve the computation speed, the user can set is_convex if the user knows whether the cost is convex or not. |
std::exception | if the expression is not quadratic. |
Binding<QuadraticCost> AddQuadraticCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const VariableRefList & | vars, | ||
std::optional< bool > | is_convex = std::nullopt |
||
) |
Adds a cost term of the form 0.5*x'*Q*x + b'x.
Applied to subset of the variables.
is_convex | Whether the cost is already known to be convex. If is_convex=nullopt (the default), then Drake will determine if this is a convex quadratic cost or not (by checking if matrix Q is positive semidefinite or not). To improve the computation speed, the user can set is_convex if the user knows whether the cost is convex or not. |
Binding<QuadraticCost> AddQuadraticCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
double | c, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars, | ||
std::optional< bool > | is_convex = std::nullopt |
||
) |
Adds a cost term of the form 0.5*x'*Q*x + b'x + c Applied to subset of the variables.
is_convex | Whether the cost is already known to be convex. If is_convex=nullopt (the default), then Drake will determine if this is a convex quadratic cost or not. To improve the computation speed, the user can set is_convex if the user knows whether the cost is convex or not. |
Binding<QuadraticCost> AddQuadraticCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars, | ||
std::optional< bool > | is_convex = std::nullopt |
||
) |
Adds a cost term of the form 0.5*x'*Q*x + b'x Applied to subset of the variables.
is_convex | Whether the cost is already known to be convex. If is_convex=nullopt (the default), then Drake will determine if this is a convex quadratic cost or not. To improve the computation speed, the user can set is_convex if the user knows whether the cost is convex or not. |
Binding<QuadraticCost> AddQuadraticErrorCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | x_desired, | ||
const VariableRefList & | vars | ||
) |
Adds a cost term of the form (x-x_desired)'Q(x-x_desired).
Binding<QuadraticCost> AddQuadraticErrorCost | ( | const Eigen::Ref< const Eigen::MatrixXd > & | Q, |
const Eigen::Ref< const Eigen::VectorXd > & | x_desired, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a cost term of the form (x-x_desired)'Q(x-x_desired).
Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint | ( | const symbolic::Expression & | linear_expression1, |
const symbolic::Expression & | linear_expression2, | ||
const symbolic::Expression & | quadratic_expression, | ||
double | tol = 0 |
||
) |
Adds rotated Lorentz cone constraint on the linear expression v1, v2 and quadratic expression u, such that v1 * v2 >= u, v1 >= 0, v2 >= 0.
linear_expression1 | The linear expression v1. |
linear_expression2 | The linear expression v2. |
quadratic_expression | The quadratic expression u. |
tol | The tolerance to determine if the matrix in v2 is positive semidefinite or not. |
binding | The newly added rotated Lorentz cone constraint, together with the bound variables. |
linear_expression1
is a linear (affine) expression, in the form of v1 = c1'*x + d1.linear_expression2
is a linear (affine) expression, in the form of v2 = c2'*x + d2.quadratic_expression
is a quadratic expression, in the form of u = x'*Q*x + b'x + aAlso the quadratic expression has to be convex, namely Q is a positive semidefinite matrix, and the quadratic expression needs to be non-negative for any x.
std::exception | if the preconditions are not satisfied. |
For example, to add the rotated Lorentz cone constraint
(x+1)(x+y) >= x²+z²+2z+5 x+1 >= 0 x+y >= 0
The user could call
Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint | ( | const Eigen::Ref< const VectorX< symbolic::Expression >> & | v | ) |
Adds a constraint that a symbolic expression.
v | is in the rotated Lorentz cone, i.e., \[ v_0v_1 \ge v_2^2 + ... + v_{n-1}^2\\ v_0 \ge 0, v_1 \ge 0 \] |
v | A linear expression of variables, \( v = A x + b\), where \( A, b \) are given matrices of the correct size, \( x \) is the vector of decision variables. |
binding | The newly added rotated Lorentz cone constraint, together with the bound variables. |
For example, to add the rotated Lorentz cone constraint
(x+1)(x+y) >= x²+z²+2z+5 = x² + (z+1)² + 2² x+1 >= 0 x+y >= 0
The user could call
Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const VariableRefList & | vars | ||
) |
Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone.
A vector \( z \in\mathbb{R}^n \) is in the rotated Lorentz cone, if
\[ z_0z_1 \ge z_2^2 + ... + z_{n-1}^2 \]
where \( A\in\mathbb{R}^{n\times m}, b\in\mathbb{R}^n\) are given matrices.
A | A matrix whose number of columns equals to the size of the decision variables. |
b | A vector whose number of rows equals to the size of the decision variables. |
vars | The decision variables on which the constraint is imposed. |
Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint | ( | const Eigen::Ref< const Eigen::MatrixXd > & | A, |
const Eigen::Ref< const Eigen::VectorXd > & | b, | ||
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone.
A vector \( z \in\mathbb{R}^n \) is in the rotated Lorentz cone, if
\[ z_0z_1 \ge z_2^2 + ... + z_{n-1}^2 \]
where \( A\in\mathbb{R}^{n\times m}, b\in\mathbb{R}^n\) are given matrices.
A | A matrix whose number of columns equals to the size of the decision variables. |
b | A vector whose number of rows equals to the size of the decision variables. |
vars | The decision variables on which the constraint is imposed. |
Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint | ( | const VariableRefList & | vars | ) |
Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone.
Namely
\[ x_0 x_1 \ge x_2^2 + ... + x_{m-1}^2\\ x_0 \ge 0, x_1 \ge 0 \]
vars | The stacked column of vars lies in the rotated Lorentz cone. |
Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint | ( | const Eigen::MatrixBase< VectorDecisionVariable< rows >> & | vars | ) |
Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone.
Namely
\[ x_0 x_1 \ge x_2^2 + ... + x_{m-1}^2\\ x_0 \ge 0, x_1 \ge 0 \]
vars | The stacked column of vars lies in the rotated Lorentz cone. |
std::vector<Binding<RotatedLorentzConeConstraint> > AddScaledDiagonallyDominantDualConeMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | X | ) |
This is an overloaded variant of scaled diagonally dominant dual cone constraint.
X | The matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X. |
std::vector<Binding<RotatedLorentzConeConstraint> > AddScaledDiagonallyDominantDualConeMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Variable >> & | X | ) |
This is an overloaded variant of scaled diagonally dominant dual cone constraint.
X | The matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X. |
std::vector<std::vector<Matrix2<symbolic::Expression> > > AddScaledDiagonallyDominantMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Expression >> & | X | ) |
This is an overloaded variant of scaled diagonally dominant matrix constraint.
X | The matrix X to be constrained scaled diagonally dominant. X. |
[Mⁱʲ(i, i), Mⁱʲ(i, j)] [Mⁱʲ(i, j), Mⁱʲ(j, j)].Note that M[i][j](0, 1) = Mⁱʲ(i, j) = (X(i, j) + X(j, i)) / 2 for i >= j, M[i][j] is the zero matrix.
std::vector<std::vector<Matrix2<symbolic::Variable> > > AddScaledDiagonallyDominantMatrixConstraint | ( | const Eigen::Ref< const MatrixX< symbolic::Variable >> & | X | ) |
This is an overloaded variant of scaled diagonally dominant matrix constraint.
X | The symmetric matrix X to be constrained scaled diagonally dominant. |
MatrixXDecisionVariable AddSosConstraint | ( | const symbolic::Polynomial & | p, |
const Eigen::Ref< const VectorX< symbolic::Monomial >> & | monomial_basis, | ||
NonnegativePolynomial | type = NonnegativePolynomial::kSos , |
||
const std::string & | gram_name = "S" |
||
) |
Adds constraints that a given polynomial p
is a sums-of-squares (SOS), that is, p
can be decomposed into mᵀQm
, where m is the monomial_basis
.
It returns the coefficients matrix Q, which is positive semidefinite.
type | The type of the polynomial. Default: is kSos, but the user can also use kSdsos and kDsos. Refer to NonnegativePolynomial for details on different types of sos polynomials. |
gram_name | The name of the gram matrix for print out. |
Reparse
to enforce p
to have this MathematicalProgram's indeterminates if necessary. std::pair<MatrixXDecisionVariable, VectorX<symbolic::Monomial> > AddSosConstraint | ( | const symbolic::Polynomial & | p, |
NonnegativePolynomial | type = NonnegativePolynomial::kSos , |
||
const std::string & | gram_name = "S" |
||
) |
Adds constraints that a given polynomial p
is a sums-of-squares (SOS), that is, p
can be decomposed into mᵀQm
, where m is a monomial basis selected from the sparsity of p
.
It returns a pair of constraint bindings expressing:
type | The type of the polynomial. Default: is kSos, but the user can also use kSdsos and kDsos. Refer to NonnegativePolynomial for the details on different type of sos polynomials. |
gram_name | The name of the gram matrix for print out. |
Reparse
to enforce p
to have this MathematicalProgram's indeterminates if necessary. MatrixXDecisionVariable AddSosConstraint | ( | const symbolic::Expression & | e, |
const Eigen::Ref< const VectorX< symbolic::Monomial >> & | monomial_basis, | ||
NonnegativePolynomial | type = NonnegativePolynomial::kSos , |
||
const std::string & | gram_name = "S" |
||
) |
Adds constraints that a given symbolic expression e
is a sums-of-squares (SOS), that is, p
can be decomposed into mᵀQm
, where m is the monomial_basis
.
Note that it decomposes e
into a polynomial with respect to indeterminates()
in this mathematical program. It returns the coefficients matrix Q, which is positive semidefinite.
type | Refer to NonnegativePolynomial class documentation. |
gram_name | The name of the gram matrix for print out. |
std::pair<MatrixXDecisionVariable, VectorX<symbolic::Monomial> > AddSosConstraint | ( | const symbolic::Expression & | e, |
NonnegativePolynomial | type = NonnegativePolynomial::kSos , |
||
const std::string & | gram_name = "S" |
||
) |
Adds constraints that a given symbolic expression e
is a sums-of-squares (SOS), that is, e
can be decomposed into mᵀQm
.
Note that it decomposes e
into a polynomial with respect to indeterminates()
in this mathematical program. It returns a pair expressing:
type | Refer to NonnegativePolynomial class documentation. |
gram_name | The name of the gram matrix for print out. |
Binding<VisualizationCallback> AddVisualizationCallback | ( | const VisualizationCallback::CallbackFunction & | callback, |
const Eigen::Ref< const VectorXDecisionVariable > & | vars | ||
) |
Adds a callback method to visualize intermediate results of the optimization.
callback | a std::function that accepts an Eigen::Vector of doubles representing the bound decision variables. |
vars | the decision variables that should be passed to the callback. |
Binding<VisualizationCallback> AddVisualizationCallback | ( | const VisualizationCallback::CallbackFunction & | callback, |
const VariableRefList & | vars | ||
) |
Adds a callback method to visualize intermediate results of the optimization.
callback | a std::function that accepts an Eigen::Vector of doubles representing the for the bound decision variables. |
vars | the decision variables that should be passed to the callback. |
const std::vector<Binding<BoundingBoxConstraint> >& bounding_box_constraints | ( | ) | const |
Getter for all bounding box constraints.
bool CheckSatisfied | ( | const Binding< Constraint > & | binding, |
const Eigen::Ref< const Eigen::VectorXd > & | prog_var_vals, | ||
double | tol = 1e-6 |
||
) | const |
Evaluates CheckSatisfied for the constraint in binding
using the value of ALL of the decision variables in this program.
std::exception | if the size of prog_var_vals is invalid. |
bool CheckSatisfied | ( | const std::vector< Binding< Constraint >> & | bindings, |
const Eigen::Ref< const Eigen::VectorXd > & | prog_var_vals, | ||
double | tol = 1e-6 |
||
) | const |
Evaluates CheckSatisfied for the all of the constraints in binding
using the value of ALL of the decision variables in this program.
std::exception | if the size of prog_var_vals is invalid. |
bool CheckSatisfiedAtInitialGuess | ( | const Binding< Constraint > & | binding, |
double | tol = 1e-6 |
||
) | const |
Evaluates CheckSatisfied for the constraint in binding
at the initial guess.
bool CheckSatisfiedAtInitialGuess | ( | const std::vector< Binding< Constraint >> & | bindings, |
double | tol = 1e-6 |
||
) | const |
Evaluates CheckSatisfied for the all of the constraints in bindings
at the initial guess.
void ClearVariableScaling | ( | ) |
Clears the scaling factors for decision variables.
See Variable scaling for more information.
std::unique_ptr<MathematicalProgram> Clone | ( | ) | const |
Clones an optimization program.
The clone will be functionally equivalent to the source program with the same:
Note that this is currently a shallow clone. The costs and constraints are not themselves cloned.
new_prog. | The newly constructed mathematical program. |
const symbolic::Variable& decision_variable | ( | int | i | ) | const |
Getter for the decision variable with index i
in the program.
const std::unordered_map<symbolic::Variable::Id, int>& decision_variable_index | ( | ) | const |
Returns the mapping from a decision variable ID to its index in the vector containing all the decision variables in the mathematical program.
Eigen::Map<const VectorX<symbolic::Variable> > decision_variables | ( | ) | const |
Getter for all decision variables in the program.
std::enable_if_t<is_eigen_vector<DerivedX>::value, VectorX<typename DerivedX::Scalar> > EvalBinding | ( | const Binding< C > & | binding, |
const Eigen::MatrixBase< DerivedX > & | prog_var_vals | ||
) | const |
Evaluates the value of some binding, for some input value for all decision variables.
binding | A Binding whose variables are decision variables in this program. |
prog_var_vals | The value of all the decision variables in this program. |
std::exception | if the size of prog_var_vals is invalid. |
Eigen::VectorXd EvalBindingAtInitialGuess | ( | const Binding< C > & | binding | ) | const |
Evaluates the evaluator in binding
at the initial guess.
binding
at the initial guess. std::enable_if_t<is_eigen_vector<DerivedX>::value, VectorX<typename DerivedX::Scalar> > EvalBindings | ( | const std::vector< Binding< C >> & | bindings, |
const Eigen::MatrixBase< DerivedX > & | prog_var_vals | ||
) | const |
Evaluates a set of bindings (plural version of EvalBinding
).
bindings | List of bindings. |
prog | |
prog_var_vals | The value of all the decision variables in this program. |
std::exception | if the size of prog_var_vals is invalid. |
void EvalVisualizationCallbacks | ( | const Eigen::Ref< const Eigen::VectorXd > & | prog_var_vals | ) | const |
Evaluates all visualization callbacks registered with the MathematicalProgram.
prog_var_vals | The value of all the decision variables in this program. |
std::exception | if the size does not match. |
const std::vector<Binding<ExponentialConeConstraint> >& exponential_cone_constraints | ( | ) | const |
Getter for exponential cone constraints.
int FindDecisionVariableIndex | ( | const symbolic::Variable & | var | ) | const |
Returns the index of the decision variable.
Internally the solvers thinks all variables are stored in an array, and it accesses each individual variable using its index. This index is used when adding constraints and costs for each solver.
var
is a decision variable in the mathematical program, otherwise this function throws a runtime error.} std::vector<int> FindDecisionVariableIndices | ( | const Eigen::Ref< const VectorXDecisionVariable > & | vars | ) | const |
Returns the indices of the decision variables.
Internally the solvers thinks all variables are stored in an array, and it accesses each individual variable using its index. This index is used when adding constraints and costs for each solver.
vars
are decision variables in the mathematical program, otherwise this function throws a runtime error.} size_t FindIndeterminateIndex | ( | const symbolic::Variable & | var | ) | const |
Returns the index of the indeterminate.
Internally a solver thinks all indeterminates are stored in an array, and it accesses each individual indeterminate using its index. This index is used when adding constraints and costs for each solver.
var
is a indeterminate in the mathematical program, otherwise this function throws a runtime error. const std::vector<Binding<Constraint> >& generic_constraints | ( | ) | const |
Getter for all generic constraints.
std::vector<Binding<Constraint> > GetAllConstraints | ( | ) | const |
Getter for returning all constraints.
Getter returning all costs.
std::vector<Binding<LinearConstraint> > GetAllLinearConstraints | ( | ) | const |
Getter returning all linear constraints (both linear equality and inequality constraints).
Note that this does not include bounding box constraints, which are technically also linear.
std::enable_if_t<is_eigen_vector<DerivedX>::value, VectorX<typename DerivedX::Scalar> > GetBindingVariableValues | ( | const Binding< C > & | binding, |
const Eigen::MatrixBase< DerivedX > & | prog_var_vals | ||
) | const |
Given the value of all decision variables, namely this.decision_variable(i) takes the value prog_var_vals(i), returns the vector that contains the value of the variables in binding.variables().
binding | binding.variables() must be decision variables in this MathematicalProgram. |
prog_var_vals | The value of ALL the decision variables in this program. |
double GetInitialGuess | ( | const symbolic::Variable & | decision_variable | ) | const |
Gets the initial guess for a single variable.
decision_variable
has been registered in the optimization program. std::exception | if the pre condition is not satisfied. |
std::enable_if_t< std::is_same_v<typename Derived::Scalar, symbolic::Variable>, MatrixLikewise<double, Derived> > GetInitialGuess | ( | const Eigen::MatrixBase< Derived > & | decision_variable_mat | ) | const |
Gets the initial guess for some variables.
decision_variable_mat
has been registered in the optimization program. std::exception | if the pre condition is not satisfied. |
const std::unordered_map<std::string, double>& GetSolverOptionsDouble | ( | const SolverId & | solver_id | ) | const |
const std::unordered_map<std::string, std::string>& GetSolverOptionsStr | ( | const SolverId & | solver_id | ) | const |
Returns the mapping from a decision variable index to its scaling factor.
See Variable scaling for more information.
const symbolic::Variable& indeterminate | ( | int | i | ) | const |
Getter for the indeterminate with index i
in the program.
Eigen::Map<const VectorX<symbolic::Variable> > indeterminates | ( | ) | const |
Getter for all indeterminates in the program.
const std::unordered_map<symbolic::Variable::Id, int>& indeterminates_index | ( | ) | const |
Returns the mapping from an indeterminate ID to its index in the vector containing all the indeterminates in the mathematical program.
const Eigen::VectorXd& initial_guess | ( | ) | const |
Getter for the initial guess.
bool IsThreadSafe | ( | ) | const |
Returns whether it is safe to solve this mathematical program concurrently.
A mathematical program is safe to solve concurrently if all of its cost, constraints, and visualization callbacks are marked as thread safe.
const std::vector<Binding<L2NormCost> >& l2norm_costs | ( | ) | const |
Getter for l2norm costs.
const std::vector<Binding<LinearComplementarityConstraint> >& linear_complementarity_constraints | ( | ) | const |
Getter for all linear complementarity constraints.
const std::vector<Binding<LinearConstraint> >& linear_constraints | ( | ) | const |
Getter for linear inequality constraints.
Note that this does not include linear_equality_constraints() nor bounding_box_constraints(). See also GetAllLinearConstraints().
const std::vector<Binding<LinearCost> >& linear_costs | ( | ) | const |
Getter for linear costs.
const std::vector<Binding<LinearEqualityConstraint> >& linear_equality_constraints | ( | ) | const |
Getter for linear equality constraints.
Note that this only includes constraints that were added explicitly as LinearEqualityConstraint or which were added symbolically (and their equality constraint nature was uncovered). There may be bounding_box_constraints() and linear_constraints() whose lower bounds also equal their upper bounds.
const std::vector<Binding<LinearMatrixInequalityConstraint> >& linear_matrix_inequality_constraints | ( | ) | const |
Getter for linear matrix inequality constraints.
const std::vector<Binding<LorentzConeConstraint> >& lorentz_cone_constraints | ( | ) | const |
Getter for Lorentz cone constraints.
|
static |
Convert an input of type F
to a FunctionCost object.
F | This class should have functions numInputs(), numOutputs and eval(x, y). |
symbolic::Polynomial MakePolynomial | ( | const symbolic::Expression & | e | ) | const |
Creates a symbolic polynomial from the given expression e
.
It uses this MathematicalProgram's indeterminates()
in constructing the polynomial.
This method helps a user create a polynomial with the right set of indeterminates which are declared in this MathematicalProgram. We recommend users to use this method over an explicit call to Polynomial constructors to avoid a possible mismatch between this MathematicalProgram's indeterminates and the user-specified indeterminates (or unspecified, which then includes all symbolic variables in the expression e
). Consider the following example.
e = ax + bx + c
MP.indeterminates() = {x} MP.decision_variables() = {a, b}
MP.MakePolynomial(e)
create a polynomial, (a + b)x + c
. Here only x
is an indeterminate of this polynomial.symbolic::Polynomial(e)
returns ax + bx + c
where all variables {a, b, x}
are indeterminates. Note that this is problematic as its indeterminates, {a, b, x}
and the MathematicalProgram's decision variables, {a, b}
overlap.e
is a subset of the decision variables in MathematicalProgram. MatrixDecisionVariable<Rows, Cols> NewBinaryVariables | ( | int | rows, |
int | cols, | ||
const std::string & | name | ||
) |
Adds binary variables, appending them to an internal vector of any existing vars.
The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().
Rows | The number of rows in the new variables. |
Cols | The number of columns in the new variables. |
rows | The number of rows in the new variables. |
cols | The number of columns in the new variables. |
name | The commonly shared name of the new variables. |
Example:
This adds a 2 x 3 matrix decision variables into the program.
The name of the variable is only used for the user in order to ease readability.
MatrixDecisionVariable<Rows, Cols> NewBinaryVariables | ( | const std::string & | name = "b" | ) |
Adds a matrix of binary variables into the optimization program.
Rows | The number of rows in the newly added binary variables. |
Cols | The number of columns in the new variables. The default is 1. |
name | Each newly added binary variable will share the same name. The default name is "b". |
VectorXDecisionVariable NewBinaryVariables | ( | int | rows, |
const std::string & | name = "b" |
||
) |
Adds binary variables to this MathematicalProgram.
The new variables are viewed as a column vector, with size rows
x 1.
VectorXDecisionVariable NewContinuousVariables | ( | int | rows, |
const std::string & | name = "x" |
||
) |
Adds continuous variables, appending them to an internal vector of any existing vars.
The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().
rows | The number of rows in the new variables. |
name | The name of the newly added variables |
Example:
This adds a 2 x 1 vector containing decision variables into the program. The names of the variables are "x(0)" and "x(1)".
The name of the variable is only used for the user in order to ease readability.
MatrixDecisionVariable<Rows, Cols> NewContinuousVariables | ( | int | rows, |
int | cols, | ||
const std::string & | name = "X" |
||
) |
Adds continuous variables, appending them to an internal vector of any existing vars.
The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().
Rows | The number of rows of the new variables, in the compile time. |
Cols | The number of columns of the new variables, in the compile time. |
rows | The number of rows in the new variables. When Rows is not Eigen::Dynamic, rows is ignored. |
cols | The number of columns in the new variables. When Cols is not Eigen::Dynamic, cols is ignored. |
name | All variables will share the same name, but different index. |
Example:
This adds a 2 x 3 matrix decision variables into the program.
The name of the variable is only used for the user in order to ease readability.
MatrixDecisionVariable<Rows, Cols> NewContinuousVariables | ( | const std::string & | name = "X" | ) |
Adds continuous variables, appending them to an internal vector of any existing vars.
The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().
Rows | The number of rows in the new variables. |
Cols | The number of columns in the new variables. The default is 1. |
name | All variables will share the same name, but different index. |
Example:
This adds a 2 x 3 matrix decision variables into the program.
The name of the variable is only used for the user in order to ease readability.
std::tuple<symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable> NewEvenDegreeDsosPolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree | ||
) |
see even_degree_nonnegative_polynomial for details.
Variant that produces a DSOS polynomial. Same as NewEvenDegreeSosPolynomial, except the returned polynomial is diagonally dominant sum of squares (dsos).
symbolic::Polynomial NewEvenDegreeFreePolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree, | ||
const std::string & | coeff_name = "a" |
||
) |
Returns a free polynomial that only contains even degree monomials.
A monomial is even degree if its total degree (sum of all variables' degree) is even. For example, xy is an even degree monomial (degree 2) while x²y is not (degree 3).
indeterminates | The monomial basis is over these indeterminates. |
degree | The highest degree of the polynomial. |
coeff_name | The coefficients of the polynomial are decision variables with this name as a base. The variable name would be "a1", "a2", etc. |
std::tuple<symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable> NewEvenDegreeNonnegativePolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree, | ||
NonnegativePolynomial | type | ||
) |
See even_degree_nonnegative_polynomial for more details.
Variant that produces different non-negative polynomials depending on type
.
type | The returned polynomial p(x) can be either SOS, SDSOS or DSOS, depending on type . |
std::tuple<symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable> NewEvenDegreeSdsosPolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree | ||
) |
see even_degree_nonnegative_polynomial for details.
Variant that produces an SDSOS polynomial.
std::tuple<symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariable> NewEvenDegreeSosPolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree | ||
) |
See even_degree_nonnegative_polynomial for more details.
Variant that produces a SOS polynomial.
symbolic::Polynomial NewFreePolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree, | ||
const std::string & | coeff_name = "a" |
||
) |
Returns a free polynomial in a monomial basis over indeterminates
of a given degree
.
It uses coeff_name
to make new decision variables and use them as coefficients. For example, NewFreePolynomial({x₀, x₁}, 2)
returns a₀x₁² + a₁x₀x₁ + a₂x₀² + a₃x₁ + a₄x₀ + a₅.
MatrixIndeterminate<rows, cols> NewIndeterminates | ( | const std::array< std::string, rows *cols > & | names | ) |
Adds indeterminates, appending them to an internal vector of any existing indeterminates.
rows | The number of rows in the new indeterminates. |
cols | The number of columns in the new indeterminates. |
names | A vector of strings containing the name for each variable. |
Example:
This adds a 2 x 3 matrix indeterminates into the program.
The name of the indeterminates is only used for the user in order to ease readability.
VectorIndeterminate<rows> NewIndeterminates | ( | const std::array< std::string, rows > & | names | ) |
Adds indeterminates, appending them to an internal vector of any existing indeterminates.
rows | The number of rows in the new indeterminates. |
cols | The number of columns in the new indeterminates. |
names | A vector of strings containing the name for each variable. |
Example:
This adds a 2 vector indeterminates into the program.
The name of the indeterminates is only used for the user in order to ease readability.
MatrixIndeterminate<rows, cols> NewIndeterminates | ( | const std::string & | name = "X" | ) |
Adds indeterminates, appending them to an internal vector of any existing indeterminates.
rows | The number of rows in the new indeterminates. |
cols | The number of columns in the new indeterminates. |
names | A vector of strings containing the name for each variable. |
Example:
This adds a 2 x 3 matrix indeterminates into the program.
The name of the indeterminates is only used for the user in order to ease readability.
VectorIndeterminate<rows> NewIndeterminates | ( | const std::string & | name = "x" | ) |
Adds indeterminates to the program.
The name for all newly added indeterminates are set to name
. The default name is "x"
VectorXIndeterminate NewIndeterminates | ( | int | rows, |
const std::vector< std::string > & | names | ||
) |
Adds indeterminates to this MathematicalProgram.
VectorXIndeterminate NewIndeterminates | ( | int | rows, |
const std::string & | name = "x" |
||
) |
Adds indeterminates to this MathematicalProgram, with default name "x".
MatrixXIndeterminate NewIndeterminates | ( | int | rows, |
int | cols, | ||
const std::vector< std::string > & | names | ||
) |
Adds indeterminates, appending them to an internal vector of any existing vars.
rows | The number of rows in the new indeterminates. |
cols | The number of columns in the new indeterminates. |
names | A vector of strings containing the name for each variable. |
Example:
This adds a 2 x 3 matrix indeterminates into the program.
The name of the variable is only used for the user in order to ease readability.
MatrixXIndeterminate NewIndeterminates | ( | int | rows, |
int | cols, | ||
const std::string & | name = "X" |
||
) |
Adds indeterminates to this MathematicalProgram, with default name "X".
The new variables are returned and viewed as a matrix, with size rows
x cols
.
symbolic::Polynomial NewOddDegreeFreePolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree, | ||
const std::string & | coeff_name = "a" |
||
) |
Returns a free polynomial that only contains odd degree monomials.
A monomial is odd degree if its total degree (sum of all variables' degree) is even. For example, xy is not an odd degree monomial (degree 2) while x²y is (degree 3).
indeterminates | The monomial basis is over these indeterminates. |
degree | The highest degree of the polynomial. |
coeff_name | The coefficients of the polynomial are decision variables with this name as a base. The variable name would be "a1", "a2", etc. |
std::pair<symbolic::Polynomial, MatrixXDecisionVariable> NewSosPolynomial | ( | const Eigen::Ref< const VectorX< symbolic::Monomial >> & | monomial_basis, |
NonnegativePolynomial | type = NonnegativePolynomial::kSos , |
||
const std::string & | gram_name = "S" |
||
) |
Returns a pair of a SOS polynomial p = mᵀQm and the Gramian matrix Q, where m is the monomial
basis.
For example, NewSosPolynomial(Vector2<Monomial>{x,y})
returns a polynomial p = Q₍₀,₀₎x² + 2Q₍₁,₀₎xy + Q₍₁,₁₎y² and Q. Depending on the type of the polynomial, we will impose different constraint on the polynomial.
gram_name | The name of the gram matrix for print out. |
symbolic::Polynomial NewSosPolynomial | ( | const Eigen::Ref< const MatrixX< symbolic::Variable >> & | gramian, |
const Eigen::Ref< const VectorX< symbolic::Monomial >> & | monomial_basis, | ||
NonnegativePolynomial | type = NonnegativePolynomial::kSos |
||
) |
Overloads NewSosPolynomial, except the Gramian matrix Q is an input instead of an output.
std::pair<symbolic::Polynomial, MatrixXDecisionVariable> NewSosPolynomial | ( | const symbolic::Variables & | indeterminates, |
int | degree, | ||
NonnegativePolynomial | type = NonnegativePolynomial::kSos , |
||
const std::string & | gram_name = "S" |
||
) |
Overloads NewSosPolynomial.
Returns a pair of a SOS polynomial p = m(x)ᵀQm(x) of degree degree
and the Gramian matrix Q that should be PSD, where m(x) is the result of calling MonomialBasis(indeterminates, degree/2)
. For example, NewSosPolynomial({x}, 4)
returns a pair of a polynomial p = Q₍₀,₀₎x⁴ + 2Q₍₁,₀₎ x³ + (2Q₍₂,₀₎ + Q₍₁,₁₎)x² + 2Q₍₂,₁₎x + Q₍₂,₂₎ and Q.
type | Depending on the type of the polynomial, we will impose different constraint on the polynomial.
|
gram_name | The name of the gram matrix for print out. |
std::exception | if degree is not a positive even integer. |
MatrixXDecisionVariable NewSymmetricContinuousVariables | ( | int | rows, |
const std::string & | name = "Symmetric" |
||
) |
Adds a runtime sized symmetric matrix as decision variables to this MathematicalProgram.
The optimization will only use the stacked columns of the lower triangular part of the symmetric matrix as decision variables.
rows | The number of rows in the symmetric matrix. |
name | The name of the matrix. It is only used the for user to understand the optimization program. The default name is "Symmetric", and each variable will be named as Symmetric(0, 0) Symmetric(1, 0) ... Symmetric(rows-1, 0) Symmetric(1, 0) Symmetric(1, 1) ... Symmetric(rows-1, 1) ... Symmetric(rows-1,0) Symmetric(rows-1,1) ... Symmetric(rows-1, rows-1)Notice that the (i,j)'th entry and (j,i)'th entry has the same name. |
MatrixDecisionVariable<rows, rows> NewSymmetricContinuousVariables | ( | const std::string & | name = "Symmetric" | ) |
Adds a static sized symmetric matrix as decision variables to this MathematicalProgram.
The optimization will only use the stacked columns of the lower triangular part of the symmetric matrix as decision variables.
rows | The number of rows in the symmetric matrix. |
name | The name of the matrix. It is only used the for user to understand the optimization program. The default name is "Symmetric", and each variable will be named as Symmetric(0, 0) Symmetric(1, 0) ... Symmetric(rows-1, 0) Symmetric(1, 0) Symmetric(1, 1) ... Symmetric(rows-1, 1) ... Symmetric(rows-1,0) Symmetric(rows-1,1) ... Symmetric(rows-1, rows-1)Notice that the (i,j)'th entry and (j,i)'th entry has the same name. |
int num_indeterminates | ( | ) | const |
Gets the number of indeterminates in the optimization program.
int num_vars | ( | ) | const |
Getter for number of variables in the optimization program.
|
delete |
|
delete |
const std::vector<Binding<PositiveSemidefiniteConstraint> >& positive_semidefinite_constraints | ( | ) | const |
Getter for positive semidefinite constraints.
const std::vector<Binding<QuadraticConstraint> >& quadratic_constraints | ( | ) | const |
Getter for quadratic constraints.
const std::vector<Binding<QuadraticCost> >& quadratic_costs | ( | ) | const |
Getter for quadratic costs.
Binding<LinearConstraint> RelaxPsdConstraintToDdDualCone | ( | const Binding< PositiveSemidefiniteConstraint > & | constraint | ) |
constraint
with a diagonally dominant dual cone constraint.constraint
, if it had already been registered in this MathematicalProgram.This provides a polyhedral (i.e. linear) necessary, but not sufficient, condition for the variables in constraint
to be positive semidefinite.
constraint
. std::vector<Binding<RotatedLorentzConeConstraint> > RelaxPsdConstraintToSddDualCone | ( | const Binding< PositiveSemidefiniteConstraint > & | constraint | ) |
constraint
with a scaled diagonally dominant dual cone constraint.constraint
, if it had already been registered in this MathematicalProgram.This provides a second-order cone necessary, but not sufficient, condition for the variables in constraint
to be positive semidefinite.
constraint
. int RemoveConstraint | ( | const Binding< Constraint > & | constraint | ) |
Removes constraint
from this mathematical program.
See Remove costs, constraints or callbacks for more details.
constraint
, then returns 0. If this program contains multiple constraint
objects, then returns the repetition of constraint
in this program. Removes cost
from this mathematical program.
See Remove costs, constraints or callbacks for more details.
cost
, then returns 0. If this program contains multiple cost
objects, then returns the repetition of cost
in this program. int RemoveDecisionVariable | ( | const symbolic::Variable & | var | ) |
Remove var
from this program's decision variable.
var
in this optimization program. return -1 if var
is not a decision variable. exception | if var is bound with any cost or constraint. |
exception | if var is not a decision variable of the program. |
int RemoveVisualizationCallback | ( | const Binding< VisualizationCallback > & | callback | ) |
Removes callback
from this mathematical program.
See Remove costs, constraints or callbacks for more details.
callback
, then returns 0. If this program contains multiple callback
objects, then returns the repetition of callback
in this program. void Reparse | ( | symbolic::Polynomial * | p | ) | const |
Reparses the polynomial p
using this MathematicalProgram's indeterminates.
const ProgramAttributes& required_capabilities | ( | ) | const |
Getter for the required capability on the solver, given the cost/constraint/variable types in the program.
const std::vector<Binding<RotatedLorentzConeConstraint> >& rotated_lorentz_cone_constraints | ( | ) | const |
Getter for rotated Lorentz cone constraints.
void SetDecisionVariableValueInVector | ( | const symbolic::Variable & | decision_variable, |
double | decision_variable_new_value, | ||
EigenPtr< Eigen::VectorXd > | values | ||
) | const |
Updates the value of a single decision_variable
inside the values
vector to be decision_variable_new_value
.
The other decision variables' values in values
are unchanged.
decision_variable | a registered decision variable in this program. | |
decision_variable_new_value | the variable's new values. | |
[in,out] | values | The vector to be tweaked; must be of size num_vars(). |
void SetDecisionVariableValueInVector | ( | const Eigen::Ref< const MatrixXDecisionVariable > & | decision_variables, |
const Eigen::Ref< const Eigen::MatrixXd > & | decision_variables_new_values, | ||
EigenPtr< Eigen::VectorXd > | values | ||
) | const |
Updates the values of some decision_variables
inside the values
vector to be decision_variables_new_values
.
The other decision variables' values in values
are unchanged.
decision_variables | registered decision variables in this program. | |
decision_variables_new_values | the variables' respective new values; must have the same rows() and cols() sizes and decision_variables . | |
[in,out] | values | The vector to be tweaked; must be of size num_vars(). |
void SetInitialGuess | ( | const symbolic::Variable & | decision_variable, |
double | variable_guess_value | ||
) |
Sets the initial guess for a single variable decision_variable
.
The guess is stored as part of this program.
std::exception | if precondition is not satisfied. |
void SetInitialGuess | ( | const Eigen::MatrixBase< DerivedA > & | decision_variable_mat, |
const Eigen::MatrixBase< DerivedB > & | x0 | ||
) |
Sets the initial guess for the decision variables stored in decision_variable_mat
to be x0
.
The guess is stored as part of this program.
void SetInitialGuessForAllVariables | ( | const Eigen::MatrixBase< Derived > & | x0 | ) |
Set the initial guess for ALL decision variables.
Note that variables begin with a default initial guess of NaN to indicate that no guess is available.
x0 | A vector of appropriate size (num_vars() x 1). |
void SetSolverOption | ( | const SolverId & | solver_id, |
const std::string & | solver_option, | ||
double | option_value | ||
) |
See set_solver_option for more details.
Set the double-valued options.
void SetSolverOption | ( | const SolverId & | solver_id, |
const std::string & | solver_option, | ||
int | option_value | ||
) |
See set_solver_option for more details.
Set the integer-valued options.
void SetSolverOption | ( | const SolverId & | solver_id, |
const std::string & | solver_option, | ||
const std::string & | option_value | ||
) |
See set_solver_option for more details.
Set the string-valued options.
void SetSolverOptions | ( | const SolverOptions & | solver_options | ) |
Overwrite the stored solver options inside MathematicalProgram with the provided solver options.
void SetVariableScaling | ( | const symbolic::Variable & | var, |
double | s | ||
) |
Setter for the scaling s
of decision variable var
.
var | the decision variable to be scaled. |
s | scaling factor (must be positive). |
See Variable scaling for more information.
const SolverOptions& solver_options | ( | ) | const |
Returns the solver options stored inside MathematicalProgram.
MatrixX<symbolic::Expression> TightenPsdConstraintToDd | ( | const Binding< PositiveSemidefiniteConstraint > & | constraint | ) |
constraint
with a positive diagonally dominant constraint.constraint
, if it had already been registered in this MathematicalProgram.This provides a polyhedral (i.e. linear) sufficient, but not necessary, condition for the variables in constraint
to be positive semidefinite.
constraint
. std::vector<std::vector<Matrix2<symbolic::Variable> > > TightenPsdConstraintToSdd | ( | const Binding< PositiveSemidefiniteConstraint > & | constraint | ) |
constraint
with a scaled diagonally dominant constraint.constraint
, if it had already been registered in this MathematicalProgram.This provides a second-order cone sufficient, but not necessary, condition for the variables in constraint
to be positive semidefinite.
constraint
. std::string to_string | ( | ) | const |
Returns string representation of this program, listing the decision variables, costs, and constraints.
Note that by default, we do not require variables to have unique names. Providing useful variable names and calling Evaluator::set_description() to describe the costs and constraints can dramatically improve the readability of the output. See the tutorial debug_mathematical_program.ipynb
for more information.
std::string ToLatex | ( | int | precision = 3 | ) |
Returns a string representation of this program in LaTeX.
This can be particularly useful e.g. in a Jupyter (python) notebook:
Note that by default, we do not require variables to have unique names. Providing useful variable names and calling Evaluator::set_description() to describe the costs and constraints can dramatically improve the readability of the output. See the tutorial debug_mathematical_program.ipynb
for more information.
const std::vector<Binding<VisualizationCallback> >& visualization_callbacks | ( | ) | const |
Getter for all callbacks.
|
static |
The optimal cost is +∞ when the problem is globally infeasible.
|
static |
The optimal cost is -∞ when the problem is unbounded.