Drake
MathematicalProgramResult Class Referencefinal

The result returned by MathematicalProgram::Solve(). More...

#include <drake/solvers/mathematical_program_result.h>

Public Member Functions

 MathematicalProgramResult ()
 Constructs the result. More...
 
bool is_success () const
 Returns true if the optimization problem is solved successfully; false otherwise. More...
 
void set_decision_variable_index (std::unordered_map< symbolic::Variable::Id, int > decision_variable_index)
 Sets decision_variable_index mapping, that maps each decision variable to its index in the aggregated vector containing all decision variables in MathematicalProgram. More...
 
void set_solution_result (SolutionResult solution_result)
 Sets SolutionResult. More...
 
const Eigen::VectorXd & get_x_val () const
 Gets the decision variable values. More...
 
SolutionResult get_solution_result () const
 Gets SolutionResult. More...
 
void set_x_val (const Eigen::VectorXd &x_val)
 Sets the decision variable values. More...
 
double get_optimal_cost () const
 Gets the optimal cost. More...
 
void set_optimal_cost (double optimal_cost)
 Sets the optimal cost. More...
 
const SolverIdget_solver_id () const
 Gets the solver ID. More...
 
void set_solver_id (const SolverId &solver_id)
 Sets the solver ID. More...
 
template<typename Solver >
const Solver::Details & get_solver_details () const
 Gets the solver details for the Solver that solved the program. More...
 
const AbstractValueget_abstract_solver_details () const
 (Advanced.) Gets the type-erased solver details. More...
 
template<typename T >
T & SetSolverDetailsType ()
 (Advanced.) Forces the solver_details to be stored using the given type T. More...
 
internal::SolverResult ConvertToSolverResult () const
 Convert MathematicalProgramResult to SolverResult. More...
 
const Eigen::VectorXd & GetSolution () const
 Gets the solution of all decision variables. 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 solution of a single decision variable. More...
 
symbolic::Expression GetSolution (const symbolic::Expression &e) const
 Substitutes the value of all decision variables into the Expression. More...
 
template<typename Derived >
std::enable_if< std::is_same< typename Derived::Scalar, symbolic::Expression >::value, Eigen::Matrix< symbolic::Expression, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > >::type GetSolution (const Eigen::MatrixBase< Derived > &m) const
 Substitutes the value of all decision variables into the Matrix<Expression>. More...
 
template<typename Evaluator >
Eigen::VectorXd EvalBinding (const Binding< Evaluator > &binding) const
 Evaluate a Binding at the solution. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 MathematicalProgramResult (const MathematicalProgramResult &)=default
 
MathematicalProgramResultoperator= (const MathematicalProgramResult &)=default
 
 MathematicalProgramResult (MathematicalProgramResult &&)=default
 
MathematicalProgramResultoperator= (MathematicalProgramResult &&)=default
 
Solution Pools

Some solvers (like Gurobi, Cplex, etc) can store a pool of (suboptimal) solutions for mixed integer programming model.

template<typename Derived >
std::enable_if< std::is_same< typename Derived::Scalar, symbolic::Variable >::value, Eigen::Matrix< double, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime > >::type GetSuboptimalSolution (const Eigen::MatrixBase< Derived > &var, int solution_number) const
 Gets the suboptimal solution corresponding to a matrix of decision variables. More...
 
double GetSuboptimalSolution (const symbolic::Variable &var, int solution_number) const
 Gets the suboptimal solution of a decision variable. More...
 
int num_suboptimal_solution () const
 Number of suboptimal solutions stored inside MathematicalProgramResult. More...
 
double get_suboptimal_objective (int solution_number) const
 Gets the suboptimal objective value. More...
 
void AddSuboptimalSolution (double suboptimal_objective, const Eigen::VectorXd &suboptimal_x)
 Adds the suboptimal solution to the result. More...
 

Detailed Description

The result returned by MathematicalProgram::Solve().

It stores the solvers::SolutionResult (whether the program is solved to optimality, detected infeasibility, etc), the optimal value for the decision variables, the optimal cost, and solver specific details.

Constructor & Destructor Documentation

◆ MathematicalProgramResult() [1/3]

◆ MathematicalProgramResult() [2/3]

◆ MathematicalProgramResult() [3/3]

Constructs the result.

Note
The solver_details is set to nullptr.

Member Function Documentation

◆ AddSuboptimalSolution()

void AddSuboptimalSolution ( double  suboptimal_objective,
const Eigen::VectorXd &  suboptimal_x 
)

Adds the suboptimal solution to the result.

See solution pools.

Parameters
suboptimal_objectiveThe objective value computed from this suboptimal solution.
suboptimal_xThe values of the decision variables in this suboptimal solution.

◆ ConvertToSolverResult()

internal::SolverResult ConvertToSolverResult ( ) const

Convert MathematicalProgramResult to SolverResult.

Note
This function doesn't set optimal_cost_lower_bound. If SolverResult.optimal_cost_lower_bound needs to be set (like in GurobiSolver), then the user will have to set it after calling ConvertToSolverResult.(Deprecated.)
Deprecated:
"MathematicalProgram methods that assume the solution is stored inside " "the program are deprecated; for details and porting advice, see " "https://github.com/RobotLocomotion/drake/issues/9633."
This will be removed from Drake on or after "2019-06-01" .

