csnlp.nlps.HasVariables#

class csnlp.nlps.HasVariables(sym_type='SX')[source]#

Bases: HasParameters[SymType]

Class for the creation and storage of symbolic variables in an NLP problem. It builds on top of HasParameters, which handles parameters.

Parameters:
sym_type{“SX”, “MX”}, optional

The CasADi symbolic variable type to use in the NLP, by default "SX".

Methods

parameter(name[, shape])

Adds a parameter to the NLP scheme.

variable(name[, shape, discrete])

Adds a variable to the NLP problem.

Attributes

discrete

Gets the boolean array indicating which variables are discrete.

np

Number of parameters in the NLP scheme.

nx

Number of variables in the NLP scheme.

p

Gets the parameters of the NLP scheme.

parameters

Gets the parameters of the NLP scheme.

variables

Gets the primal variables of the NLP scheme.

x

Gets the primary variables of the NLP scheme in vector form.

property discrete: ndarray[tuple[Any, ...], dtype[bool]]#

Gets the boolean array indicating which variables are discrete.

property np: int#

Number of parameters in the NLP scheme.

property nx: int#

Number of variables in the NLP scheme.

property p: SymType#

Gets the parameters of the NLP scheme.

parameter(name, shape=(1, 1))#

Adds a parameter to the NLP scheme.

Parameters:
namestr

Name of the new parameter. Must not be already in use.

shapetuple of 2 ints, optional

Shape of the new parameter. By default a scalar, i.e., (1, 1).

Returns:
casadi.SX or MX

The symbol for the new parameter.

Raises:
ValueError

Raises if there is already another parameter with the same name name.

Return type:

TypeVar(SymType, SX, MX)

property parameters: dict[str, SymType]#

Gets the parameters of the NLP scheme.

variable(name, shape=(1, 1), discrete=False)[source]#

Adds a variable to the NLP problem.

Parameters:
namestr

Name of the new variable. Must not be already in use.

shapetuple[int, int], optional

Shape of the new parameter. By default a scalar, i.e., (1, 1).

discretebool, optional

Flag indicating if the variable is discrete. Defaults to False.

Returns:
varcasadi.SX

The symbol of the new variable.

Raises:
ValueError

Raises if there is already another variable with the same name name.

Return type:

TypeVar(SymType, SX, MX)

property variables: dict[str, SymType]#

Gets the primal variables of the NLP scheme.

property x: SymType#

Gets the primary variables of the NLP scheme in vector form.

Examples using csnlp.nlps.HasVariables#

A simple optimization problem: hanging chain

A simple optimization problem: hanging chain

A mixed integer linear programming example

A mixed integer linear programming example

A simple problem with multiple minima

A simple problem with multiple minima

Linear MPC control

Linear MPC control

MPC controller for PWA systems

MPC controller for PWA systems

Multiple Scenario MPC

Multiple Scenario MPC

Simple open-loop MPC controller

Simple open-loop MPC controller

Scenario-based MPC

Scenario-based MPC

A simple optimization problem: Rosenbrock function

A simple optimization problem: Rosenbrock function

How scaling can help convergence

How scaling can help convergence

Comparison of CasADi’s and csnlp’s sensitivity computations

Comparison of CasADi's and csnlp's sensitivity computations

A simple example of sensitivity analysis

A simple example of sensitivity analysis

A simple example of sensitivity analysis (3d version)

A simple example of sensitivity analysis (3d version)