/
tp_test.jl
130 lines (100 loc) · 3.77 KB
/
tp_test.jl
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
######
#
# These are toy problem formulations used to test advanced features
# such as storage devices
#
######
"opf with storage"
function run_tp_strg_opf(data::Dict{String,Any}, model_constructor, solver; kwargs...)
return PMs.run_generic_model(data, model_constructor, solver, post_tp_strg_opf; multiconductor=true, kwargs...)
end
""
function post_tp_strg_opf(pm::PMs.GenericPowerModel)
variable_tp_voltage(pm)
variable_tp_branch_flow(pm)
variable_tp_storage(pm)
for c in PMs.conductor_ids(pm)
PMs.variable_generation(pm, cnd=c)
PMs.variable_dcline_flow(pm, cnd=c)
end
constraint_tp_voltage(pm)
for i in PMs.ids(pm, :ref_buses)
constraint_tp_theta_ref(pm, i)
end
for i in PMs.ids(pm, :bus), c in PMs.conductor_ids(pm)
PMs.constraint_kcl_shunt_storage(pm, i, cnd=c)
end
for i in PMs.ids(pm, :storage)
PMs.constraint_storage_state(pm, i)
constraint_tp_storage_exchange(pm, i)
for c in PMs.conductor_ids(pm)
PMs.constraint_storage_thermal_limit(pm, i, cnd=c)
end
end
for i in PMs.ids(pm, :branch)
for c in PMs.conductor_ids(pm)
constraint_ohms_tp_yt_from(pm, i, cnd=c)
constraint_ohms_tp_yt_to(pm, i, cnd=c)
PMs.constraint_voltage_angle_difference(pm, i, cnd=c)
PMs.constraint_thermal_limit_from(pm, i, cnd=c)
PMs.constraint_thermal_limit_to(pm, i, cnd=c)
end
end
for i in PMs.ids(pm, :dcline), c in PMs.conductor_ids(pm)
PMs.constraint_dcline(pm, i, cnd=c)
end
PMs.objective_min_fuel_cost(pm)
end
"multi-network opf with storage"
function run_mn_tp_strg_opf(data::Dict{String,Any}, model_constructor, solver; kwargs...)
return PMs.run_generic_model(data, model_constructor, solver, post_mn_tp_strg_opf; multiconductor=true, multinetwork=true, kwargs...)
end
""
function post_mn_tp_strg_opf(pm::PMs.GenericPowerModel)
for (n, network) in PMs.nws(pm)
variable_tp_voltage(pm, nw=n)
variable_tp_branch_flow(pm, nw=n)
variable_tp_storage(pm, nw=n)
for c in PMs.conductor_ids(pm, nw=n)
PMs.variable_generation(pm, cnd=c, nw=n)
PMs.variable_dcline_flow(pm, cnd=c, nw=n)
end
constraint_tp_voltage(pm, nw=n)
for i in PMs.ids(pm, :ref_buses, nw=n)
constraint_tp_theta_ref(pm, i, nw=n)
end
for i in PMs.ids(pm, :bus, nw=n), c in PMs.conductor_ids(pm, nw=n)
PMs.constraint_kcl_shunt_storage(pm, i, cnd=c, nw=n)
end
for i in PMs.ids(pm, :storage, nw=n)
constraint_tp_storage_exchange(pm, i, nw=n)
for c in PMs.conductor_ids(pm, nw=n)
PMs.constraint_storage_thermal_limit(pm, i, cnd=c, nw=n)
end
end
for i in PMs.ids(pm, :branch, nw=n)
for c in PMs.conductor_ids(pm, nw=n)
constraint_ohms_tp_yt_from(pm, i, cnd=c, nw=n)
constraint_ohms_tp_yt_to(pm, i, cnd=c, nw=n)
PMs.constraint_voltage_angle_difference(pm, i, cnd=c, nw=n)
PMs.constraint_thermal_limit_from(pm, i, cnd=c, nw=n)
PMs.constraint_thermal_limit_to(pm, i, cnd=c, nw=n)
end
end
for i in PMs.ids(pm, :dcline, nw=n), c in PMs.conductor_ids(pm, nw=n)
PMs.constraint_dcline(pm, i, cnd=c, nw=n)
end
end
network_ids = sort(collect(PMs.nw_ids(pm)))
n_1 = network_ids[1]
for i in PMs.ids(pm, :storage, nw=n_1)
PMs.constraint_storage_state(pm, i, nw=n_1)
end
for n_2 in network_ids[2:end]
for i in PMs.ids(pm, :storage, nw=n_2)
PMs.constraint_storage_state(pm, i, n_1, n_2)
end
n_1 = n_2
end
PMs.objective_min_fuel_cost(pm)
end