Modeling Components
- pyomo.contrib.mpc.modeling.constraints.get_piecewise_constant_constraints(inputs, time, sample_points, use_next=True)[source]
Returns an IndexedConstraint that constrains the provided variables to be constant between the provided sample points
- Parameters:
inputs (list of variables) – Time-indexed variables that will be constrained piecewise constant
time (Set) – Set of points at which provided variables will be constrained
sample_points (List of floats) – Points at which “constant constraints” will be omitted; these are points at which the provided variables may vary.
use_next (Bool (default True)) – Whether the next time point will be used in the constant constraint at each point in time. Otherwise, the previous time point is used.
- Returns:
A RangeSet indexing the list of variables provided and a Constraint indexed by the product of this RangeSet and time.
- Return type:
Set, IndexedConstraint
- pyomo.contrib.mpc.modeling.cost_expressions.get_penalty_from_constant_target(variables, time, setpoint_data, weight_data=None, variable_set=None)[source]
This function returns a tracking cost IndexedExpression for the given time-indexed variables and associated setpoint data.
- Parameters:
variables (list) – List of time-indexed variables to include in the tracking cost expression
time (iterable) – Set of variable indices for which a cost expression will be created
setpoint_data (ScalarData, dict, or ComponentMap) – Maps variable names to setpoint values
weight_data (ScalarData, dict, or ComponentMap) – Optional. Maps variable names to tracking cost weights. If not provided, weights of one are used.
variable_set (Set) – Optional. A set of indices into the provided list of variables by which the cost expression will be indexed.
- Returns:
RangeSet that indexes the list of variables provided and an Expression indexed by the RangeSet and time containing the cost term for each variable at each point in time.
- Return type:
Set, Expression
- pyomo.contrib.mpc.modeling.cost_expressions.get_penalty_from_piecewise_constant_target(variables, time, setpoint_data, weight_data=None, variable_set=None, tolerance=0.0, prefer_left=True)[source]
Returns an IndexedExpression penalizing deviation between the specified variables and piecewise constant target data.
- Parameters:
variables (List of Pyomo variables) – Variables that participate in the cost expressions.
time (Iterable) – Index used for the cost expression
setpoint_data (IntervalData) – Holds the piecewise constant values that will be used as setpoints
weight_data (ScalarData (optional)) – Weights for variables. Default is all ones.
tolerance (Float (optional)) – Tolerance used for determining whether a time point is within an interval. Default is zero.
prefer_left (Bool (optional)) – If a time point lies at the boundary of two intervals, whether the value on the left will be chosen. Default is True.
- Returns:
Pyomo Expression, indexed by time, for the total weighted tracking cost with respect to the provided setpoint.
- Return type:
Set, Expression
- pyomo.contrib.mpc.modeling.cost_expressions.get_penalty_from_target(variables, time, setpoint_data, weight_data=None, variable_set=None, tolerance=None, prefer_left=None)[source]
A function to get a penalty expression for specified variables from a target that is constant, piecewise constant, or time-varying.
This function accepts ScalarData, IntervalData, or TimeSeriesData objects, or compatible mappings/tuples as the target, and builds the appropriate penalty expression for each. Mappings are converted to ScalarData, and tuples (of data dict, time list) are unpacked and converted to IntervalData or TimeSeriesData depending on the contents of the time list.
- Parameters:
variables (List) – List of time-indexed variables to be penalized
time (Set) – Set of time points at which to construct penalty expressions. Also indexes the returned Expression.
setpoint_data (ScalarData, TimeSeriesData, or IntervalData) – Data structure representing the possibly time-varying or piecewise constant setpoint
weight_data (ScalarData (optional)) – Data structure holding the weights to be applied to each variable
variable_set (Set (optional)) – Set indexing the provided variables, if one already exists. Also indexes the returned Expression.
tolerance (Float (optional)) – Tolerance for checking inclusion within an interval. Only may be provided if IntervalData is provided as the setpoint.
prefer_left (Bool (optional)) – Flag indicating whether left endpoints of intervals should take precedence over right endpoints. Default is False. Only may be provided if IntervalData is provided as the setpoint.
- Returns:
Set indexing the list of provided variables and an Expression, indexed by this set and the provided time set, containing the penalties for each variable at each point in time.
- Return type:
Set, Expression
- pyomo.contrib.mpc.modeling.cost_expressions.get_penalty_from_time_varying_target(variables, time, setpoint_data, weight_data=None, variable_set=None)[source]
Constructs a penalty expression for the specified variables and specified time-varying target data.
- Parameters:
variables (List of Pyomo variables) – Variables that participate in the cost expressions.
time (Iterable) – Index used for the cost expression
setpoint_data (TimeSeriesData) – Holds the trajectory values that will be used as a setpoint
weight_data (ScalarData (optional)) – Weights for variables. Default is all ones.
variable_set (Set (optional)) – Set indexing the list of provided variables, if one exists already.
- Returns:
Set indexing the list of provided variables and Expression, indexed by the variable set and time, for the total weighted penalty with respect to the provided setpoint.
- Return type:
Set, Expression
- pyomo.contrib.mpc.modeling.terminal.get_penalty_at_time(variables, t, target_data, weight_data=None, time_set=None, variable_set=None)[source]
Returns an Expression penalizing the deviation of the specified variables at the specified point in time from the specified target
- Parameters:
variables (List) – List of time-indexed variables that will be penalized
t (Float) – Time point at which to apply the penalty
target_data (ScalarData) – ScalarData object containing the target for (at least) the variables to be penalized
weight_data (ScalarData (optional)) – ScalarData object containing the penalty weights for (at least) the variables to be penalized
time_set (Set (optional)) – Time set that indexes the provided variables. This is only used if target or weight data are provided as a ComponentMap with VarData as keys. In this case the Set is necessary to recover the CUIDs used internally as keys
variable_set (Set (optional)) – Set indexing the list of variables provided, if such a set already exists
- Returns:
Set indexing the list of variables provided and an Expression, indexed by this set, containing the weighted penalty expressions
- Return type:
Set, Expression
- pyomo.contrib.mpc.modeling.terminal.get_terminal_penalty(variables, time_set, target_data, weight_data=None, variable_set=None)[source]
Returns an Expression penalizing the deviation of the specified variables at the final point in time from the specified target
- Parameters:
variables (List) – List of time-indexed variables that will be penalized
time_set (Set) – Time set that indexes the provided variables. Penalties are applied at the last point in this set.
target_data (ScalarData) – ScalarData object containing the target for (at least) the variables to be penalized
weight_data (ScalarData (optional)) – ScalarData object containing the penalty weights for (at least) the variables to be penalized
variable_set (Set (optional)) – Set indexing the list of variables provided, if such a set already exists
- Returns:
Set indexing the list of variables provided and an Expression, indexed by this set, containing the weighted penalty expressions
- Return type:
Set, Expression