mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Use instance.features in LazyStatic and Objective
This commit is contained in:
@@ -215,13 +215,14 @@ class StaticLazyConstraintsComponent(Component):
|
||||
if "LazyStatic: All" not in sample:
|
||||
return x, y
|
||||
for cid in sorted(sample["LazyStatic: All"]):
|
||||
category = instance.get_constraint_category(cid)
|
||||
cfeatures = instance.features["Constraints"][cid]
|
||||
category = cfeatures["Category"]
|
||||
if category is None:
|
||||
continue
|
||||
if category not in x:
|
||||
x[category] = []
|
||||
y[category] = []
|
||||
x[category] += [instance.get_constraint_features(cid)]
|
||||
x[category] += [cfeatures["User features"]]
|
||||
if cid in sample["LazyStatic: Enforced"]:
|
||||
y[category] += [[False, True]]
|
||||
else:
|
||||
|
||||
@@ -171,7 +171,7 @@ class ObjectiveValueComponent(Component):
|
||||
y: Dict = {}
|
||||
if "Lower bound" not in sample:
|
||||
return x, y
|
||||
features = instance.get_instance_features()
|
||||
features = instance.features["Instance"]["User features"]
|
||||
if "LP value" in sample and sample["LP value"] is not None:
|
||||
features += [sample["LP value"]]
|
||||
x["Lower bound"] = [features]
|
||||
|
||||
@@ -239,33 +239,39 @@ def test_xy_sample() -> None:
|
||||
"LazyStatic: Enforced": {"c1", "c2", "c4", "c5"},
|
||||
"LazyStatic: All": {"c1", "c2", "c3", "c4", "c5"},
|
||||
}
|
||||
instance.get_constraint_category = Mock(
|
||||
side_effect=lambda cid: {
|
||||
"c1": "type-a",
|
||||
"c2": "type-a",
|
||||
"c3": "type-a",
|
||||
"c4": "type-b",
|
||||
"c5": "type-b",
|
||||
}[cid]
|
||||
)
|
||||
instance.get_constraint_features = Mock(
|
||||
side_effect=lambda cid: {
|
||||
"c1": [1, 1],
|
||||
"c2": [1, 2],
|
||||
"c3": [1, 3],
|
||||
"c4": [1, 4, 0],
|
||||
"c5": [1, 5, 0],
|
||||
}[cid]
|
||||
)
|
||||
instance.features = {
|
||||
"Constraints": {
|
||||
"c1": {
|
||||
"Category": "type-a",
|
||||
"User features": [1.0, 1.0],
|
||||
},
|
||||
"c2": {
|
||||
"Category": "type-a",
|
||||
"User features": [1.0, 2.0],
|
||||
},
|
||||
"c3": {
|
||||
"Category": "type-a",
|
||||
"User features": [1.0, 3.0],
|
||||
},
|
||||
"c4": {
|
||||
"Category": "type-b",
|
||||
"User features": [1.0, 4.0, 0.0],
|
||||
},
|
||||
"c5": {
|
||||
"Category": "type-b",
|
||||
"User features": [1.0, 5.0, 0.0],
|
||||
},
|
||||
}
|
||||
}
|
||||
x_expected = {
|
||||
"type-a": [
|
||||
[1, 1],
|
||||
[1, 2],
|
||||
[1, 3],
|
||||
[1.0, 1.0],
|
||||
[1.0, 2.0],
|
||||
[1.0, 3.0],
|
||||
],
|
||||
"type-b": [
|
||||
[1, 4, 0],
|
||||
[1, 5, 0],
|
||||
[1.0, 4.0, 0.0],
|
||||
[1.0, 5.0, 0.0],
|
||||
],
|
||||
}
|
||||
y_expected = {
|
||||
|
||||
@@ -17,9 +17,11 @@ from tests.fixtures.knapsack import get_test_pyomo_instances
|
||||
|
||||
def test_xy_sample() -> None:
|
||||
instance = cast(Instance, Mock(spec=Instance))
|
||||
instance.get_instance_features = Mock( # type: ignore
|
||||
return_value=[1.0, 2.0],
|
||||
)
|
||||
instance.features = {
|
||||
"Instance": {
|
||||
"User features": [1.0, 2.0],
|
||||
}
|
||||
}
|
||||
sample: TrainingSample = {
|
||||
"Lower bound": 1.0,
|
||||
"Upper bound": 2.0,
|
||||
|
||||
Reference in New Issue
Block a user