MIMPC++
A fast typesafe Mixed Integer MPC C++ library
Public Types | Public Member Functions | Static Public Attributes | List of all members
mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme > Class Template Referenceabstract

#include <Solver.hpp>

Inheritance diagram for mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >:
Inheritance graph
[legend]

Public Types

using SYSTEM_TYPE = SystemType
 

Public Member Functions

virtual void addInputConstraintOnIndex (int index, double lb, double ub)=0
 
virtual void addStateConstraintOnIndex (int index, double lb, double ub)=0
 
virtual void addInputConstraintOnStep (int step, const SystemType::InputVec &lb, const SystemType::InputVec &ub)=0
 
virtual void addStateConstraintOnStep (int step, const SystemType::StateVec &lb, const SystemType::StateVec &ub)=0
 
virtual void setFinalWeights (const SystemType::StateVec &final_weights)=0
 
virtual void setStateWeights (const SystemType::StateVec &state_weights)=0
 
virtual void setInputWeights (const SystemType::InputVec &state_weights)=0
 
virtual void setCost (COST_TYPE cost_type)=0
 
virtual void setSetPoint (const SystemType::StateVec &set_point)=0
 
virtual void setState (const SystemType::StateVec &state)=0
 
virtual void setInputHistory (const Eigen::Matrix< double, SystemType::NUM_INPUTS, history_depth > &bin_input_hist)=0
 
virtual void setNextInputs (const Eigen::Matrix< double, SystemType::NUM_INPUTS, num_steps_solver_delay > &next_inputs)=0
 
virtual void setSolverTimeLimit (double max_seconds)=0
 
virtual unsigned int getStepsToCompensateControllerDelay ()=0
 
virtual SOLVER_RETURN solve (const Eigen::Matrix< double, SystemType::NUM_INPUTS, N, Eigen::RowMajor > &last_open_loop_input, const Eigen::Matrix< double, SystemType::NUM_STATES, N+1, Eigen::RowMajor > &last_open_loop_state, Eigen::Matrix< double, SystemType::NUM_INPUTS, N, Eigen::RowMajor > &open_loop_input, Eigen::Matrix< double, SystemType::NUM_STATES, N+1, Eigen::RowMajor > &open_loop_state) const =0
 

Static Public Attributes

static constexpr auto PRED_STEPS = N
 
static constexpr auto MIN_STEPS_ON = min_steps_on
 
static constexpr auto MIN_STEPS_OFF = min_steps_off
 
static constexpr auto MAX_STEPS_ON = max_steps_on
 
static constexpr auto NUM_STEPS_SOLVER_DELAY = num_steps_solver_delay
 
static constexpr auto INTEGRATION_SCHEME = integration_scheme
 
static constexpr int history_depth
 

Detailed Description

template<class SystemType, int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
class mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >

This defines abstract base class defines a wrapper around any mixed integer solver and defines a low level solver interface to be used within an mpc. For a highlevel interface refer to MPC, which takes any Solver implementation as a template argument.

The solver discretizes the time into time steps of same length.

Template Parameters
SystemTyperefers to the system dynamics and must be a class implementing System
Nprediction horizon
min_steps_onnumber of discrete time steps that the binary inputs have to stay on
min_steps_offnumber of discrete time steps that the binary inputs have to stay off
max_steps_onmaximum number of discrete time steps that the binary inputs can stay on
num_steps_solver_delaynumber of discrete time steps that are solver delay, referring to the time delay from the time point system is at a current state (which will be set by setState()) and the time point at which the optimal input returned by solve() is applied to the system. This delay is compensated by predicting the systems state based on the inputs that will be applied during this delay time. This inputs are set via setNextInputs() and can be for example taken from the previous open loop prediction. Obviously, the optimal input predicted by the solver and returned by solve() is the one at num_steps_solver_delay in the next open loop prediction, as the first refer to the predicted states during the delay. The correct index for the next input can be aquired using getStepsToCompensateControllerDelay().
integration_schemediscretization method

Member Function Documentation

◆ addInputConstraintOnIndex()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::addInputConstraintOnIndex ( int  index,
double  lb,
double  ub 
)
pure virtual

Adds or replaces the bounding box constraint to the input variable with given index to all discrete time steps.

Parameters
indexindex of the respective input variable in the input vector
lblower bound
ubupper bound

Implemented in mimpc::SCIPSolver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >.

◆ addInputConstraintOnStep()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::addInputConstraintOnStep ( int  step,
const SystemType::InputVec &  lb,
const SystemType::InputVec &  ub 
)
pure virtual

Adds or replaces the bounding box constraint to the input vector at given time step

Parameters
steptime step 0<=step<=N
lblower bound
ubupper bound

◆ addStateConstraintOnIndex()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::addStateConstraintOnIndex ( int  index,
double  lb,
double  ub 
)
pure virtual

Adds or replaces the bounding box constraint to the state variable with given index to all discrete time steps.

Parameters
indexindex of the respective state variable in the state vector
lblower bound
ubupper bound

Implemented in mimpc::SCIPSolver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >.

