commonpower.control.controllers.OptimalController
- class OptimalController(name: str, solver: ~pyomo.opt.base.solvers.OptSolver = <pyomo.solvers.plugins.solvers.gurobi_direct.GurobiDirect object>, control_input_trajectory_length: int = 1, cost_fcn: ~commonpower.modeling.robust_cost.BaseRobustCost = <commonpower.modeling.robust_cost.NominalCost object>)[source]
Bases:
BaseControllerOptimal controller that solves a constrained optimization problem to find the control inputs which minimize the cost function of all its controlled entities while satisfying their constraints.
- Parameters:
name (str) – name of the controller
solver (OptSolver, optional) – solver for optimization problem
control_input_trajectory_length (int, optional) – number of time steps the controller computes control inputs for
cost_fcn (BaseRobustCost, optional) – Robust cost function. Defaults to NominalCost.
- Returns:
OptimalController
Methods
act_array_to_dictConverts numpy array of actions to dictionary.
add_entityAdd a controllable entity to the controller.
add_systemWhen adding a system to a controller, the system tree is searched recursively and all controllable entities that do not yet have a controller are added to 'nodes'.
clip_to_boundsClips the control inputs to their bounds to avoid numerical errors.
Main functionality of the controller: computes the control inputs which minimize the objective function of the controlled entities while satisfying their constraints.
detachRemove controller from all controlled entities
Create a fresh copy of the controller without any history.
filter_history_for_time_periodFilters all element histories for a given time period
flatten_obsConverts observation dictionary to a numpy array.
get_costCompute control cost for one time step
get_idGet ID of controller.
get_input_spaceDerives action space of the controller from the list of its controlled entities.
get_nodesGet controlled nodes.
Constructs the objective function for the optimal control problem.
get_top_level_nodesRetrieve the controlled entities at the highest level in the tree.
initializeInitial set-up of controller.
Delete history
Attributes
obs_mask- compute_control_input(obs: OrderedDict | None = None, input_callback: Callable | None = None) Tuple[OrderedDict, float][source]
Main functionality of the controller: computes the control inputs which minimize the objective function of the controlled entities while satisfying their constraints.
- Parameters:
obs (OrderedDict) – not needed her
input_callback (Callable) – not needed here
- Returns:
Tuple –
- tuple containing:
action (OrderedDict)
safety penalty (float) (not needed hear, only for RL controllers).
- empty_copy()[source]
Create a fresh copy of the controller without any history.
- Returns:
OptimalController – cloned controller