mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Remove tuples from ConstraintFeatures
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user