Drake
MathematicalProgram Class Reference

#include <drake/solvers/mathematical_program.h>

Inheritance diagram for MathematicalProgram:

Classes

struct  SolverData
 

Public Types

using VarType = symbolic::Variable::Type
 

Public Member Functions

 MathematicalProgram ()
 
virtual ~MathematicalProgram ()
 
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)
 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...
 
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...
 
std::pair< symbolic::Polynomial, Binding< PositiveSemidefiniteConstraint > > NewSosPolynomial (const symbolic::Variables &indeterminates, int degree)
 Returns a pair of a SOS polynomial p = xᵀQx of degree degree and a PSD constraint for the coefficients matrix Q, where x is a monomial basis over indeterminates of degree @p degree / 2. 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...
 
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< detail::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< detail::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< detail::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...
 
Binding< LinearCostAddLinearCost (const symbolic::Expression &e)
 Adds a linear cost term of the form a'*x + b. More...
 
Binding< LinearCostAddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, double b, const VariableRefList &vars)
 Adds a linear cost term of the form a'*x + b. More...
 
Binding< LinearCostAddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, double b, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 Adds a linear cost term of the form a'*x + b. More...
 
template<typename VarType >
Binding< LinearCostAddLinearCost (const Eigen::Ref< const Eigen::VectorXd > &a, const VarType &vars)
 Adds a linear cost term of the form a'*x. More...
 
Binding< QuadraticCostAddCost (const Binding< QuadraticCost > &binding)
 Adds a cost term of the form 0.5*x'*Q*x + b'x. More...
 
Binding< QuadraticCostAddQuadraticCost (const symbolic::Expression &e)
 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...
 
Binding< PolynomialCostAddPolynomialCost (const symbolic::Expression &e)
 Adds a cost term in the polynomial form. More...
 
Binding< CostAddCost (const symbolic::Expression &e)
 Adds a cost in the symbolic form. More...
 
Binding< ConstraintAddConstraint (const Binding< Constraint > &binding)
 Adds a generic constraint to the program. More...
 
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...
 
Binding< LinearConstraintAddLinearConstraint (const symbolic::Formula &f)
 Add a linear constraint represented by a symbolic formula to the program. More...
 
template<typename Derived >
std::enable_if< detail::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...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const symbolic::Formula &f)
 Adds a linear equality constraint represented by a symbolic formula to the program. More...
 
template<typename DerivedV , typename DerivedB >
std::enable_if< detail::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< detail::is_eigen_matrix_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)
 AddLinearEqualityConstraint. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::Ref< const Eigen::MatrixXd > &Aeq, const Eigen::Ref< const Eigen::VectorXd > &beq, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 AddLinearEqualityConstraint. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::Ref< const Eigen::RowVectorXd > &a, double beq, const VariableRefList &vars)
 Adds one row of linear equality constraint referencing potentially a subset of decision variables. More...
 
Binding< LinearEqualityConstraintAddLinearEqualityConstraint (const Eigen::Ref< const Eigen::RowVectorXd > &a, double beq, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 Adds one row of linear equality constraint referencing potentially a subset of decision variables. More...
 
Binding< BoundingBoxConstraintAddConstraint (const Binding< BoundingBoxConstraint > &binding)
 Adds bounding box constraints referencing potentially a subest of the decision variables. More...
 
Binding< BoundingBoxConstraintAddBoundingBoxConstraint (const Eigen::Ref< const Eigen::VectorXd > &lb, const Eigen::Ref< const Eigen::VectorXd > &ub, const VariableRefList &vars)
 AddBoundingBoxConstraint. More...
 
Binding< BoundingBoxConstraintAddBoundingBoxConstraint (const Eigen::Ref< const Eigen::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...
 
Binding< LorentzConeConstraintAddLorentzConeConstraint (const symbolic::Expression &v1, const symbolic::Expression &v2)
 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...
 
Binding< LorentzConeConstraintAddLorentzConeConstraint (const VariableRefList &vars)
 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 Eigen::Ref< const VectorX< symbolic::Expression >> &v)
 Adds a constraint that a symbolic expression. More...
 
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const VariableRefList &vars)
 Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone. More...
 
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const Eigen::Ref< const Eigen::MatrixXd > &A, const Eigen::Ref< const Eigen::VectorXd > &b, const Eigen::Ref< const VectorXDecisionVariable > &vars)
 Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone. More...
 
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const VariableRefList &vars)
 Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone. More...
 
template<int rows>
Binding< RotatedLorentzConeConstraintAddRotatedLorentzConeConstraint (const Eigen::MatrixBase< VectorDecisionVariable< rows >> &vars)
 Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone. More...
 
Binding< 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 espressions 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...
 
std::pair< Binding< PositiveSemidefiniteConstraint >, Binding< LinearEqualityConstraint > > 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 xᵀQx. More...
 
std::pair< Binding< PositiveSemidefiniteConstraint >, Binding< LinearEqualityConstraint > > 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 xTQx. More...
 
