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

@@ -8,37 +8,7 @@ using Gurobi
@testset "LearningSolver" begin
@testset "Model with annotations" begin
# Create standard JuMP model
weights = [1.0, 2.0, 3.0]
prices = [5.0, 6.0, 7.0]
capacity = 3.0
model = Model()
n = length(weights)
@variable(model, x[1:n], Bin)
@objective(model, Max, sum(x[i] * prices[i] for i in 1:n))
@constraint(model, c1, sum(x[i] * weights[i] for i in 1:n) <= capacity)
# Add ML information to the model
@feature(model, [5.0])
@feature(c1, [1.0, 2.0, 3.0])
@category(c1, "c1")
for i in 1:n
@feature(x[i], [weights[i]; prices[i]])
@category(x[i], "type-$i")
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]
model = build_knapsack_model()
solver = LearningSolver(Gurobi.Optimizer)
instance = JuMPInstance(model)
stats = solve!(solver, instance)
@@ -49,14 +19,11 @@ using Gurobi
end
@testset "Model without annotations" begin
model = Model()
@variable(model, x, Bin)
@variable(model, y, Bin)
@objective(model, Max, x + y)
model = build_knapsack_model()
solver = LearningSolver(Gurobi.Optimizer)
instance = JuMPInstance(model)
stats = solve!(solver, instance)
@test stats["mip_lower_bound"] == 2.0
@test stats["mip_lower_bound"] == 11.0
end
@testset "Save and load" begin