-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_solvers.py
33 lines (28 loc) · 1.22 KB
/
test_solvers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import logging
from discrete_optimization.vrp.parser import get_data_available, parse_file
from discrete_optimization.vrp.solvers.greedy import GreedyVrpSolver
from discrete_optimization.vrp.solvers.ortools_routing import (
FirstSolutionStrategy,
LocalSearchMetaheuristic,
OrtoolsVrpSolver,
)
def test_ortools_vrp_solver():
logging.basicConfig(level=logging.ERROR)
file_path = [f for f in get_data_available() if "vrp_31_9_1" in f][0]
vrp_problem = parse_file(file_path)
solver = OrtoolsVrpSolver(problem=vrp_problem)
solver.init_model(
first_solution_strategy=FirstSolutionStrategy.SAVINGS,
local_search_metaheuristic=LocalSearchMetaheuristic.GUIDED_LOCAL_SEARCH,
)
res = solver.solve(time_limit_seconds=20)
sol, fit = res.get_best_solution_fit()
assert vrp_problem.satisfy(sol)
def test_greedy_vrp_solver():
logging.basicConfig(level=logging.ERROR)
file_path = [f for f in get_data_available() if "vrp_31_9_1" in f][0]
vrp_problem = parse_file(file_path)
greedy_solver = GreedyVrpSolver(problem=vrp_problem, params_objective_function=None)
res = greedy_solver.solve(time_limit=20)
sol, fit = res.get_best_solution_fit()
assert vrp_problem.satisfy(sol)