template<typename DerivedA , typename DerivedB >
void SetInitialGuess (const Eigen::MatrixBase< DerivedA > &decision_variable_mat, const Eigen::MatrixBase< DerivedB > &x0)
 Set the initial guess for the decision variables stored in var to be x0. More...
 
template<typename Derived >
void SetInitialGuessForAllVariables (const Eigen::MatrixBase< Derived > &x0)
 Set the intial guess for ALL decision variables. More...
 
SolutionResult Solve ()
 Solve the MathematicalProgram. More...
 
void PrintSolution ()
 
void SetDecisionVariableValues (const Eigen::Ref< const Eigen::VectorXd > &values)
 Sets the values of all decision variables, such that the value of decision_variables_(i) is values(i). More...
 
void SetDecisionVariableValues (const Eigen::Ref< const VectorXDecisionVariable > &variables, const Eigen::Ref< const Eigen::VectorXd > &values)
 Sets the value of some decision variables, such that the value of variables(i) is values(i). More...
 
void SetDecisionVariableValue (const symbolic::Variable &var, double value)
 Sets the value of a single decision variable in the optimization program. More...
 
void SetSolverOption (const SolverId &solver_id, const std::string &solver_option, double option_value)
 Set an option for a particular solver. More...
 
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)
 
const std::map< std::string, double > & GetSolverOptionsDouble (const SolverId &solver_id)
 
const std::map< std::string, int > & GetSolverOptionsInt (const SolverId &solver_id)
 
const std::map< std::string, std::string > & GetSolverOptionsStr (const SolverId &solver_id)
 
void SetSolverId (SolverId solver_id)
 Sets the ID of the solver that was used to solve this program. More...
 
optional< SolverIdGetSolverId () const
 Returns the ID of the solver that was used to solve this program. More...
 
double GetOptimalCost () const
 Getter for optimal cost at the solution. More...
 
void SetOptimalCost (double optimal_cost)
 
double GetLowerBoundCost () const
 Getter for lower bound on optimal cost. More...
 
void SetLowerBoundCost (double lower_bound_cost)
 Setter for lower bound on optimal cost. More...
 
const std::vector< Binding< Cost > > & generic_costs () const
 Getter for all generic costs. More...
 
const std::vector< Binding< Constraint > > & generic_constraints () const
 Getter for all generic constraints. More...
 
const std::vector< Binding< LinearEqualityConstraint > > & linear_equality_constraints () const
 Getter for linear equality constraints. More...
 
const std::vector< Binding< LinearCost > > & linear_costs () const
 Getter for linear costs. More...
 
const std::vector< Binding< QuadraticCost > > & quadratic_costs () const
 Getter for quadratic costs. More...
 
const std::vector< Binding< LinearConstraint > > & linear_constraints () const
 Getter for linear constraints. More...
 
const std::vector< Binding< LorentzConeConstraint > > & lorentz_cone_constraints () const
 Getter for Lorentz cone constraint. More...
 
const std::vector< Binding< RotatedLorentzConeConstraint > > & rotated_lorentz_cone_constraints () const
 Getter for rotated Lorentz cone constraint. More...
 
const std::vector< Binding< PositiveSemidefiniteConstraint > > & positive_semidefinite_constraints () const
 Getter for positive semidefinite constraint. More...
 
const std::vector< Binding< LinearMatrixInequalityConstraint > > & linear_matrix_inequality_constraints () const
 Getter for linear matrix inequality constraint. More...
 
std::vector< Binding< Cost > > GetAllCosts () const
 Getter returning all costs (for now linear costs appended to generic costs, then quadratic costs appended to generic costs). More...
 
