mirror of https://github.com/ANL-CEEESA/RELOG.git
parent
06642c631f
commit
319e5f1ed3
@ -0,0 +1,47 @@
|
|||||||
|
# RELOG: Reverse Logistics Optimization
|
||||||
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
using DataFrames
|
||||||
|
using CSV
|
||||||
|
|
||||||
|
function centers_report(model)::DataFrame
|
||||||
|
df = DataFrame()
|
||||||
|
df."center" = String[]
|
||||||
|
df."year" = Int[]
|
||||||
|
df."input product" = String[]
|
||||||
|
df."input amount (tonne)" = Float64[]
|
||||||
|
|
||||||
|
centers = model.ext[:instance].centers
|
||||||
|
T = 1:model.ext[:instance].time_horizon
|
||||||
|
|
||||||
|
for c in centers, t in T
|
||||||
|
input_name = (c.input === nothing) ? "" : c.input.name
|
||||||
|
input = round(value(model[:z_input][c.name, t]), digits = 3)
|
||||||
|
push!(df, [c.name, t, input_name, input])
|
||||||
|
end
|
||||||
|
return df
|
||||||
|
end
|
||||||
|
|
||||||
|
function center_outputs_report(model)::DataFrame
|
||||||
|
df = DataFrame()
|
||||||
|
df."center" = String[]
|
||||||
|
df."output product" = String[]
|
||||||
|
df."year" = Int[]
|
||||||
|
df."amount collected (tonne)" = Float64[]
|
||||||
|
df."amount disposed (tonne)" = Float64[]
|
||||||
|
|
||||||
|
centers = model.ext[:instance].centers
|
||||||
|
T = 1:model.ext[:instance].time_horizon
|
||||||
|
|
||||||
|
for c in centers, m in c.outputs, t in T
|
||||||
|
collected = round(value(model[:z_collected][c.name, m.name, t]), digits = 3)
|
||||||
|
disposed = round(value(model[:z_disp][c.name, m.name, t]), digits = 3)
|
||||||
|
push!(df, [c.name, m.name, t, collected, disposed])
|
||||||
|
end
|
||||||
|
return df
|
||||||
|
end
|
||||||
|
|
||||||
|
write_centers_report(solution, filename) = CSV.write(filename, centers_report(solution))
|
||||||
|
write_center_outputs_report(solution, filename) =
|
||||||
|
CSV.write(filename, center_outputs_report(solution))
|
@ -0,0 +1,49 @@
|
|||||||
|
# RELOG: Reverse Logistics Optimization
|
||||||
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
using DataFrames
|
||||||
|
using CSV
|
||||||
|
|
||||||
|
function plants_report(model)::DataFrame
|
||||||
|
df = DataFrame()
|
||||||
|
df."plant" = String[]
|
||||||
|
df."year" = Int[]
|
||||||
|
df."operational?" = Bool[]
|
||||||
|
df."input amount (tonne)" = Float64[]
|
||||||
|
|
||||||
|
plants = model.ext[:instance].plants
|
||||||
|
T = 1:model.ext[:instance].time_horizon
|
||||||
|
|
||||||
|
for p in plants, t in T
|
||||||
|
operational = JuMP.value(model[:x][p.name, t]) > 0.5
|
||||||
|
input = value(model[:z_input][p.name, t])
|
||||||
|
operational || continue
|
||||||
|
push!(df, [p.name, t, operational, input])
|
||||||
|
end
|
||||||
|
return df
|
||||||
|
end
|
||||||
|
|
||||||
|
function plant_outputs_report(model)::DataFrame
|
||||||
|
df = DataFrame()
|
||||||
|
df."plant" = String[]
|
||||||
|
df."output product" = String[]
|
||||||
|
df."year" = Int[]
|
||||||
|
df."amount produced (tonne)" = Float64[]
|
||||||
|
df."amount disposed (tonne)" = Float64[]
|
||||||
|
|
||||||
|
plants = model.ext[:instance].plants
|
||||||
|
T = 1:model.ext[:instance].time_horizon
|
||||||
|
|
||||||
|
for p in plants, m in keys(p.output), t in T
|
||||||
|
produced = JuMP.value(model[:z_prod][p.name, m.name, t])
|
||||||
|
disposed = JuMP.value(model[:z_disp][p.name, m.name, t])
|
||||||
|
produced > 1e-3 || continue
|
||||||
|
push!(df, [p.name, m.name, t, produced, disposed])
|
||||||
|
end
|
||||||
|
return df
|
||||||
|
end
|
||||||
|
|
||||||
|
write_plants_report(solution, filename) = CSV.write(filename, plants_report(solution))
|
||||||
|
write_plant_outputs_report(solution, filename) =
|
||||||
|
CSV.write(filename, plant_outputs_report(solution))
|
@ -0,0 +1,31 @@
|
|||||||
|
# RELOG: Reverse Logistics Optimization
|
||||||
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
using DataFrames
|
||||||
|
using CSV
|
||||||
|
|
||||||
|
function transportation_report(model)::DataFrame
|
||||||
|
df = DataFrame()
|
||||||
|
df."source" = String[]
|
||||||
|
df."destination" = String[]
|
||||||
|
df."product" = String[]
|
||||||
|
df."year" = Int[]
|
||||||
|
df."amount sent (tonne)" = Float64[]
|
||||||
|
df."distance (km)" = Float64[]
|
||||||
|
|
||||||
|
E = model.ext[:E]
|
||||||
|
distances = model.ext[:distances]
|
||||||
|
T = 1:model.ext[:instance].time_horizon
|
||||||
|
|
||||||
|
for (p1, p2, m) in E, t in T
|
||||||
|
amount = value(model[:y][p1.name, p2.name, m.name, t])
|
||||||
|
amount > 1e-3 || continue
|
||||||
|
distance = distances[p1, p2, m]
|
||||||
|
push!(df, [p1.name, p2.name, m.name, t, amount, distance])
|
||||||
|
end
|
||||||
|
return df
|
||||||
|
end
|
||||||
|
|
||||||
|
write_transportation_report(solution, filename) =
|
||||||
|
CSV.write(filename, transportation_report(solution))
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,12 @@
|
|||||||
|
function report_tests()
|
||||||
|
# Load and solve the boat example
|
||||||
|
instance = RELOG.parsefile(fixture("boat_example.json"))
|
||||||
|
model = RELOG.build_model(instance, optimizer = HiGHS.Optimizer, variable_names = true)
|
||||||
|
optimize!(model)
|
||||||
|
write_to_file(model, "tmp/model.lp")
|
||||||
|
RELOG.write_plants_report(model, "tmp/plants.csv")
|
||||||
|
RELOG.write_plant_outputs_report(model, "tmp/plant_outputs.csv")
|
||||||
|
RELOG.write_centers_report(model, "tmp/centers.csv")
|
||||||
|
RELOG.write_center_outputs_report(model, "tmp/center_outputs.csv")
|
||||||
|
RELOG.write_transportation_report(model, "tmp/transportation.csv")
|
||||||
|
end
|
Loading…
Reference in new issue