mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Add ObjectiveValueComponent.xy
This commit is contained in:
@@ -11,9 +11,33 @@ from numpy.testing import assert_array_equal
|
||||
from miplearn.instance import Instance
|
||||
from miplearn.classifiers import Regressor
|
||||
from miplearn.components.objective import ObjectiveValueComponent
|
||||
from miplearn.types import TrainingSample
|
||||
from tests.fixtures.knapsack import get_test_pyomo_instances
|
||||
|
||||
|
||||
def test_xy() -> None:
|
||||
instance = cast(Instance, Mock(spec=Instance))
|
||||
instance.get_instance_features = Mock( # type: ignore
|
||||
return_value=[1.0, 2.0],
|
||||
)
|
||||
sample: TrainingSample = {
|
||||
"Lower bound": 1.0,
|
||||
"Upper bound": 2.0,
|
||||
"LP value": 3.0,
|
||||
}
|
||||
x_expected = {
|
||||
"Lower bound": [[1.0, 2.0, 3.0]],
|
||||
"Upper bound": [[1.0, 2.0, 3.0]],
|
||||
}
|
||||
y_expected = {
|
||||
"Lower bound": [[1.0]],
|
||||
"Upper bound": [[2.0]],
|
||||
}
|
||||
x_actual, y_actual = ObjectiveValueComponent.xy(instance, sample)
|
||||
assert x_actual == x_expected
|
||||
assert y_actual == y_expected
|
||||
|
||||
|
||||
def test_x_y_predict() -> None:
|
||||
# Construct instance
|
||||
instance = cast(Instance, Mock(spec=Instance))
|
||||
|
||||
@@ -69,7 +69,7 @@ def test_xy_with_lp_solution() -> None:
|
||||
]
|
||||
)
|
||||
}
|
||||
x_actual, y_actual = comp.xy(instance, sample)
|
||||
x_actual, y_actual = PrimalSolutionComponent.xy(instance, sample)
|
||||
assert len(x_actual.keys()) == 1
|
||||
assert len(y_actual.keys()) == 1
|
||||
assert_array_equal(x_actual["default"], x_expected["default"])
|
||||
|
||||
Reference in New Issue
Block a user