Remove sample.after_mip

This commit is contained in:
2021-07-01 11:45:19 -05:00
parent 7c4c301611
commit 4093ac62fd
8 changed files with 45 additions and 73 deletions

View File

@@ -25,12 +25,10 @@ def sample() -> Sample:
after_lp=Features(
lp_solve=LPSolveStats(),
),
after_mip=Features(
mip_solve=MIPSolveStats(
mip_lower_bound=1.0,
mip_upper_bound=2.0,
)
),
data={
"mip_lower_bound": 1.0,
"mip_upper_bound": 2.0,
},
)
sample.after_load.instance.to_list = Mock(return_value=[1.0, 2.0]) # type: ignore
sample.after_lp.lp_solve.to_list = Mock(return_value=[3.0]) # type: ignore

View File

@@ -36,12 +36,10 @@ def sample() -> Sample:
after_lp=Features(
variables=VariableFeatures(),
),
after_mip=Features(
variables=VariableFeatures(
names=["x[0]", "x[1]", "x[2]", "x[3]"],
values=[0.0, 1.0, 1.0, 0.0],
)
),
data={
"var_names": ["x[0]", "x[1]", "x[2]", "x[3]"],
"mip_var_values": [0.0, 1.0, 1.0, 0.0],
},
)
sample.after_load.instance.to_list = Mock(return_value=[5.0]) # type: ignore
sample.after_load.variables.to_list = Mock( # type:ignore

View File

@@ -41,14 +41,9 @@ def test_instance() -> None:
solver.solve(instance)
assert len(instance.get_samples()) == 1
sample = instance.get_samples()[0]
assert sample.after_mip is not None
features = sample.after_mip
assert features is not None
assert features.variables is not None
assert features.variables.values == [1.0, 0.0, 1.0, 1.0, 0.0, 1.0]
assert features.mip_solve is not None
assert features.mip_solve.mip_lower_bound == 4.0
assert features.mip_solve.mip_upper_bound == 4.0
assert sample.get("mip_var_values") == [1.0, 0.0, 1.0, 1.0, 0.0, 1.0]
assert sample.get("mip_lower_bound") == 4.0
assert sample.get("mip_upper_bound") == 4.0
def test_subtour() -> None:
@@ -73,10 +68,7 @@ def test_subtour() -> None:
lazy_enforced = sample.get("lazy_enforced")
assert lazy_enforced is not None
assert len(lazy_enforced) > 0
assert sample.after_mip is not None
features = sample.after_mip
assert features.variables is not None
assert features.variables.values == [
assert sample.get("mip_var_values") == [
1.0,
0.0,
0.0,

View File

@@ -38,25 +38,18 @@ def test_learning_solver(
assert len(instance.get_samples()) > 0
sample = instance.get_samples()[0]
after_mip = sample.after_mip
assert after_mip is not None
assert after_mip.variables is not None
assert after_mip.variables.values == [1.0, 0.0, 1.0, 1.0, 61.0]
assert after_mip.mip_solve is not None
assert after_mip.mip_solve.mip_lower_bound == 1183.0
assert after_mip.mip_solve.mip_upper_bound == 1183.0
assert after_mip.mip_solve.mip_log is not None
assert len(after_mip.mip_solve.mip_log) > 100
assert sample.get("mip_var_values") == [1.0, 0.0, 1.0, 1.0, 61.0]
assert sample.get("mip_lower_bound") == 1183.0
assert sample.get("mip_upper_bound") == 1183.0
mip_log = sample.get("mip_log")
assert mip_log is not None
assert len(mip_log) > 100
after_lp = sample.after_lp
assert after_lp is not None
assert after_lp.variables is not None
assert_equals(after_lp.variables.values, [1.0, 0.923077, 1.0, 0.0, 67.0])
assert after_lp.lp_solve is not None
assert after_lp.lp_solve.lp_value is not None
assert round(after_lp.lp_solve.lp_value, 3) == 1287.923
assert after_lp.lp_solve.lp_log is not None
assert len(after_lp.lp_solve.lp_log) > 100
assert_equals(sample.get("lp_var_values"), [1.0, 0.923077, 1.0, 0.0, 67.0])
assert_equals(sample.get("lp_value"), 1287.923077)
lp_log = sample.get("lp_log")
assert lp_log is not None
assert len(lp_log) > 100
solver.fit([instance], n_jobs=4)
solver.solve(instance)