Skip to content

Commit

Permalink
fix example
Browse files Browse the repository at this point in the history
  • Loading branch information
lperron committed Nov 17, 2024
1 parent 8386d7a commit 4348795
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions examples/cpp/pdptw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#include "ortools/constraint_solver/routing_index_manager.h"
#include "ortools/constraint_solver/routing_parameters.h"
#include "ortools/constraint_solver/routing_parameters.pb.h"
#include "ortools/routing/parsers/lilim_parser.h"
#include "ortools/routing/parsers/simple_graph.h"

ABSL_FLAG(std::string, pdp_file, "",
"File containing the Pickup and Delivery Problem to solve.");
Expand Down Expand Up @@ -121,17 +123,18 @@ double ComputeScalingFactorFromCallback(const C& callback, int size) {
return max_scaled_distance / max_value;
}

void SetupModel(const LiLimParser& parser, const RoutingIndexManager& manager,
RoutingModel* model,
routing::RoutingSearchParameters* search_parameters) {
void SetupModel(const routing::LiLimParser& parser,
const RoutingIndexManager& manager, RoutingModel* model,
RoutingSearchParameters* search_parameters) {
const int64_t kPenalty = 100000000;
const int64_t kFixedCost = 100000;
const int num_nodes = parser.NumberOfNodes();
const int64_t horizon =
absl::c_max_element(
parser.time_windows(),
[](const SimpleTimeWindow<int64_t>& a,
const SimpleTimeWindow<int64_t>& b) { return a.end < b.end; })
absl::c_max_element(parser.time_windows(),
[](const routing::SimpleTimeWindow<int64_t>& a,
const routing::SimpleTimeWindow<int64_t>& b) {
return a.end < b.end;
})
->end;
const double scaling_factor = ComputeScalingFactorFromCallback(
[&parser](int64_t i, int64_t j) -> double {
Expand Down Expand Up @@ -193,7 +196,8 @@ void SetupModel(const LiLimParser& parser, const RoutingIndexManager& manager,
model->AddPickupAndDelivery(index, delivery_index);
}
IntVar* const cumul = time_dimension.CumulVar(index);
const SimpleTimeWindow<int64_t>& window = parser.time_windows()[node];
const routing::SimpleTimeWindow<int64_t>& window =
parser.time_windows()[node];
cumul->SetMin(MathUtil::FastInt64Round(scaling_factor * window.start));
cumul->SetMax(MathUtil::FastInt64Round(scaling_factor * window.end));
}
Expand Down Expand Up @@ -238,7 +242,8 @@ void SetupModel(const LiLimParser& parser, const RoutingIndexManager& manager,
std::string VerboseOutput(const RoutingModel& model,
const RoutingIndexManager& manager,
const Assignment& assignment,
const LiLimParser& parser, double scaling_factor) {
const routing::LiLimParser& parser,
double scaling_factor) {
std::string output;
const RoutingDimension& time_dimension = model.GetDimensionOrDie("time");
const RoutingDimension& load_dimension = model.GetDimensionOrDie("demand");
Expand Down Expand Up @@ -285,14 +290,13 @@ std::string VerboseOutput(const RoutingModel& model,
}
return output;
}
} // namespace

// Builds and solves a model from a file in the format defined by Li & Lim
// (https://www.sintef.no/projectweb/top/pdptw/li-lim-benchmark/documentation/).
bool LoadAndSolve(absl::string_view pdp_file,
const RoutingModelParameters& model_parameters,
RoutingSearchParameters& search_parameters) {
LiLimParser parser;
routing::LiLimParser parser;
if (!parser.LoadFile(pdp_file)) {
return false;
}
Expand Down Expand Up @@ -364,8 +368,8 @@ int main(int argc, char** argv) {
operations_research::DefaultRoutingSearchParameters();
CHECK(google::protobuf::TextFormat::MergeFromString(
absl::GetFlag(FLAGS_routing_search_parameters), &search_parameters));
if (!operations_research::LoadAndSolve(
absl::GetFlag(FLAGS_pdp_file), model_parameters, search_parameters)) {
if (!operations_research::LoadAndSolve(absl::GetFlag(FLAGS_pdp_file),
model_parameters, search_parameters)) {
LOG(INFO) << "Error solving " << absl::GetFlag(FLAGS_pdp_file);
}
return EXIT_SUCCESS;
Expand Down

0 comments on commit 4348795

Please sign in to comment.