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...
|
class | SimpleRevFIFO |
| This class represent a reversible FIFO structure. More...
|
|
struct | DefaultPhaseParameters |
| This struct holds all parameters for the default search. More...
|
|
class | Solver |
| Solver Class. More...
|
|
class | BaseObject |
| A BaseObject is the root of all reversibly allocated objects. More...
|
|
class | PropagationBaseObject |
| NOLINT. More...
|
|
class | Decision |
| A Decision represents a choice point in the search tree. More...
|
|
class | DecisionVisitor |
| A DecisionVisitor is used to inspect a decision. More...
|
|
class | DecisionBuilder |
| A DecisionBuilder is responsible for creating the search tree. More...
|
|
class | Demon |
| A Demon is the base element of a propagation queue. More...
|
|
class | ModelVisitor |
| Model visitor. More...
|
|
class | Constraint |
| A constraint is the main modeling object. More...
|
|
class | CastConstraint |
| Cast constraints are special channeling constraints designed to keep a variable in sync with an expression. More...
|
|
class | SearchMonitor |
| A search monitor is a simple set of callbacks to monitor all search events. More...
|
|
class | Rev |
| This class adds reversibility to a POD type. More...
|
|
class | NumericalRev |
| Subclass of Rev<T> which adds numerical operations. More...
|
|
class | RevArray |
| Reversible array of POD types. More...
|
|
class | NumericalRevArray |
| Subclass of RevArray<T> which adds numerical operations. More...
|
|
class | IntExpr |
| The class IntExpr is the base of all integer expressions in constraint programming. More...
|
|
class | IntVarIterator |
| The class Iterator has two direct subclasses. More...
|
|
class | InitAndGetValues |
| Utility class to encapsulate an IntVarIterator and use it in a range-based loop. More...
|
|
class | IntVar |
| The class IntVar is a subset of IntExpr. More...
|
|
class | SolutionCollector |
| This class is the root class of all solution collectors. More...
|
|
class | OptimizeVar |
| This class encapsulates an objective. More...
|
|
class | SearchLimit |
| Base class of all search limits. More...
|
|
class | RegularLimit |
| Usual limit based on wall_time, number of explored branches and number of failures in the search tree. More...
|
|
class | ImprovementSearchLimit |
|
class | IntervalVar |
| Interval variables are often used in scheduling. More...
|
|
class | SequenceVar |
| A sequence variable is a variable whose domain is a set of possible orderings of the interval variables. More...
|
|
class | AssignmentElement |
|
class | IntVarElement |
|
class | IntervalVarElement |
|
class | SequenceVarElement |
| The SequenceVarElement stores a partial representation of ranked interval variables in the underlying sequence variable. More...
|
|
class | AssignmentContainer |
|
class | Assignment |
| An Assignment is a variable -> domains mapping, used to report solutions to the user. More...
|
|
class | Pack |
|
class | DisjunctiveConstraint |
|
class | SolutionPool |
| This class is used to manage a pool of solutions. More...
|
|
class | BaseIntExpr |
| This is the base class for all expressions that are not variables. More...
|
|
class | RevImmutableMultiMap |
| Reversible Immutable MultiMap class. More...
|
|
class | RevSwitch |
| A reversible switch that can switch once from false to true. More...
|
|
class | SmallRevBitSet |
| This class represents a small reversible bitset (size <= 64). More...
|
|
class | RevBitSet |
| This class represents a reversible bitset. More...
|
|
class | RevBitMatrix |
| Matrix version of the RevBitSet class. More...
|
|
class | CallMethod0 |
| Demon proxy to a method on the constraint with no arguments. More...
|
|
class | CallMethod1 |
| Demon proxy to a method on the constraint with one argument. More...
|
|
class | CallMethod2 |
| Demon proxy to a method on the constraint with two arguments. More...
|
|
class | CallMethod3 |
| Demon proxy to a method on the constraint with three arguments. More...
|
|
class | DelayedCallMethod0 |
| Low-priority demon proxy to a method on the constraint with no arguments. More...
|
|
class | DelayedCallMethod1 |
| Low-priority demon proxy to a method on the constraint with one argument. More...
|
|
class | DelayedCallMethod2 |
| Low-priority demon proxy to a method on the constraint with two arguments. More...
|
|
class | LocalSearchOperator |
| The base class for all local search operators. More...
|
|
class | VarLocalSearchOperator |
| Base operator class for operators manipulating variables. More...
|
|
class | IntVarLocalSearchHandler |
|
class | IntVarLocalSearchOperator |
| Specialization of LocalSearchOperator built from an array of IntVars which specifies the scope of the operator. More...
|
|
class | SequenceVarLocalSearchHandler |
|
class | SequenceVarLocalSearchOperator |
|
class | BaseLns |
| This is the base class for building an Lns operator. More...
|
|
class | ChangeValue |
| Defines operators which change the value of variables; each neighbor corresponds to one modified variable. More...
|
|
class | PathOperator |
| Base class of the local search operators dedicated to path modifications (a path is a set of nodes linked together by arcs). More...
|
|
class | LocalSearchState |
|
class | LocalSearchVariable |
|
class | LocalSearchFilter |
| Local Search Filters are used for fast neighbor pruning. More...
|
|
class | LocalSearchFilterManager |
| Filter manager: when a move is made, filters are executed to decide whether the solution is feasible and compute parts of the new cost. More...
|
|
class | IntVarLocalSearchFilter |
|
class | PropagationMonitor |
|
class | LocalSearchMonitor |
|
class | BooleanVar |
|
class | SymmetryBreaker |
| A symmetry breaker is an object that will visit a decision and create the 'symmetrical' decision in return. More...
|
|
class | SearchLog |
| The base class of all search logs that periodically outputs information when the search is running. More...
|
|
class | ModelCache |
| Implements a complete cache for model elements: expressions and constraints. More...
|
|
class | ArgumentHolder |
| Argument Holder: useful when visiting a model. More...
|
|
class | ModelParser |
| Model Parser. More...
|
|
class | ArrayWithOffset |
|
class | RevGrowingArray |
| This class is a reversible growing array. More...
|
|
class | RevIntSet |
| This is a special class to represent a 'residual' set of T. More...
|
|
class | RevPartialSequence |
| --— RevPartialSequence --— More...
|
|
class | UnsortedNullableRevBitset |
| This class represents a reversible bitset. More...
|
|
class | PathState |
|
class | UnaryDimensionChecker |
|
class | RoutingModel |
|
class | RoutingModelVisitor |
| Routing model visitor. More...
|
|
class | DisjunctivePropagator |
| This class acts like a CP propagator: it takes a set of tasks given by their start/duration/end features, and reduces the range of possible values. More...
|
|
struct | TravelBounds |
|
class | GlobalVehicleBreaksConstraint |
| GlobalVehicleBreaksConstraint ensures breaks constraints are enforced on all vehicles in the dimension passed to its constructor. More...
|
|
class | TypeRegulationsChecker |
|
class | TypeIncompatibilityChecker |
| Checker for type incompatibilities. More...
|
|
class | TypeRequirementChecker |
| Checker for type requirements. More...
|
|
class | TypeRegulationsConstraint |
| The following constraint ensures that incompatibilities and requirements between types are respected. More...
|
|
class | SimpleBoundCosts |
| A structure meant to store soft bounds and associated violation constants. More...
|
|
class | RoutingDimension |
| Dimensions represent quantities accumulated at nodes along the routes. More...
|
|
class | SweepArranger |
| Class to arrange indices by by their distance and their angles from the depot. More...
|
|
class | VehicleTypeCurator |
| Helper class that manages vehicles. More...
|
|
class | IntVarFilteredDecisionBuilder |
| Decision builder building a solution using heuristics with local search filters to evaluate its feasibility. More...
|
|
class | IntVarFilteredHeuristic |
| Generic filter-based heuristic applied to IntVars. More...
|
|
class | RoutingFilteredHeuristic |
| Filter-based heuristic dedicated to routing. More...
|
|
class | CheapestInsertionFilteredHeuristic |
|
class | GlobalCheapestInsertionFilteredHeuristic |
| Filter-based decision builder which builds a solution by inserting nodes at their cheapest position on any route; potentially several routes can be built in parallel. More...
|
|
class | LocalCheapestInsertionFilteredHeuristic |
| Filter-base decision builder which builds a solution by inserting nodes at their cheapest position. More...
|
|
class | CheapestAdditionFilteredHeuristic |
| Filtered-base decision builder based on the addition heuristic, extending a path from its start node with the cheapest arc. More...
|
|
class | EvaluatorCheapestAdditionFilteredHeuristic |
| A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc evaluator. More...
|
|
class | ComparatorCheapestAdditionFilteredHeuristic |
| A CheapestAdditionFilteredHeuristic where the notion of 'cheapest arc' comes from an arc comparator. More...
|
|
class | SavingsFilteredHeuristic |
| Filter-based decision builder which builds a solution by using Clarke & Wright's Savings heuristic. More...
|
|
class | SequentialSavingsFilteredHeuristic |
|
class | ParallelSavingsFilteredHeuristic |
|
class | ChristofidesFilteredHeuristic |
| Christofides addition heuristic. More...
|
|
class | BasePathFilter |
| Generic path-based filter class. More...
|
|
class | CPFeasibilityFilter |
| This filter accepts deltas for which the assignment satisfies the constraints of the Solver. More...
|
|
class | RoutingIndexManager |
| Manager for any NodeIndex <-> variable index conversion. More...
|
|
class | CumulBoundsPropagator |
|
class | RoutingLinearSolverWrapper |
|
class | RoutingGlopWrapper |
|
class | RoutingCPSatWrapper |
|
class | DimensionCumulOptimizerCore |
|
class | LocalDimensionCumulOptimizer |
|
class | GlobalDimensionCumulOptimizer |
|
class | MakeRelocateNeighborsOperator |
| Relocate neighborhood which moves chains of neighbors. More...
|
|
class | MakePairActiveOperator |
| Pair-based neighborhood operators, designed to move nodes by pairs (pairs are static and given). More...
|
|
class | MakePairInactiveOperator |
| Operator which makes pairs of active nodes inactive. More...
|
|
class | PairRelocateOperator |
| Operator which moves a pair of nodes to another position where the first node of the pair must be before the second node on the same path. More...
|
|
class | LightPairRelocateOperator |
|
class | PairExchangeOperator |
| Operator which exchanges the position of two pairs; for both pairs the first node of the pair must be before the second node on the same path. More...
|
|
class | PairExchangeRelocateOperator |
| Operator which exchanges the paths of two pairs (path have to be different). More...
|
|
class | SwapIndexPairOperator |
| Operator which iterates through each alternative of a set of pairs. More...
|
|
class | IndexPairSwapActiveOperator |
| Operator which inserts inactive nodes into a path and makes a pair of active nodes inactive. More...
|
|
class | FilteredHeuristicLocalSearchOperator |
| Class of operators using a RoutingFilteredHeuristic to insert unperformed nodes after changes have been made to the current solution. More...
|
|
class | FilteredHeuristicPathLNSOperator |
| LNS-like operator based on a filtered first solution heuristic to rebuild the solution, after the destruction phase consisting of removing one route. More...
|
|
class | RelocatePathAndHeuristicInsertUnperformedOperator |
| Heuristic-based local search operator which relocates an entire route to an empty vehicle of different vehicle class and then tries to insert unperformed nodes using the heuristic. More...
|
|
class | FilteredHeuristicExpensiveChainLNSOperator |
| Similar to the heuristic path LNS above, but instead of removing one route entirely, the destruction phase consists of removing all nodes on an "expensive" chain from a route. More...
|
|
class | FilteredHeuristicCloseNodesLNSOperator |
| Filtered heuristic LNS operator, where the destruction phase consists of removing a node and the 'num_close_nodes' nodes closest to it, along with each of their corresponding sibling pickup/deliveries that are performed. More...
|
|
class | RelocateExpensiveChain |
| RelocateExpensiveChain. More...
|
|
class | PairNodeSwapActiveOperator |
| Operator which inserts pairs of inactive nodes into a path and makes an active node inactive. More...
|
|
class | RelocateSubtrip |
| Tries to move subtrips after an insertion node. More...
|
|
class | ExchangeSubtrip |
|
|
int64 | CpRandomSeed () |
|
std::ostream & | operator<< (std::ostream &out, const Solver *const s) |
|
int64 | Zero () |
| NOLINT. More...
|
|
int64 | One () |
| This method returns 1. More...
|
|
std::ostream & | operator<< (std::ostream &out, const BaseObject *o) |
|
std::ostream & | operator<< (std::ostream &out, const Assignment &assignment) |
|
void | SetAssignmentFromAssignment (Assignment *target_assignment, const std::vector< IntVar * > &target_vars, const Assignment *source_assignment, const std::vector< IntVar * > &source_vars) |
| NOLINT. More...
|
|
uint64 | Hash1 (uint64 value) |
| Hash functions. More...
|
|
uint64 | Hash1 (uint32 value) |
|
uint64 | Hash1 (int64 value) |
|
uint64 | Hash1 (int value) |
|
uint64 | Hash1 (void *const ptr) |
|
template<class T > |
uint64 | Hash1 (const std::vector< T * > &ptrs) |
|
uint64 | Hash1 (const std::vector< int64 > &ptrs) |
|
template<class T > |
LocalSearchOperator * | MakeLocalSearchOperator (Solver *solver, const std::vector< IntVar * > &vars, const std::vector< IntVar * > &secondary_vars, std::function< int(int64)> start_empty_path_class) |
| Operator Factories. More...
|
|
template<class T > |
bool | IsArrayConstant (const std::vector< T > &values, const T &value) |
|
template<class T > |
bool | IsArrayBoolean (const std::vector< T > &values) |
|
template<class T > |
bool | AreAllOnes (const std::vector< T > &values) |
|
template<class T > |
bool | AreAllNull (const std::vector< T > &values) |
|
template<class T > |
bool | AreAllGreaterOrEqual (const std::vector< T > &values, const T &value) |
|
template<class T > |
bool | AreAllLessOrEqual (const std::vector< T > &values, const T &value) |
|
template<class T > |
bool | AreAllPositive (const std::vector< T > &values) |
|
template<class T > |
bool | AreAllNegative (const std::vector< T > &values) |
|
template<class T > |
bool | AreAllStrictlyPositive (const std::vector< T > &values) |
|
template<class T > |
bool | AreAllStrictlyNegative (const std::vector< T > &values) |
|
template<class T > |
bool | IsIncreasingContiguous (const std::vector< T > &values) |
|
template<class T > |
bool | IsIncreasing (const std::vector< T > &values) |
|
template<class T > |
bool | IsArrayInRange (const std::vector< IntVar * > &vars, T range_min, T range_max) |
|
bool | AreAllBound (const std::vector< IntVar * > &vars) |
|
bool | AreAllBooleans (const std::vector< IntVar * > &vars) |
|
template<class T > |
bool | AreAllBoundOrNull (const std::vector< IntVar * > &vars, const std::vector< T > &values) |
| Returns true if all the variables are assigned to a single value, or if their corresponding value is null. More...
|
|
bool | AreAllBoundTo (const std::vector< IntVar * > &vars, int64 value) |
| Returns true if all variables are assigned to 'value'. More...
|
|
int64 | MaxVarArray (const std::vector< IntVar * > &vars) |
|
int64 | MinVarArray (const std::vector< IntVar * > &vars) |
|
void | FillValues (const std::vector< IntVar * > &vars, std::vector< int64 > *const values) |
|
int64 | PosIntDivUp (int64 e, int64 v) |
|
int64 | PosIntDivDown (int64 e, int64 v) |
|
std::vector< int64 > | ToInt64Vector (const std::vector< int > &input) |
|
LocalSearchFilter * | MakePathStateFilter (Solver *solver, std::unique_ptr< PathState > path_state, const std::vector< IntVar * > &nexts) |
|
LocalSearchFilter * | MakeUnaryDimensionFilter (Solver *solver, std::unique_ptr< UnaryDimensionChecker > checker) |
|
void | AppendTasksFromPath (const std::vector< int64 > &path, const TravelBounds &travel_bounds, const RoutingDimension &dimension, DisjunctivePropagator::Tasks *tasks) |
|
void | AppendTasksFromIntervals (const std::vector< IntervalVar * > &intervals, DisjunctivePropagator::Tasks *tasks) |
|
void | FillPathEvaluation (const std::vector< int64 > &path, const RoutingModel::TransitCallback2 &evaluator, std::vector< int64 > *values) |
|
void | FillTravelBoundsOfVehicle (int vehicle, const std::vector< int64 > &path, const RoutingDimension &dimension, TravelBounds *travel_bounds) |
|
DecisionBuilder * | MakeSetValuesFromTargets (Solver *solver, std::vector< IntVar * > variables, std::vector< int64 > targets) |
| A decision builder which tries to assign values to variables as close as possible to target values first. More...
|
|
bool | SolveModelWithSat (const RoutingModel &model, const RoutingSearchParameters &search_parameters, const Assignment *initial_solution, Assignment *solution) |
| Attempts to solve the model using the cp-sat solver. More...
|
|
IntVarLocalSearchFilter * | MakeMaxActiveVehiclesFilter (const RoutingModel &routing_model) |
|
IntVarLocalSearchFilter * | MakeNodeDisjunctionFilter (const RoutingModel &routing_model) |
|
IntVarLocalSearchFilter * | MakeVehicleAmortizedCostFilter (const RoutingModel &routing_model) |
|
IntVarLocalSearchFilter * | MakeTypeRegulationsFilter (const RoutingModel &routing_model) |
|
void | AppendDimensionCumulFilters (const std::vector< RoutingDimension * > &dimensions, const RoutingSearchParameters ¶meters, bool filter_objective_cost, std::vector< LocalSearchFilterManager::FilterEvent > *filters) |
|
void | AppendLightWeightDimensionFilters (const PathState *path_state, const std::vector< RoutingDimension * > &dimensions, std::vector< LocalSearchFilterManager::FilterEvent > *filters) |
|
IntVarLocalSearchFilter * | MakePathCumulFilter (const RoutingDimension &dimension, const RoutingSearchParameters ¶meters, bool propagate_own_objective_value, bool filter_objective_cost, bool can_use_lp=true) |
|
IntVarLocalSearchFilter * | MakeCumulBoundsPropagatorFilter (const RoutingDimension &dimension) |
|
IntVarLocalSearchFilter * | MakeGlobalLPCumulFilter (GlobalDimensionCumulOptimizer *optimizer, bool filter_objective_cost) |
|
IntVarLocalSearchFilter * | MakePickupDeliveryFilter (const RoutingModel &routing_model, const RoutingModel::IndexPairs &pairs, const std::vector< RoutingModel::PickupAndDeliveryPolicy > &vehicle_policies) |
|
IntVarLocalSearchFilter * | MakeVehicleVarFilter (const RoutingModel &routing_model) |
|
IntVarLocalSearchFilter * | MakeVehicleBreaksFilter (const RoutingModel &routing_model, const RoutingDimension &dimension) |
|
IntVarLocalSearchFilter * | MakeCPFeasibilityFilter (RoutingModel *routing_model) |
|
RoutingModelParameters | BuildModelParametersFromFlags () |
| Builds routing search parameters from flags. More...
|
|
RoutingSearchParameters | BuildSearchParametersFromFlags () |
| Builds routing search parameters from flags. More...
|
|
RoutingModelParameters | DefaultRoutingModelParameters () |
|
RoutingSearchParameters | DefaultRoutingSearchParameters () |
|
std::string | FindErrorInRoutingSearchParameters (const RoutingSearchParameters &search_parameters) |
| Returns an empty std::string if the routing search parameters are valid, and a non-empty, human readable error description if they're not. More...
|
|
| DEFINE_INT_TYPE (RoutingNodeIndex, int) |
| Defining common types used in the routing library outside the main RoutingModel class has several purposes: 1) It allows some small libraries to avoid a dependency on routing. More...
|
|
| DEFINE_INT_TYPE (RoutingCostClassIndex, int) |
|
| DEFINE_INT_TYPE (RoutingDimensionIndex, int) |
|
| DEFINE_INT_TYPE (RoutingDisjunctionIndex, int) |
|
| DEFINE_INT_TYPE (RoutingVehicleClassIndex, int) |
|
|
template<class T > |
Demon * | MakeConstraintDemon0 (Solver *const s, T *const ct, void(T::*method)(), const std::string &name) |
|
template<class P > |
std::string | ParameterDebugString (P param) |
|
template<class P > |
std::string | ParameterDebugString (P *param) |
| Support limited to pointers to classes which define DebugString(). More...
|
|
template<class T , class P > |
Demon * | MakeConstraintDemon1 (Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1) |
|
template<class T , class P , class Q > |
Demon * | MakeConstraintDemon2 (Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2) |
|
template<class T , class P , class Q , class R > |
Demon * | MakeConstraintDemon3 (Solver *const s, T *const ct, void(T::*method)(P, Q, R), const std::string &name, P param1, Q param2, R param3) |
|
|
template<class T > |
Demon * | MakeDelayedConstraintDemon0 (Solver *const s, T *const ct, void(T::*method)(), const std::string &name) |
|
template<class T , class P > |
Demon * | MakeDelayedConstraintDemon1 (Solver *const s, T *const ct, void(T::*method)(P), const std::string &name, P param1) |
|
template<class T , class P , class Q > |
Demon * | MakeDelayedConstraintDemon2 (Solver *const s, T *const ct, void(T::*method)(P, Q), const std::string &name, P param1, Q param2) |
|
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:
- path variables:
- "next(i)" variables representing the immediate successor of the node corresponding to i; use IndexToNode() to get the node corresponding to a "next" variable value; note that node indices are strongly typed integers (cf. ortools/base/int_type.h);
- "vehicle(i)" variables representing the vehicle route to which the node corresponding to i belongs;
- "active(i)" boolean variables, true if the node corresponding to i is visited and false if not; this can be false when nodes are either optional or part of a disjunction;
- The following relationships hold for all i: active(i) == 0 <=> next(i) == i <=> vehicle(i) == -1, next(i) == j => vehicle(j) == vehicle(i).
- dimension variables, used when one is accumulating quantities along routes, such as weight or volume carried, distance or time:
- "cumul(i,d)" variables representing the quantity of dimension d when arriving at the node corresponding to i;
- "transit(i,d)" variables representing the quantity of dimension d added after visiting the node corresponding to i.
- The following relationship holds for all (i,d): next(i) == j => cumul(j,d) == cumul(i,d) + transit(i,d). 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. 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:
- Limiting the search for solutions:
- routing_solution_limit (default: kint64max): stop the search after finding 'routing_solution_limit' improving solutions;
- routing_time_limit (default: kint64max): stop the search after 'routing_time_limit' milliseconds;
- Customizing search:
- routing_first_solution (default: select the first node with an unbound successor and connect it to the first available node): selects the heuristic to build a first solution which will then be improved by local search; possible values are GlobalCheapestArc (iteratively connect two nodes which produce the cheapest route segment), LocalCheapestArc (select the first node with an unbound successor and connect it to the node which produces the cheapest route segment), PathCheapestArc (starting from a route "start" node, connect it to the node which produces the cheapest route segment, then extend the route by iterating on the last node added to the route).
- Local search neighborhoods:
- routing_no_lns (default: false): forbids the use of Large Neighborhood Search (LNS); LNS can find good solutions but is usually very slow. Refer to the description of PATHLNS in the LocalSearchOperators enum in constraint_solver.h for more information.
- routing_no_tsp (default: true): forbids the use of exact methods to solve "sub"-traveling salesman problems (TSPs) of the current model (such as sub-parts of a route, or one route in a multiple route problem). Uses dynamic programming to solve such TSPs with a maximum size (in number of nodes) up to cp_local_search_tsp_opt_size (flag with a default value of 13 nodes). It is not activated by default because it can slow down the search.
- Meta-heuristics: used to guide the search out of local minima found by local search. Note that, in general, a search with metaheuristics activated never stops, therefore one must specify a search limit. Several types of metaheuristics are provided:
Code sample: Here is a simple example solving a traveling salesman problem given a cost function callback (returns the cost of a route segment):
Define a custom distance/cost function from an index to another; in this example just returns the sum of the indices:
int64 MyDistance(int64 from, int64 to) { return from + to; }
Create a routing model for a given problem size (int number of nodes) and number of routes (here, 1):
RoutingIndexManager manager(...number of nodes..., 1); RoutingModel routing(manager);
Set the cost function by registering an std::function<int64(int64, int64)> in the model and passing its index as the vehicle cost.
const int cost = routing.RegisterTransitCallback(MyDistance); routing.SetArcCostEvaluatorOfAllVehicles(cost);
Find a solution using Solve(), returns a solution if any (owned by routing):
const Assignment* solution = routing.Solve(); CHECK(solution != nullptr);
Inspect the solution cost and route (only one route here):
LOG(INFO) << "Cost " << solution->ObjectiveValue(); const int route_number = 0; for (int64 node = routing.Start(route_number); !routing.IsEnd(node); node = solution->Value(routing.NextVar(node))) { LOG(INFO) << manager.IndexToNode(node); }
Keywords: Vehicle Routing, Traveling Salesman Problem, TSP, VRP, CVRPTW, PDP.