The Unit Commitment Problem (UCP)¶
This tutorial includes everything you need to set up IBM Decision Optimization CPLEX Modeling for Python (DOcplex), build a Mathematical Programming model, and get its solution by solving the model on the cloud with IBM ILOG CPLEX Optimizer.
When you finish this tutorial, you’ll have a foundational knowledge of Prescriptive Analytics.
Table of contents:
- Describe the business problem
- How decision optimization can help
- Use decision optimization
Describe the business problem¶
- The Model estimates the lower cost of generating electricity within a given plan. Depending on the demand for electricity, we turn on or off units that generate power and which have operational properties and costs.
- The Unit Commitment Problem answers the question “Which power generators should I run at which times and at what level in order to satisfy the demand for electricity?”. This model helps users to find not only a feasible answer to the question, but one that also optimizes its solution to meet as many of the electricity company’s overall goals as possible.
How decision optimization can help¶
Prescriptive analytics (decision optimization) technology recommends actions that are based on desired outcomes. It takes into account specific scenarios, resources, and knowledge of past and current events. With this insight, your organization can make better decisions and have greater control of business outcomes.
Prescriptive analytics is the next step on the path to insight-based actions. It creates value through synergy with predictive analytics, which analyzes data to predict future outcomes.
- Prescriptive analytics takes that insight to the next level by suggesting the optimal way to handle that future situation. Organizations that can act fast in dynamic conditions and make superior decisions in uncertain environments gain a strong competitive advantage.
With prescriptive analytics, you can:
- Automate the complex decisions and trade-offs to better manage your limited resources.
- Take advantage of a future opportunity or mitigate a future risk.
- Proactively update recommendations based on changing events.
- Meet operational goals, increase customer loyalty, prevent threats and fraud, and optimize business processes.
Checking minimum requirements¶
This notebook uses some features of pandas that are available in version 0.17.1 or above.
Use decision optimization¶
Step 1: Import the library¶
Run the following code to the import the Decision Optimization CPLEX Modeling library. The DOcplex library contains the two modeling packages, Mathematical Programming (docplex.mp) and Constraint Programming (docplex.cp).
Step 2: Model the data¶
Load data from a pandas DataFrame¶
Data for the Unit Commitment Problem is provided as a pandas DataFrame. For a standalone notebook, we provide the raw data as Python collections, but real data could be loaded from an Excel sheet, also using pandas.
Update the configuration of notebook so that display matches browser window width.
Available energy technologies¶
The following df_energy DataFrame stores CO2 cost information, indexed by energy type.
The following df_units DataFrame stores common elements for units of a given technology.
Step 3: Prepare the data¶
The pandas merge operation is used to create a join between the df_units and df_energy DataFrames. Here, the join is performed based on the ‘energy’ column of df_units and index column of df_energy.
By default, merge performs an inner join. That is, the resulting DataFrame is based on the intersection of keys from both input DataFrames.
The demand is stored as a pandas Series indexed from 1 to the number of periods.
nb periods = 192
<matplotlib.axes._subplots.AxesSubplot at 0x23fbad3d588>
Step 4: Set up the prescriptive model¶
* system is: Windows 64bit * Python version 3.7.3, located at: c:\local\python373\python.exe * docplex is present, version is (2, 11, 0) * pandas is present, version is 0.25.1
Create the DOcplex model¶
The model contains all the business constraints and defines the objective.
Define the decision variables¶
Decision variables are:
- The variable in_use[u,t] is 1 if and only if unit u is working at period t.
- The variable turn_on[u,t] is 1 if and only if unit u is in production at period t.
- The variable turn_off[u,t] is 1 if unit u is switched off at period t.
- The variable production[u,t] is a continuous variables representing the production of energy for unit u at period t.
Model: ucp - number of variables: 7680 - binary=3840, integer=0, continuous=3840 - number of constraints: 0 - linear=0 - parameters: defaults - problem type is: MILP
Express the business constraints¶
The solution must take into account the initial state. The initial state of use of the unit is determined by its initial production level.
Model: ucp - number of variables: 7680 - binary=3840, integer=0, continuous=3840 - number of constraints: 3860 - linear=3860 - parameters: defaults - problem type is: MILP
Ramp-up / ramp-down constraint¶
Variations of the production level over time in a unit is constrained by a ramp-up / ramp-down process.
We use the pandas groupby operation to collect all decision variables for each unit in separate series. Then, we iterate over units to post constraints enforcing the ramp-up / ramp-down process by setting upper bounds on the variation of the production level for consecutive periods.
Model: ucp - number of variables: 7680 - binary=3840, integer=0, continuous=3840 - number of constraints: 7700 - linear=7700 - parameters: defaults - problem type is: MILP
Turn on / turn off¶
The following constraints determine when a unit is turned on or off.
We use the same pandas groupby operation as in the previous constraint to iterate over the sequence of decision variables for each unit.
Model: ucp - number of variables: 7680 - binary=3840, integer=0, continuous=3840 - number of constraints: 11520 - linear=11520 - parameters: defaults - problem type is: MILP
Minimum uptime and downtime¶
When a unit is turned on, it cannot be turned off before a minimum uptime. Conversely, when a unit is turned off, it cannot be turned on again before a minimum downtime.
Again, let’s use the same pandas groupby operation to implement this constraint for each unit.
Total production level must be equal or higher than demand on any period.
This time, the pandas operation groupby is performed on “periods” since we have to iterate over the list of all units for each period.
Express the objective¶
Operating the different units incur different costs: fixed cost, variable cost, startup cost, co2 cost.
In a first step, we define the objective as a non-weighted sum of all these costs.
The following pandas join operation groups all the data to calculate the objective in a single DataFrame.
Solve with Decision Optimization¶
If you’re using a Community Edition of CPLEX runtimes, depending on the size of the problem, the solve stage may fail and will need a paying subscription or product installation.
Model: ucp - number of variables: 7680 - binary=3840, integer=0, continuous=3840 - number of constraints: 15455 - linear=15455 - parameters: defaults - problem type is: MILP
* model ucp solved with objective = 14213082.064 * KPI: Total Fixed Cost = 161025.131 * KPI: Total Variable Cost = 8865900.433 * KPI: Total Startup Cost = 2832.000 * KPI: Total Economic Cost = 9029757.564 * KPI: Total CO2 Cost = 5183324.500 * KPI: Total #used = 1335.000 * KPI: Total #starts = 3.000
Step 5: Investigate the solution and then run an example analysis¶
Now let’s store the results in a new pandas DataFrame.
For convenience, the different figures are organized into pivot tables with periods as row index and units as columns. The pandas unstack operation does this for us.
From these raw DataFrame results, we can compute derived results. For example, for a given unit and period, the reserve r(u,t) is defined as the unit’s maximum generation minus the current production.
Let’s plot the evolution of the reserves for the “coal2” unit:
<matplotlib.axes._subplots.AxesSubplot at 0x23fd903bf60>
Now we want to sum all unit reserves to compute the global spinning reserve. We need to sum all columns of the DataFrame to get an aggregated time series. We use the pandas sum method with axis=1 (for rows).
<matplotlib.axes._subplots.AxesSubplot at 0x23fda312710>
Number of plants online by period¶
The total number of plants online at each period t is the sum of in_use variables for all units at this period. Again, we use the pandas sum with axis=1 (for rows) to sum over all units.
<matplotlib.axes._subplots.AxesSubplot at 0x23fda37f9b0>
Costs by period¶
<matplotlib.axes._subplots.AxesSubplot at 0x23fda3c7e80>
Cost breakdown by unit and by energy¶
Text(0.5, 1.0, 'total cost by energy type')
Arbitration between CO2 cost and economic cost¶
Economic cost and CO2 cost usually push in opposite directions. In the above discussion, we have minimized the raw sum of economic cost and CO2 cost, without weights. But how good could we be on CO2, regardless of economic constraints? To know this, let’s solve again with CO2 cost as the only objective.
* current CO2 cost is: 5183324.5 * current $$$ cost is: 9029757.56390015
* absolute minimum for CO2 cost is 3399032.0 * at this point $$$ cost is 12434227.620000225
As expected, we get a significantly lower CO2 cost when minimized alone, at the price of a higher economic cost.
We could do a similar analysis for economic cost to estimate the absolute minimum of the economic cost, regardless of CO2 cost.
* absolute minimum for $$$ cost is 8887433.859000005 * at this point CO2 cost is 5375417.0
Again, the absolute minimum for economic cost is lower than the figure we obtained in the original model where we minimized the sum of economic and CO2 costs, but here we significantly increase the CO2.
But what happens in between these two extreme points?
To investigate, we will divide the interval of CO2 cost values in smaller intervals, add an upper limit on CO2, and minimize economic cost with this constraint. This will give us a Pareto optimal point with at most this CO2 value.
To avoid adding many constraints, we add only one constraint with an extra variable, and we change only the upper bound of this CO2 limit variable between successive solves.
Then we iterate (with a fixed number of iterations) and collect the cost values.
iteration #0 co2_ub=3399032.0 iteration #1 co2_ub=3438559.7 iteration #2 co2_ub=3478087.4 iteration #3 co2_ub=3517615.1 iteration #4 co2_ub=3557142.8 iteration #5 co2_ub=3596670.5 iteration #6 co2_ub=3636198.2 iteration #7 co2_ub=3675725.9 iteration #8 co2_ub=3715253.6 iteration #9 co2_ub=3754781.3 iteration #10 co2_ub=3794309.0 iteration #11 co2_ub=3833836.7 iteration #12 co2_ub=3873364.4 iteration #13 co2_ub=3912892.1 iteration #14 co2_ub=3952419.8 iteration #15 co2_ub=3991947.5 iteration #16 co2_ub=4031475.2 iteration #17 co2_ub=4071002.9 iteration #18 co2_ub=4110530.6 iteration #19 co2_ub=4150058.3 iteration #20 co2_ub=4189586.0 iteration #21 co2_ub=4229113.7 iteration #22 co2_ub=4268641.4 iteration #23 co2_ub=4308169.1 iteration #24 co2_ub=4347696.8 iteration #25 co2_ub=4387224.5 iteration #26 co2_ub=4426752.2 iteration #27 co2_ub=4466279.9 iteration #28 co2_ub=4505807.6 iteration #29 co2_ub=4545335.3 iteration #30 co2_ub=4584863.0 iteration #31 co2_ub=4624390.7 iteration #32 co2_ub=4663918.4 iteration #33 co2_ub=4703446.1 iteration #34 co2_ub=4742973.8 iteration #35 co2_ub=4782501.5 iteration #36 co2_ub=4822029.2 iteration #37 co2_ub=4861556.9 iteration #38 co2_ub=4901084.6 iteration #39 co2_ub=4940612.3 iteration #40 co2_ub=4980140.0 iteration #41 co2_ub=5019667.7 iteration #42 co2_ub=5059195.4 iteration #43 co2_ub=5098723.1 iteration #44 co2_ub=5138250.8 iteration #45 co2_ub=5177778.5 iteration #46 co2_ub=5217306.2 iteration #47 co2_ub=5256833.9 iteration #48 co2_ub=5296361.6 iteration #49 co2_ub=5335889.3 iteration #50 co2_ub=5375417.0
This figure demonstrates that the result obtained in the initial model clearly favored economic cost over CO2 cost: CO2 cost is well above 95% of its maximum value.
You learned how to set up and use IBM Decision Optimization CPLEX Modeling for Python to formulate a Mathematical Programming model and solve it with IBM Decision Optimization on Cloud.
- CPLEX Modeling for Python documentation
- Decision Optimization on Cloud
- Need help with DOcplex or to report a bug? Please go here.
- Contact us at email@example.com.
Copyright � 2017-2019 IBM. IPLA licensed Sample Materials.