mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-05 23:38:52 -06:00
Finish implementing parser
This commit is contained in:
26
test/fixtures/boat_example.ipynb
vendored
26
test/fixtures/boat_example.ipynb
vendored
@@ -2,7 +2,7 @@
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -54,31 +54,31 @@
|
||||
"nail_factory = {\n",
|
||||
" \"input\": None,\n",
|
||||
" \"outputs\": [\"Nail\"],\n",
|
||||
" \"fixed output (tonne)\": 1,\n",
|
||||
" \"variable output (tonne/tonne)\": {},\n",
|
||||
" \"fixed output (tonne)\": {\"Nail\": 1},\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)\": 1e5,\n",
|
||||
" \"disposal limit (tonne)\": {\"Nail\": None},\n",
|
||||
" \"disposal cost ($/tonne)\": {\"Nail\": 0},\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"forest = {\n",
|
||||
" \"input\": None,\n",
|
||||
" \"outputs\": [\"Wood\"],\n",
|
||||
" \"fixed output (tonne)\": 100,\n",
|
||||
" \"variable output (tonne/tonne)\": {},\n",
|
||||
" \"fixed output (tonne)\": {\"Wood\": 100},\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)\": 1e5,\n",
|
||||
" \"disposal limit (tonne)\": {\"Wood\": None},\n",
|
||||
" \"disposal cost ($/tonne)\": {\"Wood\": 0},\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"retail = {\n",
|
||||
" \"input\": \"NewBoat\",\n",
|
||||
" \"outputs\": [\"UsedBoat\"],\n",
|
||||
" \"fixed output (tonne)\": 0,\n",
|
||||
" \"fixed output (tonne)\": {\"UsedBoat\": 0},\n",
|
||||
" \"variable output (tonne/tonne)\": {\"UsedBoat\": [0.10, 0.25, 0.10]},\n",
|
||||
" \"revenue ($/tonne)\": 3_000,\n",
|
||||
" \"collection cost ($/tonne)\": {\"UsedBoat\": 100},\n",
|
||||
@@ -115,13 +115,13 @@
|
||||
" },\n",
|
||||
" \"capacities\": [\n",
|
||||
" {\n",
|
||||
" \"size\": 50,\n",
|
||||
" \"size (tonne)\": 50,\n",
|
||||
" \"opening cost ($)\": 10_000,\n",
|
||||
" \"fixed operating cost ($)\": 1_000,\n",
|
||||
" \"variable operating cost ($/tonne)\": 5,\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"size\": 500,\n",
|
||||
" \"size (tonne)\": 500,\n",
|
||||
" \"opening cost ($)\": 20_000,\n",
|
||||
" \"fixed operating cost ($)\": 2_000,\n",
|
||||
" \"variable operating cost ($/tonne)\": 5,\n",
|
||||
@@ -147,13 +147,13 @@
|
||||
" \"disposal limit (tonne)\": {\"Nail\": None, \"Wood\": None},\n",
|
||||
" \"capacities\": [\n",
|
||||
" {\n",
|
||||
" \"size\": 50,\n",
|
||||
" \"size (tonne)\": 50,\n",
|
||||
" \"opening cost ($)\": 5_000,\n",
|
||||
" \"fixed operating cost ($)\": 500,\n",
|
||||
" \"variable operating cost ($/tonne)\": 2.5,\n",
|
||||
" },\n",
|
||||
" {\n",
|
||||
" \"size\": 500,\n",
|
||||
" \"size (tonne)\": 500,\n",
|
||||
" \"opening cost ($)\": 10_000,\n",
|
||||
" \n",
|
||||
" \"fixed operating cost ($)\": 1_000,\n",
|
||||
@@ -166,7 +166,7 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
|
||||
444
test/fixtures/boat_example.json
vendored
444
test/fixtures/boat_example.json
vendored
File diff suppressed because it is too large
Load Diff
48
test/fixtures/simple.json
vendored
48
test/fixtures/simple.json
vendored
@@ -103,5 +103,53 @@
|
||||
"disposal limit (tonne)": {},
|
||||
"disposal cost ($/tonne)": {}
|
||||
}
|
||||
},
|
||||
"plants": {
|
||||
"L1": {
|
||||
"latitude (deg)": 41.881,
|
||||
"longitude (deg)": -87.623,
|
||||
"input mix (%)": {
|
||||
"P1": 95.3,
|
||||
"P2": 4.7
|
||||
},
|
||||
"output (tonne)": {
|
||||
"P3": 0.25,
|
||||
"P4": 0.12
|
||||
},
|
||||
"processing emissions (tonne)": {
|
||||
"CO2": 0.1
|
||||
},
|
||||
"storage cost ($/tonne)": {
|
||||
"P1": 0.1,
|
||||
"P2": 0.1
|
||||
},
|
||||
"storage limit (tonne)": {
|
||||
"P1": 100,
|
||||
"P2": null
|
||||
},
|
||||
"disposal cost ($/tonne)": {
|
||||
"P3": 0,
|
||||
"P4": 0.86
|
||||
},
|
||||
"disposal limit (tonne)": {
|
||||
"P3": null,
|
||||
"P4": 1000.0
|
||||
},
|
||||
"capacities": [
|
||||
{
|
||||
"size (tonne)": 100,
|
||||
"opening cost ($)": 500,
|
||||
"fixed operating cost ($)": 300,
|
||||
"variable operating cost ($/tonne)": 5.0
|
||||
},
|
||||
{
|
||||
"size (tonne)": 500,
|
||||
"opening cost ($)": 1000.0,
|
||||
"fixed operating cost ($)": 400.0,
|
||||
"variable operating cost ($/tonne)": 5.0
|
||||
}
|
||||
],
|
||||
"initial capacity (tonne)": 150
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,8 @@ end
|
||||
|
||||
function runtests()
|
||||
@testset "RELOG" begin
|
||||
instance_parse_test()
|
||||
instance_parse_test_1()
|
||||
instance_parse_test_2()
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ using RELOG
|
||||
using Test
|
||||
using OrderedCollections
|
||||
|
||||
function instance_parse_test()
|
||||
function instance_parse_test_1()
|
||||
instance = RELOG.parsefile(fixture("simple.json"))
|
||||
|
||||
# Parameters
|
||||
@@ -21,6 +21,7 @@ function instance_parse_test()
|
||||
@test instance.products_by_name["P1"] === p1
|
||||
p2 = instance.products[2]
|
||||
p3 = instance.products[3]
|
||||
p4 = instance.products[4]
|
||||
|
||||
# Centers
|
||||
@test length(instance.centers) == 3
|
||||
@@ -41,4 +42,36 @@ function instance_parse_test()
|
||||
@test c2.input === nothing
|
||||
@test c2.revenue == [0, 0, 0, 0]
|
||||
|
||||
# Plants
|
||||
@test length(instance.plants) == 1
|
||||
l1 = instance.plants[1]
|
||||
@test l1.latitude == 41.881
|
||||
@test l1.longitude == -87.623
|
||||
@test l1.input_mix ==
|
||||
Dict(p1 => [0.953, 0.953, 0.953, 0.953], p2 => [0.047, 0.047, 0.047, 0.047])
|
||||
@test l1.output == Dict(p3 => [0.25, 0.25, 0.25, 0.25], p4 => [0.12, 0.12, 0.12, 0.12])
|
||||
@test l1.emissions == Dict("CO2" => [0.1, 0.1, 0.1, 0.1])
|
||||
@test l1.storage_cost == Dict(p1 => [0.1, 0.1, 0.1, 0.1], p2 => [0.1, 0.1, 0.1, 0.1])
|
||||
@test l1.storage_limit == Dict(p1 => [100, 100, 100, 100], p2 => [Inf, Inf, Inf, Inf])
|
||||
@test l1.disposal_cost == Dict(p3 => [0, 0, 0, 0], p4 => [0.86, 0.86, 0.86, 0.86])
|
||||
@test l1.disposal_limit ==
|
||||
Dict(p3 => [Inf, Inf, Inf, Inf], p4 => [1000.0, 1000.0, 1000.0, 1000.0])
|
||||
@test l1.initial_capacity == 150
|
||||
@test length(l1.capacities) == 2
|
||||
c1 = l1.capacities[1]
|
||||
@test c1.size == 100
|
||||
@test c1.opening_cost == [500, 500, 500, 500]
|
||||
@test c1.fix_operating_cost == [300, 300, 300, 300]
|
||||
@test c1.var_operating_cost == [5, 5, 5, 5]
|
||||
c2 = l1.capacities[2]
|
||||
@test c2.size == 500
|
||||
@test c2.opening_cost == [1000, 1000, 1000, 1000]
|
||||
@test c2.fix_operating_cost == [400, 400, 400, 400]
|
||||
@test c2.var_operating_cost == [5, 5, 5, 5]
|
||||
end
|
||||
|
||||
|
||||
function instance_parse_test_2()
|
||||
# Should not crash
|
||||
RELOG.parsefile(fixture("boat_example.json"))
|
||||
end
|
||||
Reference in New Issue
Block a user