Extra material: Energy dispatch problem
Preamble: Install Pyomo and a solver
The following cell sets and verifies a global SOLVER for the notebook. If run on Google Colab, the cell installs Pyomo and the HiGHS solver, while, if run elsewhere, it assumes Pyomo and HiGHS have been previously installed. It then sets to use HiGHS as solver via the appsi module and a test is performed to verify that it is available. The solver interface is stored in a global object SOLVER for later use.
Problem description
To meet the energy demand, power plants run day and night across the country to produce electricity from a variety of sources such as fossil fuels and renewable energy. On the short-time scale, the best operating levels for electric power plants are derived every 15 minutes by solving the so-called Optimal Power Flow (OPF) model. The OPF model is an optimization problem with the objective of minimizing the total energy dispatching cost, while ensuring that the generation meets the total energy demand and taking into account operational and physical constraints.
Background: Power networks and power flow physics
We model the nation-wide transmission power network as a directed graph , where represents the set of nodes (e.g., cities, industrial districts, power plants) and denotes the set of directed edges (e.g., physical transmission lines).
Each node has a power injection and demand . The set of nodes are separated into generator and load nodes. The set of generators corresponds to the nodes for which and . Each generator has a minimum and maximum production capacity. The set of load nodes corresponds to the nodes for which and . The load nodes thus correspond to the places where electricity is being consumed, e.g., cities and industrial districts. We say that supply and demand is matched if . Since we cannot store electricity in large volumes, supply must meet demand at all times, hence adjusting to it every 15 minutes by solving the OPF.
Each edge carries a power flow and has a capacity , i.e., the maximum power flow that it may carry. Note that our choice to model a directed graph is to make the modeling of the network easier. In particular, a directed edge may carry a 'negative' flow , which implies that there is flow going from to where . The capacity does not depend on the direction of the flow, implying that the flow capacity constraints are given by .
One crucial difference of power flow problems compared to typical network flow problems is that the power flows cannot be controlled directly. Instead, as you might recall from high-school physics, the power flows are determined by the laws of electricity, which we will now present as the power flow equations. Ignore for a moment the flow capacity constraints. Let denote the phase angle of node . For each edge , let denote the line susceptance. Assuming that supply and demand is matched, i.e., , the power flows and phase angles are obtained by solving the following linear system of equations:
The first set of constraints ensures flow conservation and the second set of constrations captures the flow dependency on susceptances and angle differences. The DC power flow equations admit a unique power flow solution given matched power injections and demand .
For a given matched supply and demand vector and , we can compute the power flows on the network by solving the linear equations as described above. There are exactly and equations for the variables and variables, meaning that this system of equations admit a solution.
Optimal Power Flow problem
We assumed above that the power injections were given. However, in practice, the power injections need to be determined for each generator in the power network, where some types of generators may be cheaper than others. Moreover, we need to take into account operational constraints, such as the maximum flow and generator limits.
On the short-time scale, the power injections are calculated for each generator by solving the so-called Optimal Power Flow (OPF) problem. The goal of the OPF problem is to determine a solution with minimal costs such that:
Supply meets demand
Line capacity constraints are met
Generator capacity constraints are met
Let be the cost associated with the production of a unit energy by generator . Then, the OPF problem can be formulated as
For simplicity, you may assume that all load nodes do not produce energy, i.e., for all . You may therefore model as decision variables for all nodes (both generator and load nodes). Similarly, you may assume that all generator nodes have no demand, i.e., for all .
To summarize, the decision variables in the OPF problem are:
power injections
phase angles
power flows
All the other quantities are instance-dependent parameters. Each instance captures the network in a different moment in time, thus with different energy demand at each node and different realizations for the power produced by renewable energy sources.
Data
You will solve the OPF problem on the IEEE-118 power network, which is a standard test network consisting of 118 nodes and 179 edges. In the following, we will load the data into the notebook and provide a description of the data. We will first describe the data which are initially provided as pandas.DataFrames. We will then provide a new network data structure to easily access the data for the implementation of the optimization model.
Setup code and data import
Network data
The IEEE-118 network has 18 generators, of which:
2 hydro plants (cyan)
4 coal plants (dark gray)
4 solarfarms (yellow)
2 windmills (white)
6 gas plants (green)
Moreover, the network has 100 load nodes (gray). Each node has the following parameters:
node_idd: demandp_min: minimum production capacityp_max: maximum production capacityc_var: variable production costsis_generator: boolean value to indicate whether the node is a generator or notenergy_type: the type of energy used for electricity production
All generator nodes can filtered by the is_generator parameter. All generators have a zero demand . For the renewable energy sources (i.e., hydro, solar and wind) there are no variable costs c_var. For solar and wind, the production is fixed, i.e., p_min = p_max, meaning that all available solar and wind energy must be produced.
For the load nodes, the only important parameter is the demand . All other parameters are either zero, False, or NaN.
Edges
The IEEE-118 network has 179 edges. Each edge has the following parameters:
edge_id: the edge indicesb: the line susceptance, andf_max: the maximum edge capacity.
Network data structure
When implementing optimization problems, it is often not the easiest way to access data directly through pandas.DataFrames. We have therefore provided a new type of data structure that will help to more easily implement an optimization problem. This data structure is also found in Exercise 5 & 6 from Computer Lab 1, which is as follows:
In other words, each network consists of a dictionary, that contains a dictionary for nodes and edges, which again holds a dictionary for each node and edge. It might a be little bit confusing at first, but this data structure allows to easily access the parameters that you need for a specific constraint. For instance,
gives the demand of node 1. To filter on generator nodes, you can use the following:
Instances
Since the OPF problem is solved every 15 minutes in practice, you will be given 24 * 4 = 96 network instances that need to be solved, hence solving an entire day's worth of OPF problems. The first instance thus corresponds to the power generation within time window [00:00, 00:15], the second instance corresponds to [00:15, 00:30], and so on. The data takes into account a realistic demand and (renewable energy) generation pattern. We assume that the decisions in each time window are independent of the previous and subsequent time windows, so every 15 minutes a new OPF instance is solved independently.
The network instances are stored in the variable I as a list and can be accessed using indexing, i.e., I[0] gives the first network instance and I[95] gives the 96th network instance.
Solving the OPF problem
Observe that the stated OPF problem contains absolute decision values. We first rewrite the OPF problem into a linear optimization problem.
We then implement the model using pyomo and solve it for all instances I[0] to I[95], reporting the average objective value across all the 96 instances.
Strict fossil fuel policy pt.1
Gas and coal plants emit CO2, while renewable energy sources are carbon neutral. For this reason, the Dutch government has decided to constrain the number of active fossil-fuel-based power plants for the generation of electricity. More specifically, a maximum of 2 gas plants and 1 coal plant may be active during a single OPF instance. Any plant that is set inactive for a specific instance cannot produce any electricity.
We first write down the new model. To this end, we introduce new decision variables , , to the model, which indicate whether a generator is active or inactive.
We then implement the new model using pyomo and solve it for all instances I[0] to I[95], reporting the average objective value across the instances.
Strict fossil fuel policy pt.2
The restriction on the number of gas and coal plants may pose a threat to the availability of electricity production when renewable energy sources fail to deliver. For this reason, the grid operators have decided to slightly change the constraint that was introduced for OPF2. If the total production of energy from renewable energy sources (i.e., solar, wind and hydro) is above 1000, then the number of gas and coal plants is restricted to 2 and 1, respectively. Otherwise, the restriction on the number of gas and coal plants is lifted. These constraints can be modeled as either-or constraints.
We first write down the new model, using big- constraints to model the either-or constraint.
We now implement the new model using pyomo and solve it for all instances I[0] to I[95], reporting the average objective value across the instances.
Comparing the three models
For all three implemented models, we plot the objective values for all instances and explain the differences between the objective values in view of the different feasible regions.
The goal of the OPF problem is to minimize the total costs of dispatching energy. OPF1 is the original OPF formulation, whereas OPF2 and OPF3 are restricted versions of OPF1. This means that the feasible region of OPF1 is at least as large as OPF2 and OPF3, where we may assume that for all the generators .
If we let denote the feasible region of OPF1, OPF2 and OPF3, then we observe that which explains that the optimal objective value of OPF1 always remains below the optimal objectives values of OPF2 and OPF3.
The most important observation to make is that based on the problem descriptions, we would expect OPF2 to take on the objective values of OPF1 or OPF3, depending on which of the either-or-constraints are activated.
OPF3 uses expensive generators, and possibly not all the renewable energy
OPF2 does only uses 1000 renewable energy power, because then it may keep using all the gas and coal generators.
OPF1 uses all renewable energy at all times, because it has the flexibility to use all generators in order to mitigate operational restrictions due to line flows.