Skip to content

Commit 78efc63

Browse files
committed
Remove solve time from return
1 parent e0c9d3d commit 78efc63

File tree

7 files changed

+50
-110
lines changed

7 files changed

+50
-110
lines changed

cpp/include/cuopt/routing/cython/cython.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <raft/core/handle.hpp>
1717

1818
#include <memory>
19-
#include <utility>
2019
#include <vector>
2120

2221
namespace cuopt {
@@ -85,7 +84,7 @@ std::unique_ptr<vehicle_routing_ret_t> call_solve(routing::data_model_view_t<int
8584
routing::solver_settings_t<int, float>*);
8685

8786
// Wrapper for batch solve to expose the API to cython.
88-
std::pair<std::vector<std::unique_ptr<vehicle_routing_ret_t>>, double> call_batch_solve(
87+
std::vector<std::unique_ptr<vehicle_routing_ret_t>> call_batch_solve(
8988
std::vector<routing::data_model_view_t<int, float>*>, routing::solver_settings_t<int, float>*);
9089

9190
// Wrapper for dataset to expose the API to cython.

cpp/src/routing/utilities/cython.cu

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,27 +95,24 @@ std::unique_ptr<vehicle_routing_ret_t> call_solve(
9595
*
9696
* @param data_models Vector of data model pointers
9797
* @param settings Composable solver settings object
98-
* @return std::pair<std::vector<std::unique_ptr<vehicle_routing_ret_t>>, double>
98+
* @return std::vector<std::unique_ptr<vehicle_routing_ret_t>>
9999
*/
100-
std::pair<std::vector<std::unique_ptr<vehicle_routing_ret_t>>, double> call_batch_solve(
100+
std::vector<std::unique_ptr<vehicle_routing_ret_t>> call_batch_solve(
101101
std::vector<routing::data_model_view_t<int, float>*> data_models,
102102
routing::solver_settings_t<int, float>* settings)
103103
{
104-
raft::common::nvtx::range fun_scope("Call batch solve routing");
105-
106104
const std::size_t size = data_models.size();
107105
std::vector<std::unique_ptr<vehicle_routing_ret_t>> list(size);
108106

109-
auto start_solver = std::chrono::high_resolution_clock::now();
110-
111107
// Use OpenMP for parallel execution
112108
const int max_thread = std::min(static_cast<int>(size), omp_get_max_threads());
113-
rmm::cuda_stream_pool stream_pool(data_models.size());
109+
// rmm::cuda_stream_pool stream_pool(data_models.size());
114110

115111
#pragma omp parallel for num_threads(max_thread)
116112
for (std::size_t i = 0; i < size; ++i) {
117-
data_models[i]->get_handle_ptr()->sync_stream();
118-
raft::resource::set_cuda_stream(*(data_models[i]->get_handle_ptr()), stream_pool.get_stream(i));
113+
// data_models[i]->get_handle_ptr()->sync_stream();
114+
// raft::resource::set_cuda_stream(*(data_models[i]->get_handle_ptr()),
115+
// stream_pool.get_stream(i));
119116
auto routing_solution = cuopt::routing::solve(*data_models[i], *settings);
120117
vehicle_routing_ret_t vr_ret{
121118
routing_solution.get_vehicle_count(),
@@ -135,10 +132,7 @@ std::pair<std::vector<std::unique_ptr<vehicle_routing_ret_t>>, double> call_batc
135132
list[i] = std::make_unique<vehicle_routing_ret_t>(std::move(vr_ret));
136133
}
137134

138-
auto end = std::chrono::high_resolution_clock::now();
139-
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start_solver);
140-
141-
return {std::move(list), duration.count() / 1000.0};
135+
return list;
142136
}
143137

144138
/**

cpp/tests/routing/CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ ConfigureTest(ROUTING_L1TEST ${CMAKE_CURRENT_SOURCE_DIR}/level1/l1_routing_test.
2020

2121
# # - ${CMAKE_CURRENT_SOURCE_DIR} unit tests ----------------------------------------------------------------------------
2222
ConfigureTest(ROUTING_UNIT_TEST
23-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_types.cu
24-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/breaks.cu
25-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/heterogenous_breaks.cu
26-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_fixed_costs.cu
27-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_order_match.cu
28-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/order_locations.cu
29-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/horizontal_loading.cu
30-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/route_constraints.cu
31-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/heterogenous_fleet.cu
32-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/prize_collection.cu
33-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/objective_function.cu
34-
# ${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/top_k.cu
23+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_types.cu
24+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/breaks.cu
25+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/heterogenous_breaks.cu
26+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_fixed_costs.cu
27+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/vehicle_order_match.cu
28+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/order_locations.cu
29+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/horizontal_loading.cu
30+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/route_constraints.cu
31+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/heterogenous_fleet.cu
32+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/prize_collection.cu
33+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/objective_function.cu
34+
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/top_k.cu
3535
${CMAKE_CURRENT_SOURCE_DIR}/unit_tests/batch_tsp.cu
3636
)

cpp/tests/routing/unit_tests/batch_tsp.cu

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ TEST(batch_tsp, varying_sizes)
7272
settings.set_time_limit(5);
7373

7474
// Call batch solve
75-
auto [solutions, solve_time] = cuopt::cython::call_batch_solve(data_model_ptrs, &settings);
75+
auto solutions = cuopt::cython::call_batch_solve(data_model_ptrs, &settings);
7676

7777
// Verify all solutions
7878
ASSERT_EQ(solutions.size(), n_problems);
@@ -82,9 +82,6 @@ TEST(batch_tsp, varying_sizes)
8282
EXPECT_EQ(solutions[i]->vehicle_count_, 1)
8383
<< "TSP " << i << " (size " << tsp_sizes[i] << ") used multiple vehicles";
8484
}
85-
86-
// Verify solve time is reasonable
87-
EXPECT_GT(solve_time, 0.0) << "Solve time should be positive";
8885
}
8986

9087
} // namespace test

python/cuopt/cuopt/routing/vehicle_routing.pxd

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# cython: language_level = 3
99

1010
from libcpp cimport bool
11-
from libcpp.pair cimport pair
1211
from libcpp.string cimport string
1312
from libcpp.vector cimport vector
1413

@@ -136,7 +135,7 @@ cdef extern from "cuopt/routing/cython/cython.hpp" namespace "cuopt::cython": #
136135
solver_settings_t[int, float]* solver_settings
137136
) except +
138137

139-
cdef pair[vector[unique_ptr[vehicle_routing_ret_t]], double] call_batch_solve(
138+
cdef vector[unique_ptr[vehicle_routing_ret_t]] call_batch_solve(
140139
vector[data_model_view_t[int, float] *] data_models,
141-
solver_settings_t[int, float]* solver_settings,
140+
solver_settings_t[int, float]* solver_settings
142141
) except +

python/cuopt/cuopt/routing/vehicle_routing_wrapper.pyx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -945,21 +945,18 @@ def BatchSolve(py_data_model_list, SolverSettings solver_settings):
945945
(<DataModel>data_model_obj).c_data_model_view.get()
946946
)
947947

948-
cdef pair[
949-
vector[unique_ptr[vehicle_routing_ret_t]],
950-
double] batch_solve_result = (
948+
cdef vector[unique_ptr[vehicle_routing_ret_t]] batch_solve_result = (
951949
move(call_batch_solve(data_model_views, c_solver_settings))
952950
)
953951

954952
cdef vector[unique_ptr[vehicle_routing_ret_t]] c_solutions = (
955-
move(batch_solve_result.first)
953+
move(batch_solve_result)
956954
)
957-
cdef double solve_time = batch_solve_result.second
958955

959956
solutions = []
960957
for i in range(c_solutions.size()):
961958
solutions.append(
962959
create_assignment_from_vr_ret(c_solutions[i].get()[0])
963960
)
964961

965-
return solutions, solve_time
962+
return solutions

python/cuopt/cuopt/tests/routing/test_batch_solve.py

Lines changed: 24 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,28 @@ def create_tsp_cost_matrix(n_locations):
1818

1919
def 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

Comments
 (0)