mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-06 15:48:51 -06:00
Accelerate tests with Revise.jl
This commit is contained in:
@@ -3,35 +3,36 @@
|
||||
|
||||
using RELOG, HiGHS, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
|
||||
@testset "build" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
||||
graph = RELOG.build_graph(instance)
|
||||
model = RELOG.build_model(instance, graph, HiGHS.Optimizer)
|
||||
function model_build_test()
|
||||
@testset "build" begin
|
||||
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||
graph = RELOG.build_graph(instance)
|
||||
model = RELOG.build_model(instance, graph, HiGHS.Optimizer)
|
||||
|
||||
process_node_by_location_name =
|
||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||
process_node_by_location_name =
|
||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||
|
||||
shipping_node_by_loc_and_prod_names = Dict(
|
||||
(n.location.location_name, n.product.name) => n for n in graph.plant_shipping_nodes
|
||||
)
|
||||
shipping_node_by_loc_and_prod_names = Dict(
|
||||
(n.location.location_name, n.product.name) => n for n in graph.plant_shipping_nodes
|
||||
)
|
||||
|
||||
@test length(model[1, :open_plant]) == 12
|
||||
@test length(model[2, :flow]) == 76
|
||||
@test length(model[2, :plant_dispose]) == 16
|
||||
@test length(model[2, :capacity]) == 12
|
||||
@test length(model[2, :expansion]) == 12
|
||||
@test length(model[1, :open_plant]) == 12
|
||||
@test length(model[2, :flow]) == 76
|
||||
@test length(model[2, :plant_dispose]) == 16
|
||||
@test length(model[2, :capacity]) == 12
|
||||
@test length(model[2, :expansion]) == 12
|
||||
|
||||
# l1 = process_node_by_location_name["L1"]
|
||||
# v = model[2, :capacity][l1.index, 1]
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 1000.0
|
||||
# l1 = process_node_by_location_name["L1"]
|
||||
# v = model[2, :capacity][l1.index, 1]
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 1000.0
|
||||
|
||||
# v = model[2, :expansion][l1.index, 1]
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 750.0
|
||||
# v = model[2, :expansion][l1.index, 1]
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 750.0
|
||||
|
||||
# v = model[2, :plant_dispose][shipping_node_by_loc_and_prod_names["L1", "P2"].index, 1]
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 1.0
|
||||
end
|
||||
# v = model[2, :plant_dispose][shipping_node_by_loc_and_prod_names["L1", "P2"].index, 1]
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 1.0
|
||||
end
|
||||
end
|
||||
@@ -5,63 +5,65 @@ using RELOG, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
|
||||
basedir = dirname(@__FILE__)
|
||||
|
||||
@testset "solve (exact)" begin
|
||||
solution = RELOG.solve("$basedir/../../instances/s1.json")
|
||||
function model_solve_test()
|
||||
@testset "solve (exact)" begin
|
||||
solution = RELOG.solve(fixture("instances/s1.json"))
|
||||
|
||||
solution_filename = tempname()
|
||||
RELOG.write(solution, solution_filename)
|
||||
@test isfile(solution_filename)
|
||||
solution_filename = tempname()
|
||||
RELOG.write(solution, solution_filename)
|
||||
@test isfile(solution_filename)
|
||||
|
||||
@test "Costs" in keys(solution)
|
||||
@test "Fixed operating (\$)" in keys(solution["Costs"])
|
||||
@test "Transportation (\$)" in keys(solution["Costs"])
|
||||
@test "Variable operating (\$)" in keys(solution["Costs"])
|
||||
@test "Total (\$)" in keys(solution["Costs"])
|
||||
@test "Costs" in keys(solution)
|
||||
@test "Fixed operating (\$)" in keys(solution["Costs"])
|
||||
@test "Transportation (\$)" in keys(solution["Costs"])
|
||||
@test "Variable operating (\$)" in keys(solution["Costs"])
|
||||
@test "Total (\$)" in keys(solution["Costs"])
|
||||
|
||||
@test "Plants" in keys(solution)
|
||||
@test "F1" in keys(solution["Plants"])
|
||||
@test "F2" in keys(solution["Plants"])
|
||||
@test "F3" in keys(solution["Plants"])
|
||||
@test "F4" in keys(solution["Plants"])
|
||||
@test "Plants" in keys(solution)
|
||||
@test "F1" in keys(solution["Plants"])
|
||||
@test "F2" in keys(solution["Plants"])
|
||||
@test "F3" in keys(solution["Plants"])
|
||||
@test "F4" in keys(solution["Plants"])
|
||||
|
||||
@test "Products" in keys(solution)
|
||||
@test "P1" in keys(solution["Products"])
|
||||
@test "C1" in keys(solution["Products"]["P1"])
|
||||
@test "Dispose (tonne)" in keys(solution["Products"]["P1"]["C1"])
|
||||
@test "Products" in keys(solution)
|
||||
@test "P1" in keys(solution["Products"])
|
||||
@test "C1" in keys(solution["Products"]["P1"])
|
||||
@test "Dispose (tonne)" in keys(solution["Products"]["P1"]["C1"])
|
||||
|
||||
total_disposal =
|
||||
sum([loc["Dispose (tonne)"] for loc in values(solution["Products"]["P1"])])
|
||||
@test total_disposal == [1.0, 1.0]
|
||||
end
|
||||
|
||||
@testset "solve (heuristic)" begin
|
||||
# Should not crash
|
||||
solution = RELOG.solve("$basedir/../../instances/s1.json", heuristic = true)
|
||||
end
|
||||
|
||||
@testset "solve (infeasible)" begin
|
||||
json = JSON.parsefile("$basedir/../../instances/s1.json")
|
||||
for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
||||
location_dict["amount (tonne)"] *= 1000
|
||||
total_disposal =
|
||||
sum([loc["Dispose (tonne)"] for loc in values(solution["Products"]["P1"])])
|
||||
@test total_disposal == [1.0, 1.0]
|
||||
end
|
||||
@test_throws ErrorException("No solution available") RELOG.solve(RELOG.parse(json))
|
||||
end
|
||||
|
||||
@testset "solve (with storage)" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
filename = "$basedir/../fixtures/storage.json"
|
||||
instance = RELOG.parsefile(filename)
|
||||
@test instance.plants[1].storage_limit == 50.0
|
||||
@test instance.plants[1].storage_cost == [2.0, 1.5, 1.0]
|
||||
@testset "solve (heuristic)" begin
|
||||
# Should not crash
|
||||
solution = RELOG.solve(fixture("instances/s1.json"), heuristic = true)
|
||||
end
|
||||
|
||||
solution = RELOG.solve(filename)
|
||||
plant_dict = solution["Plants"]["mega plant"]["Chicago"]
|
||||
@test plant_dict["Variable operating cost (\$)"] == [500.0, 0.0, 100.0]
|
||||
@test plant_dict["Process (tonne)"] == [50.0, 0.0, 50.0]
|
||||
@test plant_dict["Storage (tonne)"] == [50.0, 50.0, 0.0]
|
||||
@test plant_dict["Storage cost (\$)"] == [100.0, 75.0, 0.0]
|
||||
@testset "solve (infeasible)" begin
|
||||
json = JSON.parsefile(fixture("instances/s1.json"))
|
||||
for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
||||
location_dict["amount (tonne)"] *= 1000
|
||||
end
|
||||
@test_throws ErrorException("No solution available") RELOG.solve(RELOG.parse(json))
|
||||
end
|
||||
|
||||
@test solution["Costs"]["Variable operating (\$)"] == [500.0, 0.0, 100.0]
|
||||
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
||||
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
||||
end
|
||||
@testset "solve (with storage)" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
filename = "$basedir/../fixtures/storage.json"
|
||||
instance = RELOG.parsefile(filename)
|
||||
@test instance.plants[1].storage_limit == 50.0
|
||||
@test instance.plants[1].storage_cost == [2.0, 1.5, 1.0]
|
||||
|
||||
solution = RELOG.solve(filename)
|
||||
plant_dict = solution["Plants"]["mega plant"]["Chicago"]
|
||||
@test plant_dict["Variable operating cost (\$)"] == [500.0, 0.0, 100.0]
|
||||
@test plant_dict["Process (tonne)"] == [50.0, 0.0, 50.0]
|
||||
@test plant_dict["Storage (tonne)"] == [50.0, 50.0, 0.0]
|
||||
@test plant_dict["Storage cost (\$)"] == [100.0, 75.0, 0.0]
|
||||
|
||||
@test solution["Costs"]["Variable operating (\$)"] == [500.0, 0.0, 100.0]
|
||||
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
||||
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user