mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-06 07:48:50 -06:00
Update input schema, example input file and parser
This commit is contained in:
@@ -70,67 +70,67 @@ function load(path::String)::Instance
|
||||
throw(msg)
|
||||
end
|
||||
|
||||
T = json["Parameters"]["Time horizon (years)"]
|
||||
T = json["parameters"]["time horizon (years)"]
|
||||
plants = Plant[]
|
||||
products = Product[]
|
||||
collection_centers = CollectionCenter[]
|
||||
prod_name_to_product = Dict{String, Product}()
|
||||
|
||||
# Create products
|
||||
for (product_name, product_dict) in json["Products"]
|
||||
product = Product(product_name, product_dict["Transportation cost (\$/km/tonne)"])
|
||||
for (product_name, product_dict) in json["products"]
|
||||
product = Product(product_name, product_dict["transportation cost (\$/km/tonne)"])
|
||||
push!(products, product)
|
||||
prod_name_to_product[product_name] = product
|
||||
|
||||
# Create collection centers
|
||||
if "Initial amounts" in keys(product_dict)
|
||||
for (center_name, center_dict) in product_dict["Initial amounts"]
|
||||
if "initial amounts" in keys(product_dict)
|
||||
for (center_name, center_dict) in product_dict["initial amounts"]
|
||||
center = CollectionCenter(length(collection_centers) + 1,
|
||||
center_name,
|
||||
center_dict["Latitude (deg)"],
|
||||
center_dict["Longitude (deg)"],
|
||||
center_dict["latitude (deg)"],
|
||||
center_dict["longitude (deg)"],
|
||||
product,
|
||||
center_dict["Amount (tonne)"])
|
||||
center_dict["amount (tonne)"])
|
||||
push!(collection_centers, center)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create plants
|
||||
for (plant_name, plant_dict) in json["Plants"]
|
||||
input = prod_name_to_product[plant_dict["Input"]]
|
||||
for (plant_name, plant_dict) in json["plants"]
|
||||
input = prod_name_to_product[plant_dict["input"]]
|
||||
output = Dict()
|
||||
|
||||
# Plant outputs
|
||||
if "Outputs (tonne)" in keys(plant_dict)
|
||||
if "outputs (tonne/tonne)" in keys(plant_dict)
|
||||
output = Dict(prod_name_to_product[key] => value
|
||||
for (key, value) in plant_dict["Outputs (tonne)"]
|
||||
for (key, value) in plant_dict["outputs (tonne/tonne)"]
|
||||
if value > 0)
|
||||
end
|
||||
|
||||
for (location_name, location_dict) in plant_dict["Locations"]
|
||||
for (location_name, location_dict) in plant_dict["locations"]
|
||||
sizes = PlantSize[]
|
||||
disposal_limit = Dict(p => [0.0 for t in 1:T] for p in keys(output))
|
||||
disposal_cost = Dict(p => [0.0 for t in 1:T] for p in keys(output))
|
||||
|
||||
# Disposal
|
||||
if "Disposal" in keys(location_dict)
|
||||
for (product_name, disposal_dict) in location_dict["Disposal"]
|
||||
if "disposal" in keys(location_dict)
|
||||
for (product_name, disposal_dict) in location_dict["disposal"]
|
||||
limit = [1e8 for t in 1:T]
|
||||
if "Limit (tonne)" in keys(disposal_dict)
|
||||
limit = disposal_dict["Limit (tonne)"]
|
||||
if "limit (tonne)" in keys(disposal_dict)
|
||||
limit = disposal_dict["limit (tonne)"]
|
||||
end
|
||||
disposal_limit[prod_name_to_product[product_name]] = limit
|
||||
disposal_cost[prod_name_to_product[product_name]] = disposal_dict["Cost (\$/tonne)"]
|
||||
disposal_cost[prod_name_to_product[product_name]] = disposal_dict["cost (\$/tonne)"]
|
||||
end
|
||||
end
|
||||
|
||||
# Capacities
|
||||
for (capacity_name, capacity_dict) in location_dict["Capacities (tonne)"]
|
||||
for (capacity_name, capacity_dict) in location_dict["capacities (tonne)"]
|
||||
push!(sizes, PlantSize(parse(Float64, capacity_name),
|
||||
capacity_dict["Variable operating cost (\$/tonne)"],
|
||||
capacity_dict["Fixed operating cost (\$)"],
|
||||
capacity_dict["Opening cost (\$)"]))
|
||||
capacity_dict["variable operating cost (\$/tonne)"],
|
||||
capacity_dict["fixed operating cost (\$)"],
|
||||
capacity_dict["opening cost (\$)"]))
|
||||
end
|
||||
length(sizes) > 1 || push!(sizes, sizes[1])
|
||||
sort!(sizes, by = x -> x.capacity)
|
||||
@@ -148,8 +148,8 @@ function load(path::String)::Instance
|
||||
location_name,
|
||||
input,
|
||||
output,
|
||||
location_dict["Latitude (deg)"],
|
||||
location_dict["Longitude (deg)"],
|
||||
location_dict["latitude (deg)"],
|
||||
location_dict["longitude (deg)"],
|
||||
disposal_limit,
|
||||
disposal_cost,
|
||||
sizes)
|
||||
|
||||
@@ -20,7 +20,6 @@ function build_model(instance::Instance, graph::Graph, optimizer)::Manufacturing
|
||||
create_objective_function!(model)
|
||||
create_shipping_node_constraints!(model)
|
||||
create_process_node_constraints!(model)
|
||||
JuMP.write_to_file(model.mip, "model.lp")
|
||||
return model
|
||||
end
|
||||
|
||||
@@ -194,7 +193,7 @@ function create_process_node_constraints!(model::ManufacturingModel)
|
||||
end
|
||||
end
|
||||
|
||||
function solve(filename::String; optimizer=Cbc.Optimizer, lp_optimizer=Clp.Optimizer)
|
||||
function solve(filename::String; milp_optimizer=Cbc.Optimizer, lp_optimizer=Clp.Optimizer)
|
||||
println("Reading $filename...")
|
||||
instance = RELOG.load(filename)
|
||||
|
||||
@@ -202,7 +201,7 @@ function solve(filename::String; optimizer=Cbc.Optimizer, lp_optimizer=Clp.Optim
|
||||
graph = RELOG.build_graph(instance)
|
||||
|
||||
println("Building optimization model...")
|
||||
model = RELOG.build_model(instance, graph, optimizer)
|
||||
model = RELOG.build_model(instance, graph, milp_optimizer)
|
||||
|
||||
println("Optimizing MILP...")
|
||||
JuMP.optimize!(model.mip)
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
"Parameters": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Time horizon (years)": { "type": "number" }
|
||||
"time horizon (years)": { "type": "number" }
|
||||
},
|
||||
"required": [
|
||||
"Time horizon (years)"
|
||||
"time horizon (years)"
|
||||
]
|
||||
},
|
||||
"Plant": {
|
||||
@@ -23,16 +23,21 @@
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Input": { "type": "string" },
|
||||
"Outputs (tonne)": {
|
||||
"input": { "type": "string" },
|
||||
"outputs (tonne/tonne)": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "type": "number" }
|
||||
},
|
||||
"Locations": { "$ref": "#/definitions/PlantLocation" }
|
||||
"energy (GJ/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"emissions (tonne/tonne)": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#/definitions/TimeSeries" }
|
||||
},
|
||||
"locations": { "$ref": "#/definitions/PlantLocation" }
|
||||
},
|
||||
"required": [
|
||||
"Input",
|
||||
"Locations"
|
||||
"input",
|
||||
"locations"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -41,42 +46,42 @@
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Latitude (deg)": { "type": "number" },
|
||||
"Longitude (deg)": { "type": "number" },
|
||||
"Disposal": {
|
||||
"latitude (deg)": { "type": "number" },
|
||||
"longitude (deg)": { "type": "number" },
|
||||
"disposal": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Cost ($/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"Limit (tonne)": { "$ref": "#/definitions/TimeSeries" }
|
||||
"cost ($/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"limit (tonne)": { "$ref": "#/definitions/TimeSeries" }
|
||||
},
|
||||
"required": [
|
||||
"Cost ($/tonne)"
|
||||
"cost ($/tonne)"
|
||||
]
|
||||
}
|
||||
},
|
||||
"Capacities (tonne)": {
|
||||
"capacities (tonne)": {
|
||||
"type": "object",
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Variable operating cost ($/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"Fixed operating cost ($)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"Opening cost ($)": { "$ref": "#/definitions/TimeSeries" }
|
||||
"variable operating cost ($/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"fixed operating cost ($)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"opening cost ($)": { "$ref": "#/definitions/TimeSeries" }
|
||||
},
|
||||
"required": [
|
||||
"Variable operating cost ($/tonne)",
|
||||
"Fixed operating cost ($)",
|
||||
"Opening cost ($)"
|
||||
"variable operating cost ($/tonne)",
|
||||
"fixed operating cost ($)",
|
||||
"opening cost ($)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"Latitude (deg)",
|
||||
"Longitude (deg)",
|
||||
"Capacities (tonne)"
|
||||
"latitude (deg)",
|
||||
"longitude (deg)",
|
||||
"capacities (tonne)"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -85,14 +90,14 @@
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Latitude (deg)": { "type": "number" },
|
||||
"Longitude (deg)": { "type": "number" },
|
||||
"Amount (tonne)": { "$ref": "#/definitions/TimeSeries" }
|
||||
"latitude (deg)": { "type": "number" },
|
||||
"longitude (deg)": { "type": "number" },
|
||||
"amount (tonne)": { "$ref": "#/definitions/TimeSeries" }
|
||||
},
|
||||
"required": [
|
||||
"Latitude (deg)",
|
||||
"Longitude (deg)",
|
||||
"Amount (tonne)"
|
||||
"latitude (deg)",
|
||||
"longitude (deg)",
|
||||
"amount (tonne)"
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -101,24 +106,29 @@
|
||||
"additionalProperties": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Transportation cost ($/km/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"Initial amounts": { "$ref": "#/definitions/InitialAmount" }
|
||||
"transportation cost ($/km/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"transportation energy (J/km/tonne)": { "$ref": "#/definitions/TimeSeries" },
|
||||
"transportation emissions (tonne/km/tonne)": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "$ref": "#/definitions/TimeSeries" }
|
||||
},
|
||||
"initial amounts": { "$ref": "#/definitions/InitialAmount" }
|
||||
},
|
||||
"required": [
|
||||
"Transportation cost ($/km/tonne)"
|
||||
"transportation cost ($/km/tonne)"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Parameters": { "$ref": "#/definitions/Parameters" },
|
||||
"Plants": { "$ref": "#/definitions/Plant" },
|
||||
"Products": { "$ref": "#/definitions/Product" }
|
||||
"parameters": { "$ref": "#/definitions/Parameters" },
|
||||
"plants": { "$ref": "#/definitions/Plant" },
|
||||
"products": { "$ref": "#/definitions/Product" }
|
||||
},
|
||||
"required": [
|
||||
"Parameters",
|
||||
"Plants",
|
||||
"Products"
|
||||
"parameters",
|
||||
"plants",
|
||||
"products"
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user