mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-05 23:38:52 -06:00
Implement basic reports; fix boat example
This commit is contained in:
94
test/fixtures/boat_example.ipynb
vendored
94
test/fixtures/boat_example.ipynb
vendored
@@ -2,51 +2,59 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 12,
|
||||
"execution_count": 67,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
"# cities_a = {\n",
|
||||
"# \"Chicago\": [41.881832, -87.623177],\n",
|
||||
"# \"New York City\": [40.712776, -74.005974],\n",
|
||||
"# \"Los Angeles\": [34.052235, -118.243683],\n",
|
||||
"# \"Houston\": [29.760427, -95.369804],\n",
|
||||
"# \"Phoenix\": [33.448376, -112.074036],\n",
|
||||
"# \"Philadelphia\": [39.952583, -75.165222],\n",
|
||||
"# \"San Antonio\": [29.424122, -98.493629],\n",
|
||||
"# \"San Diego\": [32.715736, -117.161087],\n",
|
||||
"# \"Dallas\": [32.776664, -96.796988],\n",
|
||||
"# \"San Jose\": [37.338208, -121.886329],\n",
|
||||
"# \"Austin\": [30.267153, -97.743061],\n",
|
||||
"# \"Jacksonville\": [30.332184, -81.655651],\n",
|
||||
"# \"Fort Worth\": [32.755488, -97.330766],\n",
|
||||
"# \"Columbus\": [39.961176, -82.998794],\n",
|
||||
"# \"Charlotte\": [35.227087, -80.843127],\n",
|
||||
"# \"Indianapolis\": [39.768403, -86.158068],\n",
|
||||
"# \"San Francisco\": [37.774929, -122.419416],\n",
|
||||
"# \"Seattle\": [47.606209, -122.332071],\n",
|
||||
"# \"Denver\": [39.739236, -104.990251],\n",
|
||||
"# \"Washington D.C.\": [38.907192, -77.036871],\n",
|
||||
"# \"Nashville\": [36.162664, -86.781602],\n",
|
||||
"# \"Detroit\": [42.331427, -83.045754],\n",
|
||||
"# \"Oklahoma City\": [35.467560, -97.516428],\n",
|
||||
"# \"Portland\": [45.505106, -122.675026],\n",
|
||||
"# \"Las Vegas\": [36.169941, -115.139830],\n",
|
||||
"# }\n",
|
||||
"\n",
|
||||
"# cities_b = {\n",
|
||||
"# \"Chicago\": [41.881832, -87.623177],\n",
|
||||
"# \"Phoenix\": [33.448376, -112.074036],\n",
|
||||
"# \"Dallas\": [32.776664, -96.796988],\n",
|
||||
"# \"San Jose\": [37.338208, -121.886329],\n",
|
||||
"# \"Seattle\": [47.606209, -122.332071],\n",
|
||||
"# \"Las Vegas\": [36.169941, -115.139830],\n",
|
||||
"# }\n",
|
||||
"\n",
|
||||
"cities_a = {\n",
|
||||
" \"Chicago\": [41.881832, -87.623177],\n",
|
||||
" \"New York City\": [40.712776, -74.005974],\n",
|
||||
" \"Los Angeles\": [34.052235, -118.243683],\n",
|
||||
" \"Houston\": [29.760427, -95.369804],\n",
|
||||
" \"Phoenix\": [33.448376, -112.074036],\n",
|
||||
" \"Philadelphia\": [39.952583, -75.165222],\n",
|
||||
" \"San Antonio\": [29.424122, -98.493629],\n",
|
||||
" \"San Diego\": [32.715736, -117.161087],\n",
|
||||
" \"Dallas\": [32.776664, -96.796988],\n",
|
||||
" \"San Jose\": [37.338208, -121.886329],\n",
|
||||
" \"Austin\": [30.267153, -97.743061],\n",
|
||||
" \"Jacksonville\": [30.332184, -81.655651],\n",
|
||||
" \"Fort Worth\": [32.755488, -97.330766],\n",
|
||||
" \"Columbus\": [39.961176, -82.998794],\n",
|
||||
" \"Charlotte\": [35.227087, -80.843127],\n",
|
||||
" \"Indianapolis\": [39.768403, -86.158068],\n",
|
||||
" \"San Francisco\": [37.774929, -122.419416],\n",
|
||||
" \"Seattle\": [47.606209, -122.332071],\n",
|
||||
" \"Denver\": [39.739236, -104.990251],\n",
|
||||
" \"Washington D.C.\": [38.907192, -77.036871],\n",
|
||||
" \"Nashville\": [36.162664, -86.781602],\n",
|
||||
" \"Detroit\": [42.331427, -83.045754],\n",
|
||||
" \"Oklahoma City\": [35.467560, -97.516428],\n",
|
||||
" \"Portland\": [45.505106, -122.675026],\n",
|
||||
" \"Las Vegas\": [36.169941, -115.139830],\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"cities_b = {\n",
|
||||
" \"Chicago\": [41.881832, -87.623177],\n",
|
||||
" \"Phoenix\": [33.448376, -112.074036],\n",
|
||||
" \"Dallas\": [32.776664, -96.796988],\n",
|
||||
" \"San Jose\": [37.338208, -121.886329],\n",
|
||||
" \"Seattle\": [47.606209, -122.332071],\n",
|
||||
" \"Las Vegas\": [36.169941, -115.139830],\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"parameters = {\n",
|
||||
" \"time horizon (years)\": 10,\n",
|
||||
" \"time horizon (years)\": 1,\n",
|
||||
" \"building period (years)\": [1],\n",
|
||||
" \"distance metric\": \"Euclidean\",\n",
|
||||
"}\n",
|
||||
@@ -54,24 +62,24 @@
|
||||
"nail_factory = {\n",
|
||||
" \"input\": None,\n",
|
||||
" \"outputs\": [\"Nail\"],\n",
|
||||
" \"fixed output (tonne)\": {\"Nail\": 1},\n",
|
||||
" \"fixed output (tonne)\": {\"Nail\": 5},\n",
|
||||
" \"variable output (tonne/tonne)\": {\"Nail\": 0},\n",
|
||||
" \"revenue ($/tonne)\": None,\n",
|
||||
" \"collection cost ($/tonne)\": {\"Nail\": 1000},\n",
|
||||
" \"operating cost ($)\": 0,\n",
|
||||
" \"disposal limit (tonne)\": {\"Nail\": None},\n",
|
||||
" \"disposal limit (tonne)\": {\"Nail\": 0},\n",
|
||||
" \"disposal cost ($/tonne)\": {\"Nail\": 0},\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"forest = {\n",
|
||||
" \"input\": None,\n",
|
||||
" \"outputs\": [\"Wood\"],\n",
|
||||
" \"fixed output (tonne)\": {\"Wood\": 100},\n",
|
||||
" \"fixed output (tonne)\": {\"Wood\": 95},\n",
|
||||
" \"variable output (tonne/tonne)\": {\"Wood\": 0},\n",
|
||||
" \"revenue ($/tonne)\": None,\n",
|
||||
" \"collection cost ($/tonne)\": {\"Wood\": 250},\n",
|
||||
" \"operating cost ($)\": 0,\n",
|
||||
" \"disposal limit (tonne)\": {\"Wood\": None},\n",
|
||||
" \"disposal limit (tonne)\": {\"Wood\": 0},\n",
|
||||
" \"disposal cost ($/tonne)\": {\"Wood\": 0},\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
@@ -80,7 +88,7 @@
|
||||
" \"outputs\": [\"UsedBoat\"],\n",
|
||||
" \"fixed output (tonne)\": {\"UsedBoat\": 0},\n",
|
||||
" \"variable output (tonne/tonne)\": {\"UsedBoat\": [0.10, 0.25, 0.10]},\n",
|
||||
" \"revenue ($/tonne)\": 3_000,\n",
|
||||
" \"revenue ($/tonne)\": 300_000,\n",
|
||||
" \"collection cost ($/tonne)\": {\"UsedBoat\": 100},\n",
|
||||
" \"operating cost ($)\": 125_000,\n",
|
||||
" \"disposal limit (tonne)\": {\"UsedBoat\": 0},\n",
|
||||
@@ -115,7 +123,7 @@
|
||||
" },\n",
|
||||
" \"capacities\": [\n",
|
||||
" {\n",
|
||||
" \"size (tonne)\": 50,\n",
|
||||
" \"size (tonne)\": 200,\n",
|
||||
" \"opening cost ($)\": 10_000,\n",
|
||||
" \"fixed operating cost ($)\": 1_000,\n",
|
||||
" \"variable operating cost ($/tonne)\": 5,\n",
|
||||
@@ -144,7 +152,7 @@
|
||||
" \"Nail\": 0,\n",
|
||||
" \"Wood\": 0,\n",
|
||||
" },\n",
|
||||
" \"disposal limit (tonne)\": {\"Nail\": None, \"Wood\": None},\n",
|
||||
" \"disposal limit (tonne)\": {\"Nail\": 0, \"Wood\": 0},\n",
|
||||
" \"capacities\": [\n",
|
||||
" {\n",
|
||||
" \"size (tonne)\": 50,\n",
|
||||
@@ -166,7 +174,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 13,
|
||||
"execution_count": 68,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -199,8 +207,10 @@
|
||||
" \"longitude (deg)\": city_location[1],\n",
|
||||
" }\n",
|
||||
" for (city_name, city_location) in cities_a.items()\n",
|
||||
" },\n",
|
||||
" \"plants\": {\n",
|
||||
" }\n",
|
||||
" ,\n",
|
||||
" \"plants\":\n",
|
||||
" {\n",
|
||||
" f\"BoatFactory ({city_name})\": {\n",
|
||||
" **boat_factory,\n",
|
||||
" \"latitude (deg)\": city_location[0],\n",
|
||||
@@ -209,7 +219,7 @@
|
||||
" for (city_name, city_location) in cities_a.items()\n",
|
||||
" } | {\n",
|
||||
" f\"RecyclingPlant ({city_name})\": {\n",
|
||||
" **boat_factory,\n",
|
||||
" **recycling_plant,\n",
|
||||
" \"latitude (deg)\": city_location[0],\n",
|
||||
" \"longitude (deg)\": city_location[1],\n",
|
||||
" }\n",
|
||||
|
||||
3054
test/fixtures/boat_example.json
vendored
3054
test/fixtures/boat_example.json
vendored
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ using JuliaFormatter
|
||||
include("instance/parse_test.jl")
|
||||
include("model/build_test.jl")
|
||||
include("model/dist_test.jl")
|
||||
include("reports_test.jl")
|
||||
|
||||
basedir = dirname(@__FILE__)
|
||||
|
||||
@@ -18,9 +19,9 @@ function runtests()
|
||||
@testset "RELOG" begin
|
||||
instance_parse_test_1()
|
||||
instance_parse_test_2()
|
||||
model_build_test_1()
|
||||
model_build_test_2()
|
||||
model_build_test()
|
||||
model_dist_test()
|
||||
report_tests()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using Test
|
||||
using HiGHS
|
||||
using JuMP
|
||||
|
||||
function model_build_test_1()
|
||||
function model_build_test()
|
||||
instance = RELOG.parsefile(fixture("simple.json"))
|
||||
model = RELOG.build_model(instance, optimizer = HiGHS.Optimizer, variable_names = true)
|
||||
y = model[:y]
|
||||
@@ -110,10 +110,3 @@ function model_build_test_1()
|
||||
"eq_disposal_limit[C1,P2,1] : z_disp[C1,P2,1] ≤ 0"
|
||||
@test ("C1", "P3", 1) ∉ keys(model[:eq_disposal_limit])
|
||||
end
|
||||
|
||||
|
||||
function model_build_test_2()
|
||||
instance = RELOG.parsefile(fixture("boat_example.json"))
|
||||
model = RELOG.build_model(instance, optimizer = HiGHS.Optimizer)
|
||||
optimize!(model)
|
||||
end
|
||||
|
||||
12
test/src/reports_test.jl
Normal file
12
test/src/reports_test.jl
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user