std::vector< Binding< LinearConstraint > > GetAllLinearConstraints () const
 Getter returning all linear constraints (both linear equality and inequality 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...
 
template<typename T >
std::shared_ptr< T > GetSolverData ()
 
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...
 
const Eigen::VectorXd GetSolutionVectorValues () const
 Returns the solution in a flat Eigen::VectorXd. More...
 
int FindDecisionVariableIndex (const symbolic::Variable &var) const
 Returns the index of the decision variable. More...
 
int num_indeterminates () const
 Gets the solution of an Eigen matrix of decision variables. More...
 
size_t FindIndeterminateIndex (const symbolic::Variable &var) const
 Returns the index of the indeterminate. More...
 
template<typename Derived >
std::enable_if< std::is_same< typename Derived::Scalar, symbolic::Variable >::value, Eigen::Matrix< double, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > >::type GetSolution (const Eigen::MatrixBase< Derived > &var) const
 Gets the solution of an Eigen matrix of decision variables. More...
 
double GetSolution (const symbolic::Variable &var) const
 Gets the value of a single decision variable. More...
 
template<typename C >
Eigen::VectorXd EvalBindingAtSolution (const Binding< C > &binding) const
 Evaluate the constraint in the Binding at the solution value. 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...
 
Does not allow copy, move, or assignment
 MathematicalProgram (const MathematicalProgram &)=delete
 
MathematicalProgramoperator= (const MathematicalProgram &)=delete
 
 MathematicalProgram (MathematicalProgram &&)=delete
 
MathematicalProgramoperator= (MathematicalProgram &&)=delete
 

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

Member Typedef Documentation

Constructor & Destructor Documentation

virtual ~MathematicalProgram ( )
inlinevirtual

Member Function Documentation

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

AddBoundingBoxConstraint.

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

Binding< BoundingBoxConstraint > 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
lbThe lower bound.
ubThe upper bound.
varsWill imposes constraint lb(i) <= vars(i) <= ub(i).
Returns
The newly constructed BoundingBoxConstraint.

Here is the call graph for this function:

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

Adds bounds for a single variable.

Parameters
lbLower bound.
ubUpper bound.
varThe decision variable.
Binding<BoundingBoxConstraint> AddBoundingBoxConstraint ( double  lb,
double  ub,
const VariableRefList vars 
)
inline

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

Parameters
lbLower bound.
ubUpper bound.
varsThe decision variables.

Here is the call graph for this function:

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

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

Template Parameters
DerivedAn Eigen Vector type with Variable as the scalar type.
Parameters
lbLower bound.
ubUpper bound.
varsThe decision variables.
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 
)
inline

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

Template Parameters
DerivedAn Eigen::Matrix with Variable as the scalar type. The matrix has unknown number of columns at compile time, or has more than one column.
Parameters
lbLower bound.
ubUpper bound.
varsThe decision variables.
Binding< Constraint > AddConstraint ( const Binding< Constraint > &  binding)

Adds a generic constraint to the program.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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.

Here is the call graph for this function:

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

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.

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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

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

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

Here is the call graph for this function:

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

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

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

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

Adds a positive semidefinite constraint on a symmetric matrix.

Here is the call graph for this function:

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

Adds a positive semidefinite constraint on a symmetric matrix.

Adds a linear matrix inequality constraint to the program.

Here is the call graph for this function:

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

Adds a generic cost to the optimization program.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Adds a cost type to the optimization program.

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

Here is the call graph for this function:

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

Adds a generic cost to the optimization program.

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

Here is the call graph for this function:

std::enable_if<detail::is_cost_functor_candidate<F>::value, Binding<Cost> >::type AddCost ( F &&  f,
const VariableRefList vars 
)
inline

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

Template Parameters
Fit should define functions numInputs, numOutputs and eval. Check drake::solvers::detail::FunctionTraits for more detail.

Here is the call graph for this function:

std::enable_if<detail::is_cost_functor_candidate<F>::value, Binding<Cost> >::type AddCost ( F &&  f,
const Eigen::Ref< const VectorXDecisionVariable > &  vars 
)
inline

Adds a cost to the optimization program on an Eigen::Vector containing decision variables.

Template Parameters
FType that defines functions numInputs, numOutputs and eval.
See also
drake::solvers::detail::FunctionTraits.

Here is the call graph for this function:

std::enable_if<detail::assert_if_is_constraint<F>::value, Binding<Cost> >::type AddCost ( F &&  ,
Vars &&   
)
inline

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

Template Parameters
FThe type to check.
Binding< LinearCost > AddCost ( const Binding< LinearCost > &  binding)

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

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

Here is the call graph for this function:

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

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

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

Here is the call graph for this function:

Binding<Cost> 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
eThe 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.
Binding<QuadraticCost> AddL2NormCost ( const Eigen::Ref< const Eigen::MatrixXd > &  A,
const Eigen::Ref< const Eigen::VectorXd > &  b,
const VariableRefList vars 
)
inline

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

Binding<LinearConstraint> AddLinearConstraint ( const Eigen::Ref< const Eigen::RowVectorXd > &  a,
double  lb,
double  ub,
const VariableRefList vars 
)
inline

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

lb <= a*vars <= ub

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

Here is the call graph for this function:

Binding<LinearConstraint> AddLinearConstraint ( const Eigen::Ref< const Eigen::RowVectorXd > &  a,
double  lb,
double  ub,
const Eigen::Ref< const VectorXDecisionVariable > &  vars 
)
inline

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

lb <= a*vars <= ub

Parameters
aA row vector.
lbA scalar, the lower bound.
ubA scalar, the upper bound.
varsThe decision variables on which to impose the linear constraint.
Binding<LinearConstraint> AddLinearConstraint ( const symbolic::Expression e,
double  lb,
double  ub 
)

Adds one row of linear constraint lb <= e <= ub where e is a symbolic expression.

Throws an exception if

  1. e is a non-linear expression.
  2. lb <= e <= ub is a trivial constraint such as 1 <= 2 <= 3.
  3. lb <= e <= ub is unsatisfiable such as 1 <= -5 <= 3
