Remove tuples from VariableFeatures

This commit is contained in:
2021-05-20 10:03:18 -05:00
parent fa969cf066
commit f9ac65bf9c
8 changed files with 98 additions and 111 deletions

View File

@@ -29,8 +29,8 @@ def sample() -> Sample:
after_load=Features(
instance=InstanceFeatures(),
variables=VariableFeatures(
names=("x[0]", "x[1]", "x[2]", "x[3]"),
categories=("default", None, "default", "default"),
names=["x[0]", "x[1]", "x[2]", "x[3]"],
categories=["default", None, "default", "default"],
),
),
after_lp=Features(
@@ -38,8 +38,8 @@ def sample() -> Sample:
),
after_mip=Features(
variables=VariableFeatures(
names=("x[0]", "x[1]", "x[2]", "x[3]"),
values=(0.0, 1.0, 1.0, 0.0),
names=["x[0]", "x[1]", "x[2]", "x[3]"],
values=[0.0, 1.0, 1.0, 0.0],
)
),
)

View File

@@ -44,7 +44,7 @@ def test_instance() -> None:
features = instance.samples[0].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.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
@@ -75,7 +75,7 @@ def test_subtour() -> None:
assert lazy_enforced is not None
assert len(lazy_enforced) > 0
assert features.variables is not None
assert features.variables.values == (
assert features.variables.values == [
1.0,
0.0,
0.0,
@@ -91,6 +91,6 @@ def test_subtour() -> None:
0.0,
1.0,
1.0,
)
]
solver.fit([instance])
solver.solve(instance)

View File

@@ -41,7 +41,7 @@ def test_learning_solver(
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.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
@@ -51,7 +51,7 @@ def test_learning_solver(
after_lp = sample.after_lp
assert after_lp is not None
assert after_lp.variables is not None
assert _round(after_lp.variables.values) == (1.0, 0.923077, 1.0, 0.0, 67.0)
assert _round(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

View File

@@ -31,28 +31,28 @@ def test_knapsack() -> None:
assert_equals(
_round(features.variables),
VariableFeatures(
names=("x[0]", "x[1]", "x[2]", "x[3]", "z"),
basis_status=("U", "B", "U", "L", "U"),
categories=("default", "default", "default", "default", None),
lower_bounds=(0.0, 0.0, 0.0, 0.0, 0.0),
obj_coeffs=(505.0, 352.0, 458.0, 220.0, 0.0),
reduced_costs=(193.615385, 0.0, 187.230769, -23.692308, 13.538462),
sa_lb_down=(-inf, -inf, -inf, -0.111111, -inf),
sa_lb_up=(1.0, 0.923077, 1.0, 1.0, 67.0),
sa_obj_down=(311.384615, 317.777778, 270.769231, -inf, -13.538462),
sa_obj_up=(inf, 570.869565, inf, 243.692308, inf),
sa_ub_down=(0.913043, 0.923077, 0.9, 0.0, 43.0),
sa_ub_up=(2.043478, inf, 2.2, inf, 69.0),
types=("B", "B", "B", "B", "C"),
upper_bounds=(1.0, 1.0, 1.0, 1.0, 67.0),
user_features=(
(23.0, 505.0),
(26.0, 352.0),
(20.0, 458.0),
(18.0, 220.0),
names=["x[0]", "x[1]", "x[2]", "x[3]", "z"],
basis_status=["U", "B", "U", "L", "U"],
categories=["default", "default", "default", "default", None],
lower_bounds=[0.0, 0.0, 0.0, 0.0, 0.0],
obj_coeffs=[505.0, 352.0, 458.0, 220.0, 0.0],
reduced_costs=[193.615385, 0.0, 187.230769, -23.692308, 13.538462],
sa_lb_down=[-inf, -inf, -inf, -0.111111, -inf],
sa_lb_up=[1.0, 0.923077, 1.0, 1.0, 67.0],
sa_obj_down=[311.384615, 317.777778, 270.769231, -inf, -13.538462],
sa_obj_up=[inf, 570.869565, inf, 243.692308, inf],
sa_ub_down=[0.913043, 0.923077, 0.9, 0.0, 43.0],
sa_ub_up=[2.043478, inf, 2.2, inf, 69.0],
types=["B", "B", "B", "B", "C"],
upper_bounds=[1.0, 1.0, 1.0, 1.0, 67.0],
user_features=[
[23.0, 505.0],
[26.0, 352.0],
[20.0, 458.0],
[18.0, 220.0],
None,
),
values=(1.0, 0.923077, 1.0, 0.0, 67.0),
],
values=[1.0, 0.923077, 1.0, 0.0, 67.0],
alvarez_2017=[
[1.0, 0.32899, 0.0, 0.0, 1.0, 1.0, 5.265874, 46.051702],
[1.0, 0.229316, 0.0, 0.076923, 1.0, 1.0, 3.532875, 5.388476],