Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions cpp/src/routing/adapters/adapted_modifier.cu
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ template <typename i_t, typename f_t, request_t REQUEST>
void adapted_modifier_t<i_t, f_t, REQUEST>::equalize_routes_and_nodes(
adapted_sol_t<i_t, f_t, REQUEST>& sol_a,
adapted_sol_t<i_t, f_t, REQUEST>& sol_b,
costs final_weight)
costs final_weight,
bool skip_adding_nodes_to_a)
{
raft::common::nvtx::range fun_scope("equalize_routes_and_nodes");

Expand All @@ -153,7 +154,7 @@ void adapted_modifier_t<i_t, f_t, REQUEST>::equalize_routes_and_nodes(
}
}

if (sol_a.sol.get_n_routes() > sol_b.sol.get_n_routes()) {
if (!skip_adding_nodes_to_a && sol_a.sol.get_n_routes() > sol_b.sol.get_n_routes()) {
auto removed_nodes = sol_a.priority_remove_diff_routes(sol_b);
missing_in_a.insert(missing_in_a.end(), removed_nodes.begin(), removed_nodes.end());
} else if (sol_b.sol.get_n_routes() > sol_a.sol.get_n_routes()) {
Expand All @@ -164,7 +165,9 @@ void adapted_modifier_t<i_t, f_t, REQUEST>::equalize_routes_and_nodes(
// If there are no mutually exclusive requests, take an early exit
if (missing_in_a.empty() && missing_in_b.empty()) { return; }

add_selected_unserviced_requests(sol_a, missing_in_a, final_weight);
if (!skip_adding_nodes_to_a) {
add_selected_unserviced_requests(sol_a, missing_in_a, final_weight);
}
add_selected_unserviced_requests(sol_b, missing_in_b, final_weight);
}

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/routing/adapters/adapted_modifier.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ struct adapted_modifier_t {

void equalize_routes_and_nodes(adapted_sol_t<i_t, f_t, REQUEST>& sol_a,
adapted_sol_t<i_t, f_t, REQUEST>& sol_b,
costs final_weight);
costs final_weight,
bool skip_adding_nodes_to_a = false);

void insert_infeasible_nodes(adapted_sol_t<i_t, f_t, REQUEST>& sol, costs& weights);

Expand Down
4 changes: 3 additions & 1 deletion cpp/src/routing/diversity/diverse_solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1167,8 +1167,10 @@ struct solve {
}

case recombiner_t::IX: {
auto skip_adding_nodes_to_a = true;
lm.equalize_routes_and_nodes(a, b, weights, skip_adding_nodes_to_a);
success = inversion.recombine(a, b);
if (success) recombine_stats.add_success();
if (success) { recombine_stats.add_success(); }
break;
}

Expand Down
19 changes: 16 additions & 3 deletions cpp/src/routing/diversity/injection_info.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
* All rights reserved. SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,7 +47,8 @@ struct injection_info_t {
auto tmp_routes = cuopt::host_copy(d_routes, stream);
auto vehicle_ids = cuopt::host_copy(d_vehicle_ids, stream);
auto node_types = cuopt::host_copy(d_types, stream);
n_sol = sol_offsets.size() - 1;

n_sol = sol_offsets.size() - 1;

accepted.resize(n_sol, -1);

Expand Down Expand Up @@ -87,6 +88,17 @@ struct injection_info_t {
added_node_ids.insert(tmp_routes[j]);
}

if (p->order_info.is_pdp()) {
for (int node_id : added_node_ids) {
int brother_id = p->get_brother_node_info(p->get_node_info_of_node(node_id)).node();
auto cond = added_node_ids.count(brother_id) > 0;
if (!cond) {
std::cout << "node_id: " << node_id << " brother_id: " << brother_id << std::endl;
}
cuopt_expects(cond, error_type_t::ValidationError, "Brother node is not served");
}
}

desired_vehicle_ids.push_back(curr_vehicle_id);
sol_routes.push_back({sol_n_routes++, new_route});
cuopt_expects(sol_n_routes <= p->get_fleet_size(),
Expand All @@ -113,6 +125,7 @@ struct injection_info_t {
std::iota(sequence.begin(), sequence.end(), 0);
S.remove_routes(sequence);
S.add_new_routes(sol_routes);
S.sol.global_runtime_checks(false, false, "Check solution after injection");
solutions.emplace_back(std::move(S));
}
return solutions;
Expand Down
14 changes: 12 additions & 2 deletions cpp/src/utilities/copy_helpers.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights
* reserved. SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: Copyright (c) 2022-2025 NVIDIA CORPORATION &
* AFFILIATES. All rights reserved. SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -173,6 +173,16 @@ inline auto device_copy(std::vector<bool> const& host_vec, rmm::cuda_stream_view
return device_vec;
}

template <typename T>
void print(std::string_view const name, std::vector<T> const& container)
{
std::cout << name << "=[";
for (auto const& item : container) {
std::cout << item << ",";
}
std::cout << "]\n";
}

template <typename T>
void print(std::string_view const name, rmm::device_uvector<T> const& container)
{
Expand Down