Parameters
eA linear symbolic expression in the form of c0 + c1 * v1 + ... + cn * vn where c_i is a constant and is a variable.
lbA scalar, the lower bound.
ubA scalar, the upper bound.
Binding<LinearConstraint> 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 includes a non-linear expression or lb <= v <= ub includes trivial/unsatisfiable constraints.

Binding<LinearConstraint> AddLinearConstraint ( const symbolic::Formula f)

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

The input formula f can be of the following forms:

  1. e1 <= e2 , which is 0 <= e2 - e1 <= ∞
  2. e1 >= e2 , which is 0 <= 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".
std::enable_if< detail::is_eigen_scalar_same<Derived, symbolic::Formula>::value, Binding<LinearConstraint> >::type AddLinearConstraint ( const Eigen::ArrayBase< Derived > &  formulas)
inline

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

A common use-case of this function is to add a linear constraint with the element-wise comparison between two Eigen matrices, using A.array() <= B.array(). See the following example.

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

A formula in formulas can be of the following forms:

  1. e1 <= e2 , which is -∞ <= e1 - e2 <= 0
  2. e1 >= e2 , which is 0 <= e1 - e2 <= ∞
  3. e1 == e2 , which is 0 <= e1 - e2 <= 0

It throws an exception if

  1. A formula in formulas is not matched with one of the above patterns. Especially, strict inequalities (<, >) are not allowed.
  2. A formula in formulas includes a non-linear expression.
  3. A formula in formulas is either a trivial constraint such as "1 <= 2" or an unsatisfiable constraint such as "2 <= 1".
Template Parameters
DerivedAn Eigen Array type of Formula.

Here is the call graph for this function:

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

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

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

Here is the caller graph for this function:

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

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.

Here is the call graph for this function:

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

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

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

Here is the call graph for this function:

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

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

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

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

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

Throws an exception if

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

Here is the caller graph for this function:

Binding<LinearEqualityConstraint> AddLinearEqualityConstraint ( const symbolic::Formula f)

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

The input formula f is either an equality formula (e1 == e2) or a conjunction of equality formulas.

It throws an exception if

  1. f is neither an equality formula nor a conjunction of equalities.
  2. f includes a non-linear expression.
std::enable_if< detail::is_eigen_vector_expression_double_pair<DerivedV, DerivedB>::value, Binding<LinearEqualityConstraint> >::type AddLinearEqualityConstraint ( const Eigen::MatrixBase< DerivedV > &  v,
const Eigen::MatrixBase< DerivedB > &  b 
)
inline

Adds linear equality constraints \( v = b \), where v(i) is a symbolic linear expression.

Throws an exception if

  1. v(i) is a non-linear expression.
  2. v(i) is a constant.
    Template Parameters
    DerivedVAn Eigen Matrix type of Expression. A column vector.
    DerivedBAn Eigen Matrix type of double. A column vector.
    Parameters
    vv(i) is a linear symbolic expression in the form of c0 + c1 * x1 + ... + cn * xn where ci is a constant and is a variable.
    bA vector of doubles.
    Returns
    The newly added linear equality constraint, together with the bound variables.

Here is the call graph for this function:

std::enable_if< detail::is_eigen_matrix_expression_double_pair<DerivedV, DerivedB>::value, Binding<LinearEqualityConstraint> >::type AddLinearEqualityConstraint ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedB > &  B,
bool  lower_triangle = false 
)
inline

Adds a linear equality constraint for a matrix of linear expression V, such that V(i, j) = B(i, j).

If V is a symmetric matrix, then the user may only want to constrain the lower triangular part of V. This function is meant to provide convenience to the user, it incurs additional copy and memory allocation. For faster speed, add each column of the matrix equality in a for loop.

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

Here is the call graph for this function:

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

AddLinearEqualityConstraint.

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

Example: to add two equality constraints which only depend on two of the elements of x, you could use

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

The code above imposes constraints

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

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

Here is the call graph for this function:

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

AddLinearEqualityConstraint.

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

Example: to add two equality constraints which only depend on two of the elements of x, you could use

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

Here is the call graph for this function:

Binding<LinearEqualityConstraint> AddLinearEqualityConstraint ( const Eigen::Ref< const Eigen::RowVectorXd > &  a,
double  beq,
const VariableRefList vars 
)
inline

Adds one row of linear equality constraint referencing potentially a subset of decision variables.

\[ ax = beq \]

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

Here is the call graph for this function:

Binding<LinearEqualityConstraint> AddLinearEqualityConstraint ( const Eigen::Ref< const Eigen::RowVectorXd > &  a,
double  beq,
const Eigen::Ref< const VectorXDecisionVariable > &  vars 
)
inline

Adds one row of linear equality constraint referencing potentially a subset of decision variables.

\[ ax = beq \]

Parameters
aA row vector.
beqA scalar.
varsThe decision variables on which the constraint is imposed.
Binding<LinearMatrixInequalityConstraint> AddLinearMatrixInequalityConstraint ( const std::vector< Eigen::Ref< const Eigen::MatrixXd >> &  F,
const VariableRefList vars 
)
inline

