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: BaseController

Optimal 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_dict

Converts numpy array of actions to dictionary.

add_entity

Add a controllable entity to the controller.

add_system

When 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_bounds

Clips the control inputs to their bounds to avoid numerical errors.

compute_control_input

Main functionality of the controller: computes the control inputs which minimize the objective function of the controlled entities while satisfying their constraints.

detach

Remove controller from all controlled entities

empty_copy

Create a fresh copy of the controller without any history.

filter_history_for_time_period

Filters all element histories for a given time period

flatten_obs

Converts observation dictionary to a numpy array.

get_cost

Compute control cost for one time step

get_id

Get ID of controller.

get_input_space

Derives action space of the controller from the list of its controlled entities.

get_nodes

Get controlled nodes.

get_objective_fcn

Constructs the objective function for the optimal control problem.

get_top_level_nodes

Retrieve the controlled entities at the highest level in the tree.

initialize

Initial set-up of controller.

reset_history

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

get_objective_fcn() Callable[source]

Constructs the objective function for the optimal control problem.

Returns:

Callable – Pyomo expression of the objective function.

reset_history() None[source]

Delete history

Returns:

None