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:
|
if "LazyStatic: All" not in sample:
|
||||||
return x, y
|
return x, y
|
||||||
for cid in sorted(sample["LazyStatic: All"]):
|
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:
|
if category is None:
|
||||||
continue
|
continue
|
||||||
if category not in x:
|
if category not in x:
|
||||||
x[category] = []
|
x[category] = []
|
||||||
y[category] = []
|
y[category] = []
|
||||||
x[category] += [instance.get_constraint_features(cid)]
|
x[category] += [cfeatures["User features"]]
|
||||||
if cid in sample["LazyStatic: Enforced"]:
|
if cid in sample["LazyStatic: Enforced"]:
|
||||||
y[category] += [[False, True]]
|
y[category] += [[False, True]]
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ class ObjectiveValueComponent(Component):
|
|||||||
y: Dict = {}
|
y: Dict = {}
|
||||||
if "Lower bound" not in sample:
|
if "Lower bound" not in sample:
|
||||||
return x, y
|
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:
|
if "LP value" in sample and sample["LP value"] is not None:
|
||||||
features += [sample["LP value"]]
|
features += [sample["LP value"]]
|
||||||
x["Lower bound"] = [features]
|
x["Lower bound"] = [features]
|
||||||
|
|||||||
@@ -239,33 +239,39 @@ def test_xy_sample() -> None:
|
|||||||
"LazyStatic: Enforced": {"c1", "c2", "c4", "c5"},
|
"LazyStatic: Enforced": {"c1", "c2", "c4", "c5"},
|
||||||
"LazyStatic: All": {"c1", "c2", "c3", "c4", "c5"},
|
"LazyStatic: All": {"c1", "c2", "c3", "c4", "c5"},
|
||||||
}
|
}
|
||||||
instance.get_constraint_category = Mock(
|
instance.features = {
|
||||||
side_effect=lambda cid: {
|
"Constraints": {
|
||||||
"c1": "type-a",
|
"c1": {
|
||||||
"c2": "type-a",
|
"Category": "type-a",
|
||||||
"c3": "type-a",
|
"User features": [1.0, 1.0],
|
||||||
"c4": "type-b",
|
},
|
||||||
"c5": "type-b",
|
"c2": {
|
||||||
}[cid]
|
"Category": "type-a",
|
||||||
)
|
"User features": [1.0, 2.0],
|
||||||
instance.get_constraint_features = Mock(
|
},
|
||||||
side_effect=lambda cid: {
|
"c3": {
|
||||||
"c1": [1, 1],
|
"Category": "type-a",
|
||||||
"c2": [1, 2],
|
"User features": [1.0, 3.0],
|
||||||
"c3": [1, 3],
|
},
|
||||||
"c4": [1, 4, 0],
|
"c4": {
|
||||||
"c5": [1, 5, 0],
|
"Category": "type-b",
|
||||||
}[cid]
|
"User features": [1.0, 4.0, 0.0],
|
||||||
)
|
},
|
||||||
|
"c5": {
|
||||||
|
"Category": "type-b",
|
||||||
|
"User features": [1.0, 5.0, 0.0],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
x_expected = {
|
x_expected = {
|
||||||
"type-a": [
|
"type-a": [
|
||||||
[1, 1],
|
[1.0, 1.0],
|
||||||
[1, 2],
|
[1.0, 2.0],
|
||||||
[1, 3],
|
[1.0, 3.0],
|
||||||
],
|
],
|
||||||
"type-b": [
|
"type-b": [
|
||||||
[1, 4, 0],
|
[1.0, 4.0, 0.0],
|
||||||
[1, 5, 0],
|
[1.0, 5.0, 0.0],
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
y_expected = {
|
y_expected = {
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ from tests.fixtures.knapsack import get_test_pyomo_instances
|
|||||||
|
|
||||||
def test_xy_sample() -> None:
|
def test_xy_sample() -> None:
|
||||||
instance = cast(Instance, Mock(spec=Instance))
|
instance = cast(Instance, Mock(spec=Instance))
|
||||||
instance.get_instance_features = Mock( # type: ignore
|
instance.features = {
|
||||||
return_value=[1.0, 2.0],
|
"Instance": {
|
||||||
)
|
"User features": [1.0, 2.0],
|
||||||
|
}
|
||||||
|
}
|
||||||
sample: TrainingSample = {
|
sample: TrainingSample = {
|
||||||
"Lower bound": 1.0,
|
"Lower bound": 1.0,
|
||||||
"Upper bound": 2.0,
|
"Upper bound": 2.0,
|
||||||
|
|||||||
Reference in New Issue
Block a user