Assignment 3: Power System Optimizationn", "

Multi-period unit commitment (60 points)

n", "

Team: Chiel Ton & Guido Adriaans

" ] }, : Notes">

NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Assignment 3: Power System Optimization</h1>n",
"<h2>Multi-period unit commitment (60 points)</h2>n",
"<h3>Team: Chiel Ton & Guido Adriaans</h3> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The necessary packages have already been loaded for you."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandasn",
"import numpyn",
"from pyomo.environ import *n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Also, for convenience, the input xlsx file has been parsed."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
"source": [
"input_filename = 'Input_assgn3_new.xlsx'n",
"UnitData = pandas.read_excel(input_filename , sheetname = 'Unit_Data', index_col= 0)n",
"Load = pandas.read_excel(input_filename , sheetname = 'Load', index_col= 0)n",
"C = pandas.read_excel(input_filename , sheetname = 'Block_cost', index_col= 0)n",
"B = pandas.read_excel(input_filename , sheetname = 'Block_size', index_col= 0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Define an optimization model."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#Your code heren",
"#Create a Concrete PYOMO model named "model"n",
"n",
"model = ConcreteModel()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>Step 1: define the sets, parameters and decision variables of the problem(<b>10 points</b>)</h2>"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
"source": [
"#Example: this is how the set of generators is definedn",
"model.I = Set(ordered = True, initialize = UnitData.index) #generatorn",
"n",
"#your code here. Define the remaining setsn",
"model.T = Set(ordered = True, initialize = Load.index) #loadn",
"model.K = Set(ordered = True, initialize = ['f1','f2','f3','f4']) #costn",
"model.F = Set(ordered = True, initialize = ['f1','f2','f3','f4']) #sizen",
"n",
"##Define parameters n",
"#load parametersn",
"#Example code heren",
"model.Load = Param(model.T, within=NonNegativeReals, mutable = True)n",
"n",
"#Generator parametersn",
"#Your code heren",
"model.Type = Param(model.I, within = Any, mutable = True)#within removedn",
"model.Pmax = Param(model.I, within = NonNegativeReals, mutable = True)n",
"model.Pmin = Param(model.I, within = NonNegativeReals, mutable = True)n",
"model.SUC = Param(model.I, within = NonNegativeReals, mutable = True)n",
"model.RU = Param(model.I, within = NonNegativeReals, mutable = True)n",
"model.RD = Param(model.I, within = NonNegativeReals, mutable = True)n",
"model.u_ini = Param(model.I, within = Boolean, mutable = True)n",
"model.P_ini = Param(model.I, within = NonNegativeReals, mutable = True)n",
"n",
"#Size paramatersn",
"#Example code here (parameters with multiple indices)n",
"model.B = Param(model.I, model.F, within = NonNegativeReals, mutable = True)n",
"n",
"#Cost parametersn",
"#Your code here (parameters with multiple indices)n",
"model.C = Param(model.I, model.K, within = NonNegativeReals, mutable = True)n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
"source": [
"##Initialize parametersn",
"n",
"#Example: initialize loadn",
"for t in model.T:n",
" model.Load[t] = Load.loc[t, 'Load']n",
"n",
"for i in model.I:n",
" #Your code here. Initialize the generator parametersn",
" model.Type[i] = UnitData.loc[i,'Type']n",
" model.Pmax[i] = UnitData.loc[i,'Pmax']n",
" model.Pmin[i] = UnitData.loc[i,'Pmin']n",
" model.SUC[i] = UnitData.loc[i,'SUC']n",
" model.RU[i] = UnitData.loc[i,'RU']n",
" model.RD[i] = UnitData.loc[i,'RD']n",
" model.u_ini[i] = UnitData.loc[i,'u_ini']n",
" model.P_ini[i] = UnitData.loc[i,'P_ini']n",
" #Example code heren",
" for f in model.F:n",
" model.B[i,f] = B.loc[i,f]n",
" #Your code here. Initialize the cost parametersn",
" model.C[i,f] = C.loc[i,f]n",
"n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true,
"scrolled": false
},
"outputs": [],
"source": [
"#Your code here. Define decision variables.n",
"model.b = Var(model.I, model.F, model.T, within = NonNegativeReals)n",
"model.P = Var(model.I, model.T, within = NonNegativeReals)n",
"model.u = Var(model.I, model.T, within = Boolean)n",
"model.SUC_var = Var(model.I, model.T, within = NonNegativeReals)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>Define the constraints of the problem (<b>35 points</b>)</h2>"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
"source": [
"#Define the constraints of the problem (in the form of Python methods)n",
"#Hint: while defining the decision variables their domain can also be specified n",
"#(e.g., if you know that a variable is positive)n",
"n",
"#Define the objective functionn",
"def cost_rule(model):n",
" return sum(sum(sum(model.C[i,f]*model.b[i,f,t] for f in model.F) + model.SUC_var[i,t] for i in model.I) for t in model.T)n",
"n",
"#Constraints (2)-(4)n",
"n",
"def portion_rule(model,i,f,t):n",
" return model.b[i,f,t] <= model.B[i,f]n",
"n",
"def size_rule(model,i,t):n",
" return model.P[i,t] <= sum(model.b[i,f,t] for f in model.K)n",
"n",
"def output1_rule(model,i,t):n",
" return model.Pmin[i]*model.u[i,t] <= model.P[i,t]n",
"n",
"def output2_rule(model,i,t):n",
" return model.Pmin[i]*model.u[i,t] <= model.P[i,t] <= model.Pmax[i]*model.u[i,t]n",
"n",
"#Constraints (5)-(8)n",
"n",
"#Example, the ramp-up constraint. Attention: there are more constraints that need to be handled carefullyn",
"#for t=1 (or, in our case, t=t1)n",
"n",
"def ramp_up_rule(model,i,t):n",
" n",
" if(model.T.ord(t)>1):n",
" t_prv = model.T.ord(t)-1n",
" t_prv = model.T[t_prv]n",
"n",
" return model.P[i,t] - model.P[i,t_prv] <= 60 * model.RU[i]n",
" n",
" else:n",
" return model.P[i,t] - model.P_ini[i] <= 60 * model.RU[i]n",
"n",
"#Your code heren",
"def ramp_down_rule(model,i,t):n",
" n",
" if(model.T.ord(t)>1):n",
" t_prv = model.T.ord(t)-1n",
" t_prv = model.T[t_prv]n",
"n",
" return model.P[i,t_prv] - model.P[i,t] <= 60 * model.RD[i]n",
" n",
" else:n",
" return model.P_ini[i] - model.P[i,t] <= 60 * model.RD[i]n",
"n",
"#Constraint (9)n",
"def pbalance_rule(model,t):n",
" return sum(model.P[i,t] for i in model.I) == model.Load[t]n",
"n",
"#Constraints (10)-(11)n",
"def startup_rule(model,i,t):n",
" n",
" if(model.T.ord(t)>1):n",
" t_prv = model.T.ord(t)-1n",
" t_prv = model.T[t_prv]n",
"n",
" return model.SUC_var[i,t] >= model.SUC[i]*(model.u[i,t]-model.u[i,t_prv])n",
" n",
" else:n",
" return model.SUC_var[i,t] >= model.SUC[i]*(model.u[i,t]-model.u_ini[i])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"#Add the constraints to the modeln",
"n",
"#Examples, add the objective function and the ramp-up constraintn",
"model.cost = Objective(rule = cost_rule, sense = 1)n",
"model.ramp_up = Constraint(model.I, model.T, rule = ramp_up_rule)n",
"n",
"#Your code here. Define the remaining constraints.n",
"n",
"#Constraints (2)-(4)n",
"model.portion = Constraint(model.I, model.F, model.T, rule = portion_rule)n",
"model.size = Constraint(model.I, model.T, rule = size_rule)n",
"model.output1 = Constraint(model.I, model.T, rule = output1_rule)n",
"model.output2 = Constraint(model.I, model.T, rule = output1_rule)n",
"n",
"#Constraints (6)-(8)n",
"model.ramp_down = Constraint(model.I, model.T, rule = ramp_down_rule)n",
"n",
"#Constraint (9)n",
"model.pbalance = Constraint(model.T, rule = pbalance_rule)n",
"n",
"#Constraints (10)-(11)n",
"model.startup = Constraint(model.I, model.T, rule = startup_rule)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"n",
"Problem: n",
"- Name: x5377n",
" Lower bound: 1769910.9144n",
" Upper bound: 1769910.9144n",
" Number of objectives: 1n",
" Number of constraints: 7705n",
" Number of variables: 5377n",
" Number of binary variables: 768n",
" Number of integer variables: 768n",
" Number of continuous variables: 4609n",
" Number of nonzeros: 15369n",
" Sense: minimizen",
"Solver: n",
"- Status: okn",
" Return code: 0n",
" Message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.n",
" Termination condition: optimaln",
" Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.n",
" Wall time: 0.0312404632568n",
" Error rc: 0n",
" Time: 0.31299996376n",
"Solution: n",
"- number of solutions: 0n",
" number of solutions displayed: 0n",
"n"
]
}
],
"source": [
"#Solve the optimization problemn",
"n",
"opt=SolverFactory('gurobi')n",
"results=opt.solve(model) n",
"print results #-> uncomment this line while testing your code to make sure that your problem is feasible!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2> Processing and visualizing results (<b>15 points</b>) </h2>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In the celss below you must write some code to process and report the results."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot the figure of a binary matrix representing the commitment status of each unit."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Plot a heatmap that depicts the hourly percentage participation of each unit in covering the total daily energy demand."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.