Use np.ndarray for constraint names

This commit is contained in:
2021-08-09 05:41:01 -05:00
parent 45667ac2e4
commit 9ddda7e1e2
7 changed files with 33 additions and 27 deletions

View File

@@ -32,9 +32,9 @@ def sample() -> Sample:
"type-b",
],
"static_constr_lazy": [True, True, True, True, False],
"static_constr_names": ["c1", "c2", "c3", "c4", "c5"],
"static_constr_names": np.array(["c1", "c2", "c3", "c4", "c5"], dtype="S"),
"static_instance_features": [5.0],
"mip_constr_lazy_enforced": {"c1", "c2", "c4"},
"mip_constr_lazy_enforced": {b"c1", b"c2", b"c4"},
"lp_constr_features": [
[1.0, 1.0],
[1.0, 2.0],
@@ -110,7 +110,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([b"c3"])])
# LearningSolver calls after_iteration (first time)
should_repeat = component.iteration_cb(solver, instance, None)
@@ -142,7 +142,7 @@ def test_usage_with_solver(instance: Instance) -> None:
)
# Should update training sample
assert sample.get_set("mip_constr_lazy_enforced") == {"c1", "c2", "c3", "c4"}
assert sample.get_set("mip_constr_lazy_enforced") == {b"c1", b"c2", b"c3", b"c4"}
#
# Should update stats
assert stats["LazyStatic: Removed"] == 1
@@ -170,7 +170,7 @@ def test_sample_predict(sample: Sample) -> None:
]
)
pred = comp.sample_predict(sample)
assert pred == ["c1", "c2", "c4"]
assert pred == [b"c1", b"c2", b"c4"]
def test_fit_xy() -> None:

View File

@@ -53,7 +53,10 @@ def test_knapsack() -> None:
["default", "default", "default", "default", None],
)
assert sample.get_vector_list("static_var_features") is not None
assert_equals(sample.get_vector("static_constr_names"), ["eq_capacity"])
assert_equals(
sample.get_vector("static_constr_names"),
np.array(["eq_capacity"], dtype="S"),
)
# assert_equals(
# sample.get_vector("static_constr_lhs"),
# [
@@ -69,7 +72,10 @@ def test_knapsack() -> None:
assert_equals(sample.get_vector("static_constr_rhs"), [0.0])
assert_equals(sample.get_vector("static_constr_senses"), ["="])
assert_equals(sample.get_vector("static_constr_features"), [None])
assert_equals(sample.get_vector("static_constr_categories"), ["eq_capacity"])
assert_equals(
sample.get_vector("static_constr_categories"),
np.array(["eq_capacity"], dtype="S"),
)
assert_equals(sample.get_vector("static_constr_lazy"), [False])
assert_equals(sample.get_vector("static_instance_features"), [67.0, 21.75])
assert_equals(sample.get_scalar("static_constr_lazy_count"), 0)
@@ -124,7 +130,7 @@ def test_knapsack() -> None:
def test_constraint_getindex() -> None:
cf = Constraints(
names=["c1", "c2", "c3"],
names=np.array(["c1", "c2", "c3"], dtype="S"),
rhs=np.array([1.0, 2.0, 3.0]),
senses=["=", "<", ">"],
lhs=[
@@ -145,7 +151,7 @@ def test_constraint_getindex() -> None:
assert_equals(
cf[[True, False, True]],
Constraints(
names=["c1", "c3"],
names=np.array(["c1", "c3"], dtype="S"),
rhs=np.array([1.0, 3.0]),
senses=["=", ">"],
lhs=[