Skip to content

Commit

Permalink
Merge pull request #39 from lanl-ansi/pm-v0.16
Browse files Browse the repository at this point in the history
Updates for PowerModels v0.16
  • Loading branch information
ccoffrin authored Apr 13, 2020
2 parents 42ec674 + 5c7dcf8 commit fa5c0b9
Show file tree
Hide file tree
Showing 23 changed files with 984 additions and 980 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
## Staged
- nothing

## v0.4.0
- Update to PowerModels v0.16 (breaking)
- Add support for Memento v0.13, v1.0

## v0.3.0
- Update to PowerModels v0.15
- Update to PowerModels v0.15 (breaking)

## v0.2.1
- Minor fix to result building in run_iterative_restoration
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PowerModelsRestoration"
uuid = "23adbb12-a187-11e9-26a2-eb4d4e6e68fb"
authors = ["David M Fobes <[email protected]>", "Noah Rhodes"]
version = "0.3.0"
version = "0.4.0"

[deps]
InfrastructureModels = "2030c09a-7f63-5d83-885d-db604e0e9cc0"
Expand All @@ -14,8 +14,8 @@ PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
InfrastructureModels = "~0.4"
JuMP = "~0.19.1, ~0.20, ~0.21"
MathOptInterface = "~0.8, ~0.9"
Memento = "~0.10, ~0.11, ~0.12"
PowerModels = "~0.15.2"
Memento = "~0.10, ~0.11, ~0.12, ~0.13, ~1.0"
PowerModels = "~0.16"
julia = "^1"

[extras]
Expand Down
4 changes: 2 additions & 2 deletions src/PowerModelsRestoration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import InfrastructureModels
import PowerModels
import Memento

const _IMs = InfrastructureModels
const _PMs = PowerModels
const _IM = InfrastructureModels
const _PM = PowerModels

include("core/variable.jl")
include("core/data.jl")
Expand Down
142 changes: 71 additions & 71 deletions src/core/constraint.jl
Original file line number Diff line number Diff line change
@@ -1,175 +1,175 @@
""
function constraint_restoration_cardinality_ub(pm::_PMs.AbstractPowerModel, n::Int, cumulative_repairs::Int)
z_storage = _PMs.var(pm, n, :z_storage)
z_gen = _PMs.var(pm, n, :z_gen)
z_branch = _PMs.var(pm, n, :z_branch)
z_bus = _PMs.var(pm, n, :z_bus)
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 _PMs.ref(pm, n, :damaged_branch))
+ sum(z_gen[i] for (i,gen) in _PMs.ref(pm, n, :damaged_gen))
+ sum(z_storage[i] for (i,storage) in _PMs.ref(pm, n, :damaged_storage))
+ sum(z_bus[i] for (i,bus) in _PMs.ref(pm, n, :damaged_bus))
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :damaged_branch))
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :damaged_gen))
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :damaged_storage))
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :damaged_bus))
<= cumulative_repairs
)
end


""
function constraint_restoration_cardinality_lb(pm::_PMs.AbstractPowerModel, n::Int, cumulative_repairs::Int)
z_storage = _PMs.var(pm, n, :z_storage)
z_gen = _PMs.var(pm, n, :z_gen)
z_branch = _PMs.var(pm, n, :z_branch)
z_bus = _PMs.var(pm, n, :z_bus)
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 _PMs.ref(pm, n, :damaged_branch))
+ sum(z_gen[i] for (i,gen) in _PMs.ref(pm, n, :damaged_gen))
+ sum(z_storage[i] for (i,storage) in _PMs.ref(pm, n, :damaged_storage))
+ sum(z_bus[i] for (i,bus) in _PMs.ref(pm, n, :damaged_bus))
sum(z_branch[i] for (i,branch) in _PM.ref(pm, n, :damaged_branch))
+ sum(z_gen[i] for (i,gen) in _PM.ref(pm, n, :damaged_gen))
+ sum(z_storage[i] for (i,storage) in _PM.ref(pm, n, :damaged_storage))
+ sum(z_bus[i] for (i,bus) in _PM.ref(pm, n, :damaged_bus))
>= cumulative_repairs
)
end


function constraint_restore_all_items(pm, n)
z_demand = _PMs.var(pm, n, :z_demand)
z_shunt = _PMs.var(pm, n, :z_shunt)
z_storage = _PMs.var(pm, n, :z_storage)
z_gen = _PMs.var(pm, n, :z_gen)
z_branch = _PMs.var(pm, n, :z_branch)
z_bus = _PMs.var(pm, n, :z_bus)

