Temporarily remove native solver callbacks; add iteration_cb

This commit is contained in:
2020-09-23 17:30:39 -05:00
parent e731f46b72
commit 425ea2b7cc
10 changed files with 201 additions and 189 deletions

View File

@@ -23,52 +23,52 @@ def test_generator():
assert np.std(d) > 0
def test_instance():
n_cities = 4
distances = np.array([
[0., 1., 2., 1.],
[1., 0., 1., 2.],
[2., 1., 0., 1.],
[1., 2., 1., 0.],
])
instance = TravelingSalesmanInstance(n_cities, distances)
for solver_name in ['gurobi', 'cplex']:
solver = LearningSolver(solver=solver_name)
solver.solve(instance)
x = instance.solution["x"]
assert x[0,1] == 1.0
assert x[0,2] == 0.0
assert x[0,3] == 1.0
assert x[1,2] == 1.0
assert x[1,3] == 0.0
assert x[2,3] == 1.0
assert instance.lower_bound == 4.0
assert instance.upper_bound == 4.0
def test_subtour():
n_cities = 6
cities = np.array([
[0., 0.],
[1., 0.],
[2., 0.],
[3., 0.],
[0., 1.],
[3., 1.],
])
distances = squareform(pdist(cities))
instance = TravelingSalesmanInstance(n_cities, distances)
for solver_name in ['gurobi', 'cplex']:
solver = LearningSolver(solver=solver_name)
solver.solve(instance)
assert hasattr(instance, "found_violated_lazy_constraints")
assert hasattr(instance, "found_violated_user_cuts")
x = instance.solution["x"]
assert x[0,1] == 1.0
assert x[0,4] == 1.0
assert x[1,2] == 1.0
assert x[2,3] == 1.0
assert x[3,5] == 1.0
assert x[4,5] == 1.0
solver.fit([instance])
solver.solve(instance)
# def test_instance():
# n_cities = 4
# distances = np.array([
# [0., 1., 2., 1.],
# [1., 0., 1., 2.],
# [2., 1., 0., 1.],
# [1., 2., 1., 0.],
# ])
# instance = TravelingSalesmanInstance(n_cities, distances)
# for solver_name in ['gurobi', 'cplex']:
# solver = LearningSolver(solver=solver_name)
# solver.solve(instance)
# x = instance.solution["x"]
# assert x[0,1] == 1.0
# assert x[0,2] == 0.0
# assert x[0,3] == 1.0
# assert x[1,2] == 1.0
# assert x[1,3] == 0.0
# assert x[2,3] == 1.0
# assert instance.lower_bound == 4.0
# assert instance.upper_bound == 4.0
#
#
# def test_subtour():
# n_cities = 6
# cities = np.array([
# [0., 0.],
# [1., 0.],
# [2., 0.],
# [3., 0.],
# [0., 1.],
# [3., 1.],
# ])
# distances = squareform(pdist(cities))
# instance = TravelingSalesmanInstance(n_cities, distances)
# for solver_name in ['gurobi', 'cplex']:
# solver = LearningSolver(solver=solver_name)
# solver.solve(instance)
# assert hasattr(instance, "found_violated_lazy_constraints")
# assert hasattr(instance, "found_violated_user_cuts")
# x = instance.solution["x"]
# assert x[0,1] == 1.0
# assert x[0,4] == 1.0
# assert x[1,2] == 1.0
# assert x[2,3] == 1.0
# assert x[3,5] == 1.0
# assert x[4,5] == 1.0
# solver.fit([instance])
# solver.solve(instance)