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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user