mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-05 23:38:52 -06:00
Reformat source code; set up lint GH Action
This commit is contained in:
@@ -8,13 +8,13 @@ using RELOG
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../instances/s1.json")
|
||||
graph = RELOG.build_graph(instance)
|
||||
process_node_by_location_name = Dict(n.location.location_name => n
|
||||
for n in graph.process_nodes)
|
||||
|
||||
process_node_by_location_name =
|
||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||
|
||||
@test length(graph.plant_shipping_nodes) == 8
|
||||
@test length(graph.collection_shipping_nodes) == 10
|
||||
@test length(graph.process_nodes) == 6
|
||||
|
||||
|
||||
node = graph.collection_shipping_nodes[1]
|
||||
@test node.location.name == "C1"
|
||||
@test length(node.incoming_arcs) == 0
|
||||
@@ -23,20 +23,19 @@ using RELOG
|
||||
@test node.outgoing_arcs[1].dest.location.plant_name == "F1"
|
||||
@test node.outgoing_arcs[1].dest.location.location_name == "L1"
|
||||
@test node.outgoing_arcs[1].values["distance"] == 1095.62
|
||||
|
||||
|
||||
node = process_node_by_location_name["L1"]
|
||||
@test node.location.plant_name == "F1"
|
||||
@test node.location.location_name == "L1"
|
||||
@test length(node.incoming_arcs) == 10
|
||||
@test length(node.outgoing_arcs) == 2
|
||||
|
||||
|
||||
node = process_node_by_location_name["L3"]
|
||||
@test node.location.plant_name == "F2"
|
||||
@test node.location.location_name == "L3"
|
||||
@test length(node.incoming_arcs) == 2
|
||||
@test length(node.outgoing_arcs) == 2
|
||||
|
||||
|
||||
@test length(graph.arcs) == 38
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,13 +7,13 @@ using RELOG
|
||||
@testset "load" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../instances/s1.json")
|
||||
|
||||
|
||||
centers = instance.collection_centers
|
||||
plants = instance.plants
|
||||
products = instance.products
|
||||
location_name_to_plant = Dict(p.location_name => p for p in plants)
|
||||
product_name_to_product = Dict(p.name => p for p in products)
|
||||
|
||||
|
||||
@test length(centers) == 10
|
||||
@test centers[1].name == "C1"
|
||||
@test centers[1].latitude == 7
|
||||
@@ -21,7 +21,7 @@ using RELOG
|
||||
@test centers[1].longitude == 7
|
||||
@test centers[1].amount == [934.56, 934.56]
|
||||
@test centers[1].product.name == "P1"
|
||||
|
||||
|
||||
@test length(plants) == 6
|
||||
|
||||
plant = location_name_to_plant["L1"]
|
||||
@@ -30,7 +30,7 @@ using RELOG
|
||||
@test plant.input.name == "P1"
|
||||
@test plant.latitude == 0
|
||||
@test plant.longitude == 0
|
||||
|
||||
|
||||
@test length(plant.sizes) == 2
|
||||
@test plant.sizes[1].capacity == 250
|
||||
@test plant.sizes[1].opening_cost == [500, 500]
|
||||
@@ -40,7 +40,7 @@ using RELOG
|
||||
@test plant.sizes[2].opening_cost == [1250, 1250]
|
||||
@test plant.sizes[2].fixed_operating_cost == [30, 30]
|
||||
@test plant.sizes[2].variable_operating_cost == [30, 30]
|
||||
|
||||
|
||||
p2 = product_name_to_product["P2"]
|
||||
p3 = product_name_to_product["P3"]
|
||||
@test length(plant.output) == 2
|
||||
@@ -50,36 +50,36 @@ using RELOG
|
||||
@test plant.disposal_limit[p3] == [1, 1]
|
||||
@test plant.disposal_cost[p2] == [-10, -10]
|
||||
@test plant.disposal_cost[p3] == [-10, -10]
|
||||
|
||||
|
||||
plant = location_name_to_plant["L3"]
|
||||
@test plant.location_name == "L3"
|
||||
@test plant.input.name == "P2"
|
||||
@test plant.latitude == 25
|
||||
@test plant.longitude == 65
|
||||
|
||||
|
||||
@test length(plant.sizes) == 2
|
||||
@test plant.sizes[1].capacity == 1000.0
|
||||
@test plant.sizes[1].opening_cost == [3000, 3000]
|
||||
@test plant.sizes[1].fixed_operating_cost == [50, 50]
|
||||
@test plant.sizes[1].variable_operating_cost == [50, 50]
|
||||
@test plant.sizes[1] == plant.sizes[2]
|
||||
|
||||
|
||||
p4 = product_name_to_product["P4"]
|
||||
@test plant.output[p3] == 0.05
|
||||
@test plant.output[p4] == 0.8
|
||||
@test plant.disposal_limit[p3] == [1e8, 1e8]
|
||||
@test plant.disposal_limit[p4] == [0, 0]
|
||||
end
|
||||
|
||||
|
||||
@testset "validate timeseries" begin
|
||||
@test_throws String RELOG.parsefile("fixtures/s1-wrong-length.json")
|
||||
end
|
||||
|
||||
|
||||
@testset "compress" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../instances/s1.json")
|
||||
compressed = RELOG._compress(instance)
|
||||
|
||||
|
||||
product_name_to_product = Dict(p.name => p for p in compressed.products)
|
||||
location_name_to_facility = Dict()
|
||||
for p in compressed.plants
|
||||
@@ -88,7 +88,7 @@ using RELOG
|
||||
for c in compressed.collection_centers
|
||||
location_name_to_facility[c.name] = c
|
||||
end
|
||||
|
||||
|
||||
p1 = product_name_to_product["P1"]
|
||||
p2 = product_name_to_product["P2"]
|
||||
p3 = product_name_to_product["P3"]
|
||||
@@ -103,10 +103,10 @@ using RELOG
|
||||
@test p1.transportation_energy ≈ [0.115]
|
||||
@test p1.transportation_emissions["CO2"] ≈ [0.051]
|
||||
@test p1.transportation_emissions["CH4"] ≈ [0.0025]
|
||||
|
||||
|
||||
@test c1.name == "C1"
|
||||
@test c1.amount ≈ [1869.12]
|
||||
|
||||
|
||||
@test l1.plant_name == "F1"
|
||||
@test l1.location_name == "L1"
|
||||
@test l1.energy ≈ [0.115]
|
||||
@@ -121,7 +121,6 @@ using RELOG
|
||||
@test l1.disposal_limit[p2] ≈ [2.0]
|
||||
@test l1.disposal_limit[p3] ≈ [2.0]
|
||||
@test l1.disposal_cost[p2] ≈ [-10.0]
|
||||
@test l1.disposal_cost[p3] ≈ [-10.0]
|
||||
@test l1.disposal_cost[p3] ≈ [-10.0]
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -11,12 +11,14 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
model = RELOG.build_model(instance, graph, Cbc.Optimizer)
|
||||
set_optimizer_attribute(model.mip, "logLevel", 0)
|
||||
|
||||
process_node_by_location_name = Dict(n.location.location_name => n
|
||||
for n in graph.process_nodes)
|
||||
process_node_by_location_name =
|
||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||
|
||||
shipping_node_by_location_and_product_names = Dict(
|
||||
(n.location.location_name, n.product.name) => n for
|
||||
n in graph.plant_shipping_nodes
|
||||
)
|
||||
|
||||
shipping_node_by_location_and_product_names = Dict((n.location.location_name, n.product.name) => n
|
||||
for n in graph.plant_shipping_nodes)
|
||||
|
||||
@test length(model.vars.flow) == 76
|
||||
@test length(model.vars.dispose) == 16
|
||||
@test length(model.vars.open_plant) == 12
|
||||
@@ -27,15 +29,15 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
v = model.vars.capacity[l1, 1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 1000.0
|
||||
|
||||
|
||||
v = model.vars.expansion[l1, 1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 750.0
|
||||
|
||||
|
||||
v = model.vars.dispose[shipping_node_by_location_and_product_names["L1", "P2"], 1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 1.0
|
||||
|
||||
|
||||
# dest = FileFormats.Model(format = FileFormats.FORMAT_LP)
|
||||
# MOI.copy_to(dest, model.mip)
|
||||
# MOI.write_to_file(dest, "model.lp")
|
||||
@@ -44,14 +46,14 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
@testset "solve (exact)" begin
|
||||
solution_filename_a = tempname()
|
||||
solution_filename_b = tempname()
|
||||
solution = RELOG.solve("$(pwd())/../instances/s1.json",
|
||||
output=solution_filename_a)
|
||||
solution =
|
||||
RELOG.solve("$(pwd())/../instances/s1.json", output = solution_filename_a)
|
||||
|
||||
@test isfile(solution_filename_a)
|
||||
|
||||
|
||||
RELOG.write(solution, solution_filename_b)
|
||||
@test isfile(solution_filename_b)
|
||||
|
||||
|
||||
@test "Costs" in keys(solution)
|
||||
@test "Fixed operating (\$)" in keys(solution["Costs"])
|
||||
@test "Transportation (\$)" in keys(solution["Costs"])
|
||||
@@ -64,11 +66,11 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
@test "F3" in keys(solution["Plants"])
|
||||
@test "F4" in keys(solution["Plants"])
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
@testset "solve (heuristic)" begin
|
||||
# Should not crash
|
||||
solution = RELOG.solve("$(pwd())/../instances/s1.json", heuristic=true)
|
||||
solution = RELOG.solve("$(pwd())/../instances/s1.json", heuristic = true)
|
||||
end
|
||||
|
||||
@testset "infeasible solve" begin
|
||||
@@ -78,21 +80,21 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
end
|
||||
RELOG.solve(RELOG.parse(json))
|
||||
end
|
||||
|
||||
|
||||
@testset "storage" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
filename = "$basedir/fixtures/storage.json"
|
||||
instance = RELOG.parsefile(filename)
|
||||
@test instance.plants[1].storage_limit == 50.0
|
||||
@test instance.plants[1].storage_cost == [2.0, 1.5, 1.0]
|
||||
|
||||
|
||||
solution = RELOG.solve(filename)
|
||||
plant_dict = solution["Plants"]["mega plant"]["Chicago"]
|
||||
@test plant_dict["Variable operating cost (\$)"] == [500.0, 0.0, 100.0]
|
||||
@test plant_dict["Process (tonne)"] == [50.0, 0.0, 50.0]
|
||||
@test plant_dict["Storage (tonne)"] == [50.0, 50.0, 0.0]
|
||||
@test plant_dict["Storage cost (\$)"] == [100.0, 75.0, 0.0]
|
||||
|
||||
|
||||
@test solution["Costs"]["Variable operating (\$)"] == [500.0, 0.0, 100.0]
|
||||
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
||||
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
||||
|
||||
@@ -20,14 +20,14 @@ load_json_gz(filename) = JSON.parse(GZip.gzopen(filename))
|
||||
# end
|
||||
|
||||
@testset "Reports" begin
|
||||
# @testset "from fixture" begin
|
||||
# check(RELOG.write_plants_report, "fixtures/nimh_plants.csv")
|
||||
# check(RELOG.write_plant_outputs_report, "fixtures/nimh_plant_outputs.csv")
|
||||
# check(RELOG.write_plant_emissions_report, "fixtures/nimh_plant_emissions.csv")
|
||||
# check(RELOG.write_transportation_report, "fixtures/nimh_transportation.csv")
|
||||
# check(RELOG.write_transportation_emissions_report, "fixtures/nimh_transportation_emissions.csv")
|
||||
# end
|
||||
|
||||
# @testset "from fixture" begin
|
||||
# check(RELOG.write_plants_report, "fixtures/nimh_plants.csv")
|
||||
# check(RELOG.write_plant_outputs_report, "fixtures/nimh_plant_outputs.csv")
|
||||
# check(RELOG.write_plant_emissions_report, "fixtures/nimh_plant_emissions.csv")
|
||||
# check(RELOG.write_transportation_report, "fixtures/nimh_transportation.csv")
|
||||
# check(RELOG.write_transportation_emissions_report, "fixtures/nimh_transportation_emissions.csv")
|
||||
# end
|
||||
|
||||
@testset "from solve" begin
|
||||
solution = RELOG.solve("$(pwd())/../instances/s1.json")
|
||||
tmp_filename = tempname()
|
||||
|
||||
@@ -8,4 +8,4 @@ using Test
|
||||
include("graph_test.jl")
|
||||
include("model_test.jl")
|
||||
include("reports_test.jl")
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user