Skip to content

Commit

Permalink
composition: fixed output
Browse files Browse the repository at this point in the history
  • Loading branch information
iSoron committed Feb 23, 2024
1 parent ae62ca1 commit f747131
Show file tree
Hide file tree
Showing 12 changed files with 989 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ run.jl
relog-web-legacy
.vscode
jobs
**/tmp
55 changes: 27 additions & 28 deletions docs/format.md

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions src/instance/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function parse(json)::Instance
tr_cost = timeseries(pdict["transportation cost (\$/km/tonne)"])
tr_energy = timeseries(pdict["transportation energy (J/km/tonne)"])
tr_emissions = timeseries(pdict["transportation emissions (tonne/km/tonne)"])
prod = Product(; name, tr_cost, tr_energy, tr_emissions)
components = pdict["components"]
prod = Product(; name, tr_cost, tr_energy, tr_emissions, components)
push!(products, prod)
products_by_name[name] = prod
end
Expand All @@ -45,7 +46,19 @@ function parse(json)::Instance
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)
to_array(x) = vcat(x'...)
prepend_time_dimension(x) = to_array(repeat([x], time_horizon))

fixed_output = Dict()
for p in outputs
m = to_array(cdict["fixed output (tonne)"][p.name])
if ndims(m) == 1
m = prepend_time_dimension(m)
end
@assert size(m) == (time_horizon, length(p.components))
fixed_output[p] = m
end

var_output = prod_dict("variable output (tonne/tonne)", 0.0)
collection_cost = prod_dict("collection cost (\$/tonne)", 0.0)
disposal_limit = prod_dict("disposal limit (tonne)", Inf)
Expand Down
3 changes: 2 additions & 1 deletion src/instance/structs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Base.@kwdef struct Product
tr_cost::Vector{Float64}
tr_energy::Vector{Float64}
tr_emissions::OrderedDict{String,Vector{Float64}}
components::Vector{String}
end

Base.@kwdef struct Center
Expand All @@ -13,7 +14,7 @@ Base.@kwdef struct Center
longitude::Float64
input::Union{Product,Nothing}
outputs::Vector{Product}
fixed_output::OrderedDict{Product,Vector{Float64}}
fixed_output::OrderedDict{Product,Array{Float64,2}}
var_output::OrderedDict{Product,Vector{Float64}}
revenue::Vector{Float64}
collection_cost::OrderedDict{Product,Vector{Float64}}
Expand Down
5 changes: 4 additions & 1 deletion src/model/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ function build_model(instance::Instance; optimizer, variable_names::Bool = false
sum(
z_input[c.name, t-offset] * c.var_output[m][offset+1] for
offset = 0:min(M - 1, t - 1)
) + c.fixed_output[m][t]
) + sum(
c.fixed_output[m][t,mi]
for mi in 1:length(m.components)
)
)
end

Expand Down
48 changes: 20 additions & 28 deletions test/fixtures/boat_example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function run_boat_example()
nail_factory = dict(
"input" => nothing,
"outputs" => ["Nail"],
"fixed output (tonne)" => dict("Nail" => 1),
"fixed output (tonne)" => dict("Nail" => [1]),
"variable output (tonne/tonne)" => dict("Nail" => 0),
"revenue (\$/tonne)" => nothing,
"collection cost (\$/tonne)" => dict("Nail" => 1000),
Expand All @@ -44,7 +44,7 @@ function run_boat_example()
forest = dict(
"input" => nothing,
"outputs" => ["Wood"],
"fixed output (tonne)" => dict("Wood" => 100),
"fixed output (tonne)" => dict("Wood" => [[100], [100], [100], [100], [100]]),
"variable output (tonne/tonne)" => dict("Wood" => 0),
"revenue (\$/tonne)" => nothing,
"collection cost (\$/tonne)" => dict("Wood" => 250),
Expand All @@ -56,7 +56,7 @@ function run_boat_example()
retail = dict(
"input" => "NewBoat",
"outputs" => ["UsedBoat"],
"fixed output (tonne)" => dict("UsedBoat" => 0),
"fixed output (tonne)" => dict("UsedBoat" => [[0], [0], [0], [0], [0]]),
"variable output (tonne/tonne)" => dict("UsedBoat" => [0.10, 0.25, 0.10]),
"revenue (\$/tonne)" => 12_000,
"collection cost (\$/tonne)" => dict("UsedBoat" => 100),
Expand All @@ -69,6 +69,7 @@ function run_boat_example()
"transportation cost (\$/km/tonne)" => 0.30,
"transportation energy (J/km/tonne)" => 7_500,
"transportation emissions (tonne/km/tonne)" => dict("CO2" => 2.68),
"components" => ["1"],
)

boat_factory = dict(
Expand Down Expand Up @@ -121,47 +122,38 @@ function run_boat_example()
"initial capacity (tonne)" => 0,
)

lat_lon_dict(city_location) = dict(
"latitude (deg)" => city_location[1],
"longitude (deg)" => city_location[2],
)
lat_lon_dict(city_location) =
dict("latitude (deg)" => city_location[1], "longitude (deg)" => city_location[2])

data = dict(
"parameters" => parameters,
"products" =>
dict("Nail" => prod, "Wood" => prod, "NewBoat" => prod, "UsedBoat" => prod),
"centers" => merge(
dict(
"NailFactory ($city_name)" => merge(
nail_factory,
lat_lon_dict(city_location)
) for (city_name, city_location) in cities_b
"NailFactory ($city_name)" =>
merge(nail_factory, lat_lon_dict(city_location)) for
(city_name, city_location) in cities_b
),
dict(
"Forest ($city_name)" => merge(
forest,
lat_lon_dict(city_location)
) for (city_name, city_location) in cities_b
"Forest ($city_name)" => merge(forest, lat_lon_dict(city_location))
for (city_name, city_location) in cities_b
),
dict(
"Retail ($city_name)" => merge(
retail,
lat_lon_dict(city_location)
) for (city_name, city_location) in cities_a
"Retail ($city_name)" => merge(retail, lat_lon_dict(city_location))
for (city_name, city_location) in cities_a
),
),
"plants" => merge(
dict(
"BoatFactory ($city_name)" => merge(
boat_factory,
lat_lon_dict(city_location)
) for (city_name, city_location) in cities_a
"BoatFactory ($city_name)" =>
merge(boat_factory, lat_lon_dict(city_location)) for
(city_name, city_location) in cities_a
),
dict(
"RecyclingPlant ($city_name)" => merge(
recycling_plant,
lat_lon_dict(city_location)
) for (city_name, city_location) in cities_a
"RecyclingPlant ($city_name)" =>
merge(recycling_plant, lat_lon_dict(city_location)) for
(city_name, city_location) in cities_a
),
),
)
Expand All @@ -186,4 +178,4 @@ function run_boat_example()
RELOG.write_transportation_report(model, fixture("boat_example/transportation.csv"))

return
end
end
Loading

0 comments on commit f747131

Please sign in to comment.