◆ addStateConstraintOnStep()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::addStateConstraintOnStep ( int  step,
const SystemType::StateVec &  lb,
const SystemType::StateVec &  ub 
)
pure virtual

Adds or replaces the bounding box constraint to the state vector at given time step

Parameters
steptime step 0<=step<=N
lblower bound
ubupper bound

◆ getStepsToCompensateControllerDelay()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual unsigned int mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::getStepsToCompensateControllerDelay ( )
pure virtual

Returns the index at which the next input calculated by solve() has to be taken, in order to correct respect the solver delay compensation. Most of the times this value should refer to #num_steps_solver_delay

Returns
num_steps_solver_delay

Implemented in mimpc::SCIPSolver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >.

◆ setCost()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setCost ( COST_TYPE  cost_type)
pure virtual

Sets the error function type

Parameters
cost_typeerror function type

◆ setFinalWeights()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setFinalWeights ( const SystemType::StateVec &  final_weights)
pure virtual

Sets the state error weights of the final predicted state

Parameters
final_weightsweight vector where each vector element refers to the respective state vector element

◆ setInputHistory()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setInputHistory ( const Eigen::Matrix< double, SystemType::NUM_INPUTS, history_depth > &  bin_input_hist)
pure virtual

Sets the input history of past inputs. This is necessary in order to respect the timing constraints.

Parameters
bin_input_histinput history matrix, where the first index refers to the input vector element and the second index to the history time step. Thereby index 0 refers to the most past element, and index history_depth refers to the current time step.

◆ setInputWeights()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setInputWeights ( const SystemType::InputVec &  state_weights)
pure virtual

Sets the input weights of all intermediate predicted inputs

Parameters
state_weightsweight vector where each vector element refers to the respective input vector element

◆ setNextInputs()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setNextInputs ( const Eigen::Matrix< double, SystemType::NUM_INPUTS, num_steps_solver_delay > &  next_inputs)
pure virtual

Sets the inputs that the will be applied to the system during the solver delay, in order to predicts the systems behaviour while the solver optimizes the next input

Parameters
next_inputsinput sequence

◆ setSetPoint()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setSetPoint ( const SystemType::StateVec &  set_point)
pure virtual

Sets the state set point. The state error is then calculated by applying the error function (as defined by setCost) to the difference between the current or predicted state and the set point. Each state error vector element is weighted by the state and final weights as specified by setStateWeights and setFinalWeights

Parameters
set_pointthe state set point

◆ setSolverTimeLimit()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setSolverTimeLimit ( double  max_seconds)
pure virtual

Sets the maximum time that the solver will try to find the optimal solution when solve is called. If the maximum time is reached, the best solution found so far will be returned.

Parameters
max_seconds

Implemented in mimpc::SCIPSolver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >.

◆ setState()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setState ( const SystemType::StateVec &  state)
pure virtual

Sets the current system state which is then used to do the optimization and prediction process.

Parameters
statesystem state

◆ setStateWeights()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual void mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::setStateWeights ( const SystemType::StateVec &  state_weights)
pure virtual

Sets the state error weights of all intermediate predicted states

Parameters
state_weightsweight vector where each vector element refers to the respective state vector element

◆ solve()

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
virtual SOLVER_RETURN mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::solve ( const Eigen::Matrix< double, SystemType::NUM_INPUTS, N, Eigen::RowMajor > &  last_open_loop_input,
const Eigen::Matrix< double, SystemType::NUM_STATES, N+1, Eigen::RowMajor > &  last_open_loop_state,
Eigen::Matrix< double, SystemType::NUM_INPUTS, N, Eigen::RowMajor > &  open_loop_input,
Eigen::Matrix< double, SystemType::NUM_STATES, N+1, Eigen::RowMajor > &  open_loop_state 
) const
pure virtual

Starts the solving process in order to find the optimal input and state sequence. Given the cost function and constraints. If a time limit as been set with setSolverTimeLimit, the method will return after that time with no or the best solution found so far.

Parameters
last_open_loop_inputan optimal open loop input sequence (i.e. from last iteration) that is used to warm start the solver
last_open_loop_statean optimal open loop state sequence (i.e. from last iteration) that is used to warm start the solver
open_loop_inputthe optimal/suboptimal input sequence found by the solver, depending on the delay compensation the next input is at discrete time step getStepsToCompensateControllerDelay()
open_loop_statethe optimal/suboptimal state sequence found by the solver
Returns
The return state indicates if the solution is optimal, suboptimal or no solution was found

Member Data Documentation

◆ history_depth

template<class SystemType , int N, int min_steps_on, int min_steps_off, int max_steps_on, int num_steps_solver_delay, INTEGRATION_SCHEME integration_scheme>
constexpr int mimpc::Solver< SystemType, N, min_steps_on, min_steps_off, max_steps_on, num_steps_solver_delay, integration_scheme >::history_depth
staticconstexpr
Initial value:
= std::max(
{0, max_steps_on - num_steps_solver_delay, min_steps_off - num_steps_solver_delay,
min_steps_on - num_steps_solver_delay})

Gives, based on the timing constraints the number of past discrete time steps that the optimization problem needs to know


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