Drake
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, 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...

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 VectorXDecisionVariable > &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, MatrixXDecisionVariableNewNonnegativePolynomial (const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis, NonnegativePolynomial type)
Returns a pair of nonnegative polynomial p = mᵀQm and the Grammian matrix Q, where m is monomial_basis. More...

symbolic::Polynomial NewNonnegativePolynomial (const Eigen::Ref< const MatrixX< symbolic::Variable >> &grammian, const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis, NonnegativePolynomial type)
Overloads NewNonnegativePolynomial(), except the Grammian matrix Q is an input instead of an output. More...

std::pair< symbolic::Polynomial, MatrixXDecisionVariableNewNonnegativePolynomial (const symbolic::Variables &indeterminates, int degree, NonnegativePolynomial type)

std::pair< symbolic::Polynomial, MatrixXDecisionVariableNewSosPolynomial (const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis)
Returns a pair of a SOS polynomial p = mᵀQm and the Grammian matrix Q, where m is the monomial basis. More...

std::pair< symbolic::Polynomial, MatrixXDecisionVariableNewSosPolynomial (const symbolic::Variables &indeterminates, int degree)
Returns a pair of a SOS polynomial p = m(x)ᵀQm(x) of degree degree and the Grammian matrix Q that should be PSD, where m(x) is the result of calling MonomialBasis(indeterminates, degree/2). 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...

void AddIndeterminates (const Eigen::Ref< const VectorXIndeterminate > &new_indeterminates)

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< internal::is_cost_functor_candidate< F >::value, Binding< Cost > >::type 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< internal::is_cost_functor_candidate< F >::value, Binding< Cost > >::type 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< internal::assert_if_is_constraint< F >::value, Binding< Cost > >::type 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...

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

Adds a cost term of the form 0.5*x'*Q*x + b'x. More...

Add a quadratic cost term of the form 0.5*x'*Q*x + b'*x + c. 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< QuadraticCostAddL2NormCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars)
Adds a cost term of the form | Ax - b |^2. More...

Binding< QuadraticCostAddL2NormCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars)
Adds a cost term of the form | Ax - b |^2. More...

Binding< QuadraticCostAddQuadraticCost (const Eigen::Ref< const Eigen::MatrixXd > &Q, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars)
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)
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)
Adds a cost term of the form 0.5*x'*Q*x + b'x Applied to subset of the variables. More...

Adds a cost term in the polynomial form. More...

Adds a cost in the symbolic form. More...

void AddMaximizeLogDeterminantSymmetricMatrixCost (const Eigen::Ref< const MatrixX< symbolic::Expression >> &X)
Adds the cost to maximize the log determinant of symmetric matrix X. 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 VectorX< symbolic::Expression >> &v, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub)

Add a constraint represented by a symbolic formula to the program. More...

template<typename Derived >
std::enable_if< is_eigen_scalar_same< Derived, symbolic::Formula >::value, Binding< Constraint > >::type AddConstraint (const Eigen::ArrayBase< Derived > &formulas)

template<typename Derived >
std::enable_if< is_eigen_scalar_same< Derived, symbolic::Formula >::value, Binding< Constraint > >::type AddConstraint (const Eigen::MatrixBase< Derived > &formulas)
Add a constraint represented by an Eigen::Matrix<symbolic::Formula> to the program. More...

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::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::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 VectorX< symbolic::Expression >> &v, const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub)
Adds linear constraints represented by symbolic expressions to the program. More...

Add a linear constraint represented by a symbolic formula to the program. More...

template<typename Derived >
std::enable_if< is_eigen_scalar_same< Derived, symbolic::Formula >::value, Binding< LinearConstraint > >::type AddLinearConstraint (const Eigen::ArrayBase< Derived > &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...

Adds a linear equality constraint represented by a symbolic formula to the program. More...

template<typename DerivedV , typename DerivedB >
std::enable_if< is_eigen_vector_expression_double_pair< DerivedV, DerivedB >::value, Binding< LinearEqualityConstraint > >::type 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< is_eigen_nonvector_expression_double_pair< DerivedV, DerivedB >::value, Binding< LinearEqualityConstraint > >::type 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)

Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const Eigen::Ref< const VectorXDecisionVariable > &vars)

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)

Binding< BoundingBoxConstraintAddBoundingBoxConstraint (const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const Eigen::Ref< const VectorXDecisionVariable > &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< std::is_same< typename Derived::Scalar, symbolic::Variable >::value &&Derived::ColsAtCompileTime==1, Binding< BoundingBoxConstraint > >::type 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< std::is_same< typename Derived::Scalar, symbolic::Variable >::value &&Derived::ColsAtCompileTime !=1, Binding< BoundingBoxConstraint > >::type 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< LorentzConeConstraintAddConstraint (const Binding< LorentzConeConstraint > &binding)
Adds Lorentz cone constraint referencing potentially a subset of the decision variables. More...

Binding< LorentzConeConstraintAddLorentzConeConstraint (const Eigen::Ref< const VectorX< symbolic::Expression >> &v)
Adds Lorentz cone constraint referencing potentially a subset of the decision variables. More...

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)
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)
Adds Lorentz cone constraint referencing potentially a subset of the decision variables (defined in the vars parameter). More...

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

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< 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 VectorXPoly &polynomials, const std::vector< Polynomiald::VarType > &poly_vars, const Eigen::VectorXd &lb, const Eigen::VectorXd &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 VectorXPoly &polynomials, const std::vector< Polynomiald::VarType > &poly_vars, const Eigen::VectorXd &lb, const Eigen::VectorXd &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...

