{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Disclaimer\n", "This notebook is only working under the versions:\n", "\n", "- JuMP 0.19 (unreleased, but currently in master)\n", "\n", "- MathOptInterface 0.4.1\n", "\n", "- GLPK 0.6.0" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Description**: This notebook demonstrates how to formulate basic power systems engineering models in JuMP using a 3 bus example. We will consider basic \"economic dispatch\" and \"unit commitment\" models without taking into account transmission constraints.\n", "\n", "This notebook was developed for the [Grid Science Winter School](http://www.cvent.com/events/grid-science-winter-school-conference/event-summary-229c17f488194f2ebb5b206820974c71.aspx) held in Santa Fe, NM in January 2015.\n", "\n", "Note that the notebook contains many interactive features which do not display correctly on read-only links. For the full experience, run this notebook locally or on [JuliaBox](https://juliabox.org/).\n", "\n", "**Authors**: Yury Dvorkin and Miles Lubin\n", "\n", "**License**: \"Creative
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Illustrative example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following notes for the sake of simplicity, we are going to use a three bus example mirroring the interface between Western and Eastern Texas. This example is taken from R. Baldick, \"[Wind and Energy Markets: A Case Study of Texas](http://dx.doi.org/10.1109/JSYST.2011.2162798),\" IEEE Systems Journal, vol. 6, pp. 27-34, 2012. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For this example, we set the following characteristics of generators, transmission lines, wind farms and demands:\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Generator 1Generator 2
$g_{min}$, MW0300
$g_{max}$, MW10001000
$c^g$, \\$/MWh50100
$c^{g0}$, \\$/MWh10000
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Line 1Line 2
$f^{max}$, MW1001000
x, p.u.0.0010.001
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Wind farm 1Wind farm 2
$w^{f}$, MW15050
$c^{w}$, \\$/MWh5050
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
Bus 1Bus 2Bus 3
$d$, MW0015000
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Economic dispatch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Economic dispatch (ED) is an optimization problem that minimizes the cost of supplying energy demand subject to operational constraints on power system assets. In its simplest modification, ED is an LP problem solved for an aggregated load and wind forecast and for a single infinitesimal moment. Mathematically, the ED problem can be written as follows:\n", "$$\n", "\\min \\sum_{i \\in I} c^g_{i} \\cdot g_{i} + c^w \\cdot w,\n", "$$\n", "where $c_{i}$ and $g_{i}$ are the incremental cost ($\\$/MWh$) and power output ($MW$) of the $i^{th}$ generator, respectively, and $c^w$ and $w$ are the incremental cost ($\\$/MWh$) and wind power injection ($MW$), respectively.\n", "\n", "s.t.\n", "\n", "
  • Minimum ($g^{\\min}$) and maximum ($g^{\\max}$) limits on power outputs of generators:
  • \n", "$$\n", "g^{\\min}_{i} \\leq g_{i} \\leq g^{\\max}_{i}.\n", "$$\n", "
  • Constraint on the wind power injection:
  • \n", "$$\n", "0 \\leq w \\leq w^f, \n", "$$\n", "where $w$ and $w^f$ are the wind power injection and wind power forecast, respectively.\n", "\n", "
  • Power balance constraint:
  • \n", "$$\n", "\\sum_{i \\in I} g_{i} + w = d^f, \n", "$$\n", "where $d^f$ is the demand forecast.\n", "\n", "Further reading on ED models can be found in A. J. Wood, B. F. Wollenberg, and G. B. SheblĂ©, \"Power Generation, Operation and Control\", Wiley, 2013." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## JuMP Implementation of Economic Dispatch " ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#push!(Base.LOAD_PATH,\"D:\\\\MOI\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
    \n", " \n", " \n", "
    " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Define the packages \n", "using JuMP # used for mathematical programming\n", "#using MathOptInterfaceXpress\n", "using GLPK\n", "using MathOptInterface\n", "const MOI = MathOptInterface\n", "using Interact # used for enabling the slider\n", "#using Gadfly # used for plotting " ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# Define some input data about the test system\n", "# Maximum power output of generators\n", "const g_max = [1000,1000];\n", "# Minimum power output of generators\n", "const g_min = [0,300];\n", "# Incremental cost of generators \n", "const c_g = [50,100];\n", "# Fixed cost of generators\n", "const c_g0 = [1000,0]\n", "# Incremental cost of wind generators\n", "const c_w = 50;\n", "# Total demand\n", "const d = 1500;\n", "# Wind forecast\n", "const w_f = 200;" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Dispatch of Generators: [1000.0, 300.0] MW\n", "Dispatch of Wind: 200.0 MW\n", "Wind spillage: 0.0 MW\n", "\n", "\n", "Total cost: 90000.0$\n" ] } ], "source": [ "# In this cell we create function solve_ed, which solves the economic dispatch problem for a given set of input parameters.\n", "function solve_ed(g_max, g_min, c_g, c_w, d, w_f)\n", " #Define the economic dispatch (ED) model\n", " ed=Model(optimizer = GLPK.GLPKOptimizerLP()) \n", " \n", " # Define decision variables \n", " @variable(ed, 0 <= g[i=1:2] <= g_max[i]) # power output of generators\n", " @variable(ed, 0 <= w <= w_f ) # wind power injection\n", "\n", " # Define the objective function\n", " @objective(ed,Min,sum(c_g[i] * g[i] for i in 1:2)+ c_w * w)\n", "\n", " # Define the constraint on the maximum and minimum power output of each generator\n", " for i in 1:2\n", " @constraint(ed, g[i] <= g_max[i]) #maximum\n", " @constraint(ed, g[i] >= g_min[i]) #minimum\n", " end\n", "\n", " # Define the constraint on the wind power injection\n", " @constraint(ed, w <= w_f)\n", "\n", " # Define the power balance constraint\n", " @constraint(ed, sum(g[i] for i in 1:2) + w == d)\n", "\n", " # Solve statement\n", " JuMP.optimize(ed)\n", " \n", " # return the optimal value of the objective function and its minimizers\n", " return JuMP.resultvalue.(g), JuMP.resultvalue(w), w_f-JuMP.resultvalue(w), JuMP.objectivevalue(ed)\n", "end\n", "\n", "# Solve the economic dispatch problem\n", "(g_opt,w_opt,ws_opt,obj)=solve_ed(g_max, g_min, c_g, c_w, d, w_f);\n", "\n", "println(\"\\n\")\n", "println(\"Dispatch of Generators: \", g_opt[i=1:2], \" MW\")\n", "println(\"Dispatch of Wind: \", w_opt, \" MW\")\n", "println(\"Wind spillage: \", w_f-w_opt, \" MW\") \n", "println(\"\\n\")\n", "println(\"Total cost: \", obj, \"\\$\") " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Economic dispatch with adjustable incremental costs" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following exercise we adjust the incremental cost of generator G1 and observe its impact on the total cost by using the manipulator" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 65000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 70000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 75000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 80000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 85000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 90000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 95000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 100000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 105000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 110000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 115000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 120000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 125000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 130000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 135000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 140000.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 141500.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 143000.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 144500.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 146000.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 147500.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 149000.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 150500.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 152000.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 153500.0\n", "Dispatch of Generators, MW: [300.0, 1000.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 155000.0\n" ] } ], "source": [ "# This cell uses the package Interact defined above. \n", "# In this cell we create a manipulator that solves the economic dispatch problem for different values of c_g1_scale.\n", "\n", "#@manipulate \n", "for c_g1_scale = 0.5:0.1:3.0\n", " c_g_scale = [c_g[1]*c_g1_scale, c_g[2]] # update the incremental cost of the first generator at every iteration\n", " g_opt,w_opt,ws_opt,obj = solve_ed(g_max, g_min, c_g_scale, c_w, d, w_f) # solve the ed problem with the updated incremental cost\n", " \n", " #HTML(\"Dispatch of Generators, MW: $(g_opt[:])
    \"*\n", " #\"Dispatch of Wind, MW: $w_opt
    \"*\n", " #\"Spillage of Wind, MW: $ws_opt
    \"*\n", " #\"Total cost, \\$: $obj\")\n", " \n", " println(\"Dispatch of Generators, MW: $(g_opt[:])\\n\"*\n", " \"Dispatch of Wind, MW: $w_opt\\n\"*\n", " \"Spillage of Wind, MW: $ws_opt\\n\"*\n", " \"Total cost, \\$: $obj\")\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Impact of the wind generation cost " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following exercise we introduce a new manipulator to vary the cost of wind generation and observe its impact the total cost, dispatch of generators G1 and G2, utilization of available wind under different values of the incremental cost of generator G1." ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "@manipulate for c_w_scale = 1:0.1:3.5\n", " # Define the vectors of outputs\n", " obj_out = Float64[] \n", " w_out = Float64[]\n", " g1_out = Float64[]\n", " g2_out = Float64[]\n", " \n", " @time for c_g1_scale = 0.5:0.01:3.0\n", " c_g_scale = [c_g[1]*c_g1_scale, c_g[2]] # update the incremental cost of the first generator at every iteration\n", " g_opt,w_opt,ws_opt,obj = solve_ed(g_max, g_min, c_g_scale, c_w_scale*c_w, d, w_f) # solve the ed problem with the updated incremental cost\n", " # Add the solution of the economic dispatch problem to the respective vectors\n", " push!(obj_out,obj)\n", " push!(w_out,w_opt)\n", " push!(g1_out,g_opt[1])\n", " push!(g2_out,g_opt[2])\n", " end\n", " \n", " # Plot the outputs\n", " # Define the size of the plots\n", " set_default_plot_size(16cm, 30cm)\n", " \n", " vstack(\n", " # Plot the total cost\n", " plot(x=0.5:0.01:3.0,y=obj_out, Geom.line,\n", " Guide.XLabel(\"c_g1_scale\"), Guide.YLabel(\"Total cost, \\$\"),\n", " Scale.y_continuous(minvalue=50000, maxvalue=200000)),\n", " # Plot the power output of Generator 1\n", " plot(x=0.5:0.01:3.0,y=g1_out, Geom.line,\n", " Guide.XLabel(\"c_g1_scale\"), Guide.YLabel(\"Dispatch of G1, MW\"),\n", " Scale.y_continuous(minvalue=0, maxvalue=1100)),\n", " # Plot the power output of Generator 2 \n", " plot(x=0.5:0.01:3.0,y=g2_out, Geom.line,\n", " Guide.XLabel(\"c_g1_scale\"), Guide.YLabel(\"Dispatch of G2, MW\"),\n", " Scale.y_continuous(minvalue=0, maxvalue=1600)),\n", " # Plot the wind power output\n", " plot(x=0.5:0.01:3.0,y=w_out, Geom.line,\n", " Guide.XLabel(\"c_g1_scale\"), Guide.YLabel(\"Dispatch of Wind, MW\"),\n", " Scale.y_continuous(minvalue=0, maxvalue=250))\n", " )\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For further reading on the impact of wind generation costs on dispatch decisions, we refer interested readers to J. M. Morales, A. J. Conejo, and J. Perez-Ruiz, \"Economic Valuation of Reserves in Power Systems With High Penetration of Wind Power,\" IEEE Transactions on Power Systems, vol. 24, pp. 900-910, 2009." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Modifying the JuMP model in place" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that in the previous exercise we entirely rebuilt the optimization model at every iteration of the internal loop, which incurs an additional computational burden. This burden can be alleviated if instead of re-building the entire model, we modify a specific constraint(s) or the objective function, as it shown in the example below.\n", "\n", "Compare the computing time in case of the above and below models. " ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "elapsed time: 0.017035575 seconds\n" ] } ], "source": [ "function solve_ed_inplace(c_w_scale)\n", " tic()\n", " obj_out = Float64[]\n", " w_out = Float64[]\n", " g1_out = Float64[]\n", " g2_out = Float64[]\n", " \n", " ed=Model(optimizer = GLPK.GLPKOptimizerLP()) \n", " \n", " # Define decision variables \n", " @variable(ed, 0 <= g[i=1:2] <= g_max[i]) # power output of generators\n", " @variable(ed, 0 <= w <= w_f ) # wind power injection\n", "\n", " # Define the objective function\n", " @objective(ed,Min,sum(c_g[i] * g[i] for i in 1:2) + c_w * w)\n", "\n", " # Define the constraint on the maximum and minimum power output of each generator\n", " for i in 1:2\n", " @constraint(ed, g[i] <= g_max[i]) #maximum\n", " @constraint(ed, g[i] >= g_min[i]) #minimum\n", " end\n", "\n", "\n", " # Define the constraint on the wind power injection\n", " @constraint(ed, w <= w_f)\n", "\n", " # Define the power balance constraint\n", " @constraint(ed, sum(g[i] for i in 1:2) + w == d)\n", " JuMP.optimize(ed)\n", " \n", " for c_g1_scale = 0.5:0.01:3.0\n", " @objective(ed, Min, c_g1_scale*c_g[1]*g[1] + c_g[2]*g[2] + c_w_scale*c_w*w)\n", " JuMP.optimize(ed)\n", " push!(obj_out,JuMP.objectivevalue(ed))\n", " push!(w_out,JuMP.resultvalue(w))\n", " push!(g1_out,JuMP.resultvalue(g[1]))\n", " push!(g2_out,JuMP.resultvalue(g[2]))\n", " end\n", " toc()\n", " return obj_out, w_out, g1_out, g2_out\n", "end\n", "solve_ed_inplace(2.0);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Adjusting specific constraints and/or the objective function is faster than re-building the entire model." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A few practical limitations of the economic dispatch model" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Inefficient usage of wind generators" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The economic dispatch problem does not perform commitment decisions and, thus, assumes that all generators must be dispatched at least at their minimum power output limit. This approach is not cost efficient and may lead to absurd decisions. For example, if $ d = \\sum_{i \\in I} g^{\\min}_{i}$, the wind power injection must be zero, i.e. all available wind generation is spilled, to meet the minimum power output constraints on generators. \n", "\n", "In the following example, we adjust the total demand and observed how it affects wind spillage.\n", "\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dispatch of Generators, MW: [0.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 30000.0\n", "Dispatch of Generators, MW: [150.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 37500.0\n", "Dispatch of Generators, MW: [300.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 45000.0\n", "Dispatch of Generators, MW: [450.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 52500.0\n", "Dispatch of Generators, MW: [600.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 60000.0\n", "Dispatch of Generators, MW: [750.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 67500.0\n", "Dispatch of Generators, MW: [900.0, 300.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 75000.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 50.0\n", "Spillage of Wind, MW: 150.0\n", "Total cost, $: 82500.0\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 90000.0\n", "Dispatch of Generators, MW: [1000.0, 450.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 105000.00000000003\n", "Dispatch of Generators, MW: [1000.0, 600.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 120000.0\n", "Dispatch of Generators, MW: [1000.0, 750.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 135000.0\n", "Dispatch of Generators, MW: [1000.0, 900.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 150000.0\n", "Dispatch of Generators, MW: [NaN, NaN]\n", "Dispatch of Wind, MW: NaN\n", "Spillage of Wind, MW: NaN\n", "Total cost, $: 160000.0\n" ] } ], "source": [ "#@manipulate \n", "for demandscale = 0.2:0.1:1.5\n", " g_opt,w_opt,ws_opt,obj = solve_ed(g_max, g_min, c_g, c_w, demandscale*d, w_f)\n", " \n", " #=html(\"Dispatch of Generators, MW: $(g_opt[:])
    \"*\n", " \"Dispatch of Wind, MW: $w_opt
    \"*\n", " \"Spillage of Wind, MW: $ws_opt
    \"*\n", " \"Total cost, \\$: $obj\")\n", " =#\n", " println(\"Dispatch of Generators, MW: $(g_opt[:])\\n\"*\n", " \"Dispatch of Wind, MW: $w_opt\\n\"*\n", " \"Spillage of Wind, MW: $ws_opt\\n\"*\n", " \"Total cost, \\$: $obj\")\n", " \n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This particular drawback can be overcome by introducing binary decisions on the \"on/off\" status of generators. This model is called unit commitment and considered later in these notes. \n", "\n", "For further reading on the interplay between wind generation and the minimum power output constraints of generators, we refer interested readers to R. Baldick, \"Wind and Energy Markets: A Case Study of Texas,\" IEEE Systems Journal, vol. 6, pp. 27-34, 2012." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Transmission-infeasible solution" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ED solution is entirely market-based and disrespects limitations of the transmission network. Indeed, the flows in transmission lines would attain the following values:\n", "\n", "$$f_{1-2} = 150 MW \\leq f_{1-2}^{\\max} = 100 MW $$\n", "\n", "$$f_{2-3} = 1200 MW \\leq f_{2-3}^{\\max} = 1000 MW $$\n", "\n", "\n", "Thus, if this ED solution was enforced in practice, the power flow limits on both lines would be violated. Therefore, in the following section we consider the optimal power flow model, which amends the ED model with network constraints.\n", "\n", "The importance of the transmission-aware decisions is emphasized in E. Lannoye, D. Flynn, and M. O'Malley, \"Transmission, Variable Generation, and Power System Flexibility,\" IEEE Transactions on Power Systems, vol. 30, pp. 57-66, 2015." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Unit Commitment model " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The Unit Commitment (UC) model can be obtained from ED model by introducing binary variable associated with each generator. This binary variable can attain two values: if it is \"1\", the generator is synchronized and, thus, can be dispatched, otherwise, i.e. if the binary variable is \"0\", that generator is not synchronized and its power output is set to 0.\n", "\n", "To obtain the mathematical formulation of the UC model, we will modify the constraints of the ED model as follows:\n", "$$\n", "g^{\\min}_{i} \\cdot u_{t,i} \\leq g_{i} \\leq g^{\\max}_{i} \\cdot u_{t,i},\n", "$$\n", "\n", "where $ u_{i} \\in \\{0;1\\}. $ In this constraint, if $ u_{i} = 0$, then $g_{i} = 0$. On the other hand, if $ u_{i} = 1$, then $g^{max}_{i} \\leq g_{i} \\leq g^{min}_{i}$.\n", "\n", "For further reading on the UC problem we refer interested readers to G. Morales-Espana, J. M. Latorre, and A. Ramos, \"Tight and Compact MILP Formulation for the Thermal Unit Commitment Problem,\" IEEE Transactions on Power Systems, vol. 28, pp. 4897-4908, 2013." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following example we convert the ED model explained above to the UC model." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "Dispatch of Generators: [1000.0, 300.0] MW\n", "Commitments of Generators: [1.0, 1.0]\n", "Dispatch of Wind: 200.0 MW\n", "Wind spillage: 0.0 MW\n", "\n", "\n", "Total cost: 90000.0$\n" ] } ], "source": [ "# In this cell we introduce binary decision u to the economic dispatch problem (function solve_ed)\n", "function solve_uc(g_max, g_min, c_g, c_w, d, w_f)\n", " #Define the unit commitment (UC) model\n", " uc=Model(optimizer = GLPK.GLPKOptimizerMIP()) \n", " \n", " # Define decision variables \n", " @variable(uc, 0 <= g[i=1:2] <= g_max[i]) # power output of generators\n", " @variable(uc, u[i=1:2], Bin) # Binary status of generators\n", " @variable(uc, 0 <= w <= w_f ) # wind power injection\n", "\n", " # Define the objective function\n", " @objective(uc,Min,sum(c_g[i] * g[i] for i in 1:2) + c_w * w)\n", "\n", " # Define the constraint on the maximum and minimum power output of each generator\n", " for i in 1:2\n", " @constraint(uc, g[i] <= g_max[i] * u[i]) #maximum\n", " @constraint(uc, g[i] >= g_min[i] * u[i]) #minimum\n", " end\n", "\n", " # Define the constraint on the wind power injection\n", " @constraint(uc, w <= w_f)\n", "\n", " # Define the power balance constraint\n", " @constraint(uc, sum(g[i] for i in 1:2) + w == d)\n", "\n", " # Solve statement\n", " JuMP.optimize(uc)\n", " \n", " status = JuMP.terminationstatus(uc)\n", " return status, JuMP.resultvalue.(g), JuMP.resultvalue(w), w_f-JuMP.resultvalue(w), JuMP.resultvalue.(u), JuMP.objectivevalue(uc)\n", "end\n", "\n", "# Solve the economic dispatch problem\n", "status,g_opt,w_opt,ws_opt,u_opt,obj=solve_uc(g_max, g_min, c_g, c_w, d, w_f);\n", "\n", " \n", "println(\"\\n\")\n", "println(\"Dispatch of Generators: \", g_opt[:], \" MW\")\n", "println(\"Commitments of Generators: \", u_opt[:])\n", "println(\"Dispatch of Wind: \", w_opt, \" MW\")\n", "println(\"Wind spillage: \", w_f-w_opt, \" MW\") \n", "println(\"\\n\")\n", "println(\"Total cost: \", obj, \"\\$\") " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Unit Commitment as a function of demand" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After implementing the UC model, we can now assess the interplay between the minimum power output constraints on generators and wind generation." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [300.0, 0.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 15000.0\n", "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [450.0, 0.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 22500.0\n", "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [600.0, 0.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 30000.0\n", "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [750.0, 0.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 37500.0\n", "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [900.0, 0.0]\n", "Dispatch of Wind, MW: 0.0\n", "Spillage of Wind, MW: 200.0\n", "Total cost, $: 45000.0\n", "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [1000.0, 0.0]\n", "Dispatch of Wind, MW: 50.0\n", "Spillage of Wind, MW: 150.0\n", "Total cost, $: 52500.0\n", "Commitment of Generators, MW: [1.0, 0.0]\n", "Dispatch of Generators, MW: [1000.0, 0.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 60000.0\n", "Commitment of Generators, MW: [1.0, 1.0]\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 50.0\n", "Spillage of Wind, MW: 150.0\n", "Total cost, $: 82500.0\n", "Commitment of Generators, MW: [1.0, 1.0]\n", "Dispatch of Generators, MW: [1000.0, 300.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 90000.0\n", "Commitment of Generators, MW: [1.0, 1.0]\n", "Dispatch of Generators, MW: [1000.0, 450.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 105000.00000000003\n", "Commitment of Generators, MW: [1.0, 1.0]\n", "Dispatch of Generators, MW: [1000.0, 600.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 120000.0\n", "Commitment of Generators, MW: [1.0, 1.0]\n", "Dispatch of Generators, MW: [1000.0, 750.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 135000.0\n", "Commitment of Generators, MW: [1.0, 1.0]\n", "Dispatch of Generators, MW: [1000.0, 900.0]\n", "Dispatch of Wind, MW: 200.0\n", "Spillage of Wind, MW: 0.0\n", "Total cost, $: 150000.0\n", "glp_intopt: optimal basis to initial LP relaxation not provided\n", "Status: InfeasibleNoResult\n" ] } ], "source": [ "#@manipulate \n", "for demandscale = 0.2:0.1:1.5\n", " status, g_opt,w_opt,ws_opt, u_opt, obj = solve_uc(g_max, g_min, c_g, c_w, demandscale*d, w_f)\n", " \n", " if status == MOI.Success\n", " #=html(\"Commitment of Generators, MW: $(u_opt[:])
    \"*\n", " \"Dispatch of Generators, MW: $(g_opt[:])
    \"*\n", " \"Dispatch of Wind, MW: $w_opt
    \"*\n", " \"Spillage of Wind, MW: $ws_opt
    \"*\n", " \"Total cost, \\$: $obj\")=#\n", " println(\"Commitment of Generators, MW: $(u_opt[:])\\n\"*\n", " \"Dispatch of Generators, MW: $(g_opt[:])\\n\"*\n", " \"Dispatch of Wind, MW: $w_opt\\n\"*\n", " \"Spillage of Wind, MW: $ws_opt\\n\"*\n", " \"Total cost, \\$: $obj\")\n", " else\n", " #html(\"Status: $status\")\n", " println(\"Status: $status\")\n", " end\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Unit Commitment with different wind availability" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the following experiment, we use a manipulator for adjusting demand and observe the different dispatch decisions under different wind generation conditions." ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "@manipulate for demandscale = 0.2:0.05:1.45\n", " w_out = Float64[]\n", " g1_out = Float64[]\n", " g2_out = Float64[]\n", " \n", " for w_f_scale = 0.5:0.05:5\n", " status, g_opt,w_opt,ws_opt, u_opt, obj = solve_uc(g_max, g_min, c_g, c_w, demandscale*d, w_f*w_f_scale)\n", " push!(g1_out,g_opt[1])\n", " push!(g2_out,g_opt[2])\n", " push!(w_out,w_opt)\n", " end\n", " \n", " set_default_plot_size(16cm, 30cm)\n", " \n", " vstack(\n", " # Plot the power output of Generator 1\n", " plot(x=0.5:0.05:2,y=g1_out[1:length(0.5:0.05:2)], Geom.line,\n", " Guide.XLabel(\"w_f_scale \"), Guide.YLabel(\"Dispatch of G1, MW\")),\n", " # Plot the power output of Generator 2 \n", " plot(x=0.5:0.05:5,y=g2_out, Geom.line,\n", " Guide.XLabel(\"w_f_scale \"), Guide.YLabel(\"Dispatch of G2, MW\")),\n", " # Plot the wind power output\n", " plot(x=0.5:0.05:5,y=w_out, Geom.line,\n", " Guide.XLabel(\"w_f_scale \"), Guide.YLabel(\"Dispatch of Wind, MW\")),\n", " ) \n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Unit Commitment with no load cost" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Like power output decisions ($g_i$), binary commitment decisions ($u_i$) can also be priced in the objective function. The physical interpretation of the cost incurred by binary commitment decisions is no-load component of the operating cost.\n", "\n", "This is implementing in the following example." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "solve_uc_nlc (generic function with 1 method)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# In this cell we redefine the UC model to account for the no-load cost\n", "\n", "function solve_uc_nlc(g_max, g_min, c_g, c_w, d, w_f, c_g0)\n", "#Define the unit commitment (UC) model\n", " uc=Model(optimizer = GLPK.GLPKOptimizerMIP()) \n", " \n", "# Define decision variables \n", "@variable(uc, 0 <= g[i=1:2] <= g_max[i]) # power output of generators\n", "@variable(uc, u[i=1:2], Bin) # Binary status of generators\n", "@variable(uc, 0 <= w <= w_f ) # wind power injection\n", "\n", "# Define the objective function\n", " @objective(uc,Min,sum(c_g[i] * g[i] for i in 1:2)+ c_w * w + sum(c_g0[i] * u[i] for i in 1:2))\n", "\n", "# Define the constraint on the maximum and minimum power output of each generator\n", "for i in 1:2\n", " @constraint(uc, g[i] <= g_max[i] * u[i]) #maximum\n", " @constraint(uc, g[i] >= g_min[i] * u[i]) #minimum\n", "end\n", "\n", "\n", "# Define the constraint on the wind power injection\n", "@constraint(uc, w <= w_f)\n", "\n", "# Define the power balance constraint\n", "@constraint(uc, sum(g[i] for i in 1:2) + w == d)\n", "\n", "# Solve statement\n", "JuMP.optimize(uc)\n", "\n", "status = JuMP.terminationstatus(uc)\n", " \n", " \n", "return status, JuMP.resultvalue(g), JuMP.resultvalue.(w), w_f-JuMP.resultvalue.(w), JuMP.resultvalue.(u), JuMP.objectivevalue(uc)\n", "end" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using the model above, we can now assess the sensitivity of the UC solution to demand under different levels of the minimum power output limits." ] }, { "cell_type": "markdown", "metadata": { "collapsed": false }, "source": [ "@manipulate for demandscale = 0.2:0.05:1.45\n", " w_out = Float64[]\n", " g1_out = Float64[]\n", " g2_out = Float64[]\n", " \n", " for pmin_scale = 0.0:0.05:3\n", " status, g_opt,w_opt,ws_opt, u_opt, obj = solve_uc_nlc(g_max, pmin_scale*g_min, c_g, c_w, demandscale*d, w_f, c_g0)\n", " push!(g1_out,g_opt[1])\n", " push!(g2_out,g_opt[2])\n", " push!(w_out,w_opt)\n", " end\n", " \n", " \n", " #set_default_plot_size(16cm, 30cm)\n", " #vstack(\n", " ## Plot the power output of Generator 1\n", " #plot(x=0.0:0.05:3,y=g1_out, Geom.line,\n", " #Guide.XLabel(\"w_f_scale \"), Guide.YLabel(\"Dispatch of G1, MW\")),\n", " ## Plot the power output of Generator 2 \n", " #plot(x=0.0:0.05:3,y=g2_out, Geom.line,\n", " #Guide.XLabel(\"w_f_scale \"), Guide.YLabel(\"Dispatch of G2, MW\")),\n", " ## Plot the wind power output\n", " #plot(x=0.0:0.05:3,y=w_out, Geom.line,\n", " #Guide.XLabel(\"w_f_scale \"), Guide.YLabel(\"Dispatch of Wind, MW\")),\n", " #)\n", " \n", "end" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.6.0", "language": "julia", "name": "julia-0.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.6.0" } }, "nbformat": 4, "nbformat_minor": 0 }