@@ -18,7 +18,28 @@ def create_tsp_cost_matrix(n_locations):
1818
1919def test_batch_solve_varying_sizes ():
2020 """Test batch solving TSPs of varying sizes."""
21- tsp_sizes = [5 , 8 , 10 , 6 , 7 , 9 ]
21+ tsp_sizes = [
22+ 5 ,
23+ 8 ,
24+ 10 ,
25+ 6 ,
26+ 7 ,
27+ 9 ,
28+ 12 ,
29+ 15 ,
30+ 11 ,
31+ 4 ,
32+ 13 ,
33+ 14 ,
34+ 8 ,
35+ 6 ,
36+ 10 ,
37+ 9 ,
38+ 7 ,
39+ 11 ,
40+ 5 ,
41+ 12 ,
42+ ]
2243
2344 # Create data models for each TSP
2445 data_models = []
@@ -33,81 +54,14 @@ def test_batch_solve_varying_sizes():
3354 settings .set_time_limit (5.0 )
3455
3556 # Call batch solve
36- solutions , solve_time = routing .BatchSolve (data_models , settings )
57+ solutions = routing .BatchSolve (data_models , settings )
3758
3859 # Verify results
3960 assert len (solutions ) == len (tsp_sizes )
4061 for i , solution in enumerate (solutions ):
41- assert solution .get_status () == routing . SolutionStatus . SUCCESS , (
62+ assert solution .get_status () == 0 , (
4263 f"TSP { i } (size { tsp_sizes [i ]} ) failed"
4364 )
4465 assert solution .get_vehicle_count () == 1 , (
4566 f"TSP { i } (size { tsp_sizes [i ]} ) used multiple vehicles"
4667 )
47-
48- # Verify solve time is reasonable
49- assert solve_time > 0.0 , "Solve time should be positive"
50-
51-
52- def test_batch_solve_same_size ():
53- """Test batch solving multiple TSPs of the same size."""
54- n_problems = 10
55- n_locations = 6
56-
57- # Create data models
58- data_models = []
59- for _ in range (n_problems ):
60- cost_matrix = create_tsp_cost_matrix (n_locations )
61- dm = routing .DataModel (n_locations , 1 )
62- dm .add_cost_matrix (cost_matrix )
63- data_models .append (dm )
64-
65- # Configure solver settings
66- settings = routing .SolverSettings ()
67- settings .set_time_limit (2.0 )
68-
69- # Call batch solve
70- solutions , solve_time = routing .BatchSolve (data_models , settings )
71-
72- # Verify all solutions succeeded
73- assert len (solutions ) == n_problems
74- for i , solution in enumerate (solutions ):
75- assert solution .get_status () == routing .SolutionStatus .SUCCESS , (
76- f"TSP { i } failed"
77- )
78-
79-
80- def test_batch_solve_single_problem ():
81- """Test batch solve with a single problem."""
82- n_locations = 5
83-
84- cost_matrix = create_tsp_cost_matrix (n_locations )
85- dm = routing .DataModel (n_locations , 1 )
86- dm .add_cost_matrix (cost_matrix )
87-
88- settings = routing .SolverSettings ()
89- settings .set_time_limit (2.0 )
90-
91- solutions , solve_time = routing .BatchSolve ([dm ], settings )
92-
93- assert len (solutions ) == 1
94- assert solutions [0 ].get_status () == routing .SolutionStatus .SUCCESS
95-
96-
97- def test_batch_solve_default_settings ():
98- """Test batch solve with default solver settings."""
99- tsp_sizes = [5 , 6 , 7 ]
100-
101- data_models = []
102- for n_locations in tsp_sizes :
103- cost_matrix = create_tsp_cost_matrix (n_locations )
104- dm = routing .DataModel (n_locations , 1 )
105- dm .add_cost_matrix (cost_matrix )
106- data_models .append (dm )
107-
108- # Call batch solve without explicit settings
109- solutions , solve_time = routing .BatchSolve (data_models )
110-
111- assert len (solutions ) == len (tsp_sizes )
112- for solution in solutions :
113- assert solution .get_status () == routing .SolutionStatus .SUCCESS
0 commit comments