Drake
Drake C++ Documentation
MathematicalProgram Class Reference

Detailed Description

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< MathematicalProgramClone () 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, MatrixXDecisionVariableNewSosPolynomial (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, MatrixXDecisionVariableNewSosPolynomial (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< VisualizationCallbackAddVisualizationCallback (const VisualizationCallback::CallbackFunction &callback, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 Adds a callback method to visualize intermediate results of the optimization. More...
 
Binding< VisualizationCallbackAddVisualizationCallback (const VisualizationCallback::CallbackFunction &callback, const VariableRefList &vars)
 Adds a callback method to visualize intermediate results of the optimization. More...
 
Binding< CostAddCost (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< LinearCostAddCost (const Binding< LinearCost > &binding)
 Adds a cost term of the form c'*x. More...
 
Binding< LinearCostAddLinearCost (const symbolic::Expression &e)
 Adds a linear cost term of the form a'*x + b. More...
 
Binding< LinearCostAddLinearCost (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< LinearCostAddLinearCost (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< LinearCostAddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, const VarType &vars)
 Adds a linear cost term of the form a'*x. More...
 
Binding< QuadraticCostAddCost (const Binding< QuadraticCost > &binding)
 Adds a cost term of the form 0.5*x'*Q*x + b'x. More...
 
Binding< QuadraticCostAddQuadraticCost (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< QuadraticCostAddQuadraticCost (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< QuadraticCostAddQuadraticCost (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< QuadraticCostAddQuadraticCost (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< QuadraticCostAddQuadraticErrorCost (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< QuadraticCostAddQuadraticErrorCost (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< QuadraticCostAdd2NormSquaredCost (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< QuadraticCostAdd2NormSquaredCost (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< L2NormCostAddCost (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< L2NormCostAddL2NormCost (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< L2NormCostAddL2NormCost (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< L2NormCostAddL2NormCost (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< PolynomialCostAddPolynomialCost (const symbolic::Expression &e)
 Adds a cost term in the polynomial form. More...
 
Binding< CostAddCost (const symbolic::Expression &e)
 Adds a cost in the symbolic form. More...
 
Binding< ConstraintAddConstraint (const Binding< Constraint > &binding)
 Adds a generic constraint to the program. More...
 
Binding< ConstraintAddConstraint (const symbolic::Expression &e, double lb, double ub)
 Adds one row of constraint lb <= e <= ub where e is a symbolic expression. More...
 
Binding< ConstraintAddConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &v, const Eigen::Ref< const Eigen::MatrixXd > &lb, const Eigen::Ref< const Eigen::MatrixXd > &ub)
 
Binding< ConstraintAddConstraint (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< LinearConstraintAddConstraint (const Binding< LinearConstraint > &binding)
 Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter). More...
 
Binding< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (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< LinearConstraintAddLinearConstraint (const symbolic::Formula &f)
 Add a linear constraint represented by a symbolic formula to the program. More...
 
Binding< LinearConstraintAddLinearConstraint (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< LinearEqualityConstraintAddConstraint (const Binding< LinearEqualityConstraint > &binding)
 Adds linear equality constraints referencing potentially a subset of the decision variables. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const symbolic::Expression &e, double b)
 Adds one row of linear constraint e = b where e is a symbolic expression. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (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< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const VariableRefList &vars)
 AddLinearEqualityConstraint. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::SparseMatrix< double > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const VariableRefList &vars)
 AddLinearEqualityConstraint. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 AddLinearEqualityConstraint. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::SparseMatrix< double > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 AddLinearEqualityConstraint. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (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< LinearEqualityConstraintAddLinearEqualityConstraint (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< BoundingBoxConstraintAddConstraint (const Binding< BoundingBoxConstraint > &binding)
 Adds bounding box constraints referencing potentially a subest of the decision variables. More...
 
Binding< BoundingBoxConstraintAddBoundingBoxConstraint (const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const VariableRefList &vars)
 AddBoundingBoxConstraint. More...
 
Binding< BoundingBoxConstraintAddBoundingBoxConstraint (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< BoundingBoxConstraintAddBoundingBoxConstraint (double lb, double ub, const symbolic::Variable &var)
 Adds bounds for a single variable. More...
 
Binding< BoundingBoxConstraintAddBoundingBoxConstraint (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< QuadraticConstraintAddConstraint (const Binding< QuadraticConstraint > &binding)
 Adds quadratic constraint. More...
 
Binding< QuadraticConstraintAddQuadraticConstraint (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< QuadraticConstraintAddQuadraticConstraint (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< QuadraticConstraintAddQuadraticConstraint (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< LorentzConeConstraintAddConstraint (const Binding< LorentzConeConstraint > &binding)
 Adds Lorentz cone constraint referencing potentially a subset of the decision variables. More...
 
Binding< LorentzConeConstraintAddLorentzConeConstraint (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< LorentzConeConstraintAddLorentzConeConstraint (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< LorentzConeConstraintAddLorentzConeConstraint (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< LorentzConeConstraintAddLorentzConeConstraint (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< LorentzConeConstraintAddLorentzConeConstraint (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< LorentzConeConstraintAddLorentzConeConstraint (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< LorentzConeConstraintAddLorentzConeConstraint (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< RotatedLorentzConeConstraintAddConstraint (const Binding< RotatedLorentzConeConstraint > &binding)
 Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables. More...
 
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (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< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const Eigen::Ref< const VectorX< symbolic::Expression >> &v)
 Adds a constraint that a symbolic expression. More...
 
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (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< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (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< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const VariableRefList &vars)
 Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone. More...
 
template<int rows>
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const Eigen::MatrixBase< VectorDecisionVariable< rows >> &vars)
 Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone. More...
 
Binding< RotatedLorentzConeConstraintAddQuadraticAsRotatedLorentzConeConstraint (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< LinearComplementarityConstraintAddConstraint (const Binding< LinearComplementarityConstraint > &binding)
 Adds a linear complementarity constraints referencing a subset of the decision variables. More...
 
Binding< LinearComplementarityConstraintAddLinearComplementarityConstraint (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< LinearComplementarityConstraintAddLinearComplementarityConstraint (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< ConstraintAddPolynomialConstraint (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< ConstraintAddPolynomialConstraint (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< PositiveSemidefiniteConstraintAddConstraint (const Binding< PositiveSemidefiniteConstraint > &binding)
 Adds a positive semidefinite constraint on a symmetric matrix. More...
 
Binding< PositiveSemidefiniteConstraintAddConstraint (std::shared_ptr< PositiveSemidefiniteConstraint > con, const Eigen::Ref< const MatrixXDecisionVariable > &symmetric_matrix_var)
 Adds a positive semidefinite constraint on a symmetric matrix. More...
 
Binding< PositiveSemidefiniteConstraintAddPositiveSemidefiniteConstraint (const Eigen::Ref< const MatrixXDecisionVariable > &symmetric_matrix_var)
 Adds a positive semidefinite constraint on a symmetric matrix. More...
 
Binding< PositiveSemidefiniteConstraintAddPositiveSemidefiniteConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &e)
 Adds a positive semidefinite constraint on a symmetric matrix of symbolic expressions e. More...
 
Binding< PositiveSemidefiniteConstraintAddPrincipalSubmatrixIsPsdConstraint (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< LinearMatrixInequalityConstraintAddPrincipalSubmatrixIsPsdConstraint (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< LinearMatrixInequalityConstraintAddConstraint (const Binding< LinearMatrixInequalityConstraint > &binding)
 Adds a linear matrix inequality constraint to the program. More...
 
Binding< LinearMatrixInequalityConstraintAddLinearMatrixInequalityConstraint (std::vector< Eigen::MatrixXd > F, const VariableRefList &vars)
 Adds a linear matrix inequality constraint to the program. More...
 
Binding< LinearMatrixInequalityConstraintAddLinearMatrixInequalityConstraint (std::vector< Eigen::MatrixXd > F, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 Adds a linear matrix inequality constraint to the program. More...
 
Binding< LinearMatrixInequalityConstraintAddLinearMatrixInequalityConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X)
 Adds a linear matrix inequality constraint on a symmetric matrix of symbolic expressions X, namely X is positive semidefinite, and each entry in X is a linear (affine) expression of decision variables. More...
 
MatrixX< symbolic::ExpressionAddPositiveDiagonallyDominantMatrixConstraint (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::ExpressionTightenPsdConstraintToDd (const Binding< PositiveSemidefiniteConstraint > &constraint)
 
Binding< LinearConstraintRelaxPsdConstraintToDdDualCone (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< ExponentialConeConstraintAddConstraint (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< ExponentialConeConstraintAddExponentialConeConstraint (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< ExponentialConeConstraintAddExponentialConeConstraint (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 SolverOptionssolver_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< intFindDecisionVariableIndices (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::Variabledecision_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::Variableindeterminate (int i) const
 Getter for the indeterminate with index i in the program. More...
 
const ProgramAttributesrequired_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
 
MathematicalProgramoperator= (const MathematicalProgram &)=delete
 
 MathematicalProgram (MathematicalProgram &&)=delete
 
MathematicalProgramoperator= (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).

Parameters
indeterminatesThe set of indeterminates x
degreeThe total degree of the polynomial p.
Precondition
This must be an even number.
Returns
(p(x), Q_oo, Q_ee). p(x) is the newly added non-negative polynomial. p(x) = m_o(x)ᵀ*Q_oo*m_o(x) + m_e(x)ᵀ*Q_ee*m_e(x) where m_o(x) and m_e(x) contain all the even/odd monomials of x respectively. The returned non-negative polynomial can be of different types, including Sum-of-squares (SOS), diagonally-dominant-sum-of-squares (dsos), and scaled-diagonally-dominant-sum-of-squares (sdsos).
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariableNewEvenDegreeNonnegativePolynomial (const symbolic::Variables &indeterminates, int degree, NonnegativePolynomial type)
 See even_degree_nonnegative_polynomial for more details. More...
 
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariableNewEvenDegreeSosPolynomial (const symbolic::Variables &indeterminates, int degree)
 See even_degree_nonnegative_polynomial for more details. More...
 
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariableNewEvenDegreeSdsosPolynomial (const symbolic::Variables &indeterminates, int degree)
 see even_degree_nonnegative_polynomial for details. More...
 
std::tuple< symbolic::Polynomial, MatrixXDecisionVariable, MatrixXDecisionVariableNewEvenDegreeDsosPolynomial (const symbolic::Variables &indeterminates, int degree)
 see even_degree_nonnegative_polynomial for details. More...
 
Matrix log determinant

Represents the log-determinant of X by introducing slack variables t, and a lower triangular matrix Z and imposing the constraints

⌈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 ∑ᵢt(i) >= lower or maximize its value by adding the cost -∑ᵢt(i) using convex optimization.

Note
The constraint log(Z(i, i)) >= t(i) is imposed as an exponential cone constraint. Please make sure your have a solver that supports exponential cone constraint (currently SCS and Mosek do).
The constraint that
⌈X         Z⌉ is positive semidifinite.
⌊Zᵀ  diag(Z)⌋

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< LinearCostAddMaximizeGeometricMeanCost (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< LinearCostAddMaximizeGeometricMeanCost (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< LinearConstraintAddPositiveDiagonallyDominantDualConeMatrixConstraint (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X)
 This is an overloaded variant of diagonally dominant dual cone constraint. More...
 
Binding< LinearConstraintAddPositiveDiagonallyDominantDualConeMatrixConstraint (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.

Note
If two costs/constraints/callbacks represent the same expression, but their evaluators point to different objects, then they are NOT regarded the same. For example, if we have
auto cost1 = prog.AddLinearCost(x[0] + x[1]);
auto cost2 = prog.AddLinearCost(x[0] + x[1]);
// cost1 and cost2 represent the same cost, but cost1.evaluator() and
// cost2.evaluator() point to different objects. So after removing cost1,
// cost2 still lives in prog.
prog.RemoveCost(cost1);
// This will print true.
std::cout << (prog.linear_costs()[0] == cost2) << "\n";
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< CostMakeCost (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...
 

Member Typedef Documentation

◆ VarType

Member Enumeration Documentation

◆ NonnegativePolynomial

enum NonnegativePolynomial
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.

Constructor & Destructor Documentation

◆ MathematicalProgram() [1/3]

◆ MathematicalProgram() [2/3]

◆ MathematicalProgram() [3/3]

◆ ~MathematicalProgram()

virtual ~MathematicalProgram ( )
virtual

Member Function Documentation

◆ Add2NormSquaredCost() [1/2]

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)

◆ Add2NormSquaredCost() [2/2]

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)

◆ AddBoundingBoxConstraint() [1/6]

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

auto x = prog.NewContinuousVariables<2>("x");
auto y = prog.NewContinuousVariables<1>("y");
Eigen::Vector3d lb(0, 1, 2);
Eigen::Vector3d ub(1, 2, 3);
// Imposes the constraint
// 0 ≤ x(0) ≤ 1
// 1 ≤ x(1) ≤ 2
// 2 ≤ y ≤ 3
prog.AddBoundingBoxConstraint(lb, ub, {x, y});

◆ AddBoundingBoxConstraint() [2/6]

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.

Parameters
lbThe lower bound.
ubThe upper bound.
varsWill imposes constraint lb(i, j) <= vars(i, j) <= ub(i, j).
Returns
The newly constructed BoundingBoxConstraint.

◆ AddBoundingBoxConstraint() [3/6]

Binding<BoundingBoxConstraint> AddBoundingBoxConstraint ( double  lb,
double  ub,
const symbolic::Variable var 
)

Adds bounds for a single variable.

Parameters
lbLower bound.
ubUpper bound.
varThe decision variable.

◆ AddBoundingBoxConstraint() [4/6]

Binding<BoundingBoxConstraint> AddBoundingBoxConstraint ( double  lb,
double  ub,
const VariableRefList vars 
)

Adds the same scalar lower and upper bound to every variable in the list.

Parameters
lbLower bound.
ubUpper bound.
varsThe decision variables.

◆ AddBoundingBoxConstraint() [5/6]

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.

Template Parameters
DerivedAn Eigen Vector type with Variable as the scalar type.
Parameters
lbLower bound.
ubUpper bound.
varsThe decision variables.

◆ AddBoundingBoxConstraint() [6/6]

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.

Template Parameters
DerivedAn Eigen::Matrix with Variable as the scalar type. The matrix has unknown number of columns at compile time, or has more than one column.
Parameters
lbLower bound.
ubUpper bound.
varsThe decision variables.

◆ AddConstraint() [1/18]

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.

Note
If binding.evaluator()->num_constraints() == 0, then this constraint is not added into the MathematicalProgram. We return binding directly.

◆ AddConstraint() [2/18]

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.

Exceptions
std::exceptionif
  1. lb <= e <= ub is a trivial constraint such as 1 <= 2 <= 3.
  2. lb <= e <= ub is unsatisfiable such as 1 <= -5 <= 3
Parameters
eA symbolic expression of the decision variables.
lbA scalar, the lower bound.
ubA 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.

◆ AddConstraint() [3/18]

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 
)

◆ AddConstraint() [4/18]

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:

  1. e1 <= e2
  2. e1 >= e2
  3. e1 == e2
  4. A conjunction of relational formulas where each conjunct is a relational formula matched by 1, 2, or 3.

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

  1. f is not matched with one of the above patterns. Especially, strict inequalities (<, >) are not allowed.
  2. f is either a trivial constraint such as "1 <= 2" or an unsatisfiable constraint such as "2 <= 1".
  3. It is not possible to find numerical bounds of 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.

Eigen::Matrix<double, 2, 2> A = ...;
auto x = prog.NewContinuousVariables(2, "x");
prog.AddConstraint((A * x).array() <= b.array());

A formula in formulas can be of the following forms:

  1. e1 <= e2
  2. e1 >= e2
  3. e1 == e2

It throws an exception if AddConstraint(const symbolic::Formula& f) throws an exception for f ∈ formulas.

Template Parameters
DerivedEigen::Matrix or Eigen::Array with Formula as the Scalar.

◆ AddConstraint() [5/18]

std::enable_if_t< is_eigen_scalar_same<Derived, symbolic::Formula>::value, Binding<Constraint> > AddConstraint ( const Eigen::DenseBase< Derived > &  formulas)

◆ AddConstraint() [6/18]

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.

◆ AddConstraint() [7/18]

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.

◆ AddConstraint() [8/18]

Binding<LinearConstraint> AddConstraint ( const Binding< LinearConstraint > &  binding)

Adds linear constraints referencing potentially a subset of the decision variables (defined in the vars parameter).

◆ AddConstraint() [9/18]

Binding<LinearEqualityConstraint> AddConstraint ( const Binding< LinearEqualityConstraint > &  binding)

Adds linear equality constraints referencing potentially a subset of the decision variables.

◆ AddConstraint() [10/18]

Binding<BoundingBoxConstraint> AddConstraint ( const Binding< BoundingBoxConstraint > &  binding)

Adds bounding box constraints referencing potentially a subest of the decision variables.

Parameters
bindingBinds a BoundingBoxConstraint with some decision variables, such that binding.evaluator()->lower_bound()(i) <= binding.variables()(i) <= binding.evaluator().upper_bound()(i)

◆ AddConstraint() [11/18]

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.

◆ AddConstraint() [12/18]

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} \]

◆ AddConstraint() [13/18]

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 \]

◆ AddConstraint() [14/18]

Adds a linear complementarity constraints referencing a subset of the decision variables.

◆ AddConstraint() [15/18]

Adds a positive semidefinite constraint on a symmetric matrix.

◆ AddConstraint() [16/18]

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.

◆ AddConstraint() [17/18]

Adds a linear matrix inequality constraint to the program.

◆ AddConstraint() [18/18]

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}.

Parameters
bindingThe binding of ExponentialConeConstraint and its bound variables.

◆ AddCost() [1/10]

Binding<Cost> AddCost ( const Binding< Cost > &  binding)

Adds a generic cost to the optimization program.

◆ AddCost() [2/10]

auto AddCost ( const std::shared_ptr< C > &  obj,
const Eigen::Ref< const VectorXDecisionVariable > &  vars 
)

Adds a cost type to the optimization program.

Parameters
objThe added objective.
varsThe decision variables on which the cost depend.

◆ AddCost() [3/10]

auto AddCost ( const std::shared_ptr< C > &  obj,
const VariableRefList vars 
)

Adds a generic cost to the optimization program.

Parameters
objThe added objective.
varsThe decision variables on which the cost depend.

◆ AddCost() [4/10]

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.

Template Parameters
Fit should define functions numInputs, numOutputs and eval. Check

◆ AddCost() [5/10]

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.

Template Parameters
FType that defines functions numInputs, numOutputs and eval.

◆ AddCost() [6/10]

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.

Template Parameters
FThe type to check.

◆ AddCost() [7/10]

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.

◆ AddCost() [8/10]

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.

◆ AddCost() [9/10]

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.

◆ AddCost() [10/10]

Binding<Cost> AddCost ( const symbolic::Expression e)

Adds a cost in the symbolic form.

Returns
The newly created cost, together with the bound variables.

◆ AddDecisionVariables()

void AddDecisionVariables ( const Eigen::Ref< const MatrixXDecisionVariable > &  decision_variables)

Appends new variables to the end of the existing variables.

Parameters
decision_variablesThe newly added decision_variables.
Precondition
decision_variables should not intersect with the existing indeterminates in the optimization program.
Exceptions
std::exceptionif the preconditions are not satisfied.

◆ AddEqualityConstraintBetweenPolynomials()

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.

Parameters
p1Note 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.
p2Note 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.
Note
It calls Reparse to enforce p1 and p2 to have this MathematicalProgram's indeterminates.

◆ AddExponentialConeConstraint() [1/2]

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}.

Parameters
AThe A matrix in the documentation above. A must have 3 rows.
bThe b vector in the documentation above.
varsThe variables bound with this constraint.

◆ AddExponentialConeConstraint() [2/2]

Binding<ExponentialConeConstraint> AddExponentialConeConstraint ( const Eigen::Ref< const Vector3< symbolic::Expression >> &  z)

Add the constraint that z is in the exponential cone.

Parameters
zThe expression in the exponential cone.
Precondition
each entry in z is a linear expression of the decision variables.

◆ AddIndeterminate()

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.

Parameters
new_indeterminateThe indeterminate to be appended to the program's old indeterminates.
Returns
indeterminate_index The index of the added indeterminate in the program's indeterminates. i.e. prog.indeterminates()(indeterminate_index) = new_indeterminate.
Precondition
new_indeterminate should not intersect with the program's decision variables.
new_indeterminate should be of CONTINUOUS type.

◆ AddIndeterminates() [1/2]

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.

Parameters
new_indeterminatesThe indeterminates to be appended to the program's old indeterminates.
Precondition
new_indeterminates should not intersect with the program's old decision variables.
Each entry in new_indeterminates should be of CONTINUOUS type.

◆ AddIndeterminates() [2/2]

void AddIndeterminates ( const symbolic::Variables new_indeterminates)

Adds indeterminates.

This method appends some indeterminates to the end of the program's old indeterminates.

Parameters
new_indeterminatesThe indeterminates to be appended to the program's old indeterminates.
Precondition
new_indeterminates should not intersect with the program's old decision variables.
Each entry in new_indeterminates should be of CONTINUOUS type.

◆ AddL2NormCost() [1/3]

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).

Note
Currently kL2NormCost is supported by SnoptSolver, IpoptSolver, GurobiSolver, MosekSolver, ClarabelSolver, and SCSSolver.

◆ AddL2NormCost() [2/3]

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)

◆ AddL2NormCost() [3/3]

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.

Exceptions
std::exceptionif e cannot be decomposed into an L2 norm.

◆ AddL2NormCostUsingConicConstraint()

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().

Returns
(s, linear_cost, lorentz_cone_constraint). 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|₂

◆ AddLinearComplementarityConstraint() [1/2]

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.

◆ AddLinearComplementarityConstraint() [2/2]

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.

◆ AddLinearConstraint() [1/10]

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).

◆ AddLinearConstraint() [2/10]

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).

◆ AddLinearConstraint() [3/10]

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).

◆ AddLinearConstraint() [4/10]

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).

◆ AddLinearConstraint() [5/10]

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

Parameters
aA row vector.
lbA scalar, the lower bound.
ubA scalar, the upper bound.
varsThe decision variables on which to impose the linear constraint.

◆ AddLinearConstraint() [6/10]

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

Parameters
aA row vector.
lbA scalar, the lower bound.
ubA scalar, the upper bound.
varsThe decision variables on which to impose the linear constraint.

◆ AddLinearConstraint() [7/10]

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.

Exceptions
std::exceptionif
  1. e is a non-linear expression.
  2. lb <= e <= ub is a trivial constraint such as 1 <= 2 <= 3.
  3. lb <= e <= ub is unsatisfiable such as 1 <= -5 <= 3
Parameters
eA linear symbolic expression in the form of c0 + c1 * v1 + ... + cn * vn where c_i is a constant and @v_i is a variable.
lbA scalar, the lower bound.
ubA scalar, the upper bound.

◆ AddLinearConstraint() [8/10]

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.

◆ AddLinearConstraint() [9/10]

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:

  1. e1 <= e2
  2. e1 >= e2
  3. e1 == e2
  4. A conjunction of relational formulas where each conjunct is a relational formula matched by 1, 2, or 3.

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

  1. f is not matched with one of the above patterns. Especially, strict inequalities (<, >) are not allowed.
  2. f includes a non-linear expression.
  3. f is either a trivial constraint such as "1 <= 2" or an unsatisfiable constraint such as "2 <= 1".
  4. It is not possible to find numerical bounds of 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.

◆ AddLinearConstraint() [10/10]

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.

Eigen::Matrix<double, 2, 2> A;
auto x = prog.NewContinuousVariables(2, "x");
... // set up A and b
prog.AddLinearConstraint((A * x).array() <= b.array());

A formula in formulas can be of the following forms:

  1. e1 <= e2
  2. e1 >= e2
  3. e1 == e2

It throws an exception if AddLinearConstraint(const symbolic::Formula& f) throws an exception for f ∈ formulas.

Template Parameters
DerivedAn Eigen Array type of Formula.

◆ AddLinearCost() [1/4]

Binding<LinearCost> AddLinearCost ( const symbolic::Expression e)

Adds a linear cost term of the form a'*x + b.

Parameters
eA linear symbolic expression.
Precondition
e is a linear expression a'*x + b, where each entry of x is a decision variable in the mathematical program.
Returns
The newly added linear constraint, together with the bound variables.

◆ AddLinearCost() [2/4]

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.

◆ AddLinearCost() [3/4]

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.

◆ AddLinearCost() [4/4]

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.

◆ AddLinearEqualityConstraint() [1/10]

Binding<LinearEqualityConstraint> AddLinearEqualityConstraint ( const symbolic::Expression e,
double  b 
)

Adds one row of linear constraint e = b where e is a symbolic expression.

Exceptions
std::exceptionif
  1. e is a non-linear expression.
  2. e is a constant.
Parameters
eA linear symbolic expression in the form of c0 + c1 * x1 + ... + cn * xn where c_i is a constant and @x_i is a variable.
bA scalar.
Returns
The newly added linear equality constraint, together with the bound variable.

◆ AddLinearEqualityConstraint() [2/10]

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

  1. f is neither an equality formula nor a conjunction of equalities.
  2. f includes a non-linear expression.

◆ AddLinearEqualityConstraint() [3/10]

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.

Exceptions
std::exceptionif
  1. v(i) is a non-linear expression.
  2. v(i) is a constant.
Template Parameters
DerivedVAn Eigen Matrix type of Expression. A column vector.
DerivedBAn Eigen Matrix type of double. A column vector.
Parameters
vv(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.
bA vector of doubles.
Returns
The newly added linear equality constraint, together with the bound variables.

◆ AddLinearEqualityConstraint() [4/10]

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.

Template Parameters
DerivedVAn Eigen Matrix type of Expression. The number of columns at compile time should not be 1.
DerivedBAn Eigen Matrix type of double.
Parameters
VAn Eigen Matrix of symbolic expressions. V(i, j) should be a linear expression.
BAn Eigen Matrix of doubles.
lower_triangleIf true, then only the lower triangular part of V is constrained, otherwise the whole matrix V is constrained.
Default: is false.
Returns
The newly added linear equality constraint, together with the bound variables.

◆ AddLinearEqualityConstraint() [5/10]

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

auto x = prog.NewContinuousVariables(6,"myvar");
Eigen::Matrix2d Aeq;
Aeq << -1, 2,
1, 1;
Eigen::Vector2d beq(1, 3);
prog.AddLinearEqualityConstraint(Aeq, beq, {x.segment<1>(2),
x.segment<1>(5)});

The code above imposes constraints

\[-x(2) + 2x(5) = 1 \]

\[ x(2) + x(5) = 3 \]

◆ AddLinearEqualityConstraint() [6/10]

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.

◆ AddLinearEqualityConstraint() [7/10]

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

auto x = prog.NewContinuousVariables(6,"myvar");
Eigen::Matrix2d Aeq;
Aeq << -1, 2,
1, 1;
Eigen::Vector2d beq(1, 3);
// Imposes constraint
// -x(0) + 2x(1) = 1
// x(0) + x(1) = 3
prog.AddLinearEqualityConstraint(Aeq, beq, x.head<2>());

◆ AddLinearEqualityConstraint() [8/10]

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.

◆ AddLinearEqualityConstraint() [9/10]

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 \]

Parameters
aA row vector.
beqA scalar.
varsThe decision variables on which the constraint is imposed.

◆ AddLinearEqualityConstraint() [10/10]

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 \]

Parameters
aA row vector.
beqA scalar.
varsThe decision variables on which the constraint is imposed.

◆ AddLinearMatrixInequalityConstraint() [1/3]

Binding<LinearMatrixInequalityConstraint> AddLinearMatrixInequalityConstraint ( std::vector< Eigen::MatrixXd >  F,
const VariableRefList vars 
)

Adds a linear matrix inequality constraint to the program.

◆ AddLinearMatrixInequalityConstraint() [2/3]

Binding<LinearMatrixInequalityConstraint> AddLinearMatrixInequalityConstraint ( std::vector< Eigen::MatrixXd >  F,
const Eigen::Ref< const VectorXDecisionVariable > &  vars 
)

Adds a linear matrix inequality constraint to the program.

◆ AddLinearMatrixInequalityConstraint() [3/3]

Binding<LinearMatrixInequalityConstraint> AddLinearMatrixInequalityConstraint ( const Eigen::Ref< const MatrixX< symbolic::Expression >> &  X)

Adds a linear matrix inequality constraint on a symmetric matrix of symbolic expressions X, namely X is positive semidefinite, and each entry in X is a linear (affine) expression of decision variables.

Parameters
XImposes constraint "X is positive semidefinite".
Precondition
X is symmetric.
X(i, j) is linear (affine) for all i, j
Returns
The newly added linear matrix inequality constraint.

◆ AddLogDeterminantLowerBoundConstraint()

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.

Parameters
XA symmetric positive semidefinite matrix X.
lowerThe lower bound of log(det(X))
Returns
(constraint, t, Z) constraint is ∑ᵢt(i) >= lower, we also return the newly created slack variables t and the lower triangular matrix Z. Note that Z is not a matrix of symbolic::Variable but symbolic::Expression, because the upper-diagonal entries of Z are not variable, but expression 0.
Precondition
X is a symmetric matrix.

◆ AddLorentzConeConstraint() [1/7]

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)).

Parameters
eval_typeThe 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.

Exceptions
std::exceptionif f cannot be decomposed into a Lorentz cone.

◆ AddLorentzConeConstraint() [2/7]

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.

Parameters
vAn Eigen::Vector of symbolic::Expression. Constraining that

\[ v_0 \ge \sqrt{v_1^2 + ... + v_{n-1}^2} \]

Returns
The newly constructed Lorentz cone constraint with the bounded variables. For example, to add the Lorentz cone constraint
x+1 >= sqrt(y² + 2y + x² + 5),
     = sqrt((y+1)²+x²+2²)
The user could call
Vector4<symbolic::Expression> v(x+1, y+1, x, 2.);
prog.AddLorentzConeConstraint(v);
Parameters
eval_typeThe evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details.

◆ AddLorentzConeConstraint() [3/7]

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)

Parameters
linear_expressionThe linear expression v1.
quadratic_expressionThe quadratic expression v2.
tolThe tolerance to determine if the matrix in v2 is positive semidefinite or not.
See also
DecomposePositiveQuadraticForm for more explanation.
Default: is 0.
Parameters
eval_typeThe evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details.
Return values
bindingThe newly added Lorentz cone constraint, together with the bound variables.
Precondition
  1. v1 is a linear expression, in the form of c'*x + d.
  2. v2 is a quadratic expression, in the form of
             x'*Q*x + b'x + a
       
    Also 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.
Exceptions
std::exceptionif 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

prog.AddLorentzConeConstraint(x+1, pow(y, 2) + 2 * y + pow(x, 2) + 4);

◆ AddLorentzConeConstraint() [4/7]

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} \]

Parameters
AA \(\mathbb{R}^{n\times m}\) matrix, whose number of columns equals to the size of the decision variables.
bA \(\mathbb{R}^n\) vector, whose number of rows equals to the size of the decision variables.
varsThe list of \( m \) decision variables.
eval_typeThe evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details.
Returns
The newly added Lorentz cone constraint.

◆ AddLorentzConeConstraint() [5/7]

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} \]

Parameters
AA \(\mathbb{R}^{n\times m}\) matrix, whose number of columns equals to the size of the decision variables.
bA \(\mathbb{R}^n\) vector, whose number of rows equals to the size of the decision variables.
varsThe Eigen vector of \( m \) decision variables.
eval_typeThe evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details.
Returns
The newly added Lorentz cone constraint.

For example, to add the Lorentz cone constraint

x+1 >= sqrt(y² + 2y + x² + 5) = sqrt((y+1)² + x² + 2²),

the user could call

Eigen::Matrix<double, 4, 2> A;
Eigen::Vector4d b;
A << 1, 0, 0, 1, 1, 0, 0, 0;
b << 1, 1, 0, 2;
// A * [x;y] + b = [x+1; y+1; x; 2]
prog.AddLorentzConeConstraint(A, b, Vector2<symbolic::Variable>(x, y));

◆ AddLorentzConeConstraint() [6/7]

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} \]

Parameters
varsThe stacked column of vars should lie within the Lorentz cone.
eval_typeThe evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details.
Returns
The newly added Lorentz cone constraint.

◆ AddLorentzConeConstraint() [7/7]

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} \]

Parameters
varsThe stacked column of vars should lie within the Lorentz cone.
eval_typeThe evaluation type when evaluating the lorentz cone constraint in generic optimization. Refer to LorentzConeConstraint::EvalType for more details.
Returns
The newly added Lorentz cone constraint.

◆ AddMaximizeGeometricMeanCost() [1/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.

Returns
cost The added cost (note that since MathematicalProgram only minimizes the cost, the returned cost evaluates to -power(∏ᵢz(i), 1/n) where z = A*x+b.
Precondition
A.rows() == b.rows(), A.rows() >= 2.

◆ AddMaximizeGeometricMeanCost() [2/2]

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).

Parameters
cThe positive coefficient of the geometric mean cost,
Default: is 1.
Returns
cost The added cost (note that since MathematicalProgram only minimizes the cost, the returned cost evaluates to -c * power(∏ᵢx(i), 1/n).
Precondition
x.rows() >= 2.
c > 0.

◆ AddMaximizeLogDeterminantCost()

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.

Parameters
XA symmetric positive semidefinite matrix X, whose log(det(X)) will be maximized.
Returns
(cost, t, Z) cost is -∑ᵢt(i), we also return the newly created slack variables t and the lower triangular matrix Z. Note that Z is not a matrix of symbolic::Variable but symbolic::Expression, because the upper-diagonal entries of Z are not variable, but expression 0.
Precondition
X is a symmetric matrix.

◆ AddPolynomialConstraint() [1/2]

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).

◆ AddPolynomialConstraint() [2/2]

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).

◆ AddPolynomialCost()

Binding<PolynomialCost> AddPolynomialCost ( const symbolic::Expression e)

Adds a cost term in the polynomial form.

Parameters
eA symbolic expression in the polynomial form.
Returns
The newly created cost and the bound variables.

◆ AddPositiveDiagonallyDominantDualConeMatrixConstraint() [1/2]

Binding<LinearConstraint> AddPositiveDiagonallyDominantDualConeMatrixConstraint ( const Eigen::Ref< const MatrixX< symbolic::Expression >> &  X)

This is an overloaded variant of diagonally dominant dual cone constraint.

Parameters
XThe matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X.
Precondition
X(i, j) should be a linear expression of decision variables.
Returns
A linear constraint of size n² encoding vᵢᵀXvᵢ ≥ 0

◆ AddPositiveDiagonallyDominantDualConeMatrixConstraint() [2/2]

Binding<LinearConstraint> AddPositiveDiagonallyDominantDualConeMatrixConstraint ( const Eigen::Ref< const MatrixX< symbolic::Variable >> &  X)

This is an overloaded variant of diagonally dominant dual cone constraint.

Parameters
XThe matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X.
Returns
A linear constraint of size n² encoding vᵢᵀXvᵢ ≥ 0

◆ AddPositiveDiagonallyDominantMatrixConstraint()

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

Parameters
XThe matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X.
Returns
Y The slack variable. Y(i, j) represents |X(i, j)| ∀ j ≠ i, with the constraint Y(i, j) >= X(i, j) and Y(i, j) >= -X(i, j). Y is a symmetric matrix. The diagonal entries Y(i, i) = X(i, i)

◆ AddPositiveSemidefiniteConstraint() [1/2]

Binding<PositiveSemidefiniteConstraint> AddPositiveSemidefiniteConstraint ( const Eigen::Ref< const MatrixXDecisionVariable > &  symmetric_matrix_var)

Adds a positive semidefinite constraint on a symmetric matrix.

Exceptions
std::exceptionin Debug mode if symmetric_matrix_var is not symmetric.
Parameters
symmetric_matrix_varA symmetric MatrixDecisionVariable object.

◆ AddPositiveSemidefiniteConstraint() [2/2]

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.

Parameters
eImposes constraint "e is positive semidefinite".
Precondition
e is symmetric.
e(i, j) is linear for all i, j
Returns
The newly added positive semidefinite constraint, with the bound variable M that are also newly added.

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

Matrix3<symbolic::Expression> e
e << x+1, 2*x+3, x+y,
2*x+3, 2, 0,
x+y, 0, x;
prog.AddPositiveSemidefiniteConstraint(e);
Note
This function will add additional variables and linear equality constraints. Consider calling AddLinearMatrixInequalityConstraint(e), which doesn't introduce new variables or linear equality constraints.

◆ AddPrincipalSubmatrixIsPsdConstraint() [1/2]

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.

Precondition
The passed symmetric_matrix_var is a symmetric matrix.
All values in minor_indices lie in the range [0, symmetric_matrix_var.rows() - 1].
Parameters
symmetric_matrix_varA symmetric MatrixDecisionVariable object.
See also
AddPositiveSemidefiniteConstraint

◆ AddPrincipalSubmatrixIsPsdConstraint() [2/2]

Binding<LinearMatrixInequalityConstraint> 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.

Precondition
The passed symmetric_matrix_var is a symmetric matrix.
All values in minor_indices lie in the range [0, symmetric_matrix_var.rows() - 1].
Parameters
eImposes constraint "e is positive semidefinite".
See also
AddLinearMatrixInequalityConstraint.
Note
the return type is Binding<LinearMatrixInequalityConstraint>, different from the overloaded function above which returns Binding<PositiveSemidefiniteConstraint>. We impose the constraint as an LMI so as to add fewer additional variables and constraints.

◆ AddQuadraticAsRotatedLorentzConeConstraint()

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

Exceptions
exceptionif this quadratic constraint is not convex (Q is not positive semidefinite)
Parameters
QThe Hessian of the quadratic constraint. Should be positive semidefinite.
bThe linear coefficient of the quadratic constraint.
cThe constant term of the quadratic constraint.
varsx in the documentation above.
psd_tolIf the minimal eigenvalue of Q is smaller than -psd_tol, then throw an exception.
Default: = 0.

◆ AddQuadraticConstraint() [1/3]

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.

Parameters
varsx in the documentation above.
hessian_typeWhether 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.
Precondition
hessian_type should be correct if it is not std::nullopt, as we will blindly trust it in the downstream code.

◆ AddQuadraticConstraint() [2/3]

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.

Parameters
varsx in the documentation above.
hessian_typeWhether 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.
Precondition
hessian_type should be correct if it is not std::nullopt, as we will blindly trust it in the downstream code.

◆ AddQuadraticConstraint() [3/3]

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.

◆ AddQuadraticCost() [1/4]

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.

Parameters
eA quadratic symbolic expression.
is_convexWhether 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.
Exceptions
std::exceptionif the expression is not quadratic.
Returns
The newly added cost together with the bound variables.

◆ AddQuadraticCost() [2/4]

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.

Parameters
is_convexWhether 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.

◆ AddQuadraticCost() [3/4]

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.

Parameters
is_convexWhether 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.

◆ AddQuadraticCost() [4/4]

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.

Parameters
is_convexWhether 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.

◆ AddQuadraticErrorCost() [1/2]

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).

◆ AddQuadraticErrorCost() [2/2]

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).

◆ AddRotatedLorentzConeConstraint() [1/6]

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.

Parameters
linear_expression1The linear expression v1.
linear_expression2The linear expression v2.
quadratic_expressionThe quadratic expression u.
tolThe tolerance to determine if the matrix in v2 is positive semidefinite or not.
See also
DecomposePositiveQuadraticForm for more explanation.
Default: is 0.
Return values
bindingThe newly added rotated Lorentz cone constraint, together with the bound variables.
Precondition
  1. linear_expression1 is a linear (affine) expression, in the form of v1 = c1'*x + d1.
  2. linear_expression2 is a linear (affine) expression, in the form of v2 = c2'*x + d2.
  1. quadratic_expression is a quadratic expression, in the form of
             u = x'*Q*x + b'x + a
       
    Also 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.
Exceptions
std::exceptionif 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

prog.AddRotatedLorentzConeConstraint(x+1, x+y, pow(x, 2) + pow(z, 2) +
2*z+5);

◆ AddRotatedLorentzConeConstraint() [2/6]

Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint ( const Eigen::Ref< const VectorX< symbolic::Expression >> &  v)

Adds a constraint that a symbolic expression.

Parameters
vis 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 \]

vA 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.
Return values
bindingThe 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

Eigen::Matrix<symbolic::Expression, 5, 1> v;
v << x+1, x+y, x, z+1, 2;
prog.AddRotatedLorentzConeConstraint(v);

◆ AddRotatedLorentzConeConstraint() [3/6]

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.

Parameters
AA matrix whose number of columns equals to the size of the decision variables.
bA vector whose number of rows equals to the size of the decision variables.
varsThe decision variables on which the constraint is imposed.

◆ AddRotatedLorentzConeConstraint() [4/6]

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.

Parameters
AA matrix whose number of columns equals to the size of the decision variables.
bA vector whose number of rows equals to the size of the decision variables.
varsThe decision variables on which the constraint is imposed.

◆ AddRotatedLorentzConeConstraint() [5/6]

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 \]

Parameters
varsThe stacked column of vars lies in the rotated Lorentz cone.
Returns
The newly added rotated Lorentz cone constraint.

◆ AddRotatedLorentzConeConstraint() [6/6]

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 \]

Parameters
varsThe stacked column of vars lies in the rotated Lorentz cone.
Returns
The newly added rotated Lorentz cone constraint.

◆ AddScaledDiagonallyDominantDualConeMatrixConstraint() [1/2]

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.

Parameters
XThe matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X.
Precondition
X(i, j) should be a linear expression of decision variables.
Returns
A vector of RotatedLorentzConeConstraint constraints of length 1/2 * n * (n-1) encoding VᵢⱼᵀXVᵢⱼ is psd

◆ AddScaledDiagonallyDominantDualConeMatrixConstraint() [2/2]

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.

Parameters
XThe matrix X. We will use 0.5(X+Xᵀ) as the "symmetric version" of X.
Returns
A vector of RotatedLorentzConeConstraint constraints of length 1/2 * n * (n-1) encoding VᵢⱼᵀXVᵢⱼ is psd

◆ AddScaledDiagonallyDominantMatrixConstraint() [1/2]

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.

Parameters
XThe matrix X to be constrained scaled diagonally dominant. X.
Precondition
X(i, j) should be a linear expression of decision variables.
Returns
M A vector of vectors of 2 x 2 symmetric matrices M. For i < j, M[i][j] is
[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.

◆ AddScaledDiagonallyDominantMatrixConstraint() [2/2]

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.

Parameters
XThe symmetric matrix X to be constrained scaled diagonally dominant.
Returns
M For i < j M[i][j] contains the slack variables, mentioned in scaled diagonally dominant matrix constraint. For i >= j, M[i][j] contains default-constructed variables (with get_id() == 0).

◆ AddSosConstraint() [1/4]

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.

Parameters
typeThe 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_nameThe name of the gram matrix for print out.
Note
It calls Reparse to enforce p to have this MathematicalProgram's indeterminates if necessary.

◆ AddSosConstraint() [2/4]

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:

  • The coefficients matrix Q, which is positive semidefinite.
  • The monomial basis m.
    Parameters
    typeThe 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_nameThe name of the gram matrix for print out.
    Note
    It calls Reparse to enforce p to have this MathematicalProgram's indeterminates if necessary.

◆ AddSosConstraint() [3/4]

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.

Parameters
typeRefer to NonnegativePolynomial class documentation.
gram_nameThe name of the gram matrix for print out.

◆ AddSosConstraint() [4/4]

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:

  • The coefficients matrix Q, which is positive semidefinite.
  • The monomial basis m.
    Parameters
    typeRefer to NonnegativePolynomial class documentation.
    gram_nameThe name of the gram matrix for print out.

◆ AddVisualizationCallback() [1/2]

Binding<VisualizationCallback> AddVisualizationCallback ( const VisualizationCallback::CallbackFunction callback,
const Eigen::Ref< const VectorXDecisionVariable > &  vars 
)

Adds a callback method to visualize intermediate results of the optimization.

Note
Just like other costs/constraints, not all solvers support callbacks. Adding a callback here will force MathematicalProgram::Solve to select a solver that support callbacks. For instance, adding a visualization callback to a quadratic programming problem may result in using a nonlinear programming solver as the default solver.
Parameters
callbacka std::function that accepts an Eigen::Vector of doubles representing the bound decision variables.
varsthe decision variables that should be passed to the callback.

◆ AddVisualizationCallback() [2/2]

Binding<VisualizationCallback> AddVisualizationCallback ( const VisualizationCallback::CallbackFunction callback,
const VariableRefList vars 
)

Adds a callback method to visualize intermediate results of the optimization.

Note
Just like other costs/constraints, not all solvers support callbacks. Adding a callback here will force MathematicalProgram::Solve to select a solver that support callbacks. For instance, adding a visualization callback to a quadratic programming problem may result in using a nonlinear programming solver as the default solver.
Parameters
callbacka std::function that accepts an Eigen::Vector of doubles representing the for the bound decision variables.
varsthe decision variables that should be passed to the callback.

◆ bounding_box_constraints()

const std::vector<Binding<BoundingBoxConstraint> >& bounding_box_constraints ( ) const

Getter for all bounding box constraints.

◆ CheckSatisfied() [1/2]

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.

Exceptions
std::exceptionif the size of prog_var_vals is invalid.

◆ CheckSatisfied() [2/2]

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.

Returns
true iff all of the constraints are satisfied.
Exceptions
std::exceptionif the size of prog_var_vals is invalid.

◆ CheckSatisfiedAtInitialGuess() [1/2]

bool CheckSatisfiedAtInitialGuess ( const Binding< Constraint > &  binding,
double  tol = 1e-6 
) const

Evaluates CheckSatisfied for the constraint in binding at the initial guess.

◆ CheckSatisfiedAtInitialGuess() [2/2]

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.

Returns
true iff all of the constraints are satisfied.

◆ ClearVariableScaling()

void ClearVariableScaling ( )

Clears the scaling factors for decision variables.

See Variable scaling for more information.

◆ Clone()

std::unique_ptr<MathematicalProgram> Clone ( ) const

Clones an optimization program.

The clone will be functionally equivalent to the source program with the same:

  • decision variables
  • constraints
  • costs
  • solver settings
  • initial guess

Note that this is currently a shallow clone. The costs and constraints are not themselves cloned.

Return values
new_prog.The newly constructed mathematical program.

◆ decision_variable()

const symbolic::Variable& decision_variable ( int  i) const

Getter for the decision variable with index i in the program.

◆ decision_variable_index()

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.

◆ decision_variables()

Eigen::Map<const VectorX<symbolic::Variable> > decision_variables ( ) const

Getter for all decision variables in the program.

◆ EvalBinding()

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.

Parameters
bindingA Binding whose variables are decision variables in this program.
prog_var_valsThe value of all the decision variables in this program.
Exceptions
std::exceptionif the size of prog_var_vals is invalid.

◆ EvalBindingAtInitialGuess()

Eigen::VectorXd EvalBindingAtInitialGuess ( const Binding< C > &  binding) const

Evaluates the evaluator in binding at the initial guess.

Returns
The value of binding at the initial guess.

◆ EvalBindings()

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).

Parameters
bindingsList of bindings.
prog
prog_var_valsThe value of all the decision variables in this program.
Returns
All binding values, concatenated into a single vector.
Exceptions
std::exceptionif the size of prog_var_vals is invalid.

◆ EvalVisualizationCallbacks()

void EvalVisualizationCallbacks ( const Eigen::Ref< const Eigen::VectorXd > &  prog_var_vals) const

Evaluates all visualization callbacks registered with the MathematicalProgram.

Parameters
prog_var_valsThe value of all the decision variables in this program.
Exceptions
std::exceptionif the size does not match.

◆ exponential_cone_constraints()

const std::vector<Binding<ExponentialConeConstraint> >& exponential_cone_constraints ( ) const

Getter for exponential cone constraints.

◆ FindDecisionVariableIndex()

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.

Precondition
{var is a decision variable in the mathematical program, otherwise this function throws a runtime error.}

◆ FindDecisionVariableIndices()

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.

Precondition
{vars are decision variables in the mathematical program, otherwise this function throws a runtime error.}

◆ FindIndeterminateIndex()

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.

Precondition
var is a indeterminate in the mathematical program, otherwise this function throws a runtime error.

◆ generic_constraints()

const std::vector<Binding<Constraint> >& generic_constraints ( ) const

Getter for all generic constraints.

◆ generic_costs()

const std::vector<Binding<Cost> >& generic_costs ( ) const

Getter for all generic costs.

◆ GetAllConstraints()

std::vector<Binding<Constraint> > GetAllConstraints ( ) const

Getter for returning all constraints.

Returns
Vector of all constraint bindings.
Note
The group ordering may change as more constraint types are added.

◆ GetAllCosts()

std::vector<Binding<Cost> > GetAllCosts ( ) const

Getter returning all costs.

Returns
Vector of all cost bindings.
Note
The group ordering may change as more cost types are added.

◆ GetAllLinearConstraints()

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.

Returns
Vector of all linear constraint bindings.

◆ GetBindingVariableValues()

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().

Parameters
bindingbinding.variables() must be decision variables in this MathematicalProgram.
prog_var_valsThe value of ALL the decision variables in this program.
Returns
binding_variable_vals binding_variable_vals(i) is the value of binding.variables()(i) in prog_var_vals.

◆ GetInitialGuess() [1/2]

double GetInitialGuess ( const symbolic::Variable decision_variable) const

Gets the initial guess for a single variable.

Precondition
decision_variable has been registered in the optimization program.
Exceptions
std::exceptionif the pre condition is not satisfied.

◆ GetInitialGuess() [2/2]

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.

Precondition
Each variable in decision_variable_mat has been registered in the optimization program.
Exceptions
std::exceptionif the pre condition is not satisfied.

◆ GetSolverOptionsDouble()

const std::unordered_map<std::string, double>& GetSolverOptionsDouble ( const SolverId solver_id) const

◆ GetSolverOptionsInt()

const std::unordered_map<std::string, int>& GetSolverOptionsInt ( const SolverId solver_id) const

◆ GetSolverOptionsStr()

const std::unordered_map<std::string, std::string>& GetSolverOptionsStr ( const SolverId solver_id) const

◆ GetVariableScaling()

const std::unordered_map<int, double>& GetVariableScaling ( ) const

Returns the mapping from a decision variable index to its scaling factor.

See Variable scaling for more information.

◆ indeterminate()

const symbolic::Variable& indeterminate ( int  i) const

Getter for the indeterminate with index i in the program.

◆ indeterminates()

Eigen::Map<const VectorX<symbolic::Variable> > indeterminates ( ) const

Getter for all indeterminates in the program.

◆ indeterminates_index()

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.

◆ initial_guess()

const Eigen::VectorXd& initial_guess ( ) const

Getter for the initial guess.

◆ IsThreadSafe()

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.

◆ l2norm_costs()

const std::vector<Binding<L2NormCost> >& l2norm_costs ( ) const

Getter for l2norm costs.

◆ linear_complementarity_constraints()

const std::vector<Binding<LinearComplementarityConstraint> >& linear_complementarity_constraints ( ) const

Getter for all linear complementarity constraints.

◆ linear_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().

◆ linear_costs()

const std::vector<Binding<LinearCost> >& linear_costs ( ) const

Getter for linear costs.

◆ linear_equality_constraints()

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.

◆ linear_matrix_inequality_constraints()

const std::vector<Binding<LinearMatrixInequalityConstraint> >& linear_matrix_inequality_constraints ( ) const

Getter for linear matrix inequality constraints.

◆ lorentz_cone_constraints()

const std::vector<Binding<LorentzConeConstraint> >& lorentz_cone_constraints ( ) const

Getter for Lorentz cone constraints.

◆ MakeCost()

static std::shared_ptr<Cost> MakeCost ( F &&  f)
static

Convert an input of type F to a FunctionCost object.

Template Parameters
FThis class should have functions numInputs(), numOutputs and eval(x, y).

◆ MakePolynomial()

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.
  • In contrast, 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.
Note
This function does not require that the decision variables in e is a subset of the decision variables in MathematicalProgram.

◆ NewBinaryVariables() [1/3]

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().

Template Parameters
RowsThe number of rows in the new variables.
ColsThe number of columns in the new variables.
Parameters
rowsThe number of rows in the new variables.
colsThe number of columns in the new variables.
nameThe commonly shared name of the new variables.
Returns
The MatrixDecisionVariable of size rows x cols, containing the new vars (not all the vars stored).

Example:

auto b = prog.NewBinaryVariables(2, 3, "b");

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.

◆ NewBinaryVariables() [2/3]

MatrixDecisionVariable<Rows, Cols> NewBinaryVariables ( const std::string &  name = "b")

Adds a matrix of binary variables into the optimization program.

Template Parameters
RowsThe number of rows in the newly added binary variables.
ColsThe number of columns in the new variables. The default is 1.
Parameters
nameEach newly added binary variable will share the same name. The default name is "b".
Returns
A matrix containing the newly added variables.

◆ NewBinaryVariables() [3/3]

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.

See also
NewBinaryVariables(int rows, int cols, const std::vector<std::string>& names);

◆ NewContinuousVariables() [1/3]

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().

Parameters
rowsThe number of rows in the new variables.
nameThe name of the newly added variables
Returns
The VectorDecisionVariable of size rows x 1, containing the new vars (not all the vars stored).

Example:

auto x = prog.NewContinuousVariables(2, "x");

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.

◆ NewContinuousVariables() [2/3]

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().

Template Parameters
RowsThe number of rows of the new variables, in the compile time.
ColsThe number of columns of the new variables, in the compile time.
Parameters
rowsThe number of rows in the new variables. When Rows is not Eigen::Dynamic, rows is ignored.
colsThe number of columns in the new variables. When Cols is not Eigen::Dynamic, cols is ignored.
nameAll variables will share the same name, but different index.
Returns
The MatrixDecisionVariable of size Rows x Cols, containing the new vars (not all the vars stored).

Example:

auto x = prog.NewContinuousVariables(2, 3, "X");
auto y = prog.NewContinuousVariables<2, 3>(2, 3, "X");

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.

◆ NewContinuousVariables() [3/3]

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().

Template Parameters
RowsThe number of rows in the new variables.
ColsThe number of columns in the new variables. The default is 1.
Parameters
nameAll variables will share the same name, but different index.
Returns
The MatrixDecisionVariable of size rows x cols, containing the new vars (not all the vars stored).

Example:

auto x = prog.NewContinuousVariables<2, 3>("X");

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.

◆ NewEvenDegreeDsosPolynomial()

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).

◆ NewEvenDegreeFreePolynomial()

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).

Parameters
indeterminatesThe monomial basis is over these indeterminates.
degreeThe highest degree of the polynomial.
coeff_nameThe coefficients of the polynomial are decision variables with this name as a base. The variable name would be "a1", "a2", etc.

◆ NewEvenDegreeNonnegativePolynomial()

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.

Parameters
typeThe returned polynomial p(x) can be either SOS, SDSOS or DSOS, depending on type.

◆ NewEvenDegreeSdsosPolynomial()

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.

◆ NewEvenDegreeSosPolynomial()

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.

◆ NewFreePolynomial()

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₅.

◆ NewIndeterminates() [1/8]

MatrixIndeterminate<rows, cols> NewIndeterminates ( const std::array< std::string, rows *cols > &  names)

Adds indeterminates, appending them to an internal vector of any existing indeterminates.

Template Parameters
rowsThe number of rows in the new indeterminates.
colsThe number of columns in the new indeterminates.
Parameters
namesA vector of strings containing the name for each variable.
Returns
The MatrixIndeterminate of size rows x cols, containing the new vars (not all the vars stored).

Example:

std::array<std::string, 6> names = {"x1", "x2", "x3", "x4", "x5", "x6"};
auto x = prog.NewIndeterminates<2, 3>(names);

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.

◆ NewIndeterminates() [2/8]

VectorIndeterminate<rows> NewIndeterminates ( const std::array< std::string, rows > &  names)

Adds indeterminates, appending them to an internal vector of any existing indeterminates.

Template Parameters
rowsThe number of rows in the new indeterminates.
colsThe number of columns in the new indeterminates.
Parameters
namesA vector of strings containing the name for each variable.
Returns
The MatrixIndeterminate of size rows x cols, containing the new vars (not all the vars stored).

Example:

std::array<std::string, 2> names = {"x1", "x2"};
auto x = prog.NewIndeterminates<2>(names);

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.

◆ NewIndeterminates() [3/8]

MatrixIndeterminate<rows, cols> NewIndeterminates ( const std::string &  name = "X")

Adds indeterminates, appending them to an internal vector of any existing indeterminates.

Template Parameters
rowsThe number of rows in the new indeterminates.
colsThe number of columns in the new indeterminates.
Parameters
namesA vector of strings containing the name for each variable.
Returns
The MatrixIndeterminate of size rows x cols, containing the new vars (not all the vars stored).

Example:

auto x = prog.NewIndeterminates<2, 3>("X");

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.

◆ NewIndeterminates() [4/8]

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"

See also
NewIndeterminates(const std::array<std::string, rows>& names)

◆ NewIndeterminates() [5/8]

VectorXIndeterminate NewIndeterminates ( int  rows,
const std::vector< std::string > &  names 
)

Adds indeterminates to this MathematicalProgram.

See also
NewIndeterminates(int rows, int cols, const std::vector<std::string>& names);

◆ NewIndeterminates() [6/8]

VectorXIndeterminate NewIndeterminates ( int  rows,
const std::string &  name = "x" 
)

Adds indeterminates to this MathematicalProgram, with default name "x".

See also
NewIndeterminates(int rows, int cols, const std::vector<std::string>& names);

◆ NewIndeterminates() [7/8]

MatrixXIndeterminate NewIndeterminates ( int  rows,
int  cols,
const std::vector< std::string > &  names 
)

Adds indeterminates, appending them to an internal vector of any existing vars.

Parameters
rowsThe number of rows in the new indeterminates.
colsThe number of columns in the new indeterminates.
namesA vector of strings containing the name for each variable.
Returns
The MatrixIndeterminate of size rows x cols, containing the new vars (not all the vars stored).

Example:

auto x = prog.NewIndeterminates(2, 3, {"x1", "x2", "x3", "x4",
"x5", "x6"});

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.

◆ NewIndeterminates() [8/8]

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.

See also
NewIndeterminates(int rows, int cols, const std::vector<std::string>& names);

◆ NewOddDegreeFreePolynomial()

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).

Parameters
indeterminatesThe monomial basis is over these indeterminates.
degreeThe highest degree of the polynomial.
coeff_nameThe coefficients of the polynomial are decision variables with this name as a base. The variable name would be "a1", "a2", etc.

◆ NewSosPolynomial() [1/3]

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.

  • if type = kSos, we impose the polynomial being SOS.
  • if type = kSdsos, we impose the polynomial being SDSOS.
  • if type = kDsos, we impose the polynomial being DSOS.
    Parameters
    gram_nameThe name of the gram matrix for print out.
    Note
    Q is a symmetric monomial_basis.rows() x monomial_basis.rows() matrix.

◆ NewSosPolynomial() [2/3]

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.

◆ NewSosPolynomial() [3/3]

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.

Parameters
typeDepending on the type of the polynomial, we will impose different constraint on the polynomial.
  • if type = kSos, we impose the polynomial being SOS.
  • if type = kSdsos, we impose the polynomial being SDSOS.
  • if type = kDsos, we impose the polynomial being DSOS.
gram_nameThe name of the gram matrix for print out.
Exceptions
std::exceptionif degree is not a positive even integer.
See also
MonomialBasis.

◆ NewSymmetricContinuousVariables() [1/2]

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.

Parameters
rowsThe number of rows in the symmetric matrix.
nameThe 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.
Returns
The newly added decision variables.

◆ NewSymmetricContinuousVariables() [2/2]

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.

Template Parameters
rowsThe number of rows in the symmetric matrix.
Parameters
nameThe 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.
Returns
The newly added decision variables.

◆ num_indeterminates()

int num_indeterminates ( ) const

Gets the number of indeterminates in the optimization program.

◆ num_vars()

int num_vars ( ) const

Getter for number of variables in the optimization program.

◆ operator=() [1/2]

MathematicalProgram& operator= ( const MathematicalProgram )
delete

◆ operator=() [2/2]

MathematicalProgram& operator= ( MathematicalProgram &&  )
delete

◆ positive_semidefinite_constraints()

const std::vector<Binding<PositiveSemidefiniteConstraint> >& positive_semidefinite_constraints ( ) const

Getter for positive semidefinite constraints.

◆ quadratic_constraints()

const std::vector<Binding<QuadraticConstraint> >& quadratic_constraints ( ) const

Getter for quadratic constraints.

◆ quadratic_costs()

const std::vector<Binding<QuadraticCost> >& quadratic_costs ( ) const

Getter for quadratic costs.

◆ RelaxPsdConstraintToDdDualCone()

Binding<LinearConstraint> RelaxPsdConstraintToDdDualCone ( const Binding< PositiveSemidefiniteConstraint > &  constraint)
  1. Relaxes the positive semidefinite constraint with a diagonally dominant dual cone constraint.
  2. Adds the diagonally dominant dual cone constraint into this MathematicalProgram.
  3. Removes the positive semidefinite 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.

Precondition
The decision variables contained in constraint have been registered with this MathematicalProgram.
Returns
The return of AddPositiveDiagonallyDominantDualConeMatrixConstraint applied to the variables in constraint.

◆ RelaxPsdConstraintToSddDualCone()

std::vector<Binding<RotatedLorentzConeConstraint> > RelaxPsdConstraintToSddDualCone ( const Binding< PositiveSemidefiniteConstraint > &  constraint)
  1. Relaxes the positive semidefinite constraint with a scaled diagonally dominant dual cone constraint.
  2. Adds the scaled diagonally dominant dual cone constraint into this MathematicalProgram.
  3. Removes the positive semidefinite 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.

Precondition
The decision variables contained in constraint have been registered with this MathematicalProgram.
Returns
The return of AddScaledDiagonallyDominantDualConeMatrixConstraint applied to the variables in constraint.

◆ RemoveConstraint()

int RemoveConstraint ( const Binding< Constraint > &  constraint)

Removes constraint from this mathematical program.

See Remove costs, constraints or callbacks for more details.

Returns
number of constraint objects removed from this program. If this program doesn't contain constraint, then returns 0. If this program contains multiple constraint objects, then returns the repetition of constraint in this program.

◆ RemoveCost()

int RemoveCost ( const Binding< Cost > &  cost)

Removes cost from this mathematical program.

See Remove costs, constraints or callbacks for more details.

Returns
number of cost objects removed from this program. If this program doesn't contain cost, then returns 0. If this program contains multiple cost objects, then returns the repetition of cost in this program.

◆ RemoveDecisionVariable()

int RemoveDecisionVariable ( const symbolic::Variable var)

Remove var from this program's decision variable.

Note
after removing the variable, the indices of some remaining variables inside this MathematicalProgram will change.
Returns
the index of var in this optimization program. return -1 if var is not a decision variable.
Exceptions
exceptionif var is bound with any cost or constraint.
exceptionif var is not a decision variable of the program.

◆ RemoveVisualizationCallback()

int RemoveVisualizationCallback ( const Binding< VisualizationCallback > &  callback)

Removes callback from this mathematical program.

See Remove costs, constraints or callbacks for more details.

Returns
number of callback objects removed from this program. If this program doesn't contain callback, then returns 0. If this program contains multiple callback objects, then returns the repetition of callback in this program.

◆ Reparse()

void Reparse ( symbolic::Polynomial p) const

Reparses the polynomial p using this MathematicalProgram's indeterminates.

◆ required_capabilities()

const ProgramAttributes& required_capabilities ( ) const

Getter for the required capability on the solver, given the cost/constraint/variable types in the program.

◆ rotated_lorentz_cone_constraints()

const std::vector<Binding<RotatedLorentzConeConstraint> >& rotated_lorentz_cone_constraints ( ) const

Getter for rotated Lorentz cone constraints.

◆ SetDecisionVariableValueInVector() [1/2]

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.

Parameters
decision_variablea registered decision variable in this program.
decision_variable_new_valuethe variable's new values.
[in,out]valuesThe vector to be tweaked; must be of size num_vars().

◆ SetDecisionVariableValueInVector() [2/2]

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.

Parameters
decision_variablesregistered decision variables in this program.
decision_variables_new_valuesthe variables' respective new values; must have the same rows() and cols() sizes and decision_variables.
[in,out]valuesThe vector to be tweaked; must be of size num_vars().

◆ SetInitialGuess() [1/2]

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.

Precondition
decision_variable is a registered decision variable in the program.
Exceptions
std::exceptionif precondition is not satisfied.

◆ SetInitialGuess() [2/2]

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.

◆ SetInitialGuessForAllVariables()

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.

Parameters
x0A vector of appropriate size (num_vars() x 1).

◆ SetSolverOption() [1/3]

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.

◆ SetSolverOption() [2/3]

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.

◆ SetSolverOption() [3/3]

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.

◆ SetSolverOptions()

void SetSolverOptions ( const SolverOptions solver_options)

Overwrite the stored solver options inside MathematicalProgram with the provided solver options.

◆ SetVariableScaling()

void SetVariableScaling ( const symbolic::Variable var,
double  s 
)

Setter for the scaling s of decision variable var.

Parameters
varthe decision variable to be scaled.
sscaling factor (must be positive).

See Variable scaling for more information.

◆ solver_options()

const SolverOptions& solver_options ( ) const

Returns the solver options stored inside MathematicalProgram.

◆ TightenPsdConstraintToDd()

MatrixX<symbolic::Expression> TightenPsdConstraintToDd ( const Binding< PositiveSemidefiniteConstraint > &  constraint)
  1. Tightens the positive semidefinite constraint with a positive diagonally dominant constraint.
  2. Adds the positive diagonally dominant constraint into this MathematicalProgram.
  3. Removes the positive semidefinite 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.

Precondition
The decision variables contained in constraint have been registered with this MathematicalProgram.
Returns
The return of AddPositiveDiagonallyDominantMatrixConstraint applied to the variables in constraint.

◆ TightenPsdConstraintToSdd()

std::vector<std::vector<Matrix2<symbolic::Variable> > > TightenPsdConstraintToSdd ( const Binding< PositiveSemidefiniteConstraint > &  constraint)
  1. Tightens the positive semidefinite constraint with a scaled diagonally dominant constraint.
  2. Adds the scaled diagonally dominant constraint into this MathematicalProgram.
  3. Removes the positive semidefinite 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.

Precondition
The decision variables contained in constraint have been registered with this MathematicalProgram.
Returns
The return of AddScaledDiagonallyDominantMatrixConstraint applied to the variables in constraint.

◆ to_string()

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.

◆ ToLatex()

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:

from IPython.display import Markdown, display
display(Markdown(prog.ToLatex()))

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.

◆ visualization_callbacks()

const std::vector<Binding<VisualizationCallback> >& visualization_callbacks ( ) const

Getter for all callbacks.

Member Data Documentation

◆ kGlobalInfeasibleCost

constexpr double kGlobalInfeasibleCost
static
Initial value:
=
std::numeric_limits<double>::infinity()

The optimal cost is +∞ when the problem is globally infeasible.

◆ kUnboundedCost

constexpr double kUnboundedCost
static
Initial value:
=
-std::numeric_limits<double>::infinity()

The optimal cost is -∞ when the problem is unbounded.


The documentation for this class was generated from the following file: