-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add template problem and tests for maximal demand delivery specificat…
…ion.
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
function solve_mdd(network, model_constructor, optimizer; kwargs...) | ||
return solve_model(network, model_constructor, optimizer, build_mdd; kwargs...) | ||
end | ||
|
||
|
||
function run_mdd(network, model_constructor, optimizer; kwargs...) | ||
Memento.warn(_LOGGER, "\"run_\" methods should be renamed \"solve_\" and will be deprecated in future versions.") | ||
return solve_owf(network, model_constructor, optimizer; kwargs...) | ||
end | ||
|
||
|
||
function solve_mn_mdd(file, model_constructor, optimizer; kwargs...) | ||
return solve_model(file, model_constructor, optimizer, build_mn_mdd; multinetwork=true, kwargs...) | ||
end | ||
|
||
|
||
function run_mn_mdd(network, model_constructor, optimizer; kwargs...) | ||
Memento.warn(_LOGGER, "\"run_\" methods should be renamed \"solve_\" and will be deprecated in future versions.") | ||
return solve_mn_mdd(network, model_constructor, optimizer; kwargs...) | ||
end | ||
|
||
|
||
function build_mdd(wm::AbstractWaterModel) | ||
# Build the water flow problem. | ||
build_wf(wm) | ||
|
||
# Add the demand maximization objective. | ||
objective_max_demand(wm) | ||
end | ||
|
||
|
||
function build_mn_mdd(wm::AbstractWaterModel) | ||
# Build the water flow problem. | ||
build_mn_wf(wm) | ||
|
||
# Add the demand maximization objective. | ||
objective_max_demand(wm) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Iterate over all possible WaterModels formulations. | ||
for formulation in [NCWaterModel, NCDWaterModel, CRDWaterModel, LAWaterModel, LRDWaterModel, PWLRDWaterModel] | ||
@testset "Maximal Demand Delivery Problems (Single Network): $(formulation)" begin | ||
network = WaterModels.parse_file("../test/data/epanet/snapshot/pump-hw-lps.inp") | ||
set_flow_partitions_si!(network, 10.0, 1.0e-4) | ||
t_h = WaterModels._calc_head_per_unit_transform(network) | ||
|
||
wm = instantiate_model(network, formulation, build_mdd) | ||
result = WaterModels.optimize_model!(wm, optimizer = _choose_solver(wm, ipopt, cbc)) | ||
|
||
@test _is_valid_status(result["termination_status"]) | ||
@test isapprox(result["solution"]["node"]["1"]["h"], t_h(10.0), rtol = 1.0e-3) | ||
@test isapprox(result["solution"]["pump"]["1"]["status"], 1.0, atol = 1.0e-3) | ||
@test result["solution"]["node"]["2"]["h"] > t_h(10.0) | ||
|
||
# In some relaxations, the objective may be near zero. | ||
@test result["objective"] >= -1.0e-6 | ||
end | ||
|
||
@testset "Maximal Demand Delivery Problems (Multinetwork): $(formulation)" begin | ||
network = WaterModels.parse_file("../test/data/epanet/multinetwork/owf-hw-lps.inp") | ||
network_mn = WaterModels.make_multinetwork(network) | ||
set_flow_partitions_si!(network_mn, 10.0, 1.0e-4) | ||
|
||
wm = instantiate_model(network_mn, formulation, build_mn_mdd) | ||
result = WaterModels.optimize_model!(wm, optimizer = _choose_solver(wm, ipopt, cbc)) | ||
|
||
@test _is_valid_status(result["termination_status"]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters