DynamicModelInterface
(class from pyomo.contrib.mpc.interfaces.model_interface
)
- class pyomo.contrib.mpc.interfaces.model_interface.DynamicModelInterface(model, time, context=NOTSET)[source]
Bases:
object
A helper class for working with dynamic models, e.g. those where many components are indexed by some ordered set referred to as “time.”
This class provides methods for interacting with time-indexed components, for instance, loading and extracting data or shifting values by some time offset. It also provides methods for constructing components useful for dynamic optimization.
- __init__(model, time, context=NOTSET)[source]
Construct with a model and a set. We will flatten the model with respect to this set and generate CUIDs with wildcards.
Methods
__init__
(model, time[, context])Construct with a model and a set.
copy_values_at_time
([source_time, target_time])Copy values of all time-indexed variables from source time point to target time points.
get_data_at_time
([time, include_expr])Gets data at a single time point or set of time points.
get_indexed_expressions
()get_indexed_variables
()get_penalty_from_target
(target_data[, time, ...])A method to get a quadratic penalty expression from a provided setpoint data structure
get_piecewise_constant_constraints
(...[, ...])A method to get an indexed constraint ensuring that inputs are piecewise constant.
get_scalar_expressions
()Get data corresponding to non-time-indexed variables.
get_scalar_variables
()load_data
(data[, time_points, tolerance, ...])Method to load data into the model.
Shift values in time indexed variables by a specified time offset.
Member Documentation
- copy_values_at_time(source_time=None, target_time=None)[source]
Copy values of all time-indexed variables from source time point to target time points.
- Parameters:
source_time (Float) – Time point from which to copy values.
target_time (Float or iterable) – Time point or points to which to copy values.
- get_data_at_time(time=None, include_expr=False)[source]
Gets data at a single time point or set of time points. Note that the returned type changes depending on whether a scalar or iterable is supplied.
- get_penalty_from_target(target_data, time=None, variables=None, weight_data=None, variable_set=None, tolerance=None, prefer_left=None)[source]
A method to get a quadratic penalty expression from a provided setpoint data structure
- Parameters:
target_data (ScalarData, TimeSeriesData, or IntervalData) – Holds target values for variables
time (Set (optional)) – Points at which to apply the tracking cost. Default will use the model’s time set.
variables (List of Pyomo VarData (optional)) – Subset of variables supplied in setpoint_data to use in the tracking cost. Default is to use all variables supplied.
weight_data (ScalarData (optional)) – Holds the weights to use in the tracking cost for each variable
variable_set (Set (optional)) – A set indexing the list of provided variables, if one already exists.
tolerance (Float (optional)) – Tolerance for checking inclusion in an interval. Only may be provided if IntervalData is provided for target_data. In this case the default is 0.0.
prefer_left (Bool (optional)) – Flag indicating whether the left end point of intervals should be preferred over the right end point. Only may be provided if IntervalData is provided for target_data. In this case the default is False.
- Returns:
Set indexing the list of variables to be penalized, and Expression indexed by this set and time. This Expression contains the weighted tracking cost for each variable at each point in time.
- Return type:
- get_piecewise_constant_constraints(variables, sample_points, use_next=True, tolerance=0.0)[source]
A method to get an indexed constraint ensuring that inputs are piecewise constant.
- Parameters:
variables (List of Pyomo Vars) – Variables to enforce piecewise constant
sample_points (List of floats) – Points marking the boundaries of intervals within which variables must be constant
use_next (Bool (optional)) – Whether to enforce constancy by setting each variable equal to itself at the next point in time (as opposed to at the previous point in time). Default is True.
tolerance (Float (optional)) – Absolute tolerance used to determine whether provided sample points are in the model’s time set.
- Returns:
First entry is a Set indexing the list of provided variables (with integers). Second entry is a constraint indexed by this set and time enforcing the piecewise constant condition via equality constraints.
- Return type:
Tuple
- get_scalar_variable_data()[source]
Get data corresponding to non-time-indexed variables.
- Returns:
Maps CUIDs of non-time-indexed variables to the value of these variables.
- Return type:
- load_data(data, time_points=None, tolerance=0.0, prefer_left=None, exclude_left_endpoint=None, exclude_right_endpoint=None)[source]
Method to load data into the model.
Loads data into indicated variables in the model, possibly at specified time points.
- Parameters:
data (ScalarData, TimeSeriesData, or mapping) – If
ScalarData
, loads values into indicated variables at all (or specified) time points. IfTimeSeriesData
, loads lists of values into time points. If mapping, checks whether each variable and value is indexed or iterable and correspondingly loads data into variables.time_points (Iterable (optional)) – Subset of time points into which data should be loaded. Default of None corresponds to loading into all time points.