template<typename Derived >
std::enable_if< std::is_same< typename Derived::Scalar, symbolic::Expression >::value, Binding< PositiveSemidefiniteConstraint > >::type AddPositiveSemidefiniteConstraint (const Eigen::MatrixBase< Derived > &e)
Adds a positive semidefinite constraint on a symmetric matrix of symbolic expressions e. More...

Binding< LinearMatrixInequalityConstraintAddConstraint (const Binding< LinearMatrixInequalityConstraint > &binding)
Adds a linear matrix inequality constraint to the program. More...

Binding< LinearMatrixInequalityConstraintAddLinearMatrixInequalityConstraint (const std::vector< Eigen::Ref< const Eigen::MatrixXd >> &F, const VariableRefList &vars)
Adds a linear matrix inequality constraint to the program. More...

Binding< LinearMatrixInequalityConstraintAddLinearMatrixInequalityConstraint (const std::vector< Eigen::Ref< const Eigen::MatrixXd >> &F, const Eigen::Ref< const VectorXDecisionVariable > &vars)
Adds a linear matrix inequality constraint to the program. 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...

MatrixXDecisionVariable AddSosConstraint (const symbolic::Polynomial &p, const Eigen::Ref< const VectorX< symbolic::Monomial >> &monomial_basis)
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)
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)
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)
Adds constraints that a given symbolic expression e is a sums-of-squares (SOS), that is, e can be decomposed into mᵀQm. More...

void 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< std::is_same< typename Derived::Scalar, symbolic::Variable >::value, Eigen::Matrix< double, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > >::type 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...

void SetSolverOption (const SolverId &solver_id, const std::string &solver_option, double option_value)

void SetSolverOption (const SolverId &solver_id, const std::string &solver_option, int option_value)

void SetSolverOption (const SolverId &solver_id, const std::string &solver_option, const std::string &option_value)

void SetSolverOptions (const SolverOptions &solver_options)
Overwrite the stored solver options inside MathematicalProgram with the provided solver options. 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< LinearConstraint > > & linear_constraints () const
Getter for linear 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...

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

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

int num_vars () const
Getter for number of variables 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...

int num_indeterminates () const
Gets the number of indeterminates in the optimization program. More...

size_t FindIndeterminateIndex (const symbolic::Variable &var) const
Returns the index of the indeterminate. More...

template<typename C , typename DerivedX >
std::enable_if< is_eigen_vector< DerivedX >::value, VectorX< typename DerivedX::Scalar > >::type 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< is_eigen_vector< DerivedX >::value, VectorX< typename DerivedX::Scalar > >::type 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< is_eigen_vector< DerivedX >::value, VectorX< typename DerivedX::Scalar > >::type 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...

const VectorXDecisionVariabledecision_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...

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

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
 indeterminates The set of indeterminates x degree The 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...

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

void AddMaximizeGeometricMeanCost (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorX< symbolic::Variable >> &x)
An overloaded version of maximize_geometric_mean. More...

void AddMaximizeGeometricMeanCost (const Eigen::Ref< const VectorX< symbolic::Variable >> &x, double c=1.0)
An overloaded version of maximize_geometric_mean. 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...

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.

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 of decision variables starting from index idx_start to idx_end (including idx_end). 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...

◆ VarType

 using VarType = symbolic::Variable::Type

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

◆ MathematicalProgram() [1/3]

 MathematicalProgram ( const MathematicalProgram & )
delete

◆ MathematicalProgram() [2/3]

 MathematicalProgram ( MathematicalProgram && )
delete

◆ MathematicalProgram() [3/3]

 MathematicalProgram ( )

◆ ~MathematicalProgram()

 virtual ~MathematicalProgram ( )
virtual

Member Function Documentation

 Binding AddBoundingBoxConstraint ( const Eigen::Ref< const Eigen::VectorXd > & lb, const Eigen::Ref< const Eigen::VectorXd > & ub, const VariableRefList & vars )

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

 Binding AddBoundingBoxConstraint ( const Eigen::Ref< const Eigen::VectorXd > & lb, const Eigen::Ref< const Eigen::VectorXd > & ub, const Eigen::Ref< const VectorXDecisionVariable > & vars )

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

Parameters
 lb The lower bound. ub The upper bound. vars Will imposes constraint lb(i) <= vars(i) <= ub(i).
Returns
The newly constructed BoundingBoxConstraint.

 Binding AddBoundingBoxConstraint ( double lb, double ub, const symbolic::Variable & var )

Adds bounds for a single variable.

Parameters
 lb Lower bound. ub Upper bound. var The decision variable.

 Binding AddBoundingBoxConstraint ( double lb, double ub, const VariableRefList & vars )

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

Parameters
 lb Lower bound. ub Upper bound. vars The decision variables.

 std::enable_if< std::is_same::value && Derived::ColsAtCompileTime == 1, Binding >::type 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
 Derived An Eigen Vector type with Variable as the scalar type.
Parameters
 lb Lower bound. ub Upper bound. vars The decision variables.

 std::enable_if< std::is_same::value && Derived::ColsAtCompileTime != 1, Binding >::type 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
 Derived An Eigen::Matrix with Variable as the scalar type. The matrix has unknown number of columns at compile time, or has more than one column.
Parameters
 lb Lower bound. ub Upper bound. vars The decision variables.

 Binding AddConstraint ( const Binding< Constraint > & binding )

Adds a generic constraint to the program.

