/
constraint.jl
177 lines (134 loc) · 5.84 KB
/
constraint.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
""
function constraint_restoration_cardinality_ub(pm::_PM.AbstractPowerModel, n::Int, cumulative_repairs::Int)
z_storage = _PM.var(pm, n, :z_storage)
z_gen = _PM.var(pm, n, :z_gen)
z_branch = _PM.var(pm, n, :z_branch)
z_bus = _PM.var(pm, n, :z_bus)
JuMP.@constraint(pm.model,
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :branch_damage))
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :gen_damage))
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :storage_damage))
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :bus_damage))
<= cumulative_repairs
)
end
""
function constraint_restoration_cardinality_lb(pm::_PM.AbstractPowerModel, n::Int, cumulative_repairs::Int)
z_storage = _PM.var(pm, n, :z_storage)
z_gen = _PM.var(pm, n, :z_gen)
z_branch = _PM.var(pm, n, :z_branch)
z_bus = _PM.var(pm, n, :z_bus)
JuMP.@constraint(pm.model,
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :branch_damage))
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :gen_damage))
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :storage_damage))
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :bus_damage))
>= cumulative_repairs
)
end
function constraint_restore_all_components(pm, n)
z_demand = _PM.var(pm, n, :z_demand)
z_shunt = _PM.var(pm, n, :z_shunt)
z_storage = _PM.var(pm, n, :z_storage)
z_gen = _PM.var(pm, n, :z_gen)
z_branch = _PM.var(pm, n, :z_branch)
z_bus = _PM.var(pm, n, :z_bus)
for (i,load) in _PM.ref(pm, n, :load)
JuMP.@constraint(pm.model, z_demand[i] == 1)
end
for (i,shunt) in _PM.ref(pm, n, :shunt)
JuMP.@constraint(pm.model, z_shunt[i] == 1)
end
for (i,storage) in _PM.ref(pm, n, :storage_damage)
JuMP.@constraint(pm.model, z_storage[i] == 1)
end
for (i,gen) in _PM.ref(pm, n, :gen_damage)
JuMP.@constraint(pm.model, z_gen[i] == 1)
end
for (i,branch) in _PM.ref(pm, n, :branch_damage)
JuMP.@constraint(pm.model, z_branch[i] == 1)
end
for (i,bus) in _PM.ref(pm, n, :bus_damage)
JuMP.@constraint(pm.model, z_bus[i] == 1)
end
end
""
function constraint_gen_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :gen_damage), i)
z_gen_1 = _PM.var(pm, nw_1, :z_gen, i)
z_gen_2 = _PM.var(pm, nw_2, :z_gen, i)
JuMP.@constraint(pm.model, z_gen_2 >= z_gen_1)
end
end
""
function constraint_bus_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :bus_damage), i)
z_bus_1 = _PM.var(pm, nw_1, :z_bus, i)
z_bus_2 = _PM.var(pm, nw_2, :z_bus, i)
JuMP.@constraint(pm.model, z_bus_2 >= z_bus_1)
end
end
""
function constraint_storage_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :storage_damage), i)
z_storage_1 = _PM.var(pm, nw_1, :z_storage, i)
z_storage_2 = _PM.var(pm, nw_2, :z_storage, i)
JuMP.@constraint(pm.model, z_storage_2 >= z_storage_1)
end
end
""
function constraint_branch_energized(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :branch_damage), i)
z_branch_1 = _PM.var(pm, nw_1, :z_branch, i)
z_branch_2 = _PM.var(pm, nw_2, :z_branch, i)
JuMP.@constraint(pm.model, z_branch_2 >= z_branch_1)
end
end
"Load delivered at each node must be greater than or equal the previous time period"
function constraint_load_increasing(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
z_demand_1 = _PM.var(pm, nw_1, :z_demand, i)
z_demand_2 = _PM.var(pm, nw_2, :z_demand, i)
JuMP.@constraint(pm.model, z_demand_2 >= z_demand_1)
end
"on/off constraint for storage connected to damaged buses"
function constraint_storage_bus_connection(pm::_PM.AbstractPowerModel, n::Int, storage_id::Int, bus_id::Int)
z_storage = _PM.var(pm, n, :z_storage, storage_id)
z_bus = _PM.var(pm, n, :z_bus, bus_id)
JuMP.@constraint(pm.model, z_storage <= z_bus)
end
"on/off constraint for generators connected to damaged buses"
function constraint_gen_bus_connection(pm::_PM.AbstractPowerModel, n::Int, gen_id::Int, bus_id::Int)
z_gen = _PM.var(pm, n, :z_gen, gen_id)
z_bus = _PM.var(pm, n, :z_bus, bus_id)
JuMP.@constraint(pm.model, z_gen <= z_bus)
end
"on/off constraint for loads connected to damaged buses"
function constraint_load_bus_connection(pm::_PM.AbstractPowerModel, n::Int, load_id::Int, bus_id::Int)
z_demand = _PM.var(pm, n, :z_demand, load_id)
z_bus = _PM.var(pm, n, :z_bus, bus_id)
JuMP.@constraint(pm.model, z_demand <= z_bus)
end
"on/off constraint for shunts connected to damaged buses"
function constraint_shunt_bus_connection(pm::_PM.AbstractPowerModel, n::Int, shunt_id::Int, bus_id::Int)
z_shunt = _PM.var(pm, n, :z_shunt, shunt_id)
z_bus = _PM.var(pm, n, :z_bus, bus_id)
JuMP.@constraint(pm.model, z_shunt <= z_bus)
end
"on/off constraint for branches connected to damaged buses"
function constraint_branch_bus_connection(pm::_PM.AbstractPowerModel, n::Int, branch_id::Int, bus_id::Int)
z_branch = _PM.var(pm, n, :z_branch, branch_id)
z_bus = _PM.var(pm, n, :z_bus, bus_id)
JuMP.@constraint(pm.model, z_branch <= z_bus)
end
function constraint_voltage_magnitude_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, vmin, vmax)
vm = _PM.var(pm, n, :vm, i)
z_voltage = _PM.var(pm, n, :z_voltage, i)
JuMP.@constraint(pm.model, vm <= vmax*z_voltage)
JuMP.@constraint(pm.model, vm >= vmin*z_voltage)
end
function constraint_voltage_magnitude_sqr_on_off(pm::_PM.AbstractPowerModel, n::Int, i::Int, vmin, vmax)
w = _PM.var(pm, n, :w, i)
z_voltage = _PM.var(pm, n, :z_voltage, i)
JuMP.@constraint(pm.model, w <= vmax^2*z_voltage)
JuMP.@constraint(pm.model, w >= vmin^2*z_voltage)
end