mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-05 23:38:52 -06:00
Conclude model implementation
This commit is contained in:
4
test/fixtures/simple.json
vendored
4
test/fixtures/simple.json
vendored
@@ -49,8 +49,8 @@
|
||||
"P3": [20, 10, 0, 0]
|
||||
},
|
||||
"variable output (tonne/tonne)": {
|
||||
"P2": [0.12, 0.25, 0.12, 0.0],
|
||||
"P3": [0.25, 0.25, 0.25, 0.0]
|
||||
"P2": [0.20, 0.25, 0.12],
|
||||
"P3": [0.25, 0.25, 0.25]
|
||||
},
|
||||
"revenue ($/tonne)": 12.0,
|
||||
"collection cost ($/tonne)": {
|
||||
|
||||
@@ -18,7 +18,8 @@ function runtests()
|
||||
@testset "RELOG" begin
|
||||
instance_parse_test_1()
|
||||
instance_parse_test_2()
|
||||
model_build_test()
|
||||
model_build_test_1()
|
||||
model_build_test_2()
|
||||
model_dist_test()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,8 +31,7 @@ function instance_parse_test_1()
|
||||
@test c1.input === p1
|
||||
@test c1.outputs == [p2, p3]
|
||||
@test c1.fixed_output == Dict(p2 => [100, 50, 0, 0], p3 => [20, 10, 0, 0])
|
||||
@test c1.var_output ==
|
||||
Dict(p2 => [0.12, 0.25, 0.12, 0.0], p3 => [0.25, 0.25, 0.25, 0.0])
|
||||
@test c1.var_output == Dict(p2 => [0.2, 0.25, 0.12], p3 => [0.25, 0.25, 0.25])
|
||||
@test c1.revenue == [12.0, 12.0, 12.0, 12.0]
|
||||
@test c1.operating_cost == [150.0, 150.0, 150.0, 150.0]
|
||||
@test c1.disposal_limit == Dict(p2 => [0, 0, 0, 0], p3 => [Inf, Inf, Inf, Inf])
|
||||
|
||||
@@ -3,7 +3,7 @@ using Test
|
||||
using HiGHS
|
||||
using JuMP
|
||||
|
||||
function model_build_test()
|
||||
function model_build_test_1()
|
||||
instance = RELOG.parsefile(fixture("simple.json"))
|
||||
model = RELOG.build_model(instance, optimizer = HiGHS.Optimizer, variable_names = true)
|
||||
y = model[:y]
|
||||
@@ -50,34 +50,70 @@ function model_build_test()
|
||||
|
||||
# Plants: Must meet input mix
|
||||
@test repr(model[:eq_input_mix]["L1", "P1", 1]) ==
|
||||
"eq_input_mix[L1,P1,1] : y[C2,L1,P1,1] - 0.953 z_input[L1,1] = 0"
|
||||
"eq_input_mix[L1,P1,1] : y[C2,L1,P1,1] - 0.953 z_input[L1,1] = 0"
|
||||
@test repr(model[:eq_input_mix]["L1", "P2", 1]) ==
|
||||
"eq_input_mix[L1,P2,1] : y[C1,L1,P2,1] - 0.047 z_input[L1,1] = 0"
|
||||
"eq_input_mix[L1,P2,1] : y[C1,L1,P2,1] - 0.047 z_input[L1,1] = 0"
|
||||
|
||||
# Plants: Calculate amount produced
|
||||
@test repr(model[:eq_z_prod]["L1", "P3", 1]) ==
|
||||
"eq_z_prod[L1,P3,1] : z_prod[L1,P3,1] - 0.25 z_input[L1,1] = 0"
|
||||
"eq_z_prod[L1,P3,1] : z_prod[L1,P3,1] - 0.25 z_input[L1,1] = 0"
|
||||
@test repr(model[:eq_z_prod]["L1", "P4", 1]) ==
|
||||
"eq_z_prod[L1,P4,1] : z_prod[L1,P4,1] - 0.12 z_input[L1,1] = 0"
|
||||
"eq_z_prod[L1,P4,1] : z_prod[L1,P4,1] - 0.12 z_input[L1,1] = 0"
|
||||
|
||||
# Plants: Produced material must be sent or disposed
|
||||
@test repr(model[:eq_balance]["L1", "P3", 1]) ==
|
||||
"eq_balance[L1,P3,1] : z_prod[L1,P3,1] - z_disp[L1,P3,1] = 0"
|
||||
"eq_balance[L1,P3,1] : z_prod[L1,P3,1] - z_disp[L1,P3,1] = 0"
|
||||
@test repr(model[:eq_balance]["L1", "P4", 1]) ==
|
||||
"eq_balance[L1,P4,1] : -y[L1,C3,P4,1] + z_prod[L1,P4,1] - z_disp[L1,P4,1] = 0"
|
||||
"eq_balance[L1,P4,1] : -y[L1,C3,P4,1] + z_prod[L1,P4,1] - z_disp[L1,P4,1] = 0"
|
||||
|
||||
# Plants: Capacity limit
|
||||
@test repr(model[:eq_capacity]["L1", 1]) ==
|
||||
"eq_capacity[L1,1] : -100 x[L1,1] + z_input[L1,1] ≤ 0"
|
||||
"eq_capacity[L1,1] : -100 x[L1,1] + z_input[L1,1] ≤ 0"
|
||||
|
||||
# Plants: Disposal limit
|
||||
@test repr(model[:eq_disposal_limit]["L1", "P4", 1]) ==
|
||||
"eq_disposal_limit[L1,P4,1] : z_disp[L1,P4,1] ≤ 1000"
|
||||
"eq_disposal_limit[L1,P4,1] : z_disp[L1,P4,1] ≤ 1000"
|
||||
@test ("L1", "P3", 1) ∉ keys(model[:eq_disposal_limit])
|
||||
|
||||
# Plants: Plant remains open
|
||||
@test repr(model[:eq_keep_open]["L1", 4]) ==
|
||||
"eq_keep_open[L1,4] : -x[L1,3] + x[L1,4] ≥ 0"
|
||||
"eq_keep_open[L1,4] : -x[L1,3] + x[L1,4] ≥ 0"
|
||||
@test repr(model[:eq_keep_open]["L1", 1]) == "eq_keep_open[L1,1] : x[L1,1] ≥ 0"
|
||||
|
||||
# Plants: Building period
|
||||
@test ("L1", 1) ∉ keys(model[:eq_building_period])
|
||||
@test repr(model[:eq_building_period]["L1", 2]) ==
|
||||
"eq_building_period[L1,2] : x[L1,2] = 0"
|
||||
|
||||
# Centers: Definition of total center input
|
||||
@test repr(model[:eq_z_input]["C1", 1]) ==
|
||||
"eq_z_input[C1,1] : -y[C2,C1,P1,1] + z_input[C1,1] = 0"
|
||||
|
||||
# Centers: Calculate amount collected
|
||||
@test repr(model[:eq_z_collected]["C1", "P2", 1]) ==
|
||||
"eq_z_collected[C1,P2,1] : -0.2 z_input[C1,1] + z_collected[C1,P2,1] = 100"
|
||||
@test repr(model[:eq_z_collected]["C1", "P2", 2]) ==
|
||||
"eq_z_collected[C1,P2,2] : -0.25 z_input[C1,1] - 0.2 z_input[C1,2] + z_collected[C1,P2,2] = 50"
|
||||
@test repr(model[:eq_z_collected]["C1", "P2", 3]) ==
|
||||
"eq_z_collected[C1,P2,3] : -0.12 z_input[C1,1] - 0.25 z_input[C1,2] - 0.2 z_input[C1,3] + z_collected[C1,P2,3] = 0"
|
||||
@test repr(model[:eq_z_collected]["C1", "P2", 4]) ==
|
||||
"eq_z_collected[C1,P2,4] : -0.12 z_input[C1,2] - 0.25 z_input[C1,3] - 0.2 z_input[C1,4] + z_collected[C1,P2,4] = 0"
|
||||
|
||||
# Centers: Collected products must be disposed or sent
|
||||
@test repr(model[:eq_balance]["C1", "P2", 1]) ==
|
||||
"eq_balance[C1,P2,1] : -y[C1,L1,P2,1] - z_disp[C1,P2,1] + z_collected[C1,P2,1] = 0"
|
||||
@test repr(model[:eq_balance]["C1", "P3", 1]) ==
|
||||
"eq_balance[C1,P3,1] : -z_disp[C1,P3,1] + z_collected[C1,P3,1] = 0"
|
||||
|
||||
# Centers: Disposal limit
|
||||
@test repr(model[:eq_disposal_limit]["C1", "P2", 1]) ==
|
||||
"eq_disposal_limit[C1,P2,1] : z_disp[C1,P2,1] ≤ 0"
|
||||
@test ("C1", "P3", 1) ∉ keys(model[:eq_disposal_limit])
|
||||
end
|
||||
|
||||
|
||||
function model_build_test_2()
|
||||
instance = RELOG.parsefile(fixture("boat_example.json"))
|
||||
model = RELOG.build_model(instance, optimizer = HiGHS.Optimizer)
|
||||
optimize!(model)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user