Horizon package¶
Subpackages¶
- horizon.ros package
- horizon.solvers package
- horizon.transcriptions package
- horizon.utils package
- Submodules
- horizon.utils.collision module
- horizon.utils.kin_dyn module
- horizon.utils.mat_storer module
- horizon.utils.plotter module
- horizon.utils.refiner module
- horizon.utils.replayer module
- horizon.utils.replayer_fd module
- horizon.utils.replayer_fd_mx module
- horizon.utils.replayer_mx module
- horizon.utils.resampler_trajectory module
- horizon.utils.rti module
- horizon.utils.send_to_gazebo module
- horizon.utils.utils module
- horizon.utils.vis_refiner_global module
- Module contents
Submodules¶
horizon.functions module¶
-
class
horizon.functions.
Constraint
(name: str, f: <sphinx.ext.autodoc.importer._MockObject object at 0x7f63294bd7c0>, used_vars: list, used_pars: list, nodes: Union[int, Iterable[T_co]], bounds=None)¶ Bases:
horizon.functions.Function
Constraint Function of Horizon.
-
getBounds
(nodes=None)¶ Getter for the bounds of the function.
Parameters: node – desired node at which the bounds are retrieved. If not specified, this returns the bounds at all nodes. Returns: value/s of the upper bounds
-
getLowerBounds
(node: int = None)¶ Getter for the lower bounds of the function.
Parameters: node – desired node at which the lower bounds are retrieved. If not specified, this returns the lower bounds at all nodes. Returns: value/s of the lower bounds
-
getType
() → str¶ Getter for the type of the Constraint.
Returns: a string describing the type of the function
-
getUpperBounds
(node: int = None)¶ Getter for the upper bounds of the function.
Parameters: node – desired node at which the upper bounds are retrieved. If not specified, this returns the upper bounds at all nodes. Returns: value/s of the upper bounds
-
setBounds
(lb, ub, nodes=None)¶ Setter for the bounds of the function.
Parameters: - lb – desired lower bounds of the function
- ub – desired upper bounds of the function
- nodes – nodes of the function the bounds are applied on. If not specified, the function is bounded along ALL the nodes.
-
setLowerBounds
(bounds, nodes=None)¶ Setter for the lower bounds of the function.
Parameters: - bounds – desired bounds of the function
- nodes – nodes of the function the bounds are applied on. If not specified, the function is bounded along ALL the nodes.
-
setNodes
(nodes, erasing=False)¶ Setter for the active nodes of the constraint function.
Parameters: - nodes – list of desired active nodes.
- erasing – choose if the inserted nodes overrides the previous active nodes of the function. ‘False’ if not specified.
-
setUpperBounds
(bounds, nodes=None)¶ Setter for the upper bounds of the function.
Parameters: - bounds – desired bounds of the function
- nodes – nodes of the function the bounds are applied on. If not specified, the function is bounded along ALL the nodes.
-
-
class
horizon.functions.
CostFunction
(name, f, used_vars, used_pars, nodes)¶ Bases:
horizon.functions.Function
Cost Function of Horizon.
-
getType
()¶ Getter for the type of the Cost Function.
Returns: a string describing the type of the function
-
-
class
horizon.functions.
Function
(name: str, f: <sphinx.ext.autodoc.importer._MockObject object at 0x7f6329a691f0>, used_vars: list, used_pars: list, nodes: Union[int, Iterable[T_co]])¶ Bases:
object
Function of Horizon: generic function of SX values from CASADI.
Notes
This function is an abstract representation of its projection over the nodes of the optimization problem. An abstract function gets internally implemented at each node, using the variables at that node.
-
deserialize
()¶ Deserialize the Function. Used to load it.
Returns: deserialized instance of Function
-
getDim
() → int¶ Getter for the dimension of the function
Returns: dimension of the function
-
getFunction
() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f63294dc6a0>¶ Getter for the CASADI function
Returns: instance of the CASADI function
-
getImpl
(nodes=None)¶ Getter for the CASADI function implemented at the desired node :param node: the desired node of the implemented function to retrieve
Returns: instance of the CASADI function at the desired node
-
getName
() → str¶ Getter for the name of the function
Returns: name of the function
-
getNodes
() → list¶ Getter for the active nodes of the function.
Returns: a list of the nodes where the function is active
-
getParameters
() → list¶ Getter for the parameters used in the function.
Returns: cs.SX} Return type: a dictionary of all the used parameters. {name
-
getType
() → str¶ Getter for the type of the Variable.
Notes
Is it useful?
Returns: a string describing the type of the function
-
getVariables
(offset=True) → list¶ Getter for the variables used in the function.
Returns: cs.SX} Return type: a dictionary of all the used variable. {name
-
serialize
()¶ Serialize the Function. Used to save it.
Returns: serialized instance of Function
-
setNodes
(nodes, erasing=False)¶ Setter for the active nodes of the function.
Parameters: - nodes – list of desired active nodes.
- erasing – choose if the inserted nodes overrides the previous active nodes of the function. ‘False’ if not specified.
-
-
class
horizon.functions.
FunctionsContainer
(logger=None)¶ Bases:
object
Container of all the function of Horizon. It is used internally by the Problem to get the abstract and implemented function.
-
build
()¶ builds the container with the updated functions.
-
addFunction
(fun: horizon.functions.Function)¶ Add a function to the Function Container.
Parameters: fun – a Function (can be Constraint or Cost Function) o add
-
deserialize
()¶ Deerialize the Function Container. Used to load it.
Returns: instance of deserialized Function Container
-
getCnstr
(name=None) → collections.OrderedDict¶ Getter for the dictionary of all the abstract constraint functions.
Parameters: of constraint. If not specified, returns all of them (name) – Returns: fun} Return type: ordered dict of the functions {name
-
getCnstrDim
() → int¶ Getter for the dimension of all the constraints :returns: the total dimension of the constraint
-
getCost
(name=None) → collections.OrderedDict¶ Getter for the dictionary of all the abstract cost functions.
Parameters: of constraint. If not specified, returns all of them (name) – Returns: fun} Return type: ordered dict of the functions {name
-
getFunction
(fun_name: str)¶ Getter for a Function inside the Function Container. :param fun_name: name of the function to retrieve
-
removeFunction
(fun_name: str)¶ Remove a function from the Function Container.
Parameters: fun_name – name of the function to be removed
-
serialize
()¶ Serialize the Function Container. Used to save it.
Returns: instance of serialized Function Container
-
setNNodes
(n_nodes)¶ set a desired number of nodes to Function Container. :param n_nodes: the desired number of nodes to be set
-
-
class
horizon.functions.
ResidualFunction
(name, f, used_vars, used_pars, nodes)¶ Bases:
horizon.functions.Function
Residual Function of Horizon.
-
getType
()¶ Getter for the type of the Cost Function.
Returns: a string describing the type of the function
-
horizon.misc_function module¶
-
horizon.misc_function.
checkNodes
(nodes, nodes_self=None)¶
-
horizon.misc_function.
checkValueEntry
(val)¶
-
horizon.misc_function.
listOfListFLOATtoINT
(listOfList)¶
-
horizon.misc_function.
unravelElements
(elements)¶
horizon.problem module¶
-
class
horizon.problem.
Problem
(N: int, crash_if_suboptimal: bool = False, logging_level=20)¶ Bases:
object
Main class of Horizon, a tool for dynamic optimization using the symbolic framework CASADI. It is a useful tool to describe and solve parametric non-linear problems for trajectory planning. It follows the structure of a generic shooting method, dividing the interval of planning [ta, tb] into a given number of shooting nodes, where each nodes contains decision variables (state, input ..) of the problem.
Horizon greatly simplifies the description of the problem, allowing the user to work only with abstract definitions of variables and functions, which are internally managed, evaluated and projected along the optimization horizon by the framework.
-
createConstraint
(name: str, g, nodes: Union[int, collections.abc.Iterable] = None, bounds=None) → horizon.functions.Constraint¶ Create a Constraint Function of the optimization problem.
Parameters: - name – name of the constraint
- g – constraint function
- nodes – nodes the constraint is active on. If not specified, the Constraint is active on ALL the nodes.
- bounds – bounds of the constraint. If not specified, the bounds are set to zero.
Returns: instance of Constraint
-
createCost
(name: str, j, nodes: Union[int, collections.abc.Iterable] = None)¶ Create a Cost Function of the optimization problem.
Parameters: - name – name of the cost function
- j – cost function
- nodes – nodes the cost function is active on. If not specified, the cost function is active on ALL the nodes.
Returns: instance of Cost Function
-
createFinalConstraint
(name: str, g, bounds=None)¶ Create a Constraint Function only active on the last node of the optimization problem.
Parameters: - name – name of the constraint
- g – constraint function
- bounds – bounds of the constraint. If not specified, the bounds are set to zero.
Returns: instance of Constraint
-
createFinalCost
(name: str, j)¶ Create a Cost Function only active on the last node of the optimization problem.
Parameters: - name – name of the cost function
- j – cost function
Returns: instance of Cost Function
-
createFinalResidual
(name: str, j)¶ Create a Residual Function only active on the last node of the optimization problem.
Parameters: - name – name of the residual function
- j – function
Returns: instance of Residual Function
-
createInputVariable
(name: str, dim: int) → horizon.variables.InputVariable¶ Create an Input Variable active on all the nodes of the optimization problem except the final one. (Input is not defined on the last node)
Parameters: - name – name of the variable
- dim – dimension of the variable
Returns: instance of Input Variable
-
createIntermediateConstraint
(name: str, g, nodes: Union[int, collections.abc.Iterable] = None, bounds=None)¶ Create a Constraint Function that can be active on all the nodes except the last one
Parameters: - name – name of the constraint
- g – constraint function
- nodes – nodes the constraint is active on. If not specified, the constraint is active on all the nodes except the last one
- bounds – bounds of the constraint. If not specified, the bounds are set to zero.
Returns: instance of Constraint
-
createIntermediateCost
(name: str, j, nodes: Union[int, collections.abc.Iterable] = None)¶ Create a Cost Function that can be active on all the nodes except the last one.
Parameters: - name – name of the function
- j – function
- nodes – nodes the function is active on. If not specified, the cost function is active on all the nodes except the last one
Returns: instance of Function
-
createIntermediateResidual
(name: str, j, nodes: Union[int, collections.abc.Iterable] = None)¶ Create a Residual Function that can be active on all the nodes except the last one.
Parameters: - name – name of the function
- j – function
- nodes – nodes the function is active on. If not specified, the function is active on all the nodes except the last one
Returns: instance of Function
-
createParameter
(name: str, dim: int, nodes: collections.abc.Iterable = None) → Union[horizon.variables.Parameter, horizon.variables.SingleParameter]¶ Create a Parameter used in the optimization problem. Can be specified over a desired portion of the horizon nodes. Parameters are specified before building the problem and can be ‘assigned’ afterwards, before solving the problem.
Parameters: - name – name of the parameter
- dim – dimension of the parameter
- nodes – nodes the parameter is defined on. If not specified, the variable is created on all the nodes.
Returns: instance of Parameter
-
createResidual
(name: str, j, nodes: Union[int, collections.abc.Iterable] = None)¶ Create a Residual Function of the optimization problem.
Parameters: - name – name of the function
- j – function
- nodes – nodes the function is active on. If not specified, it is active on ALL the nodes.
Returns: instance of Residual Function
-
createSingleParameter
(name: str, dim: int) → horizon.variables.SingleParameter¶ Create a node-independent Single Parameter used to solve the optimization problem. It is a single parameter which is not projected over the horizon. Parameters are specified before building the problem and can be ‘assigned’ afterwards, before solving the problem.
Parameters: - name – name of the parameter
- dim – dimension of the parameter
Returns: instance of Single Parameter
-
createSingleVariable
(name: str, dim: int) → horizon.variables.SingleVariable¶ Create a node-independent Single Variable of the optimization problem. It is a single decision variable which is not projected over the horizon.
Parameters: - name – name of the variable
- dim – dimension of the variable
Returns: instance of Single Variable
-
createStateVariable
(name: str, dim: int) → horizon.variables.StateVariable¶ Create a State Variable active on ALL the N+1 nodes of the optimization problem.
Parameters: - name – name of the variable
- dim – dimension of the variable
Returns: instance of the State Variable
-
createVariable
(name: str, dim: int, nodes: collections.abc.Iterable = None) → Union[horizon.variables.StateVariable, horizon.variables.SingleVariable]¶ Create a generic Variable of the optimization problem. Can be specified over a desired portion of the horizon nodes.
Parameters: - name – name of the variable
- dim – dimension of the variable
- nodes – nodes the variables is defined on. If not specified, the variable created is a Single Variable.
Returns: instance of Variable
-
deserialize
()¶ Deserialize this class. Used for loading it.
Returns: instance of the deserialized class “Problem”
-
evalFun
(fun: horizon.functions.Function, solution)¶ Evaluates a given function over the solution found.
Parameters: fun – function to evaluate Returns: fun evaluated at all nodes using the solution of horizon problem
-
getConstraints
(name=None)¶ Getter for a desired constraint of the optimization problem.
Parameters: name – name of the desired constraint. If not specified, a dict with all the constraint is returned Returns: the desired constraint/s
-
getCosts
(name=None)¶ Getter for a desired constraint of the optimization problem.
Parameters: name – name of the desired constraint. If not specified, a dict with all the constraint is returned Returns: the desired constraint/s
-
getDt
()¶ Getter of the system dt used in the optimization problem.
Returns: instance of the dt
-
getDynamics
() → <sphinx.ext.autodoc.importer._MockObject object at 0x7f63298ca520>¶ Getter of the system Dynamics used in the optimization problem.
Returns: instance of the derivative of the state
-
getInitialState
() → numpy.array¶
-
getInput
() → horizon.variables.InputAggregate¶ Getter for the aggregate Input defined for the problem. The Input contains, in order, all the Input Variables created.
Returns: instance of Input
-
getNNodes
() → int¶ Getter for the number of nodes of the optimization problem.
Returns: the number of optimization nodes
-
getParameters
(name: str = None)¶ Getter for a desired parameter of the optimization problem.
Parameters: name – name of the desired parameter. If not specified, a dict with all the parameters is returned Returns: the desired parameter/s
-
getState
() → horizon.variables.StateAggregate¶ Getter for the aggregate State defined for the problem. The State contains, in order, all the State Variables created. :returns: instance of State
-
getVariables
(name: str = None)¶ Getter for a desired variable of the optimization problem.
Parameters: name – name of the desired variable. If not specified, a dict with all the variables is returned Returns: the desired variable/s
-
removeConstraint
(name: str) → bool¶ remove the desired constraint.
Parameters: name – name of the constraint function to be removed Returns: False if function name is not found.
-
removeCostFunction
(name: str) → bool¶ remove the desired cost function.
Parameters: name – name of the cost function to be removed Returns: False if function name is not found.
-
removeVariable
(name: str) → bool¶ remove the desired variable.
Parameters: name – name of the cost function to be removed Returns: False if function name is not found.
-
resetDynamics
()¶
-
save
()¶
-
scopeNodeConstraints
(node)¶ Scope the constraints active at the desired node of the optimization problem.
Parameters: node – desired node to scope Returns: all the active constraint at the desired node
-
scopeNodeCostFunctions
(node)¶ Scope the cost functions active at the desired node of the optimization problem.
Parameters: node – desired node to scope Returns: all the active cost functions at the desired node
-
scopeNodeVars
(node: int)¶ Scope the variables active at the desired node of the optimization problem.
Parameters: node – desired node to scope Returns: all the active variables at the desired node
-
serialize
()¶ Serialize this class. Used for saving it.
Returns: instance of the serialized class “Problem”
-
setDt
(dt)¶ Setter of the system dt used in the optimization problem.
Parameters: dt – dt of the system
-
setDynamics
(xdot)¶ Setter of the system Dynamics used in the optimization problem.
Parameters: xdot – derivative of the State describing the dynamics of the system
-
setInitialState
(x0: collections.abc.Iterable)¶
-
setNNodes
(n_nodes: int)¶ set a desired number of nodes of the optimization problem.
Parameters: n_nodes – new number of nodes
-
toParameter
(var_name)¶
-
-
horizon.problem.
pickleable
(obj)¶
horizon.variables module¶
-
class
horizon.variables.
AbstractAggregate
(*args)¶ Bases:
abc.ABC
Abstract Aggregate of the Horizon Problem. Used to store more variables of the same nature.
-
getVars
(abstr=False) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f63298e6d30>¶ Getter for the variable stored in the aggregate.
Returns: a SX vector of all the variables stored
-
-
class
horizon.variables.
AbstractVariable
(tag: str, dim: int)¶ Bases:
abc.ABC
,sphinx.ext.autodoc.importer._MockObject
Abstract Variable of Horizon Problem.
Notes
Horizon allows the user to work only with abstract variables. Internally, these variables are projected over the horizon nodes.
-
getDim
() → int¶ Getter for the dimension of the abstract variable.
Returns: dimension of the variable
-
getName
()¶
-
getOffset
()¶
-
-
class
horizon.variables.
AbstractVariableView
(parent: horizon.variables.AbstractVariable, var_slice, indices)¶ Bases:
sphinx.ext.autodoc.importer._MockObject
-
getName
()¶
-
-
class
horizon.variables.
Aggregate
(*args)¶ Bases:
horizon.variables.AbstractAggregate
Aggregate of the Horizon Problem. Used to store more variables of the same nature.
-
addVariable
(var)¶ Adds a Variable to the Aggregate.
Parameters: var – variable to be added to the aggregate
-
getBounds
(node=None)¶ Getter for the bounds of the variables in the aggregate.
Parameters: node – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes Returns: array of bound values of each variable in the aggregate
-
getInitialGuess
(node=None) → numpy.array¶ [summary]
Parameters: node ([type]) – [description] Returns: [description] Return type: [type]
-
getLowerBounds
(node)¶ Getter for the lower bounds of the variables in the aggregate.
Parameters: node – which nodes the lower bounds are applied on. If not specified, the variable is bounded along ALL the nodes Returns: array of lower bound values of each variable in the aggregate
-
getUpperBounds
(node)¶ Getter for the upper bounds of the variables in the aggregate.
Parameters: node – which nodes the upper bounds are applied on. If not specified, the variable is bounded along ALL the nodes Returns: array of upper bound values of each variable in the aggregate
-
getVarIndex
(name)¶ Return offset and dimension for the variable with given name, that must belong to this aggregate. The resulting pair is such that the following code returns the variable’s SX value
off, dim = self.getVarIndex(name=’myvar’) v = self.getVars()[off:off+dim]Parameters: name ([type]) – [description]
-
getVarOffset
(offset)¶ Getter for the offset variables contained in the aggregate.
Returns: an abstract aggregate with all the offset variables referring to the relative abstract variables
-
removeVariable
(var_name)¶ Remove a Variable from the Aggregate.
Parameters: var – variable to be removed from the aggregate
-
setBounds
(lb, ub, nodes=None)¶ Setter for the bounds of the variables in the aggregate.
Parameters: - lb – desired lower bounds of the variable
- ub – desired upper bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setInitialGuess
(v0, nodes=None)¶ Parameters: - v0 ([type]) – [description]
- nodes ([type], optional) – [description]. Defaults to None.
-
setLowerBounds
(lb, nodes=None)¶ Setter for the lower bounds of the variables in the aggregate.
Parameters: - bounds – list of desired bounds of the all the variables in the aggregate
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setUpperBounds
(ub, nodes=None)¶ Setter for the upper bounds of the variables in the aggregate.
Parameters: - bounds – list of desired bounds of the all the variables in the aggregate
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
-
class
horizon.variables.
InputAggregate
(*args)¶ Bases:
horizon.variables.Aggregate
Input (Control) Aggregate of the Horizon Problem. Used to store all the control variables.
-
class
horizon.variables.
InputVariable
(tag, dim, nodes)¶ Bases:
horizon.variables.Variable
Input (Control) Variable of Horizon Problem. The variable is abstract, and gets implemented automatically over the horizon nodes except the last one.
Examples
Abstract variable “x”. Horizon nodes are N.
Implemented variable “x” –> x_0, x_1, … x_N-1
-
class
horizon.variables.
OffsetAggregate
(*args)¶ Bases:
horizon.variables.AbstractAggregate
Offset Aggregate of the Horizon Problem. Used to store more offset variables of the same nature.
-
getVarIndex
(name)¶ Return offset and dimension for the variable with given name, that must belong to this aggregate. The resulting pair is such that the following code returns the variable’s SX value
off, dim = self.getVarIndex(name=’myvar’) v = self.getVars()[off:off+dim]Parameters: name ([type]) – [description]
-
-
class
horizon.variables.
OffsetParameter
(parent_name, tag, dim, offset, par_impl)¶ Bases:
horizon.variables.AbstractVariable
-
getImpl
(nodes=None)¶ Getter for the implemented offset parameter.
Parameters: node – node at which the parameter is retrieved Returns: implemented instances of the abstract offsetted parameter
-
getName
()¶ Get name of the parameter. Warning: not always same as the tag
Returns: name of the parameter
-
getNodes
()¶ Getter for the active nodes.
Returns: list of active nodes
-
-
class
horizon.variables.
OffsetVariable
(parent_name, tag, dim, offset, var_impl)¶ Bases:
horizon.variables.AbstractVariable
-
getImpl
(nodes=None)¶ Getter for the implemented offset variable.
Parameters: node – node at which the variable is retrieved Returns: implemented instances of the abstract offsetted variable
-
getName
()¶ Get name of the variable. Warning: not always same as the tag
Returns: name of the variable
-
getNodes
()¶ Getter for the active nodes.
Returns: list of active nodes
-
-
class
horizon.variables.
Parameter
(tag, dim, nodes)¶ Bases:
horizon.variables.AbstractVariable
Parameter of Horizon Problem. It is used for parametric problems: it is a symbolic variable in the optimization problem but it is not optimized. Rather, it is kept parametric and can be assigned before solving the problem.
-
assign
(val, nodes=None)¶ Assign a value to the parameter at a desired node. Can be assigned also after the problem is built, before solving the problem. If not assigned, its default value is zero.
Parameters: - val – value of the parameter
- nodes – nodes at which the parameter is assigned
-
getImpl
(nodes=None)¶ Getter for the implemented parameter.
Parameters: node – node at which the parameter is retrieved. If not specified, this function returns an SX array with all the implemented parameters along the nodes. Returns: implemented instances of the abstract parameter
-
getName
()¶ getter for the name of the parameter
Returns: name of the parameter
-
getNodes
()¶ Getter for the nodes of the parameters.
Returns: list of nodes the parameter is active on.
-
getParOffset
(node)¶ Getter for the offset parameter. An offset parameter is used to point to the desired implemented instance of the abstract parameter.
Examples
Abstract parameter “p”. Horizon nodes are N.
Implemented parameter “p” –> p_0, p_1, … p_N-1, p_N
Offset parameter “p-1” points FOR EACH NODE at variable “p” implemented at the PREVIOUS NODE.
Parameters: nodes – offset of the node (shift to n node before or after)
-
getParOffsetDict
()¶ Getter for the offset variables.
Returns: dict with all the offset variables referring to this abstract variable
-
getValues
(nodes=None)¶ Getter for the value of the parameter.
Parameters: node – node at which the value of the parameter is retrieved. If not specified, this function returns a matrix with all the values of the parameter along the nodes. Returns: value/s of the parameter
-
-
class
horizon.variables.
ParameterView
(parent: horizon.variables.SingleParameter, var_slice, indices)¶ Bases:
horizon.variables.AbstractVariableView
-
assign
(vals, nodes=None)¶ Assign a value to the parameter at a desired node. Can be assigned also after the problem is built, before solving the problem. If not assigned, its default value is zero.
Parameters: - vals – value of the parameter
- nodes – nodes at which the parameter is assigned
-
getValues
(nodes)¶ Getter for the value of the parameter.
Parameters: node – node at which the value of the parameter is retrieved. If not specified, this function returns a matrix with all the values of the parameter along the nodes. Returns: value/s of the parameter
-
-
class
horizon.variables.
SingleParameter
(tag, dim, dummy_nodes)¶ Bases:
horizon.variables.AbstractVariable
Single Parameter of Horizon Problem. It is used for parametric problems: it is a symbolic variable in the optimization problem but it is not optimized. Rather, it is kept parametric and can be assigned before solving the problem. Parameters are specified before building the problem and can be ‘assigned’ afterwards, before solving the problem. The assigned value is the same along the horizon, since this parameter is node-independent. The Parameter is abstract, and gets implemented automatically.
-
assign
(vals)¶ Assign a value to the parameter. Can be assigned also after the problem is built, before solving the problem. If not assigned, its default value is zero.
Parameters: vals – value of the parameter
-
getImpl
(nodes=None)¶ Getter for the implemented parameter. Node is useless, since this parameter is node-independent.
Parameters: node – useless input, used to simplify the framework mechanics Returns: instance of the implemented parameter
-
getName
()¶ getter for the name of the parameter
Returns: name of the parameter
-
getNodes
()¶ Getter for the active nodes.
Returns: -1 since this parameter is node-independent
-
getParOffset
(node)¶ Getter for the offset parameter. Since the parameter is the same along the horizon, it will point to itself.
Parameters: nodes – offset of the node (shift to n node before or after)
-
getParOffsetDict
()¶ Getter for the offset parameter. Useless, since this parameter is node-independent.
Returns: empty dict
-
getValues
(nodes=None)¶ Getter for the value assigned to the parameter. It is the same throughout all the nodes, since this parameter is node-independent.
Parameters: dummy_node – useless input, used to simplify the framework mechanics Returns: value assigned to the parameter
-
-
class
horizon.variables.
SingleParameterView
(parent: horizon.variables.SingleParameter, var_slice, indices)¶ Bases:
horizon.variables.AbstractVariableView
-
assign
(vals)¶ Assign a value to the parameter. Can be assigned also after the problem is built, before solving the problem. If not assigned, its default value is zero.
Parameters: vals – value of the parameter
-
-
class
horizon.variables.
SingleVariable
(tag, dim, dummy_nodes)¶ Bases:
horizon.variables.AbstractVariable
Single Variable of Horizon Problem: generic variable of the optimization problem. The single variable is the same along the horizon, since it is node-independent. The Variable is abstract, and gets implemented automatically.
-
getBounds
(dummy_node=None)¶ Getter for the bounds of the variable.
Parameters: node – useless input, used to simplify the framework mechanics Returns: values of the bounds
-
getImpl
(nodes=None)¶ Getter for the implemented variable. Node is useless, since this variable is node-independent.
Parameters: dummy_node – useless input, used to simplify the framework mechanics Returns: implemented instances of the abstract variable
-
getImplDim
()¶ Getter for the dimension of the implemented variables.
Returns: dimension of the variable
-
getInitialGuess
(dummy_node=None)¶ Getter for the initial guess of the variable.
Parameters: node – useless input, used to simplify the framework mechanics Returns: values of the initial guess
-
getLowerBounds
(dummy_node=None)¶ Getter for the lower bounds of the variable.
Parameters: node – useless input, used to simplify the framework mechanics Returns: values of the lower bounds
-
getName
()¶ getter for the name of the variable
Returns: name of the variable
-
getNodes
()¶ Getter for the active nodes of the variable.
Returns: -1 since this parameter is node-independent
-
getUpperBounds
(dummy_node=None)¶ Getter for the upper bounds of the variable.
Parameters: node – useless input, used to simplify the framework mechanics Returns: values of the upper bounds
-
getVarOffset
(node)¶ Getter for the offset variable. Since the variable is the same along the horizon, it will point to itself.
Parameters: nodes – offset of the node (shift to n node before or after)
-
getVarOffsetDict
()¶ Getter for the offset variables. Useless, since this variable is node-independent.
Returns: empty dict
-
setBounds
(lb, ub)¶ Setter for the bounds of the variable.
Parameters: - lb – value of the lower bounds
- ub – value of the upper bounds
-
setInitialGuess
(val)¶ Setter for the initial guess of the variable.
Parameters: val – value of the initial guess
-
setLowerBounds
(bounds)¶ Setter for the lower bounds of the variable.
Parameters: bounds – value of the lower bounds
-
setUpperBounds
(bounds)¶ Setter for the upper bounds of the variable.
Parameters: bounds – value of the upper bounds
-
-
class
horizon.variables.
SingleVariableView
(parent: horizon.variables.SingleVariable, var_slice, indices)¶ Bases:
horizon.variables.AbstractVariableView
-
setBounds
(lb, ub)¶ Setter for the bounds of the variable.
Parameters: - lb – value of the lower bounds
- ub – value of the upper bounds
-
setInitialGuess
(val)¶ Setter for the initial guess of the variable.
Parameters: val – value of the initial guess
-
setLowerBounds
(bounds)¶ Setter for the lower bounds of the variable.
Parameters: bounds – value of the lower bounds
-
setUpperBounds
(bounds)¶ Setter for the upper bounds of the variable.
Parameters: bounds – value of the upper bounds
-
-
class
horizon.variables.
StateAggregate
(*args)¶ Bases:
horizon.variables.Aggregate
State Aggregate of the Horizon Problem. Used to store all the state variables.
-
class
horizon.variables.
StateVariable
(tag, dim, nodes)¶ Bases:
horizon.variables.Variable
State Variable of Horizon Problem. The variable is abstract, and gets implemented automatically over all the horizon nodes.
Examples
Abstract variable “x”. Horizon nodes are N.
Implemented variable “x” –> x_0, x_1, … x_N-1, x_N
-
class
horizon.variables.
Variable
(tag, dim, nodes)¶ Bases:
horizon.variables.AbstractVariable
Variable of Horizon Problem: generic variable of the optimization problem. The Variable is abstract, and gets implemented automatically over the horizon nodes.
Examples
Abstract variable “x”. Horizon nodes are N.
Implemented variable “x” –> x_0, x_1, … x_N-1, x_N
-
getBounds
(node=None)¶ Getter for the bounds of the variable.
Parameters: node – desired node at which the bounds are retrieved. If not specified, this returns the bounds at all nodes Returns: value/s of the bounds
-
getImpl
(nodes=None)¶ Getter for the implemented variable.
Parameters: node – node at which the variable is retrieved Returns: implemented instances of the abstract variable
-
getImplDim
()¶ Getter for the dimension of the implemented variables, considering all the nodes.
Returns: dimension of the variable multiplied by number of nodes
-
getInitialGuess
(node=None)¶ Getter for the initial guess of the variable.
Parameters: node – desired node at which the initial guess is retrieved. If not specified, this returns the lower bounds at all nodes Returns: value/s of the bounds
-
getLowerBounds
(node=None)¶ Getter for the lower bounds of the variable.
Parameters: node – desired node at which the lower bounds are retrieved. If not specified, this returns the lower bounds at all nodes Returns: value/s of the lower bounds
-
getName
()¶ getter for the name of the variable
Returns: name of the variable
-
getNodes
()¶ Getter for the active nodes of the variable.
Returns: the nodes the variable is defined on
-
getUpperBounds
(node=None)¶ Getter for the upper bounds of the variable.
Parameters: node – desired node at which the upper bounds are retrieved. If not specified, this returns the upper bounds at all nodes Returns: value/s of the upper bounds
-
getVarOffset
(node)¶ Getter for the offset variable. An offset variable is used to point to the desired implemented instance of the abstract variable.
Examples
Abstract variable “x”. Horizon nodes are N.
Implemented variable “x” –> x_0, x_1, … x_N-1, x_N
Offset variable “x-1” points FOR EACH NODE at variable “x” implemented at the PREVIOUS NODE.
Parameters: nodes – offset of the node (shift to n node before or after)
-
getVarOffsetDict
()¶ Getter for the offset variables.
Returns: dict with all the offset variables referring to this abstract variable
-
setBounds
(lb, ub, nodes=None)¶ Setter for the bounds of the variable.
Parameters: - lb – desired lower bounds of the variable
- ub – desired upper bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setInitialGuess
(val, nodes=None)¶ Setter for the initial guess of the variable.
Parameters: - val – desired initial guess of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setLowerBounds
(bounds, nodes=None)¶ Setter for the lower bounds of the variable.
Parameters: - bounds – desired bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setUpperBounds
(bounds, nodes=None)¶ Setter for the upper bounds of the variable.
Parameters: - bounds – desired bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
-
class
horizon.variables.
VariableView
(parent: horizon.variables.Variable, var_slice, indices)¶ Bases:
horizon.variables.AbstractVariableView
-
setBounds
(lb, ub, nodes=None)¶ Setter for the bounds of the variable.
Parameters: - lb – desired lower bounds of the variable
- ub – desired upper bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setInitialGuess
(val, nodes=None)¶ Setter for the initial guess of the variable.
Parameters: - val – desired initial guess of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setLowerBounds
(bounds, nodes=None)¶ Setter for the lower bounds of the variable.
Parameters: - bounds – desired bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
setUpperBounds
(bounds, nodes=None)¶ Setter for the upper bounds of the variable.
Parameters: - bounds – desired bounds of the variable
- nodes – which nodes the bounds are applied on. If not specified, the variable is bounded along ALL the nodes
-
-
class
horizon.variables.
VariablesContainer
(logger=None)¶ Bases:
object
Container of all the variables of Horizon. It is used internally by the Problem to get the abstract and implemented variables.
-
createVar
(var_type, name, dim, active_nodes)¶ Create a variable and adds it to the Variable Container.
Parameters: - var_type – type of variable
- name – name of variable
- dim – dimension of variable
- active_nodes – nodes the variable is defined on
-
deserialize
()¶ Deserialize the Variable Container. Used to load it.
Returns: instance of deserialized Variable Container
-
getInputVars
()¶ Getter for the input (control) variables in the Variable Container.
Returns: a dict with all the input (control) variables
-
getPar
(name=None)¶ Getter for the abstract parameters in the Variable Container.
Returns: a dict with all the abstract parameters
-
getParList
(offset=True)¶ Getter for the abstract parameters in the Variable Container. Used by the Horizon Problem.
Returns: a list with all the abstract parameters
-
getStateVars
()¶ Getter for the state variables in the Variable Container.
Returns: a dict with all the state variables
-
getVar
(name=None)¶ Getter for the abstract variables in the Variable Container.
Parameters: name – name of the variable to be retrieve Returns: a dict with all the abstract variables
-
getVarList
(offset=True)¶ Getter for the abstract variables in the Variable Container. Used by the Horizon Problem.
Parameters: offset – if True, get also the offset_variable Returns: a list with all the abstract variables
-
removeVar
(var_name)¶
-
serialize
()¶ Serialize the Variable Container. Used to save it.
Returns: instance of serialized Variable Container
-
setInputVar
(name, dim, nodes)¶ Creates a Input (Control) variable.
Parameters: - name – name of the variable
- dim – dimension of the variable
-
setNNodes
(n_nodes)¶ set a desired number of nodes to the Variable Container.
Parameters: n_nodes – the desired number of nodes to be set
-
setParameter
(name, dim, nodes)¶ Creates a Parameter.
Parameters: - name – name of the variable
- dim – dimension of the variable
- nodes – nodes the parameter is defined on. If not specified, all the horizon nodes are considered
-
setSingleParameter
(name, dim)¶ Creates a Single Variable.
Parameters: - name – name of the variable
- dim – dimension of the variable
-
setSingleVar
(name, dim)¶ Creates a Single variable.
Parameters: - name – name of the variable
- dim – dimension of the variable
-
setStateVar
(name, dim, nodes)¶ Creates a State variable.
Parameters: - name – name of the variable
- dim – dimension of the variable
-
setVar
(name, dim, active_nodes=None)¶ Creates a generic variable.
Parameters: - name – name of the variable
- dim – dimension of the variable
- active_nodes – nodes the variable is defined on. If not specified, a Single Variable is generated
-