-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInitializeOnOffExistingGensCE.py
More file actions
79 lines (71 loc) · 4 KB
/
InitializeOnOffExistingGensCE.py
File metadata and controls
79 lines (71 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#Michael Craig
#Dec 2, 2016
#Initialize on/off commitment state of existing units for CE model for first
#hour in each time block (seasons + demand day + ramp day).
from operator import *
from AuxFuncs import *
from GAMSAuxFuncs import *
from CalculateOpCost import calcOpCosts
import copy
#For first hour of each time block, gets gen stack, sorts gens by op cost, then
#meets demand and assigns dispatched gens to "on".
#Inputs: gen fleet, hours + hourly wind & solar gen + demand for CE model (1d list,
#slimmed to CE hours), dict mapping time block to hours in that time block
#Outputs: dict mapping block to dict mapping gen symbol to on/off in first hour of dict.
def initializeOnOffExistingGens(genFleetForCE,hoursCE,hourlyWindGenCE,hourlySolarGenCE,
demandCE,hrsByBlock):
netDemandCE = [demandCE[idx] - hourlyWindGenCE[idx] - hourlySolarGenCE[idx]
for idx in range(len(demandCE))]
firstHoursIdxs = [0] + [idx for idx in range(1,len(hoursCE)) if (hoursCE[idx]-hoursCE[idx-1]!=1)]
firstHours = [hoursCE[idx] for idx in firstHoursIdxs]
firstHoursNetDemand = [netDemandCE[idx] for idx in firstHoursIdxs]
sortedSymbols,sortedCapacs,reGenSymbols = getGenStack(genFleetForCE)
blockToOnOff = dict()
for idx in range(len(firstHours)):
currHour,hourNetDemand = firstHours[idx],firstHoursNetDemand[idx]
genToOnOff = getGenOnOffForHour(sortedSymbols,sortedCapacs,reGenSymbols,hourNetDemand,idx)
currBlock = mapHourToBlock(currHour,hrsByBlock)
blockToOnOff[currBlock] = genToOnOff
return blockToOnOff
#Get gen stack for fleet, returning sorted gen symbols, capacities, and RE gen symbols.
#Sorted in order of least -> most costly.
def getGenStack(genFleetForCE):
reFuelTypes = ['Wind','Solar']
fuelCol = genFleetForCE[0].index('Modeled Fuels')
genFleetNoRE = [row for row in genFleetForCE if row[fuelCol] not in reFuelTypes]
reGenSymbols = [createGenSymbol(row,genFleetForCE[0]) for row in genFleetForCE[1:]
if row[fuelCol] in reFuelTypes]
capacCol = genFleetNoRE[0].index('Capacity (MW)')
genCapacs = [float(row[capacCol]) for row in genFleetNoRE[1:]]
(genOpCosts,genHrs) = calcOpCosts(genFleetNoRE,1)
genSymbols = [createGenSymbol(row,genFleetNoRE[0]) for row in genFleetNoRE[1:]]
genCostSymbolCapac = [[genOpCosts[idx],genSymbols[idx],genCapacs[idx]] for idx in range(len(genOpCosts))]
sortedGenCostSymbolCapac = sorted(genCostSymbolCapac)
sortedCapacs = [row[2] for row in sortedGenCostSymbolCapac]
sortedSymbols = [row[1] for row in sortedGenCostSymbolCapac]
return sortedSymbols,sortedCapacs,reGenSymbols
#For given net demand value in hour, determine which gens should be on by
#dispatching them using gen stack.
def getGenOnOffForHour(sortedSymbols,sortedCapacs,reGenSymbols,hourNetDemand,idx):
onGens,offGens = dispatchGens(sortedSymbols,sortedCapacs,hourNetDemand)
onGens.extend(reGenSymbols)
genToOnOff = dict()
for gen in onGens: genToOnOff[gen] = 1
for gen in offGens: genToOnOff[gen] = 0
return genToOnOff
#Meet demand w/ gen stack.
def dispatchGens(sortedSymbols,sortedCapacs,hourNetDemand):
cumCapacs = [sum(sortedCapacs[:idx+1]) for idx in range(len(sortedCapacs))]
supplyGap = [hourNetDemand - cumCapac for cumCapac in cumCapacs]
supplyGapLessThanZero = [le(gap,0) for gap in supplyGap] #le is <=
if True in supplyGapLessThanZero: #enough gens to meet demand
idxMeetDemand = supplyGapLessThanZero.index(True)
onGens = [sortedSymbols[idx] for idx in range(idxMeetDemand+1)]
offGens = [sortedSymbols[idx] for idx in range(idxMeetDemand+1,len(sortedSymbols))]
else: #all gens turn on
onGens = copy.deepcopy(sortedSymbols)
offGens = []
return onGens,offGens
def mapHourToBlock(currHour,hrsByBlock):
for block in hrsByBlock:
if currHour in hrsByBlock[block]: return block