◆ EvalBinding()

Eigen::VectorXd EvalBinding ( const Binding< Evaluator > &  binding) const

Evaluate a Binding at the solution.

Parameters
bindingA binding between a constraint/cost and the variables.
Precondition
The binding.variables() must be the within the decision variables in the MathematicalProgram that generated this MathematicalProgramResult.
The user must have called set_decision_variable_index() function.

◆ get_abstract_solver_details()

const AbstractValue & get_abstract_solver_details ( ) const

(Advanced.) Gets the type-erased solver details.

Most users should use get_solver_details() instead. Throws an error if the solver_details has not been set.

◆ get_optimal_cost()

double get_optimal_cost ( ) const

Gets the optimal cost.

◆ get_solution_result()

SolutionResult get_solution_result ( ) const

Gets SolutionResult.

◆ get_solver_details()

const Solver::Details& get_solver_details ( ) const

Gets the solver details for the Solver that solved the program.

Throws an error if the solver_details has not been set.

◆ get_solver_id()

const SolverId& get_solver_id ( ) const

Gets the solver ID.

◆ get_suboptimal_objective()

double get_suboptimal_objective ( int  solution_number) const

Gets the suboptimal objective value.

See solutionpools".

Parameters
solution_numberThe index of the sub-optimal solution.
Precondition
solution_number should be in the range [0, num_suboptimal_solution()).

◆ get_x_val()

const Eigen::VectorXd& get_x_val ( ) const

Gets the decision variable values.

◆ GetSolution() [1/5]

const Eigen::VectorXd& GetSolution ( ) const

Gets the solution of all decision variables.

◆ GetSolution() [2/5]

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.

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

◆ GetSolution() [3/5]

double GetSolution ( const symbolic::Variable var) const

Gets the solution of a single decision variable.

Parameters
varThe decision variable.
Returns
The value of the decision variable after solving the problem.
Exceptions
invalid_argumentif var is not captured in the mapping decision_variable_index, as the input argument of set_decision_variable_index().

◆ GetSolution() [4/5]

symbolic::Expression GetSolution ( const symbolic::Expression e) const

Substitutes the value of all decision variables into the Expression.

Parameters
eThe decision variable.
Returns
the Expression that is the result of the substitution.

◆ GetSolution() [5/5]

std::enable_if< std::is_same<typename Derived::Scalar, symbolic::Expression>::value, Eigen::Matrix<symbolic::Expression, Derived::RowsAtCompileTime, Derived::ColsAtCompileTime> >::type GetSolution ( const Eigen::MatrixBase< Derived > &  m) const

Substitutes the value of all decision variables into the Matrix<Expression>.

Template Parameters
DerivedAn Eigen matrix containing Expression.
Returns
the Matrix<Expression> that is the result of the substitution.

◆ GetSuboptimalSolution() [1/2]

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

Gets the suboptimal solution corresponding to a matrix of decision variables.

See solution pools

Parameters
varThe decision variables.
solution_numberThe index of the sub-optimal solution.
Precondition
solution_number should be in the range [0, num_suboptimal_solution()).
Returns
The suboptimal values of the decision variables after solving the problem.

◆ GetSuboptimalSolution() [2/2]

double GetSuboptimalSolution ( const symbolic::Variable var,
int  solution_number 
) const

Gets the suboptimal solution of a decision variable.

See solution pools

Parameters
varThe decision variable.
solution_numberThe index of the sub-optimal solution.
Precondition
solution_number should be in the range [0, num_suboptimal_solution()).
Returns
The suboptimal value of the decision variable after solving the problem.

◆ is_success()

bool is_success ( ) const

Returns true if the optimization problem is solved successfully; false otherwise.

For more information on the solution status, the user could call get_solver_details() to obtain the solver-specific solution status.

◆ num_suboptimal_solution()

int num_suboptimal_solution ( ) const

Number of suboptimal solutions stored inside MathematicalProgramResult.

See solution pools.

◆ operator=() [1/2]

◆ operator=() [2/2]

MathematicalProgramResult& operator= ( const MathematicalProgramResult )
default

◆ set_decision_variable_index()

void set_decision_variable_index ( std::unordered_map< symbolic::Variable::Id, int decision_variable_index)

Sets decision_variable_index mapping, that maps each decision variable to its index in the aggregated vector containing all decision variables in MathematicalProgram.

◆ set_optimal_cost()

void set_optimal_cost ( double  optimal_cost)

Sets the optimal cost.

◆ set_solution_result()

void set_solution_result ( SolutionResult  solution_result)

Sets SolutionResult.

◆ set_solver_id()

void set_solver_id ( const SolverId solver_id)

Sets the solver ID.

◆ set_x_val()

void set_x_val ( const Eigen::VectorXd &  x_val)

Sets the decision variable values.

◆ SetSolverDetailsType()

T& SetSolverDetailsType ( )

(Advanced.) Forces the solver_details to be stored using the given type T.

Typically, only an implementation of SolverInterface will call this method. If the storage was already typed as T, this is a no-op. If there were not any solver_details previously, or if it was of a different type, initializes the storage to a default-constructed T. Returns a reference to the mutable solver_details object. The reference remains valid until the next call to this method, or until this MathematicalProgramResult is destroyed.


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