diff --git a/src/instance/parse.jl b/src/instance/parse.jl index 8e250c7..65c5a18 100644 --- a/src/instance/parse.jl +++ b/src/instance/parse.jl @@ -13,7 +13,7 @@ function parse(json)::Instance timeseries(x::Union{Nothing,Number}) = repeat([x], time_horizon) timeseries(x::Array) = x - timeseries(d::OrderedDict) = OrderedDict(k => timeseries(v) for (k,v) in d) + timeseries(d::OrderedDict) = OrderedDict(k => timeseries(v) for (k, v) in d) # Read products products = Product[] @@ -42,8 +42,8 @@ function parse(json)::Instance outputs = [products_by_name[p] for p in cdict["outputs"]] operating_cost = timeseries(cdict["operating cost (\$)"]) prod_dict(key, null_val) = OrderedDict( - p => [v === nothing ? null_val : v for v in timeseries(cdict[key][p.name])] for - p in outputs + p => [v === nothing ? null_val : v for v in timeseries(cdict[key][p.name])] + for p in outputs ) fixed_output = prod_dict("fixed output (tonne)", 0.0) var_output = prod_dict("variable output (tonne/tonne)", 0.0) @@ -68,6 +68,54 @@ function parse(json)::Instance centers_by_name[cname] = center end + plants = Plant[] + plants_by_name = OrderedDict{String,Plant}() + for (pname, pdict) in json["plants"] + prod_dict(key; scale = 1.0, null_val = Inf) = OrderedDict{Product,Vector{Float64}}( + products_by_name[p] => [ + v === nothing ? null_val : v * scale for v in timeseries(pdict[key][p]) + ] for p in keys(pdict[key]) + ) + + latitude = pdict["latitude (deg)"] + longitude = pdict["longitude (deg)"] + input_mix = prod_dict("input mix (%)", scale = 0.01) + output = prod_dict("output (tonne)") + emissions = timeseries(pdict["processing emissions (tonne)"]) + storage_cost = prod_dict("storage cost (\$/tonne)") + storage_limit = prod_dict("storage limit (tonne)") + disposal_cost = prod_dict("disposal cost (\$/tonne)") + disposal_limit = prod_dict("disposal limit (tonne)") + initial_capacity = pdict["initial capacity (tonne)"] + capacities = PlantCapacity[] + for cdict in pdict["capacities"] + size = cdict["size (tonne)"] + opening_cost = timeseries(cdict["opening cost (\$)"]) + fix_operating_cost = timeseries(cdict["fixed operating cost (\$)"]) + var_operating_cost = timeseries(cdict["variable operating cost (\$/tonne)"]) + push!( + capacities, + PlantCapacity(; size, opening_cost, fix_operating_cost, var_operating_cost), + ) + end + + plant = Plant(; + latitude, + longitude, + input_mix, + output, + emissions, + storage_cost, + storage_limit, + disposal_cost, + disposal_limit, + capacities, + initial_capacity, + ) + push!(plants, plant) + plants_by_name[pname] = plant + end + return Instance(; time_horizon, building_period, @@ -76,5 +124,7 @@ function parse(json)::Instance products_by_name, centers, centers_by_name, + plants, + plants_by_name, ) end diff --git a/src/instance/structs.jl b/src/instance/structs.jl index a476635..9a136e0 100644 --- a/src/instance/structs.jl +++ b/src/instance/structs.jl @@ -21,6 +21,27 @@ Base.@kwdef struct Center disposal_cost::OrderedDict{Product,Vector{Float64}} end +Base.@kwdef struct PlantCapacity + size::Float64 + opening_cost::Vector{Float64} + fix_operating_cost::Vector{Float64} + var_operating_cost::Vector{Float64} +end + +Base.@kwdef struct Plant + latitude::Float64 + longitude::Float64 + input_mix::OrderedDict{Product,Vector{Float64}} + output::OrderedDict{Product,Vector{Float64}} + emissions::OrderedDict{String,Vector{Float64}} + storage_cost::OrderedDict{Product,Vector{Float64}} + storage_limit::OrderedDict{Product,Vector{Float64}} + disposal_cost::OrderedDict{Product,Vector{Float64}} + disposal_limit::OrderedDict{Product,Vector{Float64}} + capacities::Vector{PlantCapacity} + initial_capacity::Float64 +end + Base.@kwdef struct Instance building_period::Vector{Int} centers_by_name::OrderedDict{String,Center} @@ -29,4 +50,6 @@ Base.@kwdef struct Instance products_by_name::OrderedDict{String,Product} products::Vector{Product} time_horizon::Int + plants::Vector{Plant} + plants_by_name::OrderedDict{String,Plant} end diff --git a/test/fixtures/boat_example.ipynb b/test/fixtures/boat_example.ipynb index 007bec9..28e3d61 100644 --- a/test/fixtures/boat_example.ipynb +++ b/test/fixtures/boat_example.ipynb @@ -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": [ diff --git a/test/fixtures/boat_example.json b/test/fixtures/boat_example.json index a37e53f..e326138 100644 --- a/test/fixtures/boat_example.json +++ b/test/fixtures/boat_example.json @@ -42,14 +42,20 @@ "outputs": [ "Nail" ], - "fixed output (tonne)": 1, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Nail": 1 + }, + "variable output (tonne/tonne)": { + "Nail": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Nail": 1000 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Nail": null + }, "disposal cost ($/tonne)": { "Nail": 0 }, @@ -61,14 +67,20 @@ "outputs": [ "Nail" ], - "fixed output (tonne)": 1, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Nail": 1 + }, + "variable output (tonne/tonne)": { + "Nail": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Nail": 1000 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Nail": null + }, "disposal cost ($/tonne)": { "Nail": 0 }, @@ -80,14 +92,20 @@ "outputs": [ "Nail" ], - "fixed output (tonne)": 1, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Nail": 1 + }, + "variable output (tonne/tonne)": { + "Nail": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Nail": 1000 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Nail": null + }, "disposal cost ($/tonne)": { "Nail": 0 }, @@ -99,14 +117,20 @@ "outputs": [ "Nail" ], - "fixed output (tonne)": 1, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Nail": 1 + }, + "variable output (tonne/tonne)": { + "Nail": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Nail": 1000 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Nail": null + }, "disposal cost ($/tonne)": { "Nail": 0 }, @@ -118,14 +142,20 @@ "outputs": [ "Nail" ], - "fixed output (tonne)": 1, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Nail": 1 + }, + "variable output (tonne/tonne)": { + "Nail": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Nail": 1000 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Nail": null + }, "disposal cost ($/tonne)": { "Nail": 0 }, @@ -137,14 +167,20 @@ "outputs": [ "Nail" ], - "fixed output (tonne)": 1, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Nail": 1 + }, + "variable output (tonne/tonne)": { + "Nail": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Nail": 1000 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Nail": null + }, "disposal cost ($/tonne)": { "Nail": 0 }, @@ -156,14 +192,20 @@ "outputs": [ "Wood" ], - "fixed output (tonne)": 100, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Wood": 100 + }, + "variable output (tonne/tonne)": { + "Wood": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Wood": 250 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Wood": null + }, "disposal cost ($/tonne)": { "Wood": 0 }, @@ -175,14 +217,20 @@ "outputs": [ "Wood" ], - "fixed output (tonne)": 100, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Wood": 100 + }, + "variable output (tonne/tonne)": { + "Wood": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Wood": 250 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Wood": null + }, "disposal cost ($/tonne)": { "Wood": 0 }, @@ -194,14 +242,20 @@ "outputs": [ "Wood" ], - "fixed output (tonne)": 100, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Wood": 100 + }, + "variable output (tonne/tonne)": { + "Wood": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Wood": 250 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Wood": null + }, "disposal cost ($/tonne)": { "Wood": 0 }, @@ -213,14 +267,20 @@ "outputs": [ "Wood" ], - "fixed output (tonne)": 100, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Wood": 100 + }, + "variable output (tonne/tonne)": { + "Wood": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Wood": 250 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Wood": null + }, "disposal cost ($/tonne)": { "Wood": 0 }, @@ -232,14 +292,20 @@ "outputs": [ "Wood" ], - "fixed output (tonne)": 100, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Wood": 100 + }, + "variable output (tonne/tonne)": { + "Wood": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Wood": 250 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Wood": null + }, "disposal cost ($/tonne)": { "Wood": 0 }, @@ -251,14 +317,20 @@ "outputs": [ "Wood" ], - "fixed output (tonne)": 100, - "variable output (tonne/tonne)": {}, + "fixed output (tonne)": { + "Wood": 100 + }, + "variable output (tonne/tonne)": { + "Wood": 0 + }, "revenue ($/tonne)": null, "collection cost ($/tonne)": { "Wood": 250 }, "operating cost ($)": 0, - "disposal limit (tonne)": 100000.0, + "disposal limit (tonne)": { + "Wood": null + }, "disposal cost ($/tonne)": { "Wood": 0 }, @@ -270,7 +342,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -297,7 +371,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -324,7 +400,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -351,7 +429,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -378,7 +458,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -405,7 +487,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -432,7 +516,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -459,7 +545,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -486,7 +574,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -513,7 +603,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -540,7 +632,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -567,7 +661,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -594,7 +690,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -621,7 +719,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -648,7 +748,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -675,7 +777,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -702,7 +806,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -729,7 +835,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -756,7 +864,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -783,7 +893,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -810,7 +922,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -837,7 +951,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -864,7 +980,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -891,7 +1009,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -918,7 +1038,9 @@ "outputs": [ "UsedBoat" ], - "fixed output (tonne)": 0, + "fixed output (tonne)": { + "UsedBoat": 0 + }, "variable output (tonne/tonne)": { "UsedBoat": [ 0.1, @@ -969,13 +1091,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1012,13 +1134,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1055,13 +1177,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1098,13 +1220,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1141,13 +1263,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1184,13 +1306,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1227,13 +1349,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1270,13 +1392,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1313,13 +1435,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1356,13 +1478,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1399,13 +1521,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1442,13 +1564,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1485,13 +1607,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1528,13 +1650,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1571,13 +1693,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1614,13 +1736,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1657,13 +1779,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1700,13 +1822,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1743,13 +1865,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1786,13 +1908,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1829,13 +1951,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1872,13 +1994,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1915,13 +2037,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -1958,13 +2080,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2001,13 +2123,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2044,13 +2166,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2087,13 +2209,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2130,13 +2252,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2173,13 +2295,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2216,13 +2338,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2259,13 +2381,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2302,13 +2424,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2345,13 +2467,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2388,13 +2510,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2431,13 +2553,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2474,13 +2596,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2517,13 +2639,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2560,13 +2682,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2603,13 +2725,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2646,13 +2768,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2689,13 +2811,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2732,13 +2854,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2775,13 +2897,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2818,13 +2940,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2861,13 +2983,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2904,13 +3026,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2947,13 +3069,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -2990,13 +3112,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -3033,13 +3155,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 @@ -3076,13 +3198,13 @@ }, "capacities": [ { - "size": 50, + "size (tonne)": 50, "opening cost ($)": 10000, "fixed operating cost ($)": 1000, "variable operating cost ($/tonne)": 5 }, { - "size": 500, + "size (tonne)": 500, "opening cost ($)": 20000, "fixed operating cost ($)": 2000, "variable operating cost ($/tonne)": 5 diff --git a/test/fixtures/simple.json b/test/fixtures/simple.json index 5781e9e..c68a1e5 100644 --- a/test/fixtures/simple.json +++ b/test/fixtures/simple.json @@ -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 + } } } diff --git a/test/src/RELOGT.jl b/test/src/RELOGT.jl index 564eb67..6039da3 100644 --- a/test/src/RELOGT.jl +++ b/test/src/RELOGT.jl @@ -14,7 +14,8 @@ end function runtests() @testset "RELOG" begin - instance_parse_test() + instance_parse_test_1() + instance_parse_test_2() end end diff --git a/test/src/instance/parse_test.jl b/test/src/instance/parse_test.jl index 085c8cb..84f6d22 100644 --- a/test/src/instance/parse_test.jl +++ b/test/src/instance/parse_test.jl @@ -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 \ No newline at end of file