Adds a linear matrix inequality constraint to the program.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

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

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

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

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

Returns
The newly constructed Lorentz cone constraint with the bounded variables.

Here is the caller graph for this function:

Binding<LorentzConeConstraint> AddLorentzConeConstraint ( const symbolic::Expression v1,
const symbolic::Expression v2 
)

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

Parameters
v1The linear expression.
v2The quadratic expression.
Return values
bindingThe newly added Lorentz cone constraint, together with the bound variables.
Precondition
  1. linear_expr is a linear expression, in the form of c'*x + d.
  2. quadratic_expr is a quadratic expression, in the form of
             0.5 * 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. Throws a 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 = [1 / sqrt(2) * R * x + R⁻ᵀb; sqrt(a - 0.5 * bᵀ * Q⁻¹ * a)]

while R satisfies Rᵀ * R = Q

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

Adds Lorentz cone constraint referencing potentially a subset of the decision variables (defined in the vars parameter).

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

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

Parameters
AA \(\mathbb{R}^{n\times m}\) matrix, whose number of columns equals to the size of the decision variables.
bA \(\mathbb{R}^n\) vector, whose number of rows equals to the size of the decision variables.
varsThe list of \( m \) decision variables.
Returns
The newly added Lorentz cone constraint.

Here is the call graph for this function:

Binding< LorentzConeConstraint > 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
AA \(\mathbb{R}^{n\times m}\) matrix, whose number of columns equals to the size of the decision variables.
bA \(\mathbb{R}^n\) vector, whose number of rows equals to the size of the decision variables.
varsThe Eigen vector of \( m \) decision variables.
Returns
The newly added Lorentz cone constraint.

Here is the call graph for this function:

Binding<LorentzConeConstraint> AddLorentzConeConstraint ( const VariableRefList vars)
inline

Imposes that a vector \( x\in\mathbb{R}^m \) lies in Lorentz cone.

Namely

\[ x_0 \ge \sqrt{x_1^2 + .. + x_{m-1}^2} \]

Parameters
varsThe stacked column of vars should lie within the Lorentz cone.
Returns
The newly added Lorentz cone constraint.

Here is the call graph for this function:

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

Imposes that a vector \( x\in\mathbb{R}^m \) lies in Lorentz cone.

Namely

\[ x_0 \ge \sqrt{x_1^2 + .. + x_{m-1}^2} \]

Parameters
varsThe stacked column of vars should lie within the Lorentz cone.
Returns
The newly added Lorentz cone constraint.
Binding<Constraint> AddPolynomialConstraint ( const VectorXPoly polynomials,
const std::vector< Polynomiald::VarType > &  poly_vars,
const Eigen::VectorXd &  lb,
const Eigen::VectorXd &  ub,
const VariableRefList vars 
)
inline

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

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

Adds a cost term in the polynomial form.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Adds a positive semidefinite constraint on a symmetric matrix.

In Debug mode,

Exceptions
errorif symmetric_matrix_var is not symmetric.
Parameters
symmetric_matrix_varA symmetric MatrixDecisionVariable object.

Here is the call graph for this function:

Here is the caller graph for this function:

std::enable_if< std::is_same<typename Derived::Scalar, symbolic::Expression>::value, Binding<PositiveSemidefiniteConstraint> >::type AddPositiveSemidefiniteConstraint ( const Eigen::MatrixBase< Derived > &  e)
inline

Adds a positive semidefinite constraint on a symmetric matrix of symbolic espressions e.

We create a new symmetric matrix of variables M being positive semidefinite, with the linear equality constraint e == M.

Template Parameters
DerivedAn Eigen Matrix of symbolic expressions.
Parameters
eImposes 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.
Binding<QuadraticCost> AddQuadraticCost ( const symbolic::Expression e)

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
eA quadratic symbolic expression. Throws a runtime error if the expression is not quadratic.
Returns
The newly added cost together with the bound variables.

Here is the caller graph for this function:

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

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

Applied to subset of the variables.

Here is the call graph for this function:

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

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

Here is the call graph for this function:

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

Here is the call graph for this function:

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Here is the call graph for this function:

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

Adds a constraint that a symbolic expression.

Parameters
vis in the rotated Lorentz cone, i.e.,

\[ v_0v_1 \ge v_2^2 + ... + v_{n-1}^2\\ v_0 \ge 0, v_1 \ge 0 \]

vA linear expression of variables, \( v = A x + b\), where \( A, b \) are given matrices of the correct size, \( x \) is the vector of decision variables.
Return values
bindingThe newly added rotated Lorentz cone constraint, together with the bound variables.

Here is the caller graph for this function:

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

Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone.

A vector \( z \in\mathbb{R}^n \) is in the rotated Lorentz cone, if

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

where \( A\in\mathbb{R}^{n\times m}, b\in\mathbb{R}^n\) are given matrices.

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

