mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-06 07:48:50 -06:00
Initial version
This commit is contained in:
18
test/instance_test.jl
Normal file
18
test/instance_test.jl
Normal file
@@ -0,0 +1,18 @@
|
||||
# Copyright (C) 2020 Argonne National Laboratory
|
||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||
|
||||
using ReverseManufacturing
|
||||
|
||||
@testset "Instance" begin
|
||||
instance = ReverseManufacturing.load("samples/s1")
|
||||
plants, products = instance.plants, instance.products
|
||||
@test length(products) == 4
|
||||
|
||||
@test sort(collect(keys(plants))) == ["F1", "F2", "F3", "F4"]
|
||||
@test plants["F1"]["input product"] == products["P1"]
|
||||
|
||||
@test sort(collect(keys(products))) == ["P1", "P2", "P3", "P4"]
|
||||
@test products["P1"]["input plants"] == [plants["F1"]]
|
||||
@test products["P1"]["transportation cost"] == 1.5
|
||||
@test products["P1"]["initial amounts"]["C1"]["latitude"] == 7.0
|
||||
end
|
||||
74
test/model_test.jl
Normal file
74
test/model_test.jl
Normal file
@@ -0,0 +1,74 @@
|
||||
# Copyright (C) 2020 Argonne National Laboratory
|
||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||
|
||||
using ReverseManufacturing, Cbc, JuMP, Printf
|
||||
|
||||
@testset "Model" begin
|
||||
instance = ReverseManufacturing.load("samples/s1")
|
||||
model = ReverseManufacturing.build_model(instance, with_optimizer(Cbc.Optimizer))
|
||||
|
||||
# Verify nodes
|
||||
@test ("P1", "Origin", "C1") in keys(model.decision_nodes)
|
||||
@test ("P1", "Origin", "C3") in keys(model.decision_nodes)
|
||||
@test ("P1", "Origin", "C8") in keys(model.decision_nodes)
|
||||
@test ("P2", "F1", "L1") in keys(model.decision_nodes)
|
||||
@test ("P2", "F1", "L2") in keys(model.decision_nodes)
|
||||
@test ("P3", "F1", "L1") in keys(model.decision_nodes)
|
||||
@test ("P3", "F1", "L2") in keys(model.decision_nodes)
|
||||
@test ("P3", "F2", "L3") in keys(model.decision_nodes)
|
||||
@test ("P3", "F2", "L4") in keys(model.decision_nodes)
|
||||
@test ("P4", "F2", "L3") in keys(model.decision_nodes)
|
||||
@test ("P4", "F2", "L4") in keys(model.decision_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.decision_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) == 1643.43
|
||||
@test arc.costs["variable"] == 70.0
|
||||
|
||||
p2_f1_l1 = model.decision_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)
|
||||
|
||||
# @show model.mip
|
||||
# JuMP.optimize!(model.mip)
|
||||
|
||||
# values = Dict(a => JuMP.value(model.vars.flow[a]) for a in model.arcs)
|
||||
# @printf("source,dest,amount\n")
|
||||
# for (arc, value) in values
|
||||
# if value > 1e-6
|
||||
# @printf("%s-%s-%s,%s-%s-%s,%.2f\n",
|
||||
# arc.source.plant_name,
|
||||
# arc.source.location_name,
|
||||
# arc.source.product_name,
|
||||
# arc.dest.plant_name,
|
||||
# arc.dest.location_name,
|
||||
# arc.dest.product_name,
|
||||
# value)
|
||||
# end
|
||||
# end
|
||||
|
||||
# for a in model.arcs
|
||||
# @printf("%20s\t%20s\t%8.2f\n",
|
||||
# "$(a.source.product_name) $(a.source.plant_name) $(a.source.location_name)",
|
||||
# "$(a.dest.product_name) $(a.dest.plant_name) $(a.dest.location_name)",
|
||||
# a.weight)
|
||||
# end
|
||||
end
|
||||
9
test/runtests.jl
Normal file
9
test/runtests.jl
Normal file
@@ -0,0 +1,9 @@
|
||||
# Copyright (C) 2020 Argonne National Laboratory
|
||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||
|
||||
using Test
|
||||
|
||||
@testset "ReverseManufacturing" begin
|
||||
include("instance_test.jl")
|
||||
include("model_test.jl")
|
||||
end
|
||||
Reference in New Issue
Block a user