mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Convert ConstraintFeatures to dataclass
This commit is contained in:
@@ -17,6 +17,7 @@ from miplearn.types import (
|
||||
Features,
|
||||
LearningSolveStats,
|
||||
InstanceFeatures,
|
||||
ConstraintFeatures,
|
||||
)
|
||||
|
||||
|
||||
@@ -35,31 +36,31 @@ def features() -> Features:
|
||||
lazy_constraint_count=4,
|
||||
),
|
||||
constraints={
|
||||
"c1": {
|
||||
"Category": "type-a",
|
||||
"User features": [1.0, 1.0],
|
||||
"Lazy": True,
|
||||
},
|
||||
"c2": {
|
||||
"Category": "type-a",
|
||||
"User features": [1.0, 2.0],
|
||||
"Lazy": True,
|
||||
},
|
||||
"c3": {
|
||||
"Category": "type-a",
|
||||
"User features": [1.0, 3.0],
|
||||
"Lazy": True,
|
||||
},
|
||||
"c4": {
|
||||
"Category": "type-b",
|
||||
"User features": [1.0, 4.0, 0.0],
|
||||
"Lazy": True,
|
||||
},
|
||||
"c5": {
|
||||
"Category": "type-b",
|
||||
"User features": [1.0, 5.0, 0.0],
|
||||
"Lazy": False,
|
||||
},
|
||||
"c1": ConstraintFeatures(
|
||||
category="type-a",
|
||||
user_features=[1.0, 1.0],
|
||||
lazy=True,
|
||||
),
|
||||
"c2": ConstraintFeatures(
|
||||
category="type-a",
|
||||
user_features=[1.0, 2.0],
|
||||
lazy=True,
|
||||
),
|
||||
"c3": ConstraintFeatures(
|
||||
category="type-a",
|
||||
user_features=[1.0, 3.0],
|
||||
lazy=True,
|
||||
),
|
||||
"c4": ConstraintFeatures(
|
||||
category="type-b",
|
||||
user_features=[1.0, 4.0, 0.0],
|
||||
lazy=True,
|
||||
),
|
||||
"c5": ConstraintFeatures(
|
||||
category="type-b",
|
||||
user_features=[1.0, 5.0, 0.0],
|
||||
lazy=False,
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
from miplearn import GurobiSolver
|
||||
from miplearn.features import FeaturesExtractor
|
||||
from miplearn.types import VariableFeatures, InstanceFeatures
|
||||
from miplearn.types import VariableFeatures, InstanceFeatures, ConstraintFeatures
|
||||
from tests.fixtures.knapsack import get_knapsack_instance
|
||||
|
||||
|
||||
@@ -36,19 +36,19 @@ def test_knapsack() -> None:
|
||||
}
|
||||
}
|
||||
assert instance.features.constraints == {
|
||||
"eq_capacity": {
|
||||
"LHS": {
|
||||
"eq_capacity": ConstraintFeatures(
|
||||
lhs={
|
||||
"x[0]": 23.0,
|
||||
"x[1]": 26.0,
|
||||
"x[2]": 20.0,
|
||||
"x[3]": 18.0,
|
||||
},
|
||||
"Sense": "<",
|
||||
"RHS": 67.0,
|
||||
"Lazy": False,
|
||||
"Category": "eq_capacity",
|
||||
"User features": [0.0],
|
||||
}
|
||||
sense="<",
|
||||
rhs=67.0,
|
||||
lazy=False,
|
||||
category="eq_capacity",
|
||||
user_features=[0.0],
|
||||
)
|
||||
}
|
||||
assert instance.features.instance == InstanceFeatures(
|
||||
user_features=[67.0, 21.75],
|
||||
|
||||
Reference in New Issue
Block a user