Here is the call graph for this function:

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

Adds a rotated Lorentz cone constraint referencing potentially a subset of decision variables, The linear expression \( z=Ax+b \) is in rotated Lorentz cone.

A vector \( z \in\mathbb{R}^n \) is in the rotated Lorentz cone, if

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

where \( A\in\mathbb{R}^{n\times m}, b\in\mathbb{R}^n\) are given matrices.

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

Here is the call graph for this function:

Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint ( const VariableRefList vars)
inline

Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone.

Namely

\[ x_0 x_1 \ge x_2^2 + ... + x_{m-1}^2\\ x_0 \ge 0, x_1 \ge 0 \]

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

Here is the call graph for this function:

Binding<RotatedLorentzConeConstraint> AddRotatedLorentzConeConstraint ( const Eigen::MatrixBase< VectorDecisionVariable< rows >> &  vars)
inline

Impose that a vector \( x\in\mathbb{R}^m \) is in rotated Lorentz cone.

Namely

\[ x_0 x_1 \ge x_2^2 + ... + x_{m-1}^2\\ x_0 \ge 0, x_1 \ge 0 \]

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

Adds constraints that a given polynomial p is a sums-of-squares (SOS), that is, p can be decomposed into xᵀQx.

It returns a pair of constraint bindings expressing:

  • The coefficients matrix Q is PSD (positive semidefinite).
  • The coefficients matching conditions in linear equality constraint.

Here is the call graph for this function:

Here is the caller graph for this function:

Adds constraints that a given symbolic expression e is a sums-of-squares (SOS), that is, e can be decomposed into xTQx.

Note that it decomposes e into a polynomial with respect to indeterminates() in this mathematical program. It returns a pair of constraint bindings expressing:

  • The coefficients matrix Q is PSD (positive semidefinite).
  • The coefficients matching conditions in linear equality constraint.

Here is the call graph for this function:

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

Getter for all bounding box constraints.

Here is the caller graph for this function:

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

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

Here is the caller graph for this function:

const VectorXDecisionVariable& decision_variables ( ) const
inline

Getter for all decision variables in the program.

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

Evaluate the constraint in the Binding at the solution value.

Returns
The value of the constraint in the binding. TODO(hongkai.dai): Do not use teample function, when the Binding is moved to a public class.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Getter for all generic constraints.

Here is the caller graph for this function:

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

Getter for all generic costs.

Here is the caller graph for this function:

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

Getter returning all costs (for now linear costs appended to generic costs, then quadratic costs appended to generic costs).

Here is the caller graph for this function:

std::vector<Binding<LinearConstraint> > GetAllLinearConstraints ( ) const
inline

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

Here is the caller graph for this function:

double GetLowerBoundCost ( ) const
inline

Getter for lower bound on optimal cost.

Defaults to -Infinity if a lower bound has not been found.

double GetOptimalCost ( ) const
inline

Getter for optimal cost at the solution.

Will return NaN if there has been no successful solution.

Here is the caller graph for this function:

std::enable_if< std::is_same<typename Derived::Scalar, symbolic::Variable>::value, Eigen::Matrix<double, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> >::type GetSolution ( const Eigen::MatrixBase< Derived > &  var) const
inline

Gets the solution of an Eigen matrix of decision variables.

Template Parameters
DerivedAn Eigen matrix containing Variable.
Parameters
varThe decision variables.
Returns
The value of the decision variable after solving the problem.

Here is the caller graph for this function:

double GetSolution ( const symbolic::Variable var) const

Gets the value of a single decision variable.

const Eigen::VectorXd GetSolutionVectorValues ( ) const
inline

Returns the solution in a flat Eigen::VectorXd.

The caller needs to compute the solution first by calling Solve.

Returns
a flat Eigen vector that represents the solution.
std::shared_ptr<T> GetSolverData ( )
inline
optional<SolverId> GetSolverId ( ) const
inline

Returns the ID of the solver that was used to solve this program.

Returns empty if Solve() has not been called.

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Here is the caller graph for this function:

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

Getter for the indeterminate with index i in the program.

const VectorXIndeterminate& indeterminates ( ) const
inline

Getter for all indeterminates in the program.

Here is the caller graph for this function:

const Eigen::VectorXd& initial_guess ( ) const
inline

Getter for the initial guess.

Here is the caller graph for this function:

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

Getter for all linear complementarity constraints.

Here is the caller graph for this function:

const std::vector<Binding<LinearConstraint> >& linear_constraints ( ) const
inline

Getter for linear constraints.

Here is the caller graph for this function:

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

Getter for linear costs.

Here is the caller graph for this function:

const std::vector<Binding<LinearEqualityConstraint> >& linear_equality_constraints ( ) const
inline

Getter for linear equality constraints.

Here is the caller graph for this function:

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

Getter for linear matrix inequality constraint.

Here is the caller graph for this function:

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

