Make sample_xy an instance method

This commit is contained in:
2021-04-06 08:27:37 -05:00
parent 54c20382c9
commit cfb17551f1
5 changed files with 39 additions and 8 deletions

View File

@@ -245,7 +245,7 @@ def test_sample_xy(
"type-a": [[False, True], [False, True], [True, False]],
"type-b": [[False, True]],
}
xy = StaticLazyConstraintsComponent.sample_xy(instance, sample)
xy = StaticLazyConstraintsComponent().sample_xy(instance, sample)
assert xy is not None
x_actual, y_actual = xy
assert x_actual == x_expected

View File

@@ -68,7 +68,7 @@ def test_sample_xy(
"Lower bound": [[1.0]],
"Upper bound": [[2.0]],
}
xy = ObjectiveValueComponent.sample_xy(instance, sample)
xy = ObjectiveValueComponent().sample_xy(instance, sample)
assert xy is not None
x_actual, y_actual = xy
assert x_actual == x_expected
@@ -87,7 +87,7 @@ def test_sample_xy_without_lp(
"Lower bound": [[1.0]],
"Upper bound": [[2.0]],
}
xy = ObjectiveValueComponent.sample_xy(instance, sample_without_lp)
xy = ObjectiveValueComponent().sample_xy(instance, sample_without_lp)
assert xy is not None
x_actual, y_actual = xy
assert x_actual == x_expected
@@ -103,7 +103,7 @@ def test_sample_xy_without_ub(
"Upper bound": [[1.0, 2.0, 3.0]],
}
y_expected = {"Lower bound": [[1.0]]}
xy = ObjectiveValueComponent.sample_xy(instance, sample_without_ub)
xy = ObjectiveValueComponent().sample_xy(instance, sample_without_ub)
assert xy is not None
x_actual, y_actual = xy
assert x_actual == x_expected
@@ -180,7 +180,7 @@ def test_sample_predict(
instance: Instance,
sample: TrainingSample,
) -> None:
x, y = ObjectiveValueComponent.sample_xy(instance, sample)
x, y = ObjectiveValueComponent().sample_xy(instance, sample)
comp = ObjectiveValueComponent()
comp.regressors["Lower bound"] = Mock(spec=Regressor)
comp.regressors["Upper bound"] = Mock(spec=Regressor)
@@ -209,7 +209,7 @@ def test_sample_predict_without_ub(
instance: Instance,
sample_without_ub: TrainingSample,
) -> None:
x, y = ObjectiveValueComponent.sample_xy(instance, sample_without_ub)
x, y = ObjectiveValueComponent().sample_xy(instance, sample_without_ub)
comp = ObjectiveValueComponent()
comp.regressors["Lower bound"] = Mock(spec=Regressor)
comp.regressors["Lower bound"].predict = Mock( # type: ignore

View File

@@ -0,0 +1,31 @@
# MIPLearn: Extensible Framework for Learning-Enhanced Mixed-Integer Optimization
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
from typing import Any, List
import pytest
from networkx import Graph
import networkx as nx
from scipy.stats import randint
from miplearn import Instance
from miplearn.problems.stab import MaxWeightStableSetGenerator
class GurobiStableSetProblem(Instance):
def __init__(self, graph: Graph) -> None:
super().__init__()
self.graph = graph
def to_model(self) -> Any:
pass
@pytest.fixture
def instance() -> Instance:
graph = nx.generators.random_graphs.binomial_graph(50, 0.5)
return GurobiStableSetProblem(graph)
def test_usage(instance: Instance) -> None:
pass