forked from b-lu/FIRM_Australia
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dispatch.py
61 lines (43 loc) · 2 KB
/
Dispatch.py
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
# Step-by-step analysis to decide the dispatch of flexible energy resources
# Copyright (c) 2019, 2020 Bin Lu, The Australian National University
# Licensed under the MIT Licence
# Correspondence: [email protected]
from Input import *
from Simulation import Reliability
import datetime as dt
from multiprocessing import Pool, cpu_count
def Flexible(instance):
"""Energy source of high flexibility"""
year, x = instance
print('Dispatch works on', year)
S = Solution(x)
startidx = int((24 / resolution) * (dt.datetime(year, 1, 1) - dt.datetime(firstyear, 1, 1)).days)
endidx = int((24 / resolution) * (dt.datetime(year+1, 1, 1) - dt.datetime(firstyear, 1, 1)).days)
Fcapacity = CPeak.sum() * pow(10, 3) # GW to MW
flexible = Fcapacity * np.ones(endidx - startidx)
for i in range(0, endidx - startidx, timestep):
flexible[i: i+timestep] = 0
Deficit, DeficitD = Reliability(S, flexible=flexible, start=startidx, end=endidx) # Sj-EDE(t, j), MW
if (Deficit + DeficitD).sum() * resolution > 0.1:
flexible[i: i+timestep] = Fcapacity
flexible = np.clip(flexible - S.Spillage, 0, None)
return flexible
def Analysis(x):
"""Dispatch.Analysis(result.x)"""
starttime = dt.datetime.now()
print('Dispatch starts at', starttime)
# Multiprocessing
pool = Pool(processes=min(cpu_count(), finalyear - firstyear + 1))
instances = map(lambda y: [y] + [x], range(firstyear, finalyear + 1))
Dispresult = pool.map(Flexible, instances)
pool.terminate()
Flex = np.concatenate(Dispresult)
np.savetxt('Results/Dispatch_Flexible{}.csv'.format(scenario), Flex, fmt='%f', delimiter=',', newline='\n', header='Flexible energy resources')
endtime = dt.datetime.now()
print('Dispatch took', endtime - starttime)
from Statistics import Information
Information(x, Flex)
return True
if __name__ == '__main__':
capacities = np.genfromtxt('Results/Optimisation_resultx.csv', delimiter=',', skip_header=1)
Analysis(capacities)