This should only be used if a more specific type of constraint is not available, as it may require the use of a significantly more expensive solver.

 Binding 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::exception if lb <= e <= ub is a trivial constraint such as 1 <= 2 <= 3. lb <= e <= ub is unsatisfiable such as 1 <= -5 <= 3
Parameters
 e A symbolic expression of the the decision variables. lb A scalar, the lower bound. ub A scalar, the upper bound.

The resulting constraint may be a BoundingBoxConstraint, LinearConstraint, LinearEqualityConstraint, or ExpressionConstraint, depending on the arguments. Constraints of the form x == 1 (which could be created as a BoundingBoxConstraint or LinearEqualityConstraint) will be constructed as a LinearEqualityConstraint.

 Binding AddConstraint ( const Eigen::Ref< const VectorX< symbolic::Expression >> & v, const Eigen::Ref< const Eigen::VectorXd > & lb, const Eigen::Ref< const Eigen::VectorXd > & ub )

 Binding< Constraint > AddConstraint ( const symbolic::Formula & f )

Add a constraint represented by a symbolic formula to the program.

The input formula f can be of the following forms:

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");
... // set up A and b

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
 Derived An Eigen Array type of Formula.

 std::enable_if< is_eigen_scalar_same::value, Binding >::type AddConstraint ( const Eigen::ArrayBase< Derived > & formulas )

 std::enable_if< is_eigen_scalar_same::value, Binding >::type AddConstraint ( const Eigen::MatrixBase< Derived > & formulas )

Add a constraint represented by an Eigen::Matrix<symbolic::Formula> to the program.

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 any f ∈ formulas.

Template Parameters
 Derived An Eigen Matrix type of Formula.

 auto AddConstraint ( std::shared_ptr< C > con, const VariableRefList & vars )

Adds a generic constraint to the program.

This should only be used if a more specific type of constraint is not available, as it may require the use of a significantly more expensive solver.

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

Adds a generic constraint to the program.

This should only be used if a more specific type of constraint is not available, as it may require the use of a significantly more expensive solver.

 Binding AddConstraint ( const Binding< LinearConstraint > & binding )

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

 Binding AddConstraint ( const Binding< LinearEqualityConstraint > & binding )

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

 Binding AddConstraint ( const Binding< BoundingBoxConstraint > & binding )

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

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

 Binding AddConstraint ( const Binding< LorentzConeConstraint > & binding )

Adds Lorentz cone constraint referencing potentially a subset of the decision variables.

The linear expression $$z=Ax+b$$ is in the Lorentz cone. A vector $$z \in\mathbb{R}^n$$ is in the Lorentz cone, if

$z_0 \ge \sqrt{z_1^2 + ... + z_{n-1}^2}$

 Binding AddConstraint ( const Binding< RotatedLorentzConeConstraint > & binding )

Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables.

The linear expression $$z=Ax+b$$ is in rotated Lorentz cone. A vector $$z \in\mathbb{R}^n$$ is in the rotated Lorentz cone, if

$z_0z_1 \ge z_2^2 + ... + z_{n-1}^2$

 Binding AddConstraint ( const Binding< LinearComplementarityConstraint > & binding )

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

 Binding AddConstraint ( const Binding< PositiveSemidefiniteConstraint > & binding )

Adds a positive semidefinite constraint on a symmetric matrix.

 Binding AddConstraint ( std::shared_ptr< PositiveSemidefiniteConstraint > con, const Eigen::Ref< const MatrixXDecisionVariable > & symmetric_matrix_var )

Adds a positive semidefinite constraint on a symmetric matrix.

 Binding AddConstraint ( const Binding< LinearMatrixInequalityConstraint > & binding )

Adds a linear matrix inequality constraint to the program.

 Binding 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
 binding The binding of ExponentialConeConstraint and its bound variables.

 Binding AddCost ( const Binding< Cost > & binding )

Adds a generic cost to the optimization program.

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

Adds a cost type to the optimization program.

Parameters
 obj The added objective. vars The decision variables on which the cost depend.

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

Adds a generic cost to the optimization program.

Parameters
 obj The added objective. vars The decision variables on which the cost depend.

 std::enable_if::value, Binding >::type AddCost ( F && f, const VariableRefList & vars )

Adds a cost to the optimization program on a list of variables.

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

 std::enable_if::value, Binding >::type 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
 F Type that defines functions numInputs, numOutputs and eval.

 std::enable_if::value, Binding >::type AddCost ( F && , Vars && )

Statically assert if a user inadvertently passes a binding-compatible Constraint.

Template Parameters
 F The type to check.

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

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

Applied to subset of the variables and pushes onto the quadratic cost data structure.

 Binding AddCost ( const symbolic::Expression & e )

Adds a cost in the symbolic form.

Note that the constant part of the cost is ignored. So if you set e = x + 2, then only the cost on x is added, the constant term 2 is ignored.

Parameters
 e The linear or quadratic expression of the cost.
Precondition
e is linear or e is quadratic. Otherwise throws a runtime error.
Returns
The newly created cost, together with the bound variables.

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

Appends new variables to the end of the existing variables.

Parameters
Precondition
decision_variables should not intersect with the existing variables or indeterminates in the optimization program.
Each entry in decision_variables should not be a dummy variable.
Exceptions
 std::runtime_error if the preconditions are not satisfied.

 void 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
 p1 Note that p1's indeterminates should have been registered as indeterminates in this MathematicalProgram object, and p1's coefficients are affine functions of decision variables in this MathematicalProgram object. p2 Note that p2's indeterminates should have been registered as indeterminates in this MathematicalProgram object, and p2's coefficients are affine functions of decision variables in this MathematicalProgram object.
