|
|
@ -18,7 +18,7 @@ using Cbc
|
|
|
|
@objective(model, Max, sum(x[i] * prices[i] for i in 1:n))
|
|
|
|
@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)
|
|
|
|
@constraint(model, c1, sum(x[i] * weights[i] for i in 1:n) <= capacity)
|
|
|
|
|
|
|
|
|
|
|
|
# Add machine-learning information
|
|
|
|
# Add ML information to the model
|
|
|
|
@feature(model, [5.0])
|
|
|
|
@feature(model, [5.0])
|
|
|
|
@feature(c1, [1.0, 2.0, 3.0])
|
|
|
|
@feature(c1, [1.0, 2.0, 3.0])
|
|
|
|
@category(c1, "c1")
|
|
|
|
@category(c1, "c1")
|
|
|
@ -27,49 +27,30 @@ using Cbc
|
|
|
|
@category(x[i], "type-$i")
|
|
|
|
@category(x[i], "type-$i")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Should store variable features
|
|
|
|
# Should store ML information
|
|
|
|
@test model.ext[:miplearn][:features][:variables] == Dict(
|
|
|
|
@test model.ext[:miplearn][:variable_features][x[1]] == [1.0, 5.0]
|
|
|
|
"x[1]" => Dict(
|
|
|
|
@test model.ext[:miplearn][:variable_features][x[2]] == [2.0, 6.0]
|
|
|
|
:user_features => [1.0, 5.0],
|
|
|
|
@test model.ext[:miplearn][:variable_features][x[3]] == [3.0, 7.0]
|
|
|
|
:category => "type-1",
|
|
|
|
@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]
|
|
|
|
|
|
|
|
|
|
|
|
),
|
|
|
|
# solver = LearningSolver(optimizer=Cbc.Optimizer)
|
|
|
|
"x[2]" => Dict(
|
|
|
|
|
|
|
|
:user_features => [2.0, 6.0],
|
|
|
|
|
|
|
|
:category => "type-2",
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
"x[3]" => Dict(
|
|
|
|
|
|
|
|
:user_features => [3.0, 7.0],
|
|
|
|
|
|
|
|
:category => "type-3",
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Should store constraint features
|
|
|
|
# # Should return correct stats
|
|
|
|
@test model.ext[:miplearn][:features][:constraints] == Dict(
|
|
|
|
# stats = solve!(solver, model)
|
|
|
|
"c1" => Dict(
|
|
|
|
# @test stats["Lower bound"] == 11.0
|
|
|
|
:user_features => [1.0, 2.0, 3.0],
|
|
|
|
|
|
|
|
:category => "c1",
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Should store instance features
|
|
|
|
# # Should add a sample to the training data
|
|
|
|
@test model.ext[:miplearn][:features][:instance] == Dict(
|
|
|
|
# @test length(model.ext[:miplearn][:training_samples]) == 1
|
|
|
|
:user_features => [5.0],
|
|
|
|
# sample = model.ext[:miplearn][:training_samples][1]
|
|
|
|
)
|
|
|
|
# @test sample["lower_bound"] == 11.0
|
|
|
|
|
|
|
|
# @test sample["solution"]["x[1]"] == 1.0
|
|
|
|
|
|
|
|
|
|
|
|
solver = LearningSolver(optimizer=Cbc.Optimizer)
|
|
|
|
# fit!(solver, [model])
|
|
|
|
|
|
|
|
|
|
|
|
# Should return correct stats
|
|
|
|
# solve!(solver, model)
|
|
|
|
stats = solve!(solver, model)
|
|
|
|
|
|
|
|
@test stats["Lower bound"] == 11.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Should add a sample to the training data
|
|
|
|
|
|
|
|
@test length(model.ext[:miplearn][:training_samples]) == 1
|
|
|
|
|
|
|
|
sample = model.ext[:miplearn][:training_samples][1]
|
|
|
|
|
|
|
|
@test sample["lower_bound"] == 11.0
|
|
|
|
|
|
|
|
@test sample["solution"]["x[1]"] == 1.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fit!(solver, [model])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
solve!(solver, model)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|