Getter for Lorentz cone constraint.

Here is the caller graph for this function:

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

Convert an input of type F to a FunctionCost object.

Template Parameters
FThis class should have functions numInputs(), numOutputs and eval(x, y).
See also
drake::solvers::detail::FunctionTraits.

Here is the call graph for this function:

MatrixDecisionVariable<Rows, Cols> NewBinaryVariables ( int  rows,
int  cols,
const std::string &  name 
)
inline

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

The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().

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

Example:

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

This adds a 2 x 3 matrix decision variables into the program.

The name of the variable is only used for the user in order to ease readability.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Adds a matrix of binary variables into the optimization program.

Template Parameters
RowsThe number of rows in the newly added binary variables.
ColsThe number of columns in the new variables. The default is 1.
Parameters
nameEach newly added binary variable will share the same name. The default name is "b".
Returns
A matrix containing the newly added variables.
VectorXDecisionVariable NewBinaryVariables ( int  rows,
const std::string &  name = "b" 
)
inline

Adds binary variables to this MathematicalProgram.

The new variables are viewed as a column vector, with size rows x 1.

See also
NewBinaryVariables(int rows, int cols, const std::vector<std::string>& names);
VectorXDecisionVariable NewContinuousVariables ( int  rows,
const std::string &  name = "x" 
)
inline

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

The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().

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

Example:

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

This adds a 2 x 1 vector containing decision variables into the program. The names of the variables are "x(0)" and "x(1)".

The name of the variable is only used for the user in order to ease readability.

Here is the caller graph for this function:

MatrixDecisionVariable<Rows, Cols> NewContinuousVariables ( int  rows,
int  cols,
const std::string &  name 
)
inline

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

The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().

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

Example:

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

This adds a 2 x 3 matrix decision variables into the program.

The name of the variable is only used for the user in order to ease readability.

Here is the call graph for this function:

MatrixDecisionVariable<Rows, Cols> NewContinuousVariables ( const std::string &  name = "X")
inline

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

The initial guess values for the new variables are set to NaN, to indicate that an initial guess has not been assigned. Callers are expected to add costs and/or constraints to have any effect during optimization. Callers can also set the initial guess of the decision variables through SetInitialGuess() or SetInitialGuessForAllVariables().

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

Example:

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

This adds a 2 x 3 matrix decision variables into the program.

The name of the variable is only used for the user in order to ease readability.

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

Here is the call graph for this function:

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

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

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

Example:

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

This adds a 2 x 3 matrix indeterminates into the program.

The name of the indeterminates is only used for the user in order to ease readability.

Here is the caller graph for this function:

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

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

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

Example:

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

This adds a 2 vector indeterminates into the program.

The name of the indeterminates is only used for the user in order to ease readability.

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

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

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

Example:

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

This adds a 2 x 3 matrix indeterminates into the program.

The name of the indeterminates is only used for the user in order to ease readability.

Here is the call graph for this function:

VectorIndeterminate<rows> NewIndeterminates ( const std::string &  name = "x")
inline

Adds indeterminates to the program.

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

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

Here is the call graph for this function:

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

Adds indeterminates to this MathematicalProgram.

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

Here is the call graph for this function:

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

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

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

Here is the call graph for this function:

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

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

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

Example:

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

This adds a 2 x 3 matrix indeterminates into the program.

The name of the variable is only used for the user in order to ease readability.

MatrixXIndeterminate NewIndeterminates ( int  rows,
int  cols,
const std::string &  name = "X" 
)

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

The new variables are returned and viewed as a matrix, with size rows x cols.

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

Here is the call graph for this function:

pair< symbolic::Polynomial, Binding< PositiveSemidefiniteConstraint > > NewSosPolynomial ( const symbolic::Variables indeterminates,
int  degree 
)

Returns a pair of a SOS polynomial p = xᵀQx of degree degree and a PSD constraint for the coefficients matrix Q, where x is a monomial basis over indeterminates of degree @p 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 a PSD constraint over Q.

Exceptions
std::runtime_errorif degree is not a positive even integer.

Here is the call graph for this function:

Here is the caller graph for this function:

MatrixXDecisionVariable NewSymmetricContinuousVariables ( int  rows,
const std::string &  name = "Symmetric" 
)

Adds a runtime sized symmetric matrix as decision variables to this MathematicalProgram.

The optimization will only use the stacked columns of the lower triangular part of the symmetric matrix as decision variables.

Parameters
rowsThe number of rows in the symmetric matrix.
nameThe name of the matrix. It is only used the for user to understand the optimization program. The default name is "Symmetric", and each variable will be named as
Symmetric(0, 0)     Symmetric(1, 0)     ... Symmetric(rows-1, 0)
Symmetric(1, 0)     Symmetric(1, 1)     ... Symmetric(rows-1, 1)
           ...
Symmetric(rows-1,0) Symmetric(rows-1,1) ... Symmetric(rows-1, rows-1)
Notice that the (i,j)'th entry and (j,i)'th entry has the same name.
Returns
The newly added decision variables.

