mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-06 07:48:50 -06:00
Accelerate tests with Revise.jl
This commit is contained in:
@@ -21,6 +21,7 @@ OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
|
||||
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
|
||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
|
||||
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
|
||||
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
|
||||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
|
||||
StochasticPrograms = "8b8459f2-c380-502b-8633-9aed2d6c2b35"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
[ Info: Reading s1.json...
|
||||
[ Info: Building graph...
|
||||
[ Info: 2 time periods
|
||||
[ Info: 6 process nodes
|
||||
[ Info: 8 shipping nodes (plant)
|
||||
[ Info: 10 shipping nodes (collection)
|
||||
[ Info: 38 arcs
|
||||
[ Info: Building optimization model...
|
||||
[ Info: Optimizing MILP...
|
||||
[ Info: Re-optimizing with integer variables fixed...
|
||||
[ Info: Extracting solution...
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
using RELOG
|
||||
|
||||
function graph_build_test()
|
||||
@testset "build_graph" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
||||
instance = RELOG.parsefile(fixture("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)
|
||||
@@ -37,3 +37,4 @@ using RELOG
|
||||
|
||||
@test length(graph.arcs) == 38
|
||||
end
|
||||
end
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
using RELOG
|
||||
|
||||
function compress_test()
|
||||
@testset "compress" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
||||
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||
compressed = RELOG._compress(instance)
|
||||
|
||||
product_name_to_product = Dict(p.name => p for p in compressed.products)
|
||||
@@ -51,3 +51,4 @@ using RELOG
|
||||
@test l1.disposal_cost[p2] ≈ [-10.0]
|
||||
@test l1.disposal_cost[p3] ≈ [-10.0]
|
||||
end
|
||||
end
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using RELOG
|
||||
|
||||
function geodb_test()
|
||||
@testset "geodb_query (2018-us-county)" begin
|
||||
region = RELOG.geodb_query("2018-us-county:17043")
|
||||
@test region.centroid.lat == 41.83956
|
||||
@@ -23,3 +24,4 @@ end
|
||||
@test region.centroid.lon == -89.50414
|
||||
@test region.population == 12_671_821
|
||||
end
|
||||
end
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
using RELOG
|
||||
|
||||
function parse_test()
|
||||
@testset "parse" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
||||
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||
|
||||
centers = instance.collection_centers
|
||||
plants = instance.plants
|
||||
@@ -78,8 +78,7 @@ using RELOG
|
||||
end
|
||||
|
||||
@testset "parse (geodb)" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../../instances/s2.json")
|
||||
instance = RELOG.parsefile(fixture("instances/s2.json"))
|
||||
|
||||
centers = instance.collection_centers
|
||||
@test centers[1].name == "C1"
|
||||
@@ -88,6 +87,6 @@ end
|
||||
end
|
||||
|
||||
# @testset "parse (invalid)" begin
|
||||
# basedir = dirname(@__FILE__)
|
||||
# @test_throws ErrorException RELOG.parsefile("$basedir/../fixtures/s1-wrong-length.json")
|
||||
# @test_throws ErrorException RELOG.parsefile(fixture("s1-wrong-length.json"))
|
||||
# end
|
||||
end
|
||||
@@ -3,9 +3,9 @@
|
||||
|
||||
using RELOG, HiGHS, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
|
||||
function model_build_test()
|
||||
@testset "build" begin
|
||||
basedir = dirname(@__FILE__)
|
||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
||||
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||
graph = RELOG.build_graph(instance)
|
||||
model = RELOG.build_model(instance, graph, HiGHS.Optimizer)
|
||||
|
||||
@@ -35,3 +35,4 @@ using RELOG, HiGHS, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
# @test lower_bound(v) == 0.0
|
||||
# @test upper_bound(v) == 1.0
|
||||
end
|
||||
end
|
||||
@@ -5,8 +5,9 @@ using RELOG, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
|
||||
basedir = dirname(@__FILE__)
|
||||
|
||||
function model_solve_test()
|
||||
@testset "solve (exact)" begin
|
||||
solution = RELOG.solve("$basedir/../../instances/s1.json")
|
||||
solution = RELOG.solve(fixture("instances/s1.json"))
|
||||
|
||||
solution_filename = tempname()
|
||||
RELOG.write(solution, solution_filename)
|
||||
@@ -36,11 +37,11 @@ end
|
||||
|
||||
@testset "solve (heuristic)" begin
|
||||
# Should not crash
|
||||
solution = RELOG.solve("$basedir/../../instances/s1.json", heuristic = true)
|
||||
solution = RELOG.solve(fixture("instances/s1.json"), heuristic = true)
|
||||
end
|
||||
|
||||
@testset "solve (infeasible)" begin
|
||||
json = JSON.parsefile("$basedir/../../instances/s1.json")
|
||||
json = JSON.parsefile(fixture("instances/s1.json"))
|
||||
for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
||||
location_dict["amount (tonne)"] *= 1000
|
||||
end
|
||||
@@ -65,3 +66,4 @@ end
|
||||
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
||||
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
||||
end
|
||||
end
|
||||
@@ -6,9 +6,10 @@ using RELOG, JSON, GZip
|
||||
|
||||
basedir = @__DIR__
|
||||
|
||||
function reports_test()
|
||||
@testset "Reports" begin
|
||||
@testset "from solve" begin
|
||||
solution = RELOG.solve("$basedir/../instances/s1.json")
|
||||
solution = RELOG.solve(fixture("instances/s1.json"))
|
||||
tmp_filename = tempname()
|
||||
# The following should not crash
|
||||
RELOG.write_plant_emissions_report(solution, tmp_filename)
|
||||
@@ -19,3 +20,4 @@ basedir = @__DIR__
|
||||
RELOG.write_transportation_report(solution, tmp_filename)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -2,19 +2,46 @@
|
||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||
|
||||
using Test
|
||||
using RELOG
|
||||
using Revise
|
||||
|
||||
includet("instance/compress_test.jl")
|
||||
includet("instance/geodb_test.jl")
|
||||
includet("instance/parse_test.jl")
|
||||
includet("graph/build_test.jl")
|
||||
includet("model/build_test.jl")
|
||||
includet("model/solve_test.jl")
|
||||
includet("reports_test.jl")
|
||||
|
||||
function fixture(path)
|
||||
for candidate in [
|
||||
"fixtures/$path",
|
||||
"test/fixtures/$path"
|
||||
]
|
||||
if isfile(candidate)
|
||||
return candidate
|
||||
end
|
||||
end
|
||||
error("Fixture not found: $path")
|
||||
end
|
||||
|
||||
function runtests()
|
||||
@testset "RELOG" begin
|
||||
@testset "Instance" begin
|
||||
include("instance/compress_test.jl")
|
||||
include("instance/geodb_test.jl")
|
||||
include("instance/parse_test.jl")
|
||||
compress_test()
|
||||
geodb_test()
|
||||
parse_test()
|
||||
end
|
||||
@testset "Graph" begin
|
||||
include("graph/build_test.jl")
|
||||
graph_build_test()
|
||||
end
|
||||
@testset "Model" begin
|
||||
include("model/build_test.jl")
|
||||
include("model/solve_test.jl")
|
||||
model_build_test()
|
||||
model_solve_test()
|
||||
end
|
||||
include("reports_test.jl")
|
||||
reports_test()
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
runtests()
|
||||
|
||||
Reference in New Issue
Block a user