mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-10 01:08:52 -06:00
Move graph creation to graph.jl; simplify model.jl
This commit is contained in:
@@ -4,61 +4,54 @@
|
||||
using ReverseManufacturing, Cbc, JuMP, Printf, JSON
|
||||
|
||||
@testset "Model" begin
|
||||
instance = ReverseManufacturing.load("samples/s1")
|
||||
model = ReverseManufacturing.build_model(instance, Cbc.Optimizer)
|
||||
|
||||
# Verify nodes
|
||||
@test ("P1", "Origin", "C1") in keys(model.shipping_nodes)
|
||||
@test ("P1", "Origin", "C3") in keys(model.shipping_nodes)
|
||||
@test ("P1", "Origin", "C8") in keys(model.shipping_nodes)
|
||||
@test ("P2", "F1", "L1") in keys(model.shipping_nodes)
|
||||
@test ("P2", "F1", "L2") in keys(model.shipping_nodes)
|
||||
@test ("P3", "F1", "L1") in keys(model.shipping_nodes)
|
||||
@test ("P3", "F1", "L2") in keys(model.shipping_nodes)
|
||||
@test ("P3", "F2", "L3") in keys(model.shipping_nodes)
|
||||
@test ("P3", "F2", "L4") in keys(model.shipping_nodes)
|
||||
@test ("P4", "F2", "L3") in keys(model.shipping_nodes)
|
||||
@test ("P4", "F2", "L4") in keys(model.shipping_nodes)
|
||||
@test ("P1", "F1", "L1") in keys(model.process_nodes)
|
||||
@test ("P1", "F1", "L2") in keys(model.process_nodes)
|
||||
@test ("P2", "F2", "L3") in keys(model.process_nodes)
|
||||
@test ("P2", "F2", "L4") in keys(model.process_nodes)
|
||||
@test ("P3", "F4", "L6") in keys(model.process_nodes)
|
||||
@test ("P4", "F3", "L5") in keys(model.process_nodes)
|
||||
|
||||
# Verify some arcs
|
||||
p1_orig_c1 = model.shipping_nodes["P1", "Origin", "C1"]
|
||||
p1_f1_l1 = model.process_nodes["P1", "F1", "L1"]
|
||||
@test length(p1_orig_c1.outgoing_arcs) == 2
|
||||
@test length(p1_f1_l1.incoming_arcs) == 10
|
||||
|
||||
arc = p1_orig_c1.outgoing_arcs[1]
|
||||
@test arc.dest.location_name == "L1"
|
||||
@test arc.values["distance"] == 1095.62
|
||||
@test round(arc.costs["transportation"], digits=2) == 16.43
|
||||
@test arc.costs["variable"] == 30.0
|
||||
|
||||
p2_f1_l1 = model.shipping_nodes["P2", "F1", "L1"]
|
||||
p2_f2_l3 = model.process_nodes["P2", "F2", "L3"]
|
||||
@test length(p2_f1_l1.incoming_arcs) == 1
|
||||
@test length(p2_f1_l1.outgoing_arcs) == 2
|
||||
|
||||
arc = p2_f1_l1.incoming_arcs[1]
|
||||
@test arc.values["weight"] == 0.2
|
||||
@test isempty(arc.costs)
|
||||
@testset "build" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = ReverseManufacturing.load("$basedir/../instances/samples/s1.json")
|
||||
graph = ReverseManufacturing.build_graph(instance)
|
||||
model = ReverseManufacturing.build_model(instance, graph, Cbc.Optimizer)
|
||||
|
||||
process_node_by_location_name = Dict(n.plant.location_name => n
|
||||
for n in graph.process_nodes)
|
||||
|
||||
shipping_node_by_location_and_product_names = Dict((n.location.location_name, n.product.name) => n
|
||||
for n in graph.plant_shipping_nodes)
|
||||
|
||||
|
||||
@test length(model.vars.flow) == 38
|
||||
@test length(model.vars.dispose) == 8
|
||||
@test length(model.vars.open_plant) == 6
|
||||
@test length(model.vars.capacity) == 6
|
||||
@test length(model.vars.expansion) == 6
|
||||
|
||||
l1 = process_node_by_location_name["L1"]
|
||||
v = model.vars.capacity[l1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 1000.0
|
||||
|
||||
v = model.vars.expansion[l1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 750.0
|
||||
|
||||
v = model.vars.dispose[shipping_node_by_location_and_product_names["L1", "P2"]]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 1.0
|
||||
|
||||
end
|
||||
|
||||
@testset "build" begin
|
||||
solution = ReverseManufacturing.solve("$(pwd())/../instances/samples/s1.json")
|
||||
# println(JSON.print(solution, 2))
|
||||
|
||||
# @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 "L2" in keys(solution["plants"]["F1"])
|
||||
# @test "total output" in keys(solution["plants"]["F1"]["L2"])
|
||||
|
||||
# @test "capacity" in keys(solution["plants"]["F1"]["L1"])
|
||||
end
|
||||
end
|
||||
|
||||
@testset "Solve" begin
|
||||
solution = ReverseManufacturing.solve("$(pwd())/../instances/samples/s1.json")
|
||||
println(JSON.print(solution, 2))
|
||||
|
||||
@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 "L2" in keys(solution["plants"]["F1"])
|
||||
@test "total output" in keys(solution["plants"]["F1"]["L2"])
|
||||
|
||||
@test "capacity" in keys(solution["plants"]["F1"]["L1"])
|
||||
end
|
||||
Reference in New Issue
Block a user