Here is the call graph for this function:

Here is the caller graph for this function:

MatrixDecisionVariable<rows, rows> NewSymmetricContinuousVariables ( const std::string &  name = "Symmetric")
inline

Adds a static sized symmetric matrix as decision variables to this MathematicalProgram.

The optimization will only use the stacked columns of the lower triangular part of the symmetric matrix as decision variables.

Template Parameters
rowsThe number of rows in the symmetric matrix.
Parameters
nameThe name of the matrix. It is only used the for user to understand the optimization program. The default name is "Symmetric", and each variable will be named as
Symmetric(0, 0)     Symmetric(1, 0)     ... Symmetric(rows-1, 0)
Symmetric(1, 0)     Symmetric(1, 1)     ... Symmetric(rows-1, 1)
           ...
Symmetric(rows-1,0) Symmetric(rows-1,1) ... Symmetric(rows-1, rows-1)
Notice that the (i,j)'th entry and (j,i)'th entry has the same name.
Returns
The newly added decision variables.

Here is the call graph for this function:

int num_indeterminates ( ) const
inline

Gets the solution of an Eigen matrix of decision variables.

Template Parameters
DerivedAn Eigen matrix containing Variable.
Parameters
varThe decision variables.
Returns
The value of the decision variable after solving the problem.Gets the number of indeterminates in the optimization program

Here is the caller graph for this function:

int num_vars ( ) const
inline

Getter for number of variables in the optimization program.

Here is the caller graph for this function:

MathematicalProgram& operator= ( const MathematicalProgram )
delete
MathematicalProgram& operator= ( MathematicalProgram &&  )
delete
const std::vector<Binding<PositiveSemidefiniteConstraint> >& positive_semidefinite_constraints ( ) const
inline

Getter for positive semidefinite constraint.

Here is the caller graph for this function:

void PrintSolution ( )
inline

Here is the caller graph for this function:

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

Getter for quadratic costs.

Here is the caller graph for this function:

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

Getter for rotated Lorentz cone constraint.

Here is the caller graph for this function:

void SetDecisionVariableValue ( const symbolic::Variable var,
double  value 
)

Sets the value of a single decision variable in the optimization program.

Parameters
varA decision variable in the program.
valueThe value of that decision variable.

Here is the call graph for this function:

void SetDecisionVariableValues ( const Eigen::Ref< const Eigen::VectorXd > &  values)

Sets the values of all decision variables, such that the value of decision_variables_(i) is values(i).

Parameters
valuesThe values set to all the decision variables.

Here is the caller graph for this function:

void SetDecisionVariableValues ( const Eigen::Ref< const VectorXDecisionVariable > &  variables,
const Eigen::Ref< const Eigen::VectorXd > &  values 
)

Sets the value of some decision variables, such that the value of variables(i) is values(i).

Parameters
variablesThe value of these decision variables will be set.
valuesThe values set to the decision variables.

Here is the call graph for this function:

void SetInitialGuess ( const Eigen::MatrixBase< DerivedA > &  decision_variable_mat,
const Eigen::MatrixBase< DerivedB > &  x0 
)
inline

Set the initial guess for the decision variables stored in var to be x0.

Variables begin with a default initial guess of NaN to indicate that no guess is available.

Here is the caller graph for this function:

void SetInitialGuessForAllVariables ( const Eigen::MatrixBase< Derived > &  x0)
inline

Set the intial guess for ALL decision variables.

Note that variables begin with a default initial guess of NaN to indicate that no guess is available.

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

Here is the caller graph for this function:

void SetLowerBoundCost ( double  lower_bound_cost)
inline

Setter for lower bound on optimal cost.

Here is the caller graph for this function:

void SetOptimalCost ( double  optimal_cost)
inline

Here is the caller graph for this function:

void SetSolverId ( SolverId  solver_id)
inline

Sets the ID of the solver that was used to solve this program.

Here is the caller graph for this function:

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

Set an option for a particular solver.

This interface does not do any verification of solver parameters beyond what an individual solver does for itself. It does not even verify that the specified solver exists. Use this only when you have particular knowledge of what solver is being invoked, and exactly what tuning is required.

Supported solver names/options:

"SNOPT" – Paramater names and values as specified in SNOPT User's Guide section 7.7 "Description of the optional parameters", used as described in section 7.5 for snSet().

"IPOPT" – Paramater names and values as specified in IPOPT users guide section "Options Reference" http://www.coin-or.org/Ipopt/documentation/node40.html

"GUROBI" – Parameter name and values as specified in GUROBI Reference Manual, section 10.2 "Parameter Descriptions" https://www.gurobi.com/documentation/6.5/refman/parameters.html

Here is the caller graph for this function:

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

Solve the MathematicalProgram.

Returns
SolutionResult indicating if the solution was successful.

Here is the caller graph for this function:


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