From 9abcea05cd7fe275ee35dd4fe24cda864a4ca08a Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Tue, 26 Jan 2021 22:28:20 -0600 Subject: [PATCH] Objective: Use LP value as feature --- miplearn/components/objective.py | 5 ++--- tests/components/test_objective.py | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/miplearn/components/objective.py b/miplearn/components/objective.py index 098e02c..e997dd3 100644 --- a/miplearn/components/objective.py +++ b/miplearn/components/objective.py @@ -108,9 +108,8 @@ class ObjectiveValueComponent(Component): def x(instances: Union[List[str], List[Instance]]) -> np.ndarray: result = [] for instance in InstanceIterator(instances): - for _ in instance.training_data: - instance_features = instance.get_instance_features() - result.append(instance_features) + for sample in instance.training_data: + result.append(instance.get_instance_features() + [sample["LP value"]]) return np.array(result) @staticmethod diff --git a/tests/components/test_objective.py b/tests/components/test_objective.py index 4e8f520..4e25494 100644 --- a/tests/components/test_objective.py +++ b/tests/components/test_objective.py @@ -23,10 +23,12 @@ def test_x_y_predict() -> None: { "Lower bound": 1.0, "Upper bound": 2.0, + "LP value": 3.0, }, { "Lower bound": 1.5, "Upper bound": 2.2, + "LP value": 3.4, }, ] @@ -41,7 +43,7 @@ def test_x_y_predict() -> None: ) # Should build x correctly - x_expected = np.array([[1.0, 2.0], [1.0, 2.0]]) + x_expected = np.array([[1.0, 2.0, 3.0], [1.0, 2.0, 3.4]]) assert_array_equal(comp.x([instance]), x_expected) # Should build y correctly