Note
It calls Reparse to enforce p1 and p2 to have this MathematicalProgram's indeterminates.

 Binding 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
 A The A matrix in the documentation above. A must have 3 rows. b The b vector in the documentation above. vars The variables bound with this constraint.

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

Add the constraint that z is in the exponential cone.

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

 void AddIndeterminates ( const Eigen::Ref< const VectorXIndeterminate > & new_indeterminates )

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

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

 Binding AddL2NormCost ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & b, const VariableRefList & vars )

Adds a cost term of the form | Ax - b |^2.

 Binding AddL2NormCost ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & b, const Eigen::Ref< const VectorXDecisionVariable > & vars )

Adds a cost term of the form | Ax - b |^2.

 Binding AddLinearComplementarityConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & M, const Eigen::Ref< const Eigen::VectorXd > & q, const VariableRefList & vars )

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

 Binding AddLinearComplementarityConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & M, const Eigen::Ref< const Eigen::VectorXd > & q, const Eigen::Ref< const VectorXDecisionVariable > & vars )

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

 Binding AddLinearConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & lb, const Eigen::Ref< const Eigen::VectorXd > & ub, const VariableRefList & vars )

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

 Binding AddLinearConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & lb, const Eigen::Ref< const Eigen::VectorXd > & ub, const Eigen::Ref< const VectorXDecisionVariable > & vars )

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

 Binding 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
 a A row vector. lb A scalar, the lower bound. ub A scalar, the upper bound. vars The decision variables on which to impose the linear constraint.

 Binding 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
 a A row vector. lb A scalar, the lower bound. ub A scalar, the upper bound. vars The decision variables on which to impose the linear constraint.

 Binding 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::exception if e is a non-linear expression. lb <= e <= ub is a trivial constraint such as 1 <= 2 <= 3. lb <= e <= ub is unsatisfiable such as 1 <= -5 <= 3
Parameters
 e A linear symbolic expression in the form of c0 + c1 * v1 + ... + cn * vn where c_i is a constant and @v_i is a variable. lb A scalar, the lower bound. ub A scalar, the upper bound.

 Binding AddLinearConstraint ( const Eigen::Ref< const VectorX< symbolic::Expression >> & v, const Eigen::Ref< const Eigen::VectorXd > & lb, const Eigen::Ref< const Eigen::VectorXd > & ub )

Adds linear constraints represented by symbolic expressions to the program.

It throws if @v includes a non-linear expression or lb <= v <= ub includes trivial/unsatisfiable constraints.

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

 std::enable_if< is_eigen_scalar_same::value, Binding >::type AddLinearConstraint ( const Eigen::ArrayBase< Derived > & 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

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
 Derived An Eigen Array type of Formula.

 Binding AddLinearCost ( const symbolic::Expression & e )

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

Parameters
 e A 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.

 Binding AddLinearCost ( const Eigen::Ref< const Eigen::VectorXd > & a, double b, const VariableRefList & vars )

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

Applied to a subset of the variables and pushes onto the linear cost data structure.

 Binding AddLinearCost ( const Eigen::Ref< const Eigen::VectorXd > & a, double b, const Eigen::Ref< const VectorXDecisionVariable > & vars )

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

Applied to a subset of the variables and pushes onto the linear cost data structure.

 Binding AddLinearCost ( const Eigen::Ref< const Eigen::VectorXd > & a, const VarType & vars )

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

Applied to a subset of the variables and pushes onto the linear cost data structure.

 Binding AddLinearEqualityConstraint ( const symbolic::Expression & e, double b )

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

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

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

 std::enable_if< is_eigen_vector_expression_double_pair::value, Binding >::type 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::exception if v(i) is a non-linear expression. v(i) is a constant.
Template Parameters
 DerivedV An Eigen Matrix type of Expression. A column vector. DerivedB An Eigen Matrix type of double. A column vector.
Parameters
 v v(i) is a linear symbolic expression in the form of  c0 + c1 * x1 + ... + cn * xn  where ci is a constant and @xi is a variable. b A vector of doubles.
Returns
The newly added linear equality constraint, together with the bound variables.

 std::enable_if< is_eigen_nonvector_expression_double_pair::value, Binding >::type 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
 DerivedV An Eigen Matrix type of Expression. The number of columns at compile time should not be 1. DerivedB An Eigen Matrix type of double.
Parameters
 V An Eigen Matrix of symbolic expressions. V(i, j) should be a linear expression. B An Eigen Matrix of doubles. lower_triangle If true, then only the lower triangular part of V is constrained, otherwise the whole matrix V is constrained. Default: is false.
Returns
The newly added linear equality constraint, together with the bound variables.

 Binding AddLinearEqualityConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & Aeq, const Eigen::Ref< const Eigen::VectorXd > & beq, const VariableRefList & vars )

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);
x.segment<1>(5)});

The code above imposes constraints

$-x(2) + 2x(5) = 1$

$x(2) + x(5) = 3$

 Binding AddLinearEqualityConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & Aeq, const Eigen::Ref< const Eigen::VectorXd > & beq, const Eigen::Ref< const VectorXDecisionVariable > & vars )

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

 Binding 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
 a A row vector. beq A scalar. vars The decision variables on which the constraint is imposed.

 Binding 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
 a A row vector. beq A scalar. vars The decision variables on which the constraint is imposed.

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

