mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 01:18:52 -06:00
Use np.ndarray in Variables
This commit is contained in:
@@ -24,7 +24,7 @@ def sample() -> Sample:
|
||||
{
|
||||
"static_var_names": ["x[0]", "x[1]", "x[2]", "x[3]"],
|
||||
"static_var_categories": ["default", None, "default", "default"],
|
||||
"mip_var_values": [0.0, 1.0, 1.0, 0.0],
|
||||
"mip_var_values": np.array([0.0, 1.0, 1.0, 0.0]),
|
||||
"static_instance_features": [5.0],
|
||||
"static_var_features": [
|
||||
[0.0, 0.0],
|
||||
|
||||
@@ -32,7 +32,8 @@ def test_knapsack() -> None:
|
||||
# -------------------------------------------------------
|
||||
extractor.extract_after_load_features(instance, solver, sample)
|
||||
assert_equals(
|
||||
sample.get_vector("static_var_names"), ["x[0]", "x[1]", "x[2]", "x[3]", "z"]
|
||||
sample.get_vector("static_var_names"),
|
||||
["x[0]", "x[1]", "x[2]", "x[3]", "z"],
|
||||
)
|
||||
assert_equals(
|
||||
sample.get_vector("static_var_lower_bounds"), [0.0, 0.0, 0.0, 0.0, 0.0]
|
||||
|
||||
@@ -17,7 +17,7 @@ def test_usage() -> None:
|
||||
# Save instance to disk
|
||||
filename = tempfile.mktemp()
|
||||
FileInstance.save(original, filename)
|
||||
sample = Hdf5Sample(filename)
|
||||
sample = Hdf5Sample(filename, check_data=True)
|
||||
assert len(sample.get_bytes("pickled")) > 0
|
||||
|
||||
# Solve instance from disk
|
||||
|
||||
@@ -9,6 +9,7 @@ from scipy.stats import uniform, randint
|
||||
|
||||
from miplearn.problems.tsp import TravelingSalesmanGenerator, TravelingSalesmanInstance
|
||||
from miplearn.solvers.learning import LearningSolver
|
||||
from miplearn.solvers.tests import assert_equals
|
||||
|
||||
|
||||
def test_generator() -> None:
|
||||
@@ -41,7 +42,7 @@ def test_instance() -> None:
|
||||
solver.solve(instance)
|
||||
assert len(instance.get_samples()) == 1
|
||||
sample = instance.get_samples()[0]
|
||||
assert sample.get_vector("mip_var_values") == [1.0, 0.0, 1.0, 1.0, 0.0, 1.0]
|
||||
assert_equals(sample.get_vector("mip_var_values"), [1.0, 0.0, 1.0, 1.0, 0.0, 1.0])
|
||||
assert sample.get_scalar("mip_lower_bound") == 4.0
|
||||
assert sample.get_scalar("mip_upper_bound") == 4.0
|
||||
|
||||
@@ -68,22 +69,25 @@ def test_subtour() -> None:
|
||||
lazy_enforced = sample.get_set("mip_constr_lazy_enforced")
|
||||
assert lazy_enforced is not None
|
||||
assert len(lazy_enforced) > 0
|
||||
assert sample.get_vector("mip_var_values") == [
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
]
|
||||
assert_equals(
|
||||
sample.get_vector("mip_var_values"),
|
||||
[
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
],
|
||||
)
|
||||
solver.fit([instance])
|
||||
solver.solve(instance)
|
||||
|
||||
@@ -38,7 +38,9 @@ def test_learning_solver(
|
||||
assert len(instance.get_samples()) > 0
|
||||
sample = instance.get_samples()[0]
|
||||
|
||||
assert sample.get_vector("mip_var_values") == [1.0, 0.0, 1.0, 1.0, 61.0]
|
||||
assert_equals(
|
||||
sample.get_vector("mip_var_values"), [1.0, 0.0, 1.0, 1.0, 61.0]
|
||||
)
|
||||
assert sample.get_scalar("mip_lower_bound") == 1183.0
|
||||
assert sample.get_scalar("mip_upper_bound") == 1183.0
|
||||
mip_log = sample.get_scalar("mip_log")
|
||||
|
||||
Reference in New Issue
Block a user