Drake
SolverOptions Class Reference

Detailed Description

Stores options for multiple solvers.

This interface does not do any verification of solver parameters. 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" – Parameter 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(). The SNOPT user guide can be obtained from https://web.stanford.edu/group/SOL/guides/sndoc7.pdf

"IPOPT" – Parameter 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/9.0/refman/parameters.html

"SCS" – Parameter name and values as specified in the struct SCS_SETTINGS in SCS header file https://github.com/cvxgrp/scs/blob/master/include/scs.h Note that the SCS code on github master might be more up-to-date than the version used in Drake.

"MOSEK" – Parameter name and values as specified in Mosek Reference https://docs.mosek.com/9.2/capi/parameters.html

"OSQP" – Parameter name and values as specified in OSQP Reference https://osqp.org/docs/interfaces/solver_settings.html#solver-settings

"dReal" – Parameter name and values as specified in dReal Reference https://github.com/dreal/dreal4/blob/master/README.md#command-line-options. Note that Drake only supports a subset of the options listed in the reference.

See also
DrealSolver for the subset of these options supported by the solver interface.

"IBEX" – Parameter name and values as specified in IBEX Reference http://www.ibex-lib.org/doc/optim.html?highlight=eps#options. Note that Drake only supports a subset of the options listed in the reference.

See also
IbexSolver for the subset of these options supported by the solver interface.

#include <drake/solvers/solver_options.h>

Public Types

using OptionValue = std::variant< double, int, std::string >
 The values stored in SolverOptions can be double, int, or string. More...
 

Public Member Functions

 SolverOptions ()=default
 
void SetOption (const SolverId &solver_id, const std::string &solver_option, double option_value)
 Sets a double-valued solver option for a specific solver. More...
 
void SetOption (const SolverId &solver_id, const std::string &solver_option, int option_value)
 Sets an integer-valued solver option for a specific solver. More...
 
void SetOption (const SolverId &solver_id, const std::string &solver_option, const std::string &option_value)
 Sets a string-valued solver option for a specific solver. More...
 
void SetOption (CommonSolverOption key, OptionValue value)
 Sets a common option for all solvers supporting that option (for example, printing the progress in each iteration). More...
 
const std::unordered_map< std::string, double > & GetOptionsDouble (const SolverId &solver_id) const
 
const std::unordered_map< std::string, int > & GetOptionsInt (const SolverId &solver_id) const
 
const std::unordered_map< std::string, std::string > & GetOptionsStr (const SolverId &solver_id) const
 
const std::unordered_map< CommonSolverOption, OptionValue > & common_solver_options () const
 Gets the common options for all solvers. More...
 
std::string get_print_file_name () const
 Returns the kPrintFileName set via CommonSolverOption, or else an empty string if the option has not been set. More...
 
bool get_print_to_console () const
 Returns the kPrintToConsole set via CommonSolverOption, or else false if the option has not been set. More...
 
template<typename T >
const std::unordered_map< std::string, T > & GetOptions (const SolverId &solver_id) const
 
std::unordered_set< SolverIdGetSolverIds () const
 Returns the IDs that have any option set. More...
 
void Merge (const SolverOptions &other)
 Merges the other solver options into this. More...
 
bool operator== (const SolverOptions &other) const
 Returns true if this and other have exactly the same solvers, with exactly the same keys and values for the options for each solver. More...
 
bool operator!= (const SolverOptions &other) const
 Negate operator==. More...
 
void CheckOptionKeysForSolver (const SolverId &solver_id, const std::unordered_set< std::string > &allowable_double_keys, const std::unordered_set< std::string > &allowable_int_keys, const std::unordered_set< std::string > &allowable_str_keys) const
 Check if for a given solver_id, the option keys are included in double_keys, int_keys and str_keys. More...
 
Implements CopyConstructible, CopyAssignable, MoveConstructible, MoveAssignable
 SolverOptions (const SolverOptions &)=default
 
SolverOptionsoperator= (const SolverOptions &)=default
 
 SolverOptions (SolverOptions &&)=default
 
SolverOptionsoperator= (SolverOptions &&)=default
 

Member Typedef Documentation

◆ OptionValue

using OptionValue = std::variant<double, int, std::string>

The values stored in SolverOptions can be double, int, or string.

In the future, we might re-order or add more allowed types without any deprecation period, so be sure to use std::visit or std::get<T> to retrieve the variant's value in a future-proof way.

Constructor & Destructor Documentation

◆ SolverOptions() [1/3]

SolverOptions ( )
default

◆ SolverOptions() [2/3]

SolverOptions ( const SolverOptions )
default

◆ SolverOptions() [3/3]

SolverOptions ( SolverOptions &&  )
default

Member Function Documentation

◆ CheckOptionKeysForSolver()

void CheckOptionKeysForSolver ( const SolverId solver_id,
const std::unordered_set< std::string > &  allowable_double_keys,
const std::unordered_set< std::string > &  allowable_int_keys,
const std::unordered_set< std::string > &  allowable_str_keys 
) const

Check if for a given solver_id, the option keys are included in double_keys, int_keys and str_keys.

Parameters
solver_idIf this SolverOptions has set options for this solver_id, then we check if the option keys are a subset of double_keys, int_keys and str_keys.
double_keysThe set of allowable keys for double options.
int_keysThe set of allowable keys for int options.
str_keysThe set of allowable keys for string options.
Exceptions
std::exceptionif the solver contains un-allowed options.

◆ common_solver_options()

const std::unordered_map<CommonSolverOption, OptionValue>& common_solver_options ( ) const

Gets the common options for all solvers.

Refer to CommonSolverOption for more details.

◆ get_print_file_name()

std::string get_print_file_name ( ) const

Returns the kPrintFileName set via CommonSolverOption, or else an empty string if the option has not been set.

◆ get_print_to_console()

bool get_print_to_console ( ) const

Returns the kPrintToConsole set via CommonSolverOption, or else false if the option has not been set.

◆ GetOptions()

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

◆ GetOptionsDouble()

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

◆ GetOptionsInt()

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

◆ GetOptionsStr()

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

◆ GetSolverIds()

std::unordered_set<SolverId> GetSolverIds ( ) const

Returns the IDs that have any option set.

◆ Merge()

void Merge ( const SolverOptions other)

Merges the other solver options into this.

If other and this option both define the same option for the same solver, we ignore then one from other and keep the one from this.

◆ operator!=()

bool operator!= ( const SolverOptions other) const

Negate operator==.

◆ operator=() [1/2]

SolverOptions& operator= ( SolverOptions &&  )
default

◆ operator=() [2/2]

SolverOptions& operator= ( const SolverOptions )
default

◆ operator==()

bool operator== ( const SolverOptions other) const

Returns true if this and other have exactly the same solvers, with exactly the same keys and values for the options for each solver.

◆ SetOption() [1/4]

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

Sets a double-valued solver option for a specific solver.

◆ SetOption() [2/4]

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

Sets an integer-valued solver option for a specific solver.

◆ SetOption() [3/4]

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

Sets a string-valued solver option for a specific solver.

◆ SetOption() [4/4]

void SetOption ( CommonSolverOption  key,
OptionValue  value 
)

Sets a common option for all solvers supporting that option (for example, printing the progress in each iteration).

If the solver doesn't support the option, the option is ignored.


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