Skip to content
Open
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
2 changes: 1 addition & 1 deletion cpp/include/cuopt/routing/data_model_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class data_model_view_t {
i_t num_orders = -1);

/**
* @brief Set a cost (distance) matrix for all locations (depot included) at
* @brief Set a cost matrix for all locations (depot included) at
* once. A cost matrix is defined a square matrix containing the
* costs, taken pairwise, between all locations. Entries are non-negative
* real numbers. Diagonal elements
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/routing/arc_value.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static constexpr NodeInfo<i_t> load(i_t pos, NodeInfo<i_t> const* path_node)

// All values pre-loaded overload
template <typename i_t, typename f_t, bool is_device = true>
static constexpr double get_distance(const NodeInfo<i_t>& l1,
static constexpr double get_arc_cost(const NodeInfo<i_t>& l1,
const NodeInfo<i_t>& l2,
const VehicleInfo<f_t, is_device>& vehicle_info)
{
Expand Down Expand Up @@ -96,7 +96,7 @@ static constexpr double get_arc_dimension(dim_t dim,
const NodeInfo<i_t>& l2,
const VehicleInfo<f_t>& vehicle_info)
{
if (dim == dim_t::DIST) { return get_distance(l1, l2, vehicle_info); }
if (dim == dim_t::COST) { return get_arc_cost(l1, l2, vehicle_info); }
return get_transit_time(l1, l2, vehicle_info);
}

Expand All @@ -105,8 +105,8 @@ static constexpr double get_arc_of_dimension(const NodeInfo<i_t>& l1,
const NodeInfo<i_t>& l2,
const VehicleInfo<f_t, is_device>& vehicle_info)
{
if constexpr (dim == dim_t::DIST) {
return get_distance(l1, l2, vehicle_info);
if constexpr (dim == dim_t::COST) {
return get_arc_cost(l1, l2, vehicle_info);
} else if constexpr (dim == dim_t::TIME) {
return get_transit_time(l1, l2, vehicle_info, true);
} else if constexpr (dim == dim_t::SERVICE_TIME) {
Expand Down
12 changes: 6 additions & 6 deletions cpp/src/routing/dimensions.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace detail {
constexpr double EPSILON = 0.0001;

enum class dim_t {
DIST = 0,
COST = 0,
// time
TIME,
// pdp capacity ( positive/negative supply )
Expand Down Expand Up @@ -241,8 +241,8 @@ static HDI const auto& get_dimension_of(const T& obj) noexcept
{
if constexpr (I == dim_t::TIME) {
return obj.time_dim;
} else if constexpr (I == dim_t::DIST) {
return obj.distance_dim;
} else if constexpr (I == dim_t::COST) {
return obj.cost_dim;
} else if constexpr (I == dim_t::CAP) {
return obj.capacity_dim;
} else if constexpr (I == dim_t::PRIZE) {
Expand Down Expand Up @@ -278,8 +278,8 @@ constexpr auto dim_to_string() noexcept
{
if constexpr (I == (int)dim_t::TIME) {
return "Time dimension";
} else if constexpr (I == (int)dim_t::DIST) {
return "Distance dimension";
} else if constexpr (I == (int)dim_t::COST) {
return "Cost dimension";
} else if constexpr (I == (int)dim_t::CAP) {
return "Capacity dimension";
} else if constexpr (I == (int)dim_t::PRIZE) {
Expand Down Expand Up @@ -395,7 +395,7 @@ class enabled_dimensions_t {
return get_dimension<(size_t)dim>();
}

cost_dimension_info_t distance_dim;
cost_dimension_info_t cost_dim;
time_dimension_info_t time_dim;
capacity_dimension_info_t capacity_dim;
prize_dimension_info_t prize_dim;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/routing/diversity/helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

constexpr bool is_constraint(size_t index)
{
if (index == DIST) return false;
if (index == COST) return false;
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions cpp/src/routing/diversity/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#define DEPO 0

// Array indexes for evaluation of distinct features
// distance
constexpr int DIST = 0;
// cost
constexpr int COST = 0;
// time
constexpr int TIME = 1;
// pdp capacity ( positive/negative supply )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ __global__ void lexicographic_search(typename solution_t<i_t, f_t, REQUEST>::vie
bool is_delivery_time_dist_feasible =
node_stack.delivery_node.time_dim.forward_feasible(
node_stack.s_route.vehicle_info()) &&
node_stack.delivery_node.distance_dim.forward_feasible(
node_stack.s_route.vehicle_info());
node_stack.delivery_node.cost_dim.forward_feasible(node_stack.s_route.vehicle_info());
if (!is_delivery_time_dist_feasible) {
if (--node_stack.stack_top <= 1) { break; }
cuopt_assert(node_stack.template k_max_ejection_check<REQUEST>(), "");
Expand Down Expand Up @@ -393,8 +392,7 @@ __global__ void lexicographic_search(typename solution_t<i_t, f_t, REQUEST>::vie
bool is_delivery_time_dist_feasible =
node_stack.delivery_node.time_dim.forward_feasible(
node_stack.s_route.vehicle_info()) &&
node_stack.delivery_node.distance_dim.forward_feasible(
node_stack.s_route.vehicle_info());
node_stack.delivery_node.cost_dim.forward_feasible(node_stack.s_route.vehicle_info());
if (!is_delivery_time_dist_feasible) {
if (--node_stack.stack_top <= 1) { break; }
advance = true;
Expand Down
42 changes: 21 additions & 21 deletions cpp/src/routing/ges/lexicographic_search/node_stack.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DI static void copy_forward_data(dst_t& dst, const src_t& src)
std::is_same<dst_t, node_t<int, float, request_t::VRP>>::value;

if constexpr (is_src_a_node && !is_dst_a_node) {
dst.distance_forward = src.distance_dim.distance_forward;
dst.cost_forward = src.cost_dim.cost_forward;
dst.transit_time_forward = src.time_dim.transit_time_forward;
dst.latest_arrival_forward = src.time_dim.latest_arrival_forward;
dst.unavoidable_wait_forward = src.time_dim.unavoidable_wait_forward;
Expand All @@ -42,7 +42,7 @@ DI static void copy_forward_data(dst_t& dst, const src_t& src)
}
});
} else if constexpr (is_dst_a_node && !is_src_a_node) {
dst.distance_dim.distance_forward = src.distance_forward;
dst.cost_dim.cost_forward = src.cost_forward;
dst.time_dim.transit_time_forward = src.transit_time_forward;
dst.time_dim.latest_arrival_forward = src.latest_arrival_forward;
dst.time_dim.unavoidable_wait_forward = src.unavoidable_wait_forward;
Expand All @@ -55,7 +55,7 @@ DI static void copy_forward_data(dst_t& dst, const src_t& src)
}
});
} else if constexpr (!is_src_a_node && !is_dst_a_node) {
dst.distance_forward = src.distance_forward;
dst.cost_forward = src.cost_forward;
dst.transit_time_forward = src.transit_time_forward;
dst.latest_arrival_forward = src.latest_arrival_forward;
dst.unavoidable_wait_forward = src.unavoidable_wait_forward;
Expand All @@ -66,7 +66,7 @@ DI static void copy_forward_data(dst_t& dst, const src_t& src)
dst.max_to_node[i] = src.max_to_node[i];
}
} else {
dst.distance_dim.distance_forward = src.distance_dim.distance_forward;
dst.cost_dim.cost_forward = src.cost_dim.cost_forward;
dst.time_dim.transit_time_forward = src.time_dim.transit_time_forward;
dst.time_dim.latest_arrival_forward = src.time_dim.latest_arrival_forward;
dst.time_dim.unavoidable_wait_forward = src.time_dim.unavoidable_wait_forward;
Expand Down Expand Up @@ -119,7 +119,7 @@ struct node_stack_t {

// this will be in shared memory for each thread
struct __align__(32ul) item_t {
double distance_forward;
double cost_forward;
double transit_time_forward;
double latest_arrival_forward;
double unavoidable_wait_forward;
Expand Down Expand Up @@ -210,7 +210,7 @@ struct node_stack_t {
(solution_ptr->get_max_active_nodes_for_all_routes() + 1) * sizeof(f_t);
sh_size += shared_for_time_buffers;
}
if (solution_ptr->problem_ptr->dimensions_info.distance_dim.has_constraints()) {
if (solution_ptr->problem_ptr->dimensions_info.cost_dim.has_constraints()) {
const size_t shared_for_dist_buffers =
(2 + (max_neighbors<i_t, REQUEST>(k_max) + 1)) *
(solution_ptr->get_max_active_nodes_for_all_routes() + 1) * sizeof(f_t);
Expand All @@ -233,7 +233,7 @@ struct node_stack_t {
wrap_ptr_as_span<i_t>(sh_ptr, max_neighbors<i_t, REQUEST>(k_max) * blockDim.x);

loop_over_constrained_dimensions(dim_info(), [&](auto I) {
if constexpr ((I == size_t(dim_t::DIST)) || (I == size_t(dim_t::TIME))) {
if constexpr ((I == size_t(dim_t::COST)) || (I == size_t(dim_t::TIME))) {
thrust::tie(dim_delivery_to_all[I], sh_ptr) =
wrap_ptr_as_span<f_t>(sh_ptr, 2 * (route_length + 1));
thrust::tie(dim_buffer_route[I], sh_ptr) =
Expand All @@ -254,7 +254,7 @@ struct node_stack_t {
(best_sequence.size() + p_scores.size() + gathered.size() + max_to_node.size()) * sizeof(i_t);

loop_over_constrained_dimensions(dim_info(), [&](auto I) {
if constexpr ((I == size_t(dim_t::DIST)) || (I == size_t(dim_t::TIME))) {
if constexpr ((I == size_t(dim_t::COST)) || (I == size_t(dim_t::TIME))) {
total_bytes += (dim_delivery_to_all[I].size() + dim_buffer_route[I].size()) * sizeof(f_t);
}
});
Expand Down Expand Up @@ -292,7 +292,7 @@ struct node_stack_t {
template <size_t d>
DI void compute_dim_buffers()
{
if constexpr ((d == size_t(dim_t::DIST)) || (d == size_t(dim_t::TIME))) {
if constexpr ((d == size_t(dim_t::COST)) || (d == size_t(dim_t::TIME))) {
constexpr dim_t dim = dim_t(d);
i_t n_nodes_route = s_route.get_num_nodes();
auto& node_infos = s_route.requests().node_info;
Expand Down Expand Up @@ -357,7 +357,7 @@ struct node_stack_t {
* upfront in the lexicographic search kernel so we can safely skip here. Ideal way to handle
* this smoothly is to pass vehicle_info to calculate_forward and calculate_backward methods
*/
if constexpr ((dim == dim_t::DIST) || (dim == dim_t::TIME)) {
if constexpr ((dim == dim_t::COST) || (dim == dim_t::TIME)) {
return dim_delivery_to_all[size_t(dim)][intra_idx];
} else {
return f_t{};
Expand All @@ -374,7 +374,7 @@ struct node_stack_t {
DI f_t get_dim_to_delivery(i_t intra_idx) const
{
if (!dim_info().has_dimension(dim)) { return f_t{}; }
if constexpr ((dim == dim_t::DIST) || (dim == dim_t::TIME)) {
if constexpr ((dim == dim_t::COST) || (dim == dim_t::TIME)) {
return dim_delivery_to_all[size_t(dim)][intra_idx + route_length + 1];
} else {
return f_t{};
Expand All @@ -391,7 +391,7 @@ struct node_stack_t {
DI f_t get_dim_between(i_t intra_idx_1, i_t intra_idx_2) const
{
if (!dim_info().has_dimension(dim)) { return f_t{}; }
if constexpr ((dim == dim_t::DIST) || (dim == dim_t::TIME)) {
if constexpr ((dim == dim_t::COST) || (dim == dim_t::TIME)) {
i_t gap_between = intra_idx_2 - intra_idx_1 - 1;
return dim_buffer_route[size_t(dim)][intra_idx_1 + gap_between * route_length];
} else {
Expand Down Expand Up @@ -864,10 +864,10 @@ struct node_stack_t {
f_t orig_time = get_arc_of_dimension<i_t, f_t, I>(
delivery_node.node_info(), node_info, s_route.vehicle_info());
return orig_time == dim_from_buffer;
} else if constexpr (I == (size_t)dim_t::DIST) {
f_t orig_dist = get_arc_of_dimension<i_t, f_t, I>(
} else if constexpr (I == (size_t)dim_t::COST) {
f_t orig_cost = get_arc_of_dimension<i_t, f_t, I>(
delivery_node.node_info(), node_info, s_route.vehicle_info());
return orig_dist == dim_from_buffer;
return orig_cost == dim_from_buffer;
} else {
return true;
}
Expand All @@ -881,10 +881,10 @@ struct node_stack_t {
f_t orig_time = get_arc_of_dimension<i_t, f_t, I>(
node_info, delivery_node.node_info(), s_route.vehicle_info());
return orig_time == dim_from_buffer;
} else if constexpr (I == (size_t)dim_t::DIST) {
f_t orig_dist = get_arc_of_dimension<i_t, f_t, I>(
} else if constexpr (I == (size_t)dim_t::COST) {
f_t orig_cost = get_arc_of_dimension<i_t, f_t, I>(
node_info, delivery_node.node_info(), s_route.vehicle_info());
return orig_dist == dim_from_buffer;
return orig_cost == dim_from_buffer;
} else {
return true;
}
Expand All @@ -900,10 +900,10 @@ struct node_stack_t {
f_t orig_time =
get_arc_of_dimension<i_t, f_t, I>(node_info_1, node_info_2, s_route.vehicle_info());
return orig_time == dim_from_buffer;
} else if constexpr (I == (size_t)dim_t::DIST) {
f_t orig_dist =
} else if constexpr (I == (size_t)dim_t::COST) {
f_t orig_cost =
get_arc_of_dimension<i_t, f_t, I>(node_info_1, node_info_2, s_route.vehicle_info());
return orig_dist == dim_from_buffer;
return orig_cost == dim_from_buffer;
} else {
return true;
}
Expand Down
18 changes: 9 additions & 9 deletions cpp/src/routing/local_search/compute_compatible.cu
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ void local_search_t<i_t, f_t, REQUEST>::calculate_route_compatibility(
RAFT_CHECK_CUDA(sol.sol_handle->get_stream());
}

// sort the viable matrix according to the distance after the insertion
// sort the viable matrix according to the cost after the insertion
template <typename i_t, typename f_t>
void problem_t<i_t, f_t>::sort_viable_matrix(rmm::device_uvector<i_t>& viable_from_matrix,
rmm::device_uvector<i_t>& viable_to_matrix)
Expand All @@ -477,7 +477,7 @@ void problem_t<i_t, f_t>::sort_viable_matrix(rmm::device_uvector<i_t>& viable_fr
i_t segment = idx / l_n_requests;
return segment;
});
// sort according to distance
// sort according to cost
thrust::stable_sort(
handle_ptr->get_thrust_policy(),
thrust::make_zip_iterator(viable_from_matrix.begin(), segments.begin()),
Expand All @@ -489,19 +489,19 @@ void problem_t<i_t, f_t>::sort_viable_matrix(rmm::device_uvector<i_t>& viable_fr
i_t from_node_2 = thrust::get<1>(second);
if (to_node_1 == -1) return false;
if (to_node_2 == -1) return true;
auto dist_between_1 = get_distance(
auto cost_between_1 = get_arc_cost(
NodeInfo<i_t>(
from_node_1, order_info_view.get_order_location(from_node_1), node_type_t::PICKUP),
NodeInfo<i_t>(
to_node_1, order_info_view.get_order_location(to_node_1), node_type_t::PICKUP),
l_vehicle_info);
auto dist_between_2 = get_distance(
auto cost_between_2 = get_arc_cost(
NodeInfo<i_t>(
from_node_2, order_info_view.get_order_location(from_node_2), node_type_t::PICKUP),
NodeInfo<i_t>(
to_node_2, order_info_view.get_order_location(to_node_2), node_type_t::PICKUP),
l_vehicle_info);
return dist_between_1 < dist_between_2;
return cost_between_1 < cost_between_2;
});
// sort the segments
thrust::stable_sort(handle_ptr->get_thrust_policy(),
Expand All @@ -521,7 +521,7 @@ void problem_t<i_t, f_t>::sort_viable_matrix(rmm::device_uvector<i_t>& viable_fr
i_t segment = idx / l_n_requests;
return segment;
});
// sort according to distance
// sort according to cost
thrust::stable_sort(
handle_ptr->get_thrust_policy(),
thrust::make_zip_iterator(viable_to_matrix.begin(), segments.begin()),
Expand All @@ -533,19 +533,19 @@ void problem_t<i_t, f_t>::sort_viable_matrix(rmm::device_uvector<i_t>& viable_fr
i_t to_node_2 = thrust::get<1>(second);
if (from_node_1 == -1) return false;
if (from_node_2 == -1) return true;
auto dist_between_1 = get_distance(
auto cost_between_1 = get_arc_cost(
NodeInfo<i_t>(
from_node_1, order_info_view.get_order_location(from_node_1), node_type_t::PICKUP),
NodeInfo<i_t>(
to_node_1, order_info_view.get_order_location(to_node_1), node_type_t::PICKUP),
l_vehicle_info);
auto dist_between_2 = get_distance(
auto cost_between_2 = get_arc_cost(
NodeInfo<i_t>(
from_node_2, order_info_view.get_order_location(from_node_2), node_type_t::PICKUP),
NodeInfo<i_t>(
to_node_2, order_info_view.get_order_location(to_node_2), node_type_t::PICKUP),
l_vehicle_info);
return dist_between_1 < dist_between_2;
return cost_between_1 < cost_between_2;
});
// sort the segments again to get back the segmented sorted
thrust::stable_sort(handle_ptr->get_thrust_policy(),
Expand Down
11 changes: 5 additions & 6 deletions cpp/src/routing/local_search/permutation_helper.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ DI bool forward_fragment_update_cvrp(const node_t<i_t, f_t, REQUEST>& curr_node,
{
cuopt_assert(fragment_size != 0, "Fragment size cannot be zero!");

f_t arc_value = get_arc_of_dimension<i_t, f_t, dim_t::DIST, true>(
f_t arc_value = get_arc_of_dimension<i_t, f_t, dim_t::COST, true>(
curr_node.request.info, fragment[0].request.info, s_route.vehicle_info());
fragment[fragment_size - 1].distance_dim.distance_forward =
curr_node.distance_dim.distance_forward + arc_value + fragment_dist;
fragment[fragment_size - 1].cost_dim.cost_forward =
curr_node.cost_dim.cost_forward + arc_value + fragment_dist;
fragment[fragment_size - 1].capacity_dim.gathered[0] =
curr_node.capacity_dim.gathered[0] + fragment_demand;
fragment[fragment_size - 1].capacity_dim.max_to_node[0] =
Expand Down Expand Up @@ -295,10 +295,9 @@ DI bool backward_fragment_update_cvrp(const node_t<i_t, f_t, REQUEST>& curr_node
const infeasible_cost_t& weights,
double excess_limit)
{
f_t arc_value = get_arc_of_dimension<i_t, f_t, dim_t::DIST, true>(
f_t arc_value = get_arc_of_dimension<i_t, f_t, dim_t::COST, true>(
fragment[fragment_size - 1].request.info, curr_node.request.info, s_route.vehicle_info());
fragment[0].distance_dim.distance_backward =
curr_node.distance_dim.distance_backward + arc_value + fragment_dist;
fragment[0].cost_dim.cost_backward = curr_node.cost_dim.cost_backward + arc_value + fragment_dist;

fragment[0].capacity_dim.max_after[0] = curr_node.capacity_dim.max_after[0] + fragment_demand;

Expand Down
Loading