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
Gets the boolean array indicating which variables are discrete.
Number of parameters in the NLP scheme.
Number of variables in the NLP scheme.
Gets the parameters of the NLP scheme.
Gets the parameters of the NLP scheme.
Gets the primal variables of the NLP scheme.
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 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)
- 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 x: SymType#
Gets the primary variables of the NLP scheme in vector form.
Examples using csnlp.nlps.HasVariables#
A simple optimization problem: Rosenbrock function
Comparison of CasADi’s and csnlp’s sensitivity computations
A simple example of sensitivity analysis (3d version)