Implement first version of multi-period simulations

This commit is contained in:
2020-05-05 19:08:09 -05:00
parent f970dca68d
commit 9f6bfef327
10 changed files with 334 additions and 237 deletions

View File

@@ -8,7 +8,7 @@ using ReverseManufacturing
basedir = dirname(@__FILE__)
instance = ReverseManufacturing.load("$basedir/../instances/samples/s1.json")
graph = ReverseManufacturing.build_graph(instance)
process_node_by_location_name = Dict(n.plant.location_name => n
process_node_by_location_name = Dict(n.location.location_name => n
for n in graph.process_nodes)
@test length(graph.plant_shipping_nodes) == 8
@@ -20,19 +20,19 @@ using ReverseManufacturing
@test length(node.incoming_arcs) == 0
@test length(node.outgoing_arcs) == 2
@test node.outgoing_arcs[1].source.location.name == "C1"
@test node.outgoing_arcs[1].dest.plant.plant_name == "F1"
@test node.outgoing_arcs[1].dest.plant.location_name == "L1"
@test node.outgoing_arcs[1].dest.location.plant_name == "F1"
@test node.outgoing_arcs[1].dest.location.location_name == "L1"
@test node.outgoing_arcs[1].values["distance"] == 1095.62
node = process_node_by_location_name["L1"]
@test node.plant.plant_name == "F1"
@test node.plant.location_name == "L1"
@test node.location.plant_name == "F1"
@test node.location.location_name == "L1"
@test length(node.incoming_arcs) == 10
@test length(node.outgoing_arcs) == 2
node = process_node_by_location_name["L3"]
@test node.plant.plant_name == "F2"
@test node.plant.location_name == "L3"
@test node.location.plant_name == "F2"
@test node.location.location_name == "L3"
@test length(node.incoming_arcs) == 2
@test length(node.outgoing_arcs) == 2

View File

@@ -21,7 +21,7 @@ using ReverseManufacturing
@test centers[1].latitude == 7
@test centers[1].latitude == 7
@test centers[1].longitude == 7
@test centers[1].amount == 934.56
@test centers[1].amount == [934.56, 934.56]
@test centers[1].product.name == "P1"
@test length(plants) == 6
@@ -32,40 +32,40 @@ using ReverseManufacturing
@test plant.input.name == "P1"
@test plant.latitude == 0
@test plant.longitude == 0
@test plant.opening_cost == 500
@test plant.fixed_operating_cost == 30
@test plant.variable_operating_cost == 30
@test plant.opening_cost == [500, 500]
@test plant.fixed_operating_cost == [30, 30]
@test plant.variable_operating_cost == [30, 30]
@test plant.base_capacity == 250
@test plant.max_capacity == 1000
@test plant.expansion_cost == 1
@test plant.expansion_cost == [1, 1]
p2 = product_name_to_product["P2"]
p3 = product_name_to_product["P3"]
@test length(plant.output) == 2
@test plant.output[p2] == 0.2
@test plant.output[p3] == 0.5
@test plant.disposal_limit[p2] == 1
@test plant.disposal_limit[p3] == 1
@test plant.disposal_cost[p2] == -10
@test plant.disposal_cost[p3] == -10
@test plant.disposal_limit[p2] == [1, 1]
@test plant.disposal_limit[p3] == [1, 1]
@test plant.disposal_cost[p2] == [-10, -10]
@test plant.disposal_cost[p3] == [-10, -10]
plant = location_name_to_plant["L3"]
@test plant.location_name == "L3"
@test plant.input.name == "P2"
@test plant.latitude == 25
@test plant.longitude == 65
@test plant.opening_cost == 3000
@test plant.fixed_operating_cost == 50
@test plant.variable_operating_cost == 50
@test plant.opening_cost == [3000, 3000]
@test plant.fixed_operating_cost == [50, 50]
@test plant.variable_operating_cost == [50, 50]
@test plant.base_capacity == 1e8
@test plant.max_capacity == 1e8
@test plant.expansion_cost == 0
@test plant.expansion_cost == [0, 0]
p4 = product_name_to_product["P4"]
@test plant.output[p3] == 0.05
@test plant.output[p4] == 0.8
@test plant.disposal_limit[p3] == 0.0
@test plant.disposal_limit[p4] == 0.0
@test plant.disposal_limit[p3] == [0, 0]
@test plant.disposal_limit[p4] == [0, 0]
end
end

View File

@@ -1,7 +1,7 @@
# Copyright (C) 2020 Argonne National Laboratory
# Written by Alinson Santos Xavier <axavier@anl.gov>
using ReverseManufacturing, Cbc, JuMP, Printf, JSON
using ReverseManufacturing, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
@testset "Model" begin
@testset "build" begin
@@ -10,42 +10,46 @@ using ReverseManufacturing, Cbc, JuMP, Printf, 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
process_node_by_location_name = Dict(n.location.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
@test length(model.vars.flow) == 76
@test length(model.vars.dispose) == 16
@test length(model.vars.open_plant) == 12
@test length(model.vars.capacity) == 12
@test length(model.vars.expansion) == 12
l1 = process_node_by_location_name["L1"]
v = model.vars.capacity[l1]
v = model.vars.capacity[l1, 1]
@test lower_bound(v) == 0.0
@test upper_bound(v) == 1000.0
v = model.vars.expansion[l1]
v = model.vars.expansion[l1, 1]
@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"]]
v = model.vars.dispose[shipping_node_by_location_and_product_names["L1", "P2"], 1]
@test lower_bound(v) == 0.0
@test upper_bound(v) == 1.0
dest = FileFormats.Model(format = FileFormats.FORMAT_LP)
MOI.copy_to(dest, model.mip)
MOI.write_to_file(dest, "model.lp")
end
@testset "solve" begin
solution = ReverseManufacturing.solve("$(pwd())/../instances/samples/s1.json")
JSON.print(stdout, solution, 4)
#JSON.print(stdout, solution, 4)
@test "costs" in keys(solution)
@test "fixed" in keys(solution["costs"])
@test "fixed operating" in keys(solution["costs"])
@test "transportation" in keys(solution["costs"])
@test "variable" in keys(solution["costs"])
@test "variable operating" in keys(solution["costs"])
@test "total" in keys(solution["costs"])
@test "plants" in keys(solution)
@@ -53,10 +57,6 @@ using ReverseManufacturing, Cbc, JuMP, Printf, JSON
@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