Remove tuples from ConstraintFeatures

This commit is contained in:
2021-05-20 10:23:53 -05:00
parent f9ac65bf9c
commit c494f3e804
9 changed files with 139 additions and 147 deletions

View File

@@ -33,20 +33,20 @@ def sample() -> Sample:
lazy_constraint_count=4,
),
constraints=ConstraintFeatures(
names=("c1", "c2", "c3", "c4", "c5"),
categories=(
names=["c1", "c2", "c3", "c4", "c5"],
categories=[
"type-a",
"type-a",
"type-a",
"type-b",
"type-b",
),
lazy=(True, True, True, True, False),
],
lazy=[True, True, True, True, False],
),
),
after_lp=Features(
instance=InstanceFeatures(),
constraints=ConstraintFeatures(names=("c1", "c2", "c3", "c4", "c5")),
constraints=ConstraintFeatures(names=["c1", "c2", "c3", "c4", "c5"]),
),
after_mip=Features(
extra={
@@ -132,7 +132,7 @@ def test_usage_with_solver(instance: Instance) -> None:
# Should ask internal solver to remove some constraints
assert internal.remove_constraints.call_count == 1
internal.remove_constraints.assert_has_calls([call(("c3",))])
internal.remove_constraints.assert_has_calls([call(["c3"])])
# LearningSolver calls after_iteration (first time)
should_repeat = component.iteration_cb(solver, instance, None)
@@ -141,7 +141,7 @@ def test_usage_with_solver(instance: Instance) -> None:
# Should ask internal solver to verify if constraints in the pool are
# satisfied and add the ones that are not
assert sample.after_load.constraints is not None
c = sample.after_load.constraints[False, False, True, False, False]
c = sample.after_load.constraints[[False, False, True, False, False]]
internal.are_constraints_satisfied.assert_called_once_with(c, tol=1.0)
internal.are_constraints_satisfied.reset_mock()
internal.add_constraints.assert_called_once_with(c)

View File

@@ -65,26 +65,26 @@ def test_knapsack() -> None:
assert_equals(
_round(features.constraints),
ConstraintFeatures(
basis_status=("N",),
categories=("eq_capacity",),
dual_values=(13.538462,),
names=("eq_capacity",),
lazy=(False,),
lhs=(
(
basis_status=["N"],
categories=["eq_capacity"],
dual_values=[13.538462],
names=["eq_capacity"],
lazy=[False],
lhs=[
[
("x[0]", 23.0),
("x[1]", 26.0),
("x[2]", 20.0),
("x[3]", 18.0),
("z", -1.0),
),
),
rhs=(0.0,),
sa_rhs_down=(-24.0,),
sa_rhs_up=(2.0,),
senses=("=",),
slacks=(0.0,),
user_features=((0.0,),),
],
],
rhs=[0.0],
sa_rhs_down=[-24.0],
sa_rhs_up=[2.0],
senses=["="],
slacks=[0.0],
user_features=[[0.0]],
),
)
assert_equals(
@@ -98,39 +98,39 @@ def test_knapsack() -> None:
def test_constraint_getindex() -> None:
cf = ConstraintFeatures(
names=("c1", "c2", "c3"),
rhs=(1.0, 2.0, 3.0),
senses=("=", "<", ">"),
lhs=(
(
names=["c1", "c2", "c3"],
rhs=[1.0, 2.0, 3.0],
senses=["=", "<", ">"],
lhs=[
[
("x1", 1.0),
("x2", 1.0),
),
(
],
[
("x2", 2.0),
("x3", 2.0),
),
(
],
[
("x3", 3.0),
("x4", 3.0),
),
),
],
],
)
assert_equals(
cf[True, False, True],
cf[[True, False, True]],
ConstraintFeatures(
names=("c1", "c3"),
rhs=(1.0, 3.0),
senses=("=", ">"),
lhs=(
(
names=["c1", "c3"],
rhs=[1.0, 3.0],
senses=["=", ">"],
lhs=[
[
("x1", 1.0),
("x2", 1.0),
),
(
],
[
("x3", 3.0),
("x4", 3.0),
),
),
],
],
),
)