Adds a linear matrix inequality constraint to the program.

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

Adds a linear matrix inequality constraint to the program.

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

Adds Lorentz cone constraint referencing potentially a subset of the decision variables.

Parameters
 v An 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.);

 Binding AddLorentzConeConstraint ( const symbolic::Expression & linear_expression, const symbolic::Expression & quadratic_expression, double tol = 0 )

Adds Lorentz cone constraint on the linear expression v1 and quadratic expression v2, such that v1 >= sqrt(v2)

Parameters
 linear_expression The linear expression v1. quadratic_expression The quadratic expression v2. tol The tolerance to determine if the matrix in v2 is positive semidefinite or not.
Default: is 0.
Return values
 binding The 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::runtime_error if the preconditions are not satisfied.

Notice this constraint is equivalent to the vector [z;y] is within a Lorentz cone, where

 z = v1
y = R * x + d


while (R, d) satisfies y'*y = x'*Q*x + b'*x + a For example, to add the Lorentz cone constraint

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


the user could call

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

 Binding AddLorentzConeConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & b, const VariableRefList & vars )

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
 A A $$\mathbb{R}^{n\times m}$$ matrix, whose number of columns equals to the size of the decision variables. b A $$\mathbb{R}^n$$ vector, whose number of rows equals to the size of the decision variables. vars The list of $$m$$ decision variables.
Returns
The newly added Lorentz cone constraint.

 Binding AddLorentzConeConstraint ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & b, const Eigen::Ref< const VectorXDecisionVariable > & vars )

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
 A A $$\mathbb{R}^{n\times m}$$ matrix, whose number of columns equals to the size of the decision variables. b A $$\mathbb{R}^n$$ vector, whose number of rows equals to the size of the decision variables. vars The Eigen vector of $$m$$ decision variables.
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]

 Binding AddLorentzConeConstraint ( const VariableRefList & vars )

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
 vars The stacked column of vars should lie within the Lorentz cone.
Returns
The newly added Lorentz cone constraint.

 Binding AddLorentzConeConstraint ( const Eigen::MatrixBase< VectorDecisionVariable< rows >> & vars )

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
 vars The stacked column of vars should lie within the Lorentz cone.
Returns
The newly added Lorentz cone constraint.

 void AddMaximizeGeometricMeanCost ( const Eigen::Ref< const Eigen::MatrixXd > & A, const Eigen::Ref< const Eigen::VectorXd > & b, const Eigen::Ref< const VectorX< symbolic::Variable >> & x )

Precondition
A.rows() == b.rows(), A.rows() >= 2.

 void AddMaximizeGeometricMeanCost ( const Eigen::Ref< const VectorX< symbolic::Variable >> & x, double c = 1.0 )

We add the cost to maximize the geometric mean of x, i.e., c*power(∏ᵢx(i), 1/n).

Parameters
 c The positive coefficient of the geometric mean cost, Default: is 1.
Precondition
x.rows() >= 2.
c > 0.

 void AddMaximizeLogDeterminantSymmetricMatrixCost ( const Eigen::Ref< const MatrixX< symbolic::Expression >> & X )

Adds the cost to maximize the log determinant of symmetric matrix X.

log(det(X)) is a concave function of X, so we can maximize it through convex optimization. In order to do that, we introduce slack variables t, and a lower triangular matrix Z, with the constraints ⌈X Z⌉ is positive semidifinite. ⌊Zᵀ diag(Z)⌋ log(Z(i, i)) >= t(i) and we will minimize -∑ᵢt(i).

Parameters
 X A symmetric positive semidefinite matrix X, whose log(det(X)) will be maximized.
Precondition
X is a symmetric matrix.
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 does).

 Binding AddPolynomialConstraint ( const VectorXPoly & polynomials, const std::vector< Polynomiald::VarType > & poly_vars, const Eigen::VectorXd & lb, const Eigen::VectorXd & ub, const VariableRefList & vars )

Adds a polynomial constraint to the program referencing a subset of the decision variables (defined in the vars parameter).

 Binding AddPolynomialConstraint ( const VectorXPoly & polynomials, const std::vector< Polynomiald::VarType > & poly_vars, const Eigen::VectorXd & lb, const Eigen::VectorXd & ub, const Eigen::Ref< const VectorXDecisionVariable > & vars )

Adds a polynomial constraint to the program referencing a subset of the decision variables (defined in the vars parameter).

 Binding AddPolynomialCost ( const symbolic::Expression & e )

Adds a cost term in the polynomial form.

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

 MatrixX 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
 X The 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)

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

Adds a positive semidefinite constraint on a symmetric matrix.

Exceptions
 std::runtime_error in Debug mode if symmetric_matrix_var is not symmetric.
