gym_anm.agents.mpc.MPCAgent
- class gym_anm.agents.mpc.MPCAgent(simulator, action_space, gamma, safety_margin=0.9, planning_steps=1)[source]
Bases:
object
A base class for an agent that solves a MPC DC Optimal Power Flow.
This agent accesses the full state of the distribution network at time \(t\) and then solves an N-stage optimization problem. The optimization problem solved is an instance of a Direct Current (DC) Optimal Power Flow problem.
The construction of the DC OPF problem relies on 3 assumptions:
transmission lines are lossless, i.e., \(r_{ij} = 0, \forall e_{ij} \in \mathcal E,\)
the difference between adjacent bus voltage angles is small, i.e., \(\angle V_i = \angle V_j, \forall e_{ij} \in \mathcal E\),
nodal voltage magnitude are close to unity, i.e., \(|V_{i}| = 1, \forall i \in \mathcal N\).
The construction of the N-stage optimization problem relies on two additional assumptions:
All sub-classes must implement the :py:func`forecast()` method to provide forecasts of demand and generation over the optimization horizon \([t+1,t+N]\).
All values are used in per-unit.
- __init__(simulator, action_space, gamma, safety_margin=0.9, planning_steps=1)[source]
- Parameters:
simulator (
gym_anm.simulator.simulator.Simulator
) – The electricity distribution network simulator.action_space (
gym.spaces.Box
) – The action space of the environment (used to clip actions).gamma (float) – The discount factor in [0, 1].
safety_margin (float, optional) – The safety margin constant \(\beta\) in [0, 1], used to further constraint the power flow on each transmission line, thus likely accounting for the error introduced in the DC approximation.
planning_steps (int, optional) – The number (N) of stages (time steps) taken into account in the optimization problem.
Methods
__init__
(simulator, action_space, gamma[, ...])- param simulator:
The electricity distribution network simulator.
act
(env)Select an action by solving the N-stage DC OPF.
forecast
(env)Forecast the demand and generation over the optimization horizon.
- act(env)[source]
Select an action by solving the N-stage DC OPF.
- Parameters:
env (py:class:gym_anm.ANMEnv) – The
gym-anm
environment.- Returns:
The action vector to apply in the environment.
- Return type:
numpy.ndarray
- forecast(env)[source]
Forecast the demand and generation over the optimization horizon.
This method must be implemented by all sub-classes of
MPCAgent
. It gets called inact()
and must return the predictions of future load demand, \(\tilde P_{l,k}^{(dev)}\), and maximum generation at non-slack generators, \(\tilde P_{g,k}^{(max)}\).- Parameters:
env (py:class:gym_anm.ANMEnv) – The
gym-anm
environment.- Returns:
P_load_forecast (array_like) – A (N_load, N) array of forecasted load power injections (<0), where N is the length of the optimization horizon. The rows should be ordered in increasing order of device ID.
P_gen_forecast (array_like) – A (N_gen-1, N) array of forecasted maximum generation from non-slack generators, where N is the length of the optimization horizon. The rows should be ordered in increasing order of device ID.