|
|
@ -1,13 +1,14 @@
|
|
|
|
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
|
|
|
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
|
|
|
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
|
|
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
|
|
|
# Released under the modified BSD license. See COPYING.md for more details.
|
|
|
|
# Released under the modified BSD license. See COPYING.md for more details.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from miplearn import GurobiSolver
|
|
|
|
from miplearn.features import ModelFeaturesExtractor
|
|
|
|
from miplearn.features import ModelFeaturesExtractor
|
|
|
|
from tests.fixtures.knapsack import get_knapsack_instance
|
|
|
|
from tests.fixtures.knapsack import get_knapsack_instance
|
|
|
|
from tests.solvers import get_internal_solvers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_knapsack() -> None:
|
|
|
|
def test_knapsack() -> None:
|
|
|
|
for solver_factory in get_internal_solvers():
|
|
|
|
for solver_factory in [GurobiSolver]:
|
|
|
|
# Initialize model, instance and internal solver
|
|
|
|
# Initialize model, instance and internal solver
|
|
|
|
solver = solver_factory()
|
|
|
|
solver = solver_factory()
|
|
|
|
instance = get_knapsack_instance(solver)
|
|
|
|
instance = get_knapsack_instance(solver)
|
|
|
@ -20,4 +21,11 @@ def test_knapsack() -> None:
|
|
|
|
|
|
|
|
|
|
|
|
# Test constraint features
|
|
|
|
# Test constraint features
|
|
|
|
print(solver, features)
|
|
|
|
print(solver, features)
|
|
|
|
assert features["ConstraintRHS"]["eq_capacity"] == 67.0
|
|
|
|
assert features["constraints"]["eq_capacity"]["lhs"] == {
|
|
|
|
|
|
|
|
"x[0]": 23.0,
|
|
|
|
|
|
|
|
"x[1]": 26.0,
|
|
|
|
|
|
|
|
"x[2]": 20.0,
|
|
|
|
|
|
|
|
"x[3]": 18.0,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
assert features["constraints"]["eq_capacity"]["sense"] == "<"
|
|
|
|
|
|
|
|
assert features["constraints"]["eq_capacity"]["rhs"] == 67.0
|
|
|
|