Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp/src/routing/diversity/diverse_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,9 +865,9 @@ struct solve {
temp_pair.first = injection_info.solutions[next_injection];
if (!p->has_vehicle_fixed_costs()) {
auto injection_it = next_injection;
while (injection_it < injection_info.n_sol &&
while (injection_it < injection_info.n_sol-1 &&
Copy link
Contributor

@hlinsen hlinsen Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reporting the bug and submitting the PR!
Could you please add the failing test here https://github.com/NVIDIA/cuopt/blob/branch-25.10/python/cuopt/cuopt/tests/routing/test_initial_solutions.py? Assuming you have the code ready.

Regarding the fix, after the change in your example we would be skipping sol[0] and add try to add it while omitting the target vehicle check.
We should set accepted in the for loop:

            while (injection_it < injection_info.n_sol &&
                   temp_pair.first.sol.get_n_routes() > target_vehicles_) {
              injection_info.accepted[injection_it] = 0;
              temp_pair.first = injection_info.solutions[injection_it++];
            }

And here check that next_injection < injection_info.n_sol as we could skip all solutions due to vehicle count and try to insert temp.first then write to accepted thus the out of bounds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hlinsen, thank you for your patience, and apologies for the delayed response.

Unfortunately, I don’t have a minimal failing test case available, as I encountered the issue on a large instance while working on my own implementation. I hope that’s not a problem, since the issue seems fairly clear from the code itself.

Regarding the fix, I think it depends on how you envision the logic of the algorithm. If the primary objective is to minimize the number of vehicles, and a solution with fewer vehicles has already been found, then it might make sense to skip all initial solutions with more vehicles.

That said, in my opinion, it could still be beneficial to include those initial solutions with more vehicles, since the crossover algorithm might be able to leverage them to generate improved solutions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In cuOpt we always assume minimization unless vehicle_fixed_costs are set or we use a fixed vehicle count in this case it does not change throughout the solve. Before the vehicle skip loop we are explicitly checking if vehicle fixed costs are set so following that logic we would not want to insert these vehicles at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SomovMike , let me know if my comment makes sense. We should try to merge this asap since the fix is pretty small in any case :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @hlinsen, okey, I got it. Your comment makes sense.

temp_pair.first.sol.get_n_routes() > target_vehicles_) {
temp_pair.first = injection_info.solutions[injection_it++];
temp_pair.first = injection_info.solutions[++injection_it];
}
next_injection = injection_it;
}
Expand Down
Loading