Network Model

Network of power devices.

class dem.network.Terminal

Bases: object

Device terminal.

power

Power consumed (positive value) or produced (negative value) at this terminal.

class dem.network.Net(terminals, name=None)

Bases: object

Connection point for device terminals.

A net defines the power balance constraint ensuring that power sums to zero across all connected terminals at each time point.

Parameters:
  • terminals (list of Terminal) – The terminals connected to this net
  • name (string) – (optional) Display name of net
price

Price associated with this net.

class dem.network.Device(terminals, name=None)

Bases: object

Base class for network device.

Subclasses are expected to override constraints and/or cost to define the device-specific cost function.

Parameters:
  • terminals (list of Terminal) – The terminals of the device
  • name (string) – (optional) Display name of device
cost

Device objective, to be overriden by subclasses.

Return type:cvxpy expression of size \(T imes K\)
constraints

Device constraints, to be overriden by subclasses.

Return type:list of cvxpy constraints
problem

The network optimization problem.

Return type:cvxpy.Problem
results

Network optimization results.

Return type:Results
init_problem(time_horizon=1, num_scenarios=1)

Initialize the network optimization problem.

Parameters:
  • time_horizon (int) – The time horizon \(T\) to optimize over.
  • num_scenarios (int) – The number of scenarios for robust MPC.
class dem.network.Group(devices, nets, terminals=[], name=None)

Bases: dem.network.Device

A single device composed of multiple devices and nets.

The Group device allows for creating new devices composed of existing base devices or other groups.

Parameters:
  • devices (list of Device) – Interal devices to be included.
  • nets (list of Net) – Internal nets to be included.
  • terminals (list of Terminal) – (optional) Terminals for new device.
  • name (string) – (optional) Display name of group device
class dem.network.Results(power=None, price=None)

Bases: object

Network optimization results.

summary()

Summary of results.

Return type:str
plot()

Plot results.

exception dem.network.OptimizationError

Bases: exceptions.Exception

Error due to infeasibility or numerical problems during optimziation.

dem.network.run_mpc(device, time_steps, predict, execute, **kwargs)

Execute model predictive control.

This method executes the model predictive control loop, roughly:

for t in time_steps:
  predict(t)
  device.problem.solve()
  execute(t)

It is the responsibility of the provided predict and execute functions to update the device models with the desired predictions and execute the actions as appropriate.

Parameters:
  • device (Device) – Device (or network of devices) to optimize
  • time_steps (sequence) – Time steps to optimize over
  • predict (single argument function) – Prediction step
  • execute (single argument function) – Execution step
Returns:

Model predictive control results

Return type:

Results

Raise:

OptimizationError