![]() |
Google OR-Tools v9.15
a fast and portable software suite for combinatorial optimization
|
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from the Traveling Salesman Problem to more complex problems such as the Capacitated Vehicle Routing Problem with Time Windows. More...
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from the Traveling Salesman Problem to more complex problems such as the Capacitated Vehicle Routing Problem with Time Windows.
The objective of a vehicle routing problem is to build routes covering a set of nodes minimizing the overall cost of the routes (usually proportional to the sum of the lengths of each segment of the routes) while respecting some problem-specific constraints (such as the length of a route). A route is equivalent to a path connecting nodes, starting/ending at specific starting/ending nodes.
The term "vehicle routing" is historical and the category of problems solved is not limited to the routing of vehicles: any problem involving finding routes visiting a given number of nodes optimally falls under this category of problems, such as finding the optimal sequence in a playlist.
The literature around vehicle routing problems is extremely dense but one can find some basic introductions in the following links:
The vehicle routing library is a vertical layer above the constraint programming library (ortools/constraint_programming:cp).
One has access to all underlying constrained variables of the vehicle routing model which can therefore be enriched by adding any constraint available in the constraint programming library.
There are two sets of variables available:
Solving the vehicle routing problems is mainly done using approximate methods (namely local search, cf. http://en.wikipedia.org/wiki/Local_search_(optimization) ), potentially combined with exact techniques based on dynamic programming and exhaustive tree search. TODO(user): Add a section on costs (vehicle arc costs, span costs, disjunctions costs). Advanced tips: Flags are available to tune the search used to solve routing problems. Here is a quick overview of the ones one might want to modify:
Code sample:
Here is a simple example solving a traveling salesman problem given a cost function callback (returns the cost of a route segment):
Definition in file routing.h.
#include <algorithm>#include <atomic>#include <cstdint>#include <deque>#include <functional>#include <limits>#include <memory>#include <optional>#include <set>#include <string>#include <tuple>#include <utility>#include <vector>#include "absl/container/flat_hash_map.h"#include "absl/container/flat_hash_set.h"#include "absl/functional/any_invocable.h"#include "absl/hash/hash.h"#include "absl/log/check.h"#include "absl/strings/string_view.h"#include "absl/time/time.h"#include "absl/types/span.h"#include "ortools/base/logging.h"#include "ortools/base/strong_vector.h"#include "ortools/base/types.h"#include "ortools/constraint_solver/constraint_solver.h"#include "ortools/constraint_solver/constraint_solveri.h"#include "ortools/constraint_solver/routing_enums.pb.h"#include "ortools/constraint_solver/routing_heuristic_parameters.pb.h"#include "ortools/constraint_solver/routing_index_manager.h"#include "ortools/constraint_solver/routing_parameters.pb.h"#include "ortools/constraint_solver/routing_types.h"#include "ortools/constraint_solver/routing_utils.h"#include "ortools/graph/graph.h"#include "ortools/util/piecewise_linear_function.h"#include "ortools/util/range_query_function.h"#include "ortools/util/saturated_arithmetic.h"#include "ortools/util/sorted_interval_list.h"Go to the source code of this file.
Namespaces | |
| namespace | operations_research |
| OR-Tools root namespace. | |
Functions | |
| void | operations_research::FillPathEvaluation (absl::Span< const int64_t > path, const RoutingModel::TransitCallback2 &evaluator, std::vector< int64_t > *values) |
| bool | operations_research::SolveModelWithSat (RoutingModel *model, RoutingSearchStats *search_stats, const RoutingSearchParameters &search_parameters, const operations_research::Assignment *initial_solution, operations_research::Assignment *solution) |