-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOptimisation.py
73 lines (55 loc) · 3.05 KB
/
Optimisation.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
62
63
64
65
66
67
68
69
70
71
72
73
# To optimise the configurations of energy generation, storage and transmission assets
# Copyright (c) 2019, 2020 Bin Lu, The Australian National University
# Licensed under the MIT Licence
# Correspondence: [email protected]
from scipy.optimize import differential_evolution
from argparse import ArgumentParser
import datetime as dt
import csv
parser = ArgumentParser()
parser.add_argument('-i', default=400, type=int, required=False, help='maxiter=4000, 400')
parser.add_argument('-p', default=1, type=int, required=False, help='popsize=2, 10')
parser.add_argument('-m', default=0.5, type=float, required=False, help='mutation=0.5')
parser.add_argument('-r', default=0.3, type=float, required=False, help='recombination=0.3')
parser.add_argument('-s', default=11, type=int, required=False, help='11, 12, 13, ...')
args = parser.parse_args()
scenario = args.s
from Input import *
from Simulation import Reliability
from Network import Transmission
def F(x):
"""This is the objective function."""
S = Solution(x)
Deficit, DeficitD = Reliability(S, flexible=np.zeros(intervals)) # Sj-EDE(t, j), MW
Flexible = (Deficit + DeficitD / efficiencyD).sum() * resolution / years / (0.5 * (1 + efficiency)) # MWh p.a.
Hydro = Flexible + GBaseload.sum() * resolution / years # Hydropower & biomass: MWh p.a.
PenHydro = max(0, Hydro - 20 * pow(10, 6)) # TWh p.a. to MWh p.a.
Deficit, DeficitD = Reliability(S, flexible=np.ones(intervals) * CPeak.sum() * pow(10, 3)) # Sj-EDE(t, j), GW to MW
PenDeficit = max(0, (Deficit + DeficitD / efficiencyD).sum() * resolution) # MWh
TDC = Transmission(S) if scenario>=21 else np.zeros((intervals, len(DCloss))) # TDC: TDC(t, k), MW
CDC = np.amax(abs(TDC), axis=0) * pow(10, -3) # CDC(k), MW to GW
PenDC = max(0, CDC[6] - CDC6max) * pow(10, 3) # GW to MW
cost = factor * np.array([sum(S.CPV), sum(S.CWind), sum(S.CPHP), S.CPHS] + list(CDC) + [sum(S.CPV), sum(S.CWind), Hydro * pow(10, -6), -1, -1]) # $b p.a.
if scenario<=17:
cost[-1], cost[-2] = [0] * 2
cost = cost.sum()
loss = np.sum(abs(TDC), axis=0) * DCloss
loss = loss.sum() * pow(10, -9) * resolution / years # PWh p.a.
LCOE = cost / abs(energy - loss)
Func = LCOE + PenHydro + PenDeficit + PenDC
return Func
if __name__=='__main__':
starttime = dt.datetime.now()
print("Optimisation starts at", starttime)
lb = [0.] * pzones + [0.] * wzones + contingency + [0.]
ub = [50.] * pzones + [50.] * wzones + [50.] * nodes + [5000.]
result = differential_evolution(func=F, bounds=list(zip(lb, ub)), tol=0,
maxiter=args.i, popsize=args.p, mutation=args.m, recombination=args.r,
disp=True, polish=False, updating='deferred', workers=-1)
with open('Results/Optimisation_resultx{}.csv'.format(scenario), 'a', newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(result.x)
endtime = dt.datetime.now()
print("Optimisation took", endtime - starttime)
from Dispatch import Analysis
Analysis(result.x)