Parameters
 symmetric_matrix_var A symmetric MatrixDecisionVariable object.

 std::enable_if< std::is_same::value, Binding >::type AddPositiveSemidefiniteConstraint ( const Eigen::MatrixBase< Derived > & 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.

Template Parameters
 Derived An Eigen Matrix of symbolic expressions.
Parameters
 e Imposes constraint "e is positive semidefinite".
Precondition
{1. e is symmetric.
1. 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;

Add a quadratic cost term of the form 0.5*x'*Q*x + b'*x + c.

Notice that in the optimization program, the constant term c in the cost is ignored.

Parameters
Exceptions
 std::runtime error if the expression is not quadratic.
Returns
The newly added cost together with the bound variables.

 Binding AddQuadraticCost ( const Eigen::Ref< const Eigen::MatrixXd > & Q, const Eigen::Ref< const Eigen::VectorXd > & b, const VariableRefList & vars )

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

Applied to subset of the variables.

 Binding AddQuadraticCost ( const Eigen::Ref< const Eigen::MatrixXd > & Q, const Eigen::Ref< const Eigen::VectorXd > & b, double c, const Eigen::Ref< const VectorXDecisionVariable > & vars )

Adds a cost term of the form 0.5*x'*Q*x + b'x + c Applied to subset of the variables.

 Binding AddQuadraticCost ( const Eigen::Ref< const Eigen::MatrixXd > & Q, const Eigen::Ref< const Eigen::VectorXd > & b, const Eigen::Ref< const VectorXDecisionVariable > & vars )

Adds a cost term of the form 0.5*x'*Q*x + b'x Applied to subset of the variables.

 Binding AddQuadraticErrorCost ( const Eigen::Ref< const Eigen::MatrixXd > & Q, const Eigen::Ref< const Eigen::VectorXd > & x_desired, const VariableRefList & vars )

Adds a cost term of the form (x-x_desired)'Q(x-x_desired).

 Binding AddQuadraticErrorCost ( const Eigen::Ref< const Eigen::MatrixXd > & Q, const Eigen::Ref< const Eigen::VectorXd > & x_desired, const Eigen::Ref< const VectorXDecisionVariable > & vars )

Adds a cost term of the form (x-x_desired)'Q(x-x_desired).

 Binding 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_expression1 The linear expression v1. linear_expression2 The linear expression v2. quadratic_expression The quadratic expression u. tol The tolerance to determine if the matrix in v2 is positive semidefinite or not.
Default: is 0.
Return values
 binding The 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::runtime_error if the preconditions are not satisfied.

For example, to add the rotated Lorentz cone constraint

(x+1)(x+y) >= x²+z²+2z+5
x+1 >= 0
x+y >= 0


The user could call

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

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

Adds a constraint that a symbolic expression.

Parameters
 v is in the rotated Lorentz cone, i.e., $v_0v_1 \ge v_2^2 + ... + v_{n-1}^2\\ v_0 \ge 0, v_1 \ge 0$ v A linear expression of variables, $$v = A x + b$$, where $$A, b$$ are given matrices of the correct size, $$x$$ is the vector of decision variables.
Return values
 binding The newly added rotated Lorentz cone constraint, together with the bound variables.

For example, to add the rotated Lorentz cone constraint

(x+1)(x+y) >= x²+z²+2z+5 = x² + (z+1)² + 2²
x+1 >= 0
x+y >= 0


The user could call

Eigen::Matrix<symbolic::Expression, 5, 1> v;
v << x+1, x+y, x, z+1, 2;

 Binding 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
 A A matrix whose number of columns equals to the size of the decision variables. b A vector whose number of rows equals to the size fo the decision variables. vars The decision variables on which the constraint is imposed.

 Binding 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
 A A matrix whose number of columns equals to the size of the decision variables. b A vector whose number of rows equals to the size fo the decision variables. vars The decision variables on which the constraint is imposed.

 Binding 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
 vars The stacked column of vars lies in the rotated Lorentz cone.
Returns
The newly added rotated Lorentz cone constraint.

 Binding 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
 vars The stacked column of vars lies in the rotated Lorentz cone.
Returns
The newly added rotated Lorentz cone constraint.

 std::vector > > AddScaledDiagonallyDominantMatrixConstraint ( const Eigen::Ref< const MatrixX< symbolic::Expression >> & X )

This is an overloaded variant of scaled diagonally dominant matrix constraint.

Parameters
 X The 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.

 std::vector > > AddScaledDiagonallyDominantMatrixConstraint ( const Eigen::Ref< const MatrixX< symbolic::Variable >> & X )

This is an overloaded variant of scaled diagonally dominant matrix constraint.

Parameters
 X The 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 dummy variables.

 MatrixXDecisionVariable AddSosConstraint ( const symbolic::Polynomial & p, const Eigen::Ref< const VectorX< symbolic::Monomial >> & monomial_basis )

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.

Note
It calls Reparse to enforce p to have this MathematicalProgram's indeterminates if necessary.

 std::pair > AddSosConstraint ( const symbolic::Polynomial & p )

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:

Note
It calls Reparse to enforce p to have this MathematicalProgram's indeterminates if necessary.
• The coefficients matrix Q, which is positive semidefinite.
• The monomial basis m.

 MatrixXDecisionVariable AddSosConstraint ( const symbolic::Expression & e, const Eigen::Ref< const VectorX< symbolic::Monomial >> & monomial_basis )

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.

 std::pair > AddSosConstraint ( const symbolic::Expression & e )

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.

 Binding 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
 callback a std::function that accepts an Eigen::Vector of doubles representing the bound decision variables. vars the decision variables that should be passed to the callback.

 Binding 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
 callback a std::function that accepts an Eigen::Vector of doubles representing the for the bound decision variables. vars the decision variables that should be passed to the callback.

◆ bounding_box_constraints()

 const std::vector >& bounding_box_constraints ( ) const

Getter for all bounding box constraints.

◆ Clone()

 std::unique_ptr 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

However, the clone's x values will be initialized to NaN, and all internal solvers will be freshly constructed.

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

 const VectorXDecisionVariable& decision_variables ( ) const

Getter for all decision variables in the program.

◆ EvalBinding()

 std::enable_if::value, VectorX >::type 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
 binding A Binding whose variables are decision variables in this program. prog_var_vals The value of all the decision variables in this program.
Exceptions
 std::logic_error if 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::value, VectorX >::type 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
 bindings List of bindings. prog prog_var_vals The value of all the decision variables in this program.
Returns
All binding values, concatenated into a single vector.
Exceptions
 std::logic_error if 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_vals The value of all the decision variables in this program.
Exceptions
 std::logic_error if the size does not match.

◆ exponential_cone_constraints()

 const std::vector >& 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 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 >& generic_constraints ( ) const

Getter for all generic constraints.

◆ generic_costs()

 const std::vector >& generic_costs ( ) const

Getter for all generic costs.

◆ GetAllConstraints()

 std::vector > 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 > 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 > GetAllLinearConstraints ( ) const

Getter returning all linear constraints (both linear equality and inequality constraints).

Returns
Vector of all linear constraint bindings.

◆ GetBindingVariableValues()

 std::enable_if::value, VectorX >::type 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
 binding binding.variables() must be decision variables in this MathematicalProgram. prog_var_vals The 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::runtime_error if the pre condition is not satisfied.

◆ GetInitialGuess() [2/2]

 std::enable_if< std::is_same::value, Eigen::Matrix >::type 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::runtime_error if the pre condition is not satisfied.

◆ GetSolverOptionsDouble()

 const std::unordered_map& GetSolverOptionsDouble ( const SolverId & solver_id ) const

◆ GetSolverOptionsInt()

 const std::unordered_map& GetSolverOptionsInt ( const SolverId & solver_id ) const

◆ GetSolverOptionsStr()

 const std::unordered_map& GetSolverOptionsStr ( const SolverId & solver_id ) const

◆ GetVariableScaling()

 const std::unordered_map& GetVariableScaling ( ) const

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

◆ indeterminate()

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

Getter for the indeterminate with index i in the program.

◆ indeterminates()

 const VectorXIndeterminate& indeterminates ( ) const

Getter for all indeterminates in the program.

◆ indeterminates_index()

 const std::unordered_map& 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.

◆ linear_complementarity_constraints()

 const std::vector >& linear_complementarity_constraints ( ) const

Getter for all linear complementarity constraints.

◆ linear_constraints()

 const std::vector >& linear_constraints ( ) const

Getter for linear constraints.

◆ linear_costs()

 const std::vector >& linear_costs ( ) const

Getter for linear costs.

◆ linear_equality_constraints()

 const std::vector >& linear_equality_constraints ( ) const

Getter for linear equality constraints.

◆ linear_matrix_inequality_constraints()

 const std::vector >& linear_matrix_inequality_constraints ( ) const

Getter for linear matrix inequality constraints.

◆ lorentz_cone_constraints()

 const std::vector >& lorentz_cone_constraints ( ) const

Getter for Lorentz cone constraints.

◆ MakeCost()

 static std::shared_ptr MakeCost ( F && f )
static

Convert an input of type F to a FunctionCost object.

Template Parameters
 F This 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 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
 Rows The number of rows in the new variables. Cols The number of columns in the new variables.
Parameters
 rows The number of rows in the new variables. cols The number of columns in the new variables. name The commonly shared name of the new variables.
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 NewBinaryVariables ( const std::string & name = "b" )

Adds a matrix of binary variables into the optimization program.

Template Parameters
 Rows The number of rows in the newly added binary variables. Cols The number of columns in the new variables. The default is 1.
Parameters
 name Each 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.

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
 rows The number of rows in the new variables. name The 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 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
 Rows The number of rows of the new variables, in the compile time. Cols The number of columns of the new variables, in the compile time.
Parameters
 rows The number of rows in the new variables. When Rows is not Eigen::Dynamic, rows is ignored. cols The number of columns in the new variables. When Cols is not Eigen::Dynamic, cols is ignored. name All variables will share the same name, but different index.
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 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
 Rows The number of rows in the new variables. Cols The number of columns in the new variables. The default is 1.
Parameters
 name All 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 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
 indeterminates The monomial basis is over these indeterminates. degree The highest degree of the polynomial. coeff_name The coefficients of the polynomial are decision variables with this name as a base. The variable name would be "a1", "a2", etc.

◆ NewEvenDegreeNonnegativePolynomial()

 std::tuple 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
 type The returned polynomial p(x) can be either SOS, SDSOS or DSOS, depending on type.

◆ NewEvenDegreeSdsosPolynomial()

 std::tuple NewEvenDegreeSdsosPolynomial ( const symbolic::Variables & indeterminates, int degree )

see even_degree_nonnegative_polynomial for details.

Variant that produces an SDSOS polynomial.

◆ NewEvenDegreeSosPolynomial()

 std::tuple 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 NewIndeterminates ( const std::array< std::string, rows *cols > & names )

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

Template Parameters
 rows The number of rows in the new indeterminates. cols The number of columns in the new indeterminates.
Parameters
 names A 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 NewIndeterminates ( const std::array< std::string, rows > & names )

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

Template Parameters
 rows The number of rows in the new indeterminates. cols The number of columns in the new indeterminates.
Parameters
 names A 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 NewIndeterminates ( const std::string & name = "X" )

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

Template Parameters
 rows The number of rows in the new indeterminates. cols The number of columns in the new indeterminates.
Parameters
 names A 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 NewIndeterminates ( const std::string & name = "x" )

The name for all newly added indeterminates are set to name. The default name is "x"

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

◆ NewIndeterminates() [5/8]

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

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

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
 rows The number of rows in the new indeterminates. cols The number of columns in the new indeterminates. names A vector of strings containing the name for each variable.
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.

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

◆ NewNonnegativePolynomial() [1/3]

 std::pair NewNonnegativePolynomial ( const Eigen::Ref< const VectorX< symbolic::Monomial >> & monomial_basis, NonnegativePolynomial type )

Returns a pair of nonnegative polynomial p = mᵀQm and the Grammian matrix Q, where m is monomial_basis.

Adds Q as decision variables to the program. Depending on the type of the polynomial, we will impose different constraint on Q.

• if type = kSos, we impose Q being positive semidefinite.
• if type = kSdsos, we impose Q being scaled diagonally dominant.
• if type = kDsos, we impose Q being positive diagonally dominant.
Parameters
 monomial_basis The monomial basis. type The type of the nonnegative polynomial.
Returns
(p, Q) The polynomial p and the Grammian matrix Q. Q has been added as decision variables to the program.

◆ NewNonnegativePolynomial() [2/3]

 symbolic::Polynomial NewNonnegativePolynomial ( const Eigen::Ref< const MatrixX< symbolic::Variable >> & grammian, const Eigen::Ref< const VectorX< symbolic::Monomial >> & monomial_basis, NonnegativePolynomial type )

Overloads NewNonnegativePolynomial(), except the Grammian matrix Q is an input instead of an output.

◆ NewNonnegativePolynomial() [3/3]

 std::pair NewNonnegativePolynomial ( const symbolic::Variables & indeterminates, int degree, NonnegativePolynomial type )

Instead of passing the monomial basis, we use a monomial basis that contains all monomials of indeterminates of total order up to degree / 2, hence the returned polynomial p contains all the monomials of indeterminates of total order up to degree.

Parameters
 indeterminates All the indeterminates in the polynomial p. degree The polynomial p will contain all the monomials up to order degree. type The type of the nonnegative polynomial.
Returns
(p, Q) The polynomial p and the Grammian matrix Q. Q has been added as decision variables to the program.
Precondition
degree is a positive even number.

◆ 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
 indeterminates The monomial basis is over these indeterminates. degree The highest degree of the polynomial. coeff_name The coefficients of the polynomial are decision variables with this name as a base. The variable name would be "a1", "a2", etc.

◆ NewSosPolynomial() [1/2]

 std::pair NewSosPolynomial ( const Eigen::Ref< const VectorX< symbolic::Monomial >> & monomial_basis )

Returns a pair of a SOS polynomial p = mᵀQm and the Grammian 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.

Note
Q is a symmetric monomial_basis.rows() x monomial_basis.rows() matrix.

◆ NewSosPolynomial() [2/2]

 std::pair NewSosPolynomial ( const symbolic::Variables & indeterminates, int degree )

Returns a pair of a SOS polynomial p = m(x)ᵀQm(x) of degree degree and the Grammian 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.

Exceptions
 std::runtime_error if degree is not a positive even integer.
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
 rows The number of rows in the symmetric matrix. name The name of the matrix. It is only used the for user to understand the optimization program. The default name is "Symmetric", and each variable will be named as Symmetric(0, 0) Symmetric(1, 0) ... Symmetric(rows-1, 0) Symmetric(1, 0) Symmetric(1, 1) ... Symmetric(rows-1, 1) ... Symmetric(rows-1,0) Symmetric(rows-1,1) ... Symmetric(rows-1, rows-1)  Notice that the (i,j)'th entry and (j,i)'th entry has the same name.
Returns

◆ NewSymmetricContinuousVariables() [2/2]

 MatrixDecisionVariable 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
 rows The number of rows in the symmetric matrix.
Parameters
 name The name of the matrix. It is only used the for user to understand the optimization program. The default name is "Symmetric", and each variable will be named as Symmetric(0, 0) Symmetric(1, 0) ... Symmetric(rows-1, 0) Symmetric(1, 0) Symmetric(1, 1) ... Symmetric(rows-1, 1) ... Symmetric(rows-1,0) Symmetric(rows-1,1) ... Symmetric(rows-1, rows-1)  Notice that the (i,j)'th entry and (j,i)'th entry has the same name.
Returns

◆ 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 >& positive_semidefinite_constraints ( ) const

Getter for positive semidefinite constraints.

 const std::vector >& quadratic_costs ( ) const

◆ 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 >& 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_variable a registered decision variable in this program. decision_variable_new_value the variable's new values. [in,out] values The vector to be tweaked; must be of size num_vars().

◆ 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_variables registered decision variables in this program. decision_variables_new_values the variables' respective new values; must have the same rows() and cols() sizes and decision_variables. [in,out] values The vector to be tweaked; must be of size num_vars().

◆ 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::runtime_error if 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
 x0 A 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 )

◆ SetSolverOption() [2/3]

 void SetSolverOption ( const SolverId & solver_id, const std::string & solver_option, int option_value )

◆ SetSolverOption() [3/3]

 void SetSolverOption ( const SolverId & solver_id, const std::string & solver_option, const std::string & option_value )

◆ 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 of decision variables starting from index idx_start to idx_end (including idx_end).

Parameters
 var the decision variable to be scaled. s scaling factor (must be positive).

◆ solver_options()

 const SolverOptions& solver_options ( ) const

Returns the solver options stored inside MathematicalProgram.

◆ visualization_callbacks()

 const std::vector >& visualization_callbacks ( ) const

Getter for all callbacks.

◆ 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: