Finish multi-period output; update paths

v0.1
Alinson S. Xavier 5 years ago
parent e37d411bf4
commit 8f59322e3f

1
.gitignore vendored

@ -4,3 +4,4 @@ instances/Makefile
instances/run.jl
notebooks
.idea
*.lp

@ -54,15 +54,72 @@
},
"F1": {
"L1": {
"total output": {},
"total output": {
"P2": [
200.0,
200.0
],
"P3": [
500.0,
500.0
]
},
"latitude": 0.0,
"expansion cost": [
750.0,
0.0
],
"output": {
"dispose": {},
"send": {}
"dispose": {
"P2": {
"amount": [
1.0,
1.0
],
"cost": [
-10.0,
-10.0
]
},
"P3": {
"amount": [
1.0,
1.0
],
"cost": [
-10.0,
-10.0
]
}
},
"send": {
"P2": {
"F2": {
"L4": {
"amount": [
199.0,
199.0
],
"latitude": 0.75,
"distance": 85.87,
"longitude": 0.2
}
}
},
"P3": {
"F4": {
"L6": {
"amount": [
499.0,
499.0
],
"latitude": 50.0,
"distance": 6893.41,
"longitude": 50.0
}
}
}
}
},
"longitude": 0.0,
"total input": [
@ -155,7 +212,16 @@
]
},
"L2": {
"total output": {},
"total output": {
"P2": [
747.728,
747.728
],
"P3": [
1869.3199999999997,
1869.3199999999997
]
},
"latitude": 0.5,
"expansion cost": [
3738.6399999999967,
@ -163,7 +229,34 @@
],
"output": {
"dispose": {},
"send": {}
"send": {
"P2": {
"F2": {
"L4": {
"amount": [
747.728,
747.728
],
"latitude": 0.75,
"distance": 43.35,
"longitude": 0.2
}
}
},
"P3": {
"F4": {
"L6": {
"amount": [
1869.3199999999997,
1869.3199999999997
],
"latitude": 50.0,
"distance": 6828.89,
"longitude": 50.0
}
}
}
}
},
"longitude": 0.5,
"total input": [
@ -308,38 +401,17 @@
}
},
"F2": {
"L3": {
"total output": {},
"latitude": 25.0,
"expansion cost": [
0.0,
0.0
],
"output": {
"dispose": {},
"send": {}
},
"longitude": 65.0,
"total input": [
0.0,
0.0
],
"fixed operating cost": [
-0.0,
-0.0
],
"input": {},
"opening cost": [
-0.0,
0.0
],
"capacity": [
0.0,
0.0
]
},
"L4": {
"total output": {},
"total output": {
"P4": [
757.3824000000001,
757.3824000000001
],
"P3": [
47.336400000000005,
47.336400000000005
]
},
"latitude": 0.75,
"expansion cost": [
0.0,
@ -347,7 +419,34 @@
],
"output": {
"dispose": {},
"send": {}
"send": {
"P4": {
"F3": {
"L5": {
"amount": [
757.3824000000001,
757.3824000000001
],
"latitude": 100.0,
"distance": 8811.73,
"longitude": 100.0
}
}
},
"P3": {
"F4": {
"L6": {
"amount": [
47.336400000000005,
47.336400000000005
],
"latitude": 50.0,
"distance": 6824.63,
"longitude": 50.0
}
}
}
}
},
"longitude": 0.2,
"total input": [
@ -513,16 +612,16 @@
130.0
],
"total": [
225924.922057,
216936.282057
225904.922057,
216916.282057
],
"transportation": [
133.464057,
133.464057
],
"disposal": [
0.0,
0.0
-20.0,
-20.0
]
}
}

@ -197,7 +197,7 @@ function get_solution(model::ManufacturingModel)
end
for plant in instance.plants
skip_plant = false
skip_plant = true
process_node = plant_to_process_node[plant]
plant_dict = Dict{Any, Any}(
"input" => Dict(),
@ -261,40 +261,42 @@ function get_solution(model::ManufacturingModel)
output["costs"]["variable operating"] += dict["variable operating cost"]
end
# # Outputs
# for shipping_node in plant_to_shipping_nodes[plant]
# product_name = shipping_node.product.name
# plant_dict["total output"][product_name] = 0.0
# plant_dict["output"]["send"][product_name] = product_dict = Dict()
# disposal_amount = JuMP.value(vars.dispose[shipping_node])
# if disposal_amount > 1e-5
# plant_dict["output"]["dispose"][product_name] = disposal_dict = Dict()
# disposal_dict["amount"] = JuMP.value(model.vars.dispose[shipping_node])
# disposal_dict["cost"] = disposal_dict["amount"] * plant.disposal_cost[shipping_node.product]
# plant_dict["total output"][product_name] += disposal_amount
# output["costs"]["disposal"] += disposal_dict["cost"]
# end
# for a in shipping_node.outgoing_arcs
# val = JuMP.value(vars.flow[a])
# if val <= 1e-3
# continue
# end
# skip_plant = false
# dict = Dict(
# "amount" => val,
# "distance" => a.values["distance"],
# "latitude" => a.dest.location.latitude,
# "longitude" => a.dest.location.longitude,
# )
# if a.dest.location.plant_name ∉ keys(product_dict)
# product_dict[a.dest.location.plant_name] = Dict()
# end
# product_dict[a.dest.location.plant_name][a.dest.location.location_name] = dict
# plant_dict["total output"][product_name] += val
# end
# end
# Outputs
for shipping_node in plant_to_shipping_nodes[plant]
product_name = shipping_node.product.name
plant_dict["total output"][product_name] = zeros(T)
plant_dict["output"]["send"][product_name] = product_dict = Dict()
disposal_amount = [JuMP.value(vars.dispose[shipping_node, t]) for t in 1:T]
if sum(disposal_amount) > 1e-5
skip_plant = false
plant_dict["output"]["dispose"][product_name] = disposal_dict = Dict()
disposal_dict["amount"] = [JuMP.value(model.vars.dispose[shipping_node, t]) for t in 1:T]
disposal_dict["cost"] = [disposal_dict["amount"][t] * plant.disposal_cost[shipping_node.product][t]
for t in 1:T]
plant_dict["total output"][product_name] += disposal_amount
output["costs"]["disposal"] += disposal_dict["cost"]
end
for a in shipping_node.outgoing_arcs
vals = [JuMP.value(vars.flow[a, t]) for t in 1:T]
if sum(vals) <= 1e-3
continue
end
skip_plant = false
dict = Dict(
"amount" => vals,
"distance" => a.values["distance"],
"latitude" => a.dest.location.latitude,
"longitude" => a.dest.location.longitude,
)
if a.dest.location.plant_name keys(product_dict)
product_dict[a.dest.location.plant_name] = Dict()
end
product_dict[a.dest.location.plant_name][a.dest.location.location_name] = dict
plant_dict["total output"][product_name] += vals
end
end
if !skip_plant
if plant.plant_name keys(output["plants"])

@ -6,7 +6,7 @@ using ReverseManufacturing
@testset "Graph" begin
@testset "build_graph" begin
basedir = dirname(@__FILE__)
instance = ReverseManufacturing.load("$basedir/../instances/samples/s1.json")
instance = ReverseManufacturing.load("$basedir/../instances/s1.json")
graph = ReverseManufacturing.build_graph(instance)
process_node_by_location_name = Dict(n.location.location_name => n
for n in graph.process_nodes)

@ -6,7 +6,7 @@ using ReverseManufacturing
@testset "Instance" begin
@testset "load" begin
basedir = dirname(@__FILE__)
instance = ReverseManufacturing.load("$basedir/../instances/samples/s1.json")
instance = ReverseManufacturing.load("$basedir/../instances/s1.json")
centers = instance.collection_centers
plants = instance.plants

@ -6,7 +6,7 @@ using ReverseManufacturing, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormat
@testset "Model" begin
@testset "build" begin
basedir = dirname(@__FILE__)
instance = ReverseManufacturing.load("$basedir/../instances/samples/s1.json")
instance = ReverseManufacturing.load("$basedir/../instances/s1.json")
graph = ReverseManufacturing.build_graph(instance)
model = ReverseManufacturing.build_model(instance, graph, Cbc.Optimizer)
@ -43,8 +43,8 @@ using ReverseManufacturing, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormat
end
@testset "solve" begin
solution = ReverseManufacturing.solve("$(pwd())/../instances/samples/s1.json")
#JSON.print(stdout, solution, 4)
solution = ReverseManufacturing.solve("$(pwd())/../instances/s1.json")
JSON.print(stdout, solution, 4)
@test "costs" in keys(solution)
@test "fixed operating" in keys(solution["costs"])

Loading…
Cancel
Save