Implement BenchmarkRunner

This commit is contained in:
2021-05-25 18:18:38 -05:00
parent c6b76f57d2
commit 9689306876
13 changed files with 285 additions and 476 deletions

View File

@@ -17,5 +17,20 @@ include("instance/file.jl")
include("solvers/jump.jl")
include("solvers/learning.jl")
include("solvers/macros.jl")
include("utils/benchmark.jl")
DynamicLazyConstraintsComponent = miplearn.DynamicLazyConstraintsComponent
UserCutsComponent = miplearn.UserCutsComponent
ObjectiveValueComponent = miplearn.ObjectiveValueComponent
PrimalSolutionComponent = miplearn.PrimalSolutionComponent
StaticLazyConstraintsComponent = miplearn.StaticLazyConstraintsComponent
MinPrecisionThreshold = miplearn.MinPrecisionThreshold
export DynamicLazyConstraintsComponent,
UserCutsComponent,
ObjectiveValueComponent,
PrimalSolutionComponent,
StaticLazyConstraintsComponent,
MinPrecisionThreshold
end # module

View File

@@ -11,10 +11,21 @@ struct LearningSolver
end
function LearningSolver(optimizer_factory)::LearningSolver
py = miplearn.LearningSolver(solver=JuMPSolver(optimizer_factory))
function LearningSolver(
optimizer_factory;
components = nothing,
mode::AbstractString = "exact",
simulate_perfect::Bool = false,
solve_lp::Bool = true,
)::LearningSolver
return LearningSolver(
py,
miplearn.LearningSolver(
solver=JuMPSolver(optimizer_factory),
mode=mode,
solve_lp=solve_lp,
simulate_perfect=simulate_perfect,
components=components,
),
optimizer_factory,
)
end
@@ -36,7 +47,6 @@ end
function parallel_solve!(solver::LearningSolver, instances::Vector{FileInstance})
filenames = [instance.filename for instance in instances]
optimizer_factory = solver.optimizer_factory
solver_filename = tempname()
save(solver_filename, solver)
@sync @distributed for filename in filenames

68
src/utils/benchmark.jl Normal file
View File

@@ -0,0 +1,68 @@
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
using CSV
using DataFrames
mutable struct BenchmarkRunner
solvers::Dict
results::Union{Nothing,DataFrame}
end
function BenchmarkRunner(; solvers::Dict)
return BenchmarkRunner(
solvers,
nothing, # results
)
end
function parallel_solve!(
runner::BenchmarkRunner,
instances::Vector{FileInstance};
n_trials::Int = 3,
)::Nothing
for (solver_name, solver) in runner.solvers
for i in 1:n_trials
for instance in instances
stats = solve!(solver, instance)
stats["Solver"] = solver_name
stats = Dict(k => isnothing(v) ? missing : v for (k, v) in stats)
if runner.results === nothing
runner.results = DataFrame(stats)
else
push!(runner.results, stats, cols=:union)
end
end
end
end
end
function fit!(
runner::BenchmarkRunner,
instances::Vector{FileInstance}
)::Nothing
for (solver_name, solver) in runner.solvers
fit!(solver, instances)
end
end
function write_csv!(
runner::BenchmarkRunner,
filename::AbstractString,
)::Nothing
@info "Writing: $filename"
CSV.write(filename, runner.results)
return
end
export BenchmarkRunner,
parallel_solve!,
fit!,
write_csv!