mirror of
https://github.com/ANL-CEEESA/MIPLearn.jl.git
synced 2025-12-06 08:28:52 -06:00
Rewrite FileInstance
This commit is contained in:
18
test/fixtures/knapsack.jl
vendored
18
test/fixtures/knapsack.jl
vendored
@@ -28,15 +28,15 @@ function build_knapsack_model()
|
||||
end
|
||||
|
||||
# Should store ML information
|
||||
@test model.ext[:miplearn][:variable_features]["x[1]"] == [1.0, 5.0]
|
||||
@test model.ext[:miplearn][:variable_features]["x[2]"] == [2.0, 6.0]
|
||||
@test model.ext[:miplearn][:variable_features]["x[3]"] == [3.0, 7.0]
|
||||
@test model.ext[:miplearn][:variable_categories]["x[1]"] == "type-1"
|
||||
@test model.ext[:miplearn][:variable_categories]["x[2]"] == "type-2"
|
||||
@test model.ext[:miplearn][:variable_categories]["x[3]"] == "type-3"
|
||||
@test model.ext[:miplearn][:constraint_features]["c1"] == [1.0, 2.0, 3.0]
|
||||
@test model.ext[:miplearn][:constraint_categories]["c1"] == "c1"
|
||||
@test model.ext[:miplearn][:instance_features] == [5.0]
|
||||
@test model.ext[:miplearn]["variable_features"]["x[1]"] == [1.0, 5.0]
|
||||
@test model.ext[:miplearn]["variable_features"]["x[2]"] == [2.0, 6.0]
|
||||
@test model.ext[:miplearn]["variable_features"]["x[3]"] == [3.0, 7.0]
|
||||
@test model.ext[:miplearn]["variable_categories"]["x[1]"] == "type-1"
|
||||
@test model.ext[:miplearn]["variable_categories"]["x[2]"] == "type-2"
|
||||
@test model.ext[:miplearn]["variable_categories"]["x[3]"] == "type-3"
|
||||
@test model.ext[:miplearn]["constraint_features"]["c1"] == [1.0, 2.0, 3.0]
|
||||
@test model.ext[:miplearn]["constraint_categories"]["c1"] == "c1"
|
||||
@test model.ext[:miplearn]["instance_features"] == [5.0]
|
||||
|
||||
return model
|
||||
end
|
||||
|
||||
@@ -19,6 +19,6 @@ using Cbc
|
||||
solve!(solver, file_instance)
|
||||
|
||||
loaded = load_instance(filename)
|
||||
@test length(loaded.py.samples) == 1
|
||||
@test length(loaded.samples) == 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -13,7 +13,7 @@ using MIPLearn
|
||||
instance = JuMPInstance(model)
|
||||
stats = solve!(solver, instance)
|
||||
@test stats["mip_lower_bound"] == 11.0
|
||||
@test length(instance.py.samples) == 1
|
||||
@test length(instance.samples) == 1
|
||||
fit!(solver, [instance])
|
||||
solve!(solver, instance)
|
||||
end
|
||||
@@ -41,6 +41,6 @@ using MIPLearn
|
||||
solver = LearningSolver(Cbc.Optimizer)
|
||||
solve!(solver, instance, discard_output=true)
|
||||
loaded = load_instance(instance.filename)
|
||||
@test length(loaded.py.samples) == 0
|
||||
@test length(loaded.samples) == 0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -8,17 +8,19 @@ using DataFrames
|
||||
|
||||
|
||||
@testset "BenchmarkRunner" begin
|
||||
# Initialize instances and generate training data
|
||||
@info "Building training data..."
|
||||
instances = [
|
||||
build_knapsack_file_instance(),
|
||||
build_knapsack_file_instance(),
|
||||
]
|
||||
parallel_solve!(
|
||||
stats = parallel_solve!(
|
||||
LearningSolver(Cbc.Optimizer),
|
||||
instances,
|
||||
)
|
||||
@test length(stats) == 2
|
||||
@test stats[1] !== nothing
|
||||
@test stats[2] !== nothing
|
||||
|
||||
# Fit and benchmark
|
||||
benchmark = BenchmarkRunner(
|
||||
solvers=Dict(
|
||||
"baseline" => LearningSolver(
|
||||
@@ -34,13 +36,15 @@ using DataFrames
|
||||
),
|
||||
),
|
||||
)
|
||||
@info "Fitting..."
|
||||
fit!(benchmark, instances)
|
||||
parallel_solve!(benchmark, instances, n_trials=1)
|
||||
|
||||
# Write CSV
|
||||
@info "Benchmarking..."
|
||||
parallel_solve!(benchmark, instances, n_trials=2)
|
||||
|
||||
csv_filename = tempname()
|
||||
write_csv!(benchmark, csv_filename)
|
||||
@test isfile(csv_filename)
|
||||
csv = DataFrame(CSV.File(csv_filename))
|
||||
@test size(csv)[1] == 6
|
||||
@test size(csv)[1] == 12
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user