for (i,load) in _PMs.ref(pm, n, :load)
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 _PMs.ref(pm, n, :shunt)
for (i,shunt) in _PM.ref(pm, n, :shunt)
JuMP.@constraint(pm.model, z_shunt[i] == 1)
end

for (i,storage) in _PMs.ref(pm, n, :damaged_storage)
for (i,storage) in _PM.ref(pm, n, :damaged_storage)
JuMP.@constraint(pm.model, z_storage[i] == 1)
end
for (i,gen) in _PMs.ref(pm, n, :damaged_gen)
for (i,gen) in _PM.ref(pm, n, :damaged_gen)
JuMP.@constraint(pm.model, z_gen[i] == 1)
end
for (i,branch) in _PMs.ref(pm, n, :damaged_branch)
for (i,branch) in _PM.ref(pm, n, :damaged_branch)
JuMP.@constraint(pm.model, z_branch[i] == 1)
end
for (i,bus) in _PMs.ref(pm, n, :damaged_bus)
for (i,bus) in _PM.ref(pm, n, :damaged_bus)
JuMP.@constraint(pm.model, z_bus[i] == 1)
end
end


""
function constraint_active_gen(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PMs.ref(pm, nw_1, :damaged_gen), i)
z_gen_1 = _PMs.var(pm, nw_1, :z_gen, i)
z_gen_2 = _PMs.var(pm, nw_2, :z_gen, i)
function constraint_active_gen(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :damaged_gen), 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_active_bus(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PMs.ref(pm, nw_1, :damaged_gen), i)
z_bus_1 = _PMs.var(pm, nw_1, :z_bus, i)
z_bus_2 = _PMs.var(pm, nw_2, :z_bus, i)
function constraint_active_bus(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :damaged_gen), 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_active_storage(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PMs.ref(pm, nw_1, :damaged_storage), i)
z_storage_1 = _PMs.var(pm, nw_1, :z_storage, i)
z_storage_2 = _PMs.var(pm, nw_2, :z_storage, i)
function constraint_active_storage(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :damaged_storage), 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_active_branch(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PMs.ref(pm, nw_1, :damaged_branch), i)
z_branch_1 = _PMs.var(pm, nw_1, :z_branch, i)
z_branch_2 = _PMs.var(pm, nw_2, :z_branch, i)
function constraint_active_branch(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
if haskey(_PM.ref(pm, nw_1, :damaged_branch), 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_increasing_load(pm::_PMs.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)
function constraint_increasing_load(pm::_PM.AbstractPowerModel, i::Int, nw_1::Int, nw_2::Int)

z_demand_1 = _PMs.var(pm, nw_1, :z_demand, i)
z_demand_2 = _PMs.var(pm, nw_2, :z_demand, i)
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::_PMs.AbstractPowerModel, n::Int, storage_id::Int, bus_id::Int)
z_storage = _PMs.var(pm, n, :z_storage, storage_id)
z_bus = _PMs.var(pm, n, :z_bus, bus_id)
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::_PMs.AbstractPowerModel, n::Int, gen_id::Int, bus_id::Int)
z_gen = _PMs.var(pm, n, :z_gen, gen_id)
z_bus = _PMs.var(pm, n, :z_bus, bus_id)
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::_PMs.AbstractPowerModel, n::Int, load_id::Int, bus_id::Int)
z_demand = _PMs.var(pm, n, :z_demand, load_id)
z_bus = _PMs.var(pm, n, :z_bus, bus_id)
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::_PMs.AbstractPowerModel, n::Int, shunt_id::Int, bus_id::Int)
z_shunt = _PMs.var(pm, n, :z_shunt, shunt_id)
z_bus = _PMs.var(pm, n, :z_bus, bus_id)
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::_PMs.AbstractPowerModel, n::Int, branch_id::Int, bus_id::Int)
z_branch = _PMs.var(pm, n, :z_branch, branch_id)
z_bus = _PMs.var(pm, n, :z_bus, bus_id)
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::_PMs.AbstractPowerModel, n::Int, i::Int, vmin, vmax)
vm = _PMs.var(pm, n, :vm, i)
z_voltage = _PMs.var(pm, n, :z_voltage, i)
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::_PMs.AbstractPowerModel, n::Int, i::Int, vmin, vmax)
w = _PMs.var(pm, n, :w, i)
z_voltage = _PMs.var(pm, n, :z_voltage, i)
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)
Expand Down
Loading

0 comments on commit fa5c0b9

Please sign in to comment.