-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement basic reports; fix boat example
- Loading branch information
Showing
11 changed files
with
280 additions
and
3,144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ authors = ["Alinson S. Xavier <[email protected]>"] | |
version = "0.1.0" | ||
|
||
[deps] | ||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" | ||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" | ||
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d" | ||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" | ||
JuMP = "4076af6c-e467-56ae-b986-b466b2749572" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.