Update routing C++ samples

This commit is contained in:
Laurent Perron
2025-01-29 13:25:34 +01:00
parent 093e8fd759
commit 0ce4b910ab
15 changed files with 45 additions and 0 deletions

View File

@@ -88,6 +88,9 @@ void PrintSolution(const RoutingIndexManager& manager,
LOG(INFO) << "Objective: " << solution.ObjectiveValue();
int64_t total_distance{0};
for (int vehicle_id = 0; vehicle_id < manager.num_vehicles(); ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t distance{0};

View File

@@ -89,6 +89,9 @@ void PrintSolution(const RoutingIndexManager& manager,
const RoutingDimension& time_dimension = routing.GetDimensionOrDie("Time");
int64_t total_time{0};
for (int vehicle_id = 0; vehicle_id < manager.num_vehicles(); ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t index = routing.Start(vehicle_id);
std::stringstream route;

View File

@@ -88,6 +88,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
int64_t total_distance = 0;
int64_t total_load = 0;
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance = 0;

View File

@@ -98,6 +98,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
int64_t total_distance{0};
int64_t total_load{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance{0};

View File

@@ -81,6 +81,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingModel& routing, const Assignment& solution) {
int64_t max_route_distance{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance{0};

View File

@@ -91,6 +91,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
LOG(INFO) << "Objective: " << solution.ObjectiveValue();
int64_t max_route_distance{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance{0};

View File

@@ -101,6 +101,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingModel& routing, const Assignment& solution) {
int64_t total_distance{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance{0};

View File

@@ -101,6 +101,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingModel& routing, const Assignment& solution) {
int64_t total_distance{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance = 0;

View File

@@ -101,6 +101,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingModel& routing, const Assignment& solution) {
int64_t total_distance{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance{0};

View File

@@ -90,6 +90,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingDimension& time_dimension = routing.GetDimensionOrDie("Time");
int64_t total_time{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for vehicle " << vehicle_id << ":";
std::ostringstream route;

View File

@@ -85,6 +85,9 @@ void print_solution(const RoutingIndexManager& routing_manager,
for (int vehicle_id = 0; vehicle_id < routing_manager.num_vehicles();
++vehicle_id) {
int64_t index = routing_model.Start(vehicle_id);
if (routing_model.IsEnd(routing_model.NextVar(index)->Value())) {
continue;
}
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance = 0;
std::stringstream route;

View File

@@ -94,6 +94,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingModel& routing, const Assignment& solution) {
int64_t max_route_distance{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance{0};

View File

@@ -86,6 +86,9 @@ void PrintSolution(const DataModel& data, const RoutingIndexManager& manager,
const RoutingDimension& time_dimension = routing.GetDimensionOrDie("Time");
int64_t total_time{0};
for (int vehicle_id = 0; vehicle_id < data.num_vehicles; ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for vehicle " << vehicle_id << ":";
std::ostringstream route;

View File

@@ -37,6 +37,9 @@ void PrintSolution(const RoutingIndexManager& manager,
const RoutingModel& routing, const Assignment& solution) {
int64_t max_route_distance = 0;
for (int vehicle_id = 0; vehicle_id < manager.num_vehicles(); ++vehicle_id) {
if (!routing.IsVehicleUsed(solution, vehicle_id)) {
continue;
}
int64_t index = routing.Start(vehicle_id);
LOG(INFO) << "Route for Vehicle " << vehicle_id << ":";
int64_t route_distance = 0;

View File

@@ -82,6 +82,9 @@ void PrintSolution(
int64_t total_time{0};
std::ostringstream route;
for (int vehicle_id = 0; vehicle_id < routes.size(); ++vehicle_id) {
if (routes[vehicle_id].size() <= 2) {
continue;
}
route << "\nRoute " << vehicle_id << ": \n";
route << " " << routes[vehicle_id][0] << " Time("