mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-07 00:48:50 -06:00
BenchmarkRunner: Ensure outputs are discarded
This commit is contained in:
@@ -18,7 +18,7 @@ using Gurobi
|
||||
solver = LearningSolver(Gurobi.Optimizer)
|
||||
solve!(solver, file_instance)
|
||||
|
||||
loaded = load_jump_instance(filename)
|
||||
loaded = load_instance(filename)
|
||||
@test length(loaded.py.samples) == 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,7 +20,7 @@ using MIPLearn
|
||||
@test isfile(filename)
|
||||
|
||||
# Read model from file
|
||||
loaded = load_jump_instance(filename)
|
||||
loaded = load_instance(filename)
|
||||
x = variable_by_name(loaded.model, "x")
|
||||
@test loaded.model.ext[:miplearn][:variable_features][x] == [1.0]
|
||||
@test loaded.model.ext[:miplearn][:variable_categories][x] == "cat1"
|
||||
|
||||
@@ -35,4 +35,12 @@ using Gurobi
|
||||
loaded = load_solver(filename)
|
||||
@test loaded.py.components == "Placeholder"
|
||||
end
|
||||
|
||||
@testset "Discard output" begin
|
||||
instance = build_knapsack_file_instance()
|
||||
solver = LearningSolver(Gurobi.Optimizer)
|
||||
solve!(solver, instance, discard_output=true)
|
||||
loaded = load_instance(instance.filename)
|
||||
@test length(loaded.py.samples) == 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,24 +8,39 @@ using Gurobi
|
||||
|
||||
|
||||
@testset "BenchmarkRunner" begin
|
||||
# Configure benchmark suite
|
||||
benchmark = BenchmarkRunner(
|
||||
solvers=Dict(
|
||||
"Baseline" => LearningSolver(Gurobi.Optimizer, components=[]),
|
||||
"Proposed" => LearningSolver(Gurobi.Optimizer),
|
||||
),
|
||||
)
|
||||
|
||||
# Solve instances in parallel
|
||||
# Initialie instances and generate training data
|
||||
instances = [
|
||||
build_knapsack_file_instance(),
|
||||
build_knapsack_file_instance(),
|
||||
]
|
||||
parallel_solve!(benchmark, instances)
|
||||
parallel_solve!(
|
||||
LearningSolver(Gurobi.Optimizer),
|
||||
instances,
|
||||
)
|
||||
|
||||
# Fit and benchmark
|
||||
benchmark = BenchmarkRunner(
|
||||
solvers=Dict(
|
||||
"baseline" => LearningSolver(
|
||||
Gurobi.Optimizer,
|
||||
components=[],
|
||||
),
|
||||
"ml-exact" => LearningSolver(
|
||||
Gurobi.Optimizer,
|
||||
),
|
||||
"ml-heur" => LearningSolver(
|
||||
Gurobi.Optimizer,
|
||||
mode="heuristic",
|
||||
),
|
||||
),
|
||||
)
|
||||
fit!(benchmark, instances)
|
||||
parallel_solve!(benchmark, instances, n_trials=1)
|
||||
|
||||
# Write CSV
|
||||
csv_filename = tempname()
|
||||
write_csv!(benchmark, csv_filename)
|
||||
@test isfile(csv_filename)
|
||||
csv = DataFrame(CSV.File(csv_filename))
|
||||
@test size(csv)[1] == 6
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user