Drake
Drake C++ Documentation

Detailed Description

This class is a factory class to generate SystemConstraintWrapper.

Namely this class helps to convert a SystemConstraint to a solvers::Constraint. Internally this class will convert a System<double> to System<AutoDiffXd> (and System<symbolic::Expression> if possible), and store these systems (of different scalar types) inside this class. Using this class with a system that cannot be converted to System<AutoDiffXd> will cause a runtime error.

#include <drake/systems/optimization/system_constraint_adapter.h>

Public Member Functions

 SystemConstraintAdapter (const System< double > *system)
 
template<typename UpdateContextFromDecisionVariablesGenericFunction >
std::shared_ptr< SystemConstraintWrapperCreate (SystemConstraintIndex index, const Context< double > &context, UpdateContextFromDecisionVariablesGenericFunction updater, int x_size) const
 This method creates a solvers::Constraint from a SystemConstraint. More...
 
std::optional< std::vector< solvers::Binding< solvers::Constraint > > > MaybeCreateConstraintSymbolically (SystemConstraintIndex index, const Context< symbolic::Expression > &context) const
 Given a SystemConstraint and the Context to evaluate this SystemConstraint, parse the constraint in the symbolic forms. More...
 
std::optional< solvers::Binding< solvers::Constraint > > MaybeCreateGenericConstraintSymbolically (SystemConstraintIndex index, const Context< symbolic::Expression > &context) const
 Given a SystemConstraint and the Context to evaluate this SystemConstraint, parses the constraint to a generic nonlinear constraint lower <= SystemConstraint.Calc(context) <= upper. More...
 
const System< AutoDiffXd > & system_autodiff () const
 Getters for the system instantiated with AutoDiffXd. More...
 
const System< symbolic::Expression > & system_symbolic () const
 Returns the symbolic system. More...
 
Does not allow copy, move, or assignment
 SystemConstraintAdapter (const SystemConstraintAdapter &)=delete
 
SystemConstraintAdapteroperator= (const SystemConstraintAdapter &)=delete
 
 SystemConstraintAdapter (SystemConstraintAdapter &&)=delete
 
SystemConstraintAdapteroperator= (SystemConstraintAdapter &&)=delete
 

Constructor & Destructor Documentation

◆ SystemConstraintAdapter() [1/3]

◆ SystemConstraintAdapter() [2/3]

◆ SystemConstraintAdapter() [3/3]

SystemConstraintAdapter ( const System< double > *  system)
explicit

Member Function Documentation

◆ Create()

std::shared_ptr<SystemConstraintWrapper> Create ( SystemConstraintIndex  index,
const Context< double > &  context,
UpdateContextFromDecisionVariablesGenericFunction  updater,
int  x_size 
) const

This method creates a solvers::Constraint from a SystemConstraint.

The newly created constraint represents lower <= system_constraint.Calc(UpdateContextFromDecisionVariablesGeneric(x)) <= upper, where lower and upper are obtained from SystemConstraint::lower_bound() and SystemConstraint::upper_bound().

Parameters
indexThe index of the constraint stored inside system in the class constructor.
contextSystemConstraint::Calc function requires a context as the input. On the other hand, the generated constraint might be imposed on a partial subset of variables (state, time, input and parameters) inside the context. Hence we use UpdateContextFromDecisionVariablesGeneric to select the decision variables inside context. The unselected variables will remain to its values stored in context.

◆ MaybeCreateConstraintSymbolically()

std::optional<std::vector<solvers::Binding<solvers::Constraint> > > MaybeCreateConstraintSymbolically ( SystemConstraintIndex  index,
const Context< symbolic::Expression > &  context 
) const

Given a SystemConstraint and the Context to evaluate this SystemConstraint, parse the constraint in the symbolic forms.

Currently we support parsing the following forms:

  1. bounding box ( lower <= x <= upper )
  2. linear equality ( aᵀx = b )
  3. linear inequality ( lower <= aᵀx <= upper )

If the SystemConstraint cannot be parsed to the forms above, then returns nullopt; otherwise returns a vector containing the parsed constraint.

Parameters
indexThe index of the constraint in the System object.
contextThe context used to evaluate the SystemConstraint.
Return values
constraintsIf the SystemConstraint can be parsed to the constraint in the above forms, then constraints.value()[i] is the i'th row of the SystemConstraint evaluation result; if the SystemConstraint cannot be parsed in the above forms (either due to the System is not instantiated with symbolic::Expression, or the constraint is not linear), then constraints.has_value() = false.

◆ MaybeCreateGenericConstraintSymbolically()

std::optional<solvers::Binding<solvers::Constraint> > MaybeCreateGenericConstraintSymbolically ( SystemConstraintIndex  index,
const Context< symbolic::Expression > &  context 
) const

Given a SystemConstraint and the Context to evaluate this SystemConstraint, parses the constraint to a generic nonlinear constraint lower <= SystemConstraint.Calc(context) <= upper.

If the SystemConstraint cannot be parsed to the form above, then returns empty; otherwise returns a parsed constraint, together with the bound variables. We currently only support systems without abstract state or abstract parameters.

Parameters
indexThe index of the constraint in the System object.
contextThe context used to evaluate the SystemConstraint.
Note
each expression in context (like state, parameter, etc) should be either a single symbolic variable, or a constant. Currently we do not support complicated symbolic expressions.
Return values
constraintA generic nonlinear constraint parsed from SystemConstraint. If the SystemConstraint cannot be parsed to the generic constraint using context instantiated with symbolic::Expression, then constraint.has_value() = false.
Exceptions
std::exceptionif the system contains abstract state or abstract parameters.

◆ operator=() [1/2]

◆ operator=() [2/2]

SystemConstraintAdapter& operator= ( const SystemConstraintAdapter )
delete

◆ system_autodiff()

const System<AutoDiffXd>& system_autodiff ( ) const

Getters for the system instantiated with AutoDiffXd.

◆ system_symbolic()

const System<symbolic::Expression>& system_symbolic ( ) const

Returns the symbolic system.

Throws a runtime error if the system cannot be instantiated with symbolic::Expression.


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