C++ Reference: class RoutingModel

This documentation is automatically generated.

Method
ActiveVar

Return type: IntVar*

Arguments: int64 index

Returns the active variable of the node corresponding to index.

AddAllActive

Return type: void

Constrains all nodes to be active (to belong to a route).

AddAtSolutionCallback

Return type: void

Arguments: std::function<void()> callback

Adds a callback called each time a solution is found during the search. This is a shortcut to creating a monitor to call the callback on AtSolution() and adding it with AddSearchMonitor.

AddConstantDimension

Return type: bool

Arguments: int64 value, int64 capacity, bool fix_start_cumul_to_zero, const std::string& name

AddConstantDimensionWithSlack

Return type: bool

Arguments: int64 value, int64 capacity, int64 slack_max, bool fix_start_cumul_to_zero, const std::string& name

Creates a dimension where the transit variable is constrained to be equal to 'value'; 'capacity' is the upper bound of the cumul variables. 'name' is the name used to reference the dimension; this name is used to get cumul and transit variables from the routing model. Returns false if a dimension with the same name has already been created (and doesn't create the new dimension).

AddDimension

Return type: bool

Arguments: NodeEvaluator2* evaluator, int64 slack_max, int64 capacity, bool fix_start_cumul_to_zero, const std::string& name

Creates a dimension where the transit variable is constrained to be equal to evaluator(i, next(i)); 'slack_max' is the upper bound of the slack variable and 'capacity' is the upper bound of the cumul variables. 'name' is the name used to reference the dimension; this name is used to get cumul and transit variables from the routing model. Returns false if a dimension with the same name has already been created (and doesn't create the new dimension). Takes ownership of the callback 'evaluator'.

AddDimensionDependentDimensionWithVehicleCapacity

Return type: bool

Arguments: const std::vector<NodeEvaluator2*>& pure_transits, const std::vector<VariableNodeEvaluator2*>& dependent_transits, const RoutingDimension* base_dimension, int64 slack_max, std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero, const std::string& name

Creates a dimension with transits depending on the cumuls of another dimension. 'pure_transits' are the per-vehicle fixed transits as above. 'dependent_transits' is a vector containing for each vehicle a function taking two nodes and returning a function taking a dimension cumul value and returning a transit value. 'base_dimension' indicates the dimension from which the cumul variable is taken. If 'base_dimension' is nullptr, then the newly created dimension is self-based.

AddDimensionDependentDimensionWithVehicleCapacity

Return type: bool

Arguments: const std::vector<VariableNodeEvaluator2*>& transits, const RoutingDimension* base_dimension, int64 slack_max, std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero, const std::string& name

As above, but pure_transits are taken to be zero evaluators.

AddDimensionDependentDimensionWithVehicleCapacity

Return type: bool

Arguments: VariableNodeEvaluator2* transits, const RoutingDimension* base_dimension, int64 slack_max, int64 vehicle_capacity, bool fix_start_cumul_to_zero, const std::string& name

Homogeneous versions of the functions above.

AddDimensionDependentDimensionWithVehicleCapacity

Return type: bool

Arguments: NodeEvaluator2* pure_transits, VariableNodeEvaluator2* dependent_transits, const RoutingDimension* base_dimension, int64 slack_max, int64 vehicle_capacity, bool fix_start_cumul_to_zero, const std::string& name

AddDimensionWithVehicleCapacity

Return type: bool

Arguments: NodeEvaluator2* evaluator, int64 slack_max, std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero, const std::string& name

Takes ownership of both 'evaluator' and 'vehicle_capacity' callbacks.

AddDimensionWithVehicleTransitAndCapacity

Return type: bool

Arguments: const std::vector<NodeEvaluator2*>& evaluators, int64 slack_max, std::vector<int64> vehicle_capacities, bool fix_start_cumul_to_zero, const std::string& name

AddDimensionWithVehicleTransits

Return type: bool

Arguments: const std::vector<NodeEvaluator2*>& evaluators, int64 slack_max, int64 capacity, bool fix_start_cumul_to_zero, const std::string& name

AddDisjunction

Return type: void

Arguments: const std::vector<NodeIndex>& nodes

Adds a disjunction constraint on the nodes: exactly one of the nodes is active. Start and end nodes of any vehicle cannot be part of a disjunction.

AddDisjunction

Return type: void

Arguments: const std::vector<NodeIndex>& nodes, int64 penalty

Adds a penalized disjunction constraint on the nodes: at most one of the nodes is active; if none are active a penalty cost is applied (this cost is added to the global cost function). This is equivalent to adding the constraint: p + Sum(i)active[i] == 1, where p is a boolean variable and the following cost to the cost function: p * penalty. "penalty" must be positive to make the disjunction optional; a negative penalty will force one node of the disjunction to be performed, and therefore p == 0. Note: passing a vector with a single node will model an optional node with a penalty cost if it is not visited.

AddDisjunction

Return type: void

Arguments: const std::vector<NodeIndex>& nodes, int64 penalty, int64 max_cardinality

Same as above except that instead of allowing at most one of the nodes to be active, the maximum number of active nodes is max_cardinality.

AddIntervalToAssignment

Return type: void

Arguments: IntervalVar* const interval

AddLocalSearchFilter

Return type: void

Arguments: LocalSearchFilter* filter

Adds a custom local search filter to the list of filters used to speed up local search by pruning unfeasible variable assignments. Calling this method after the routing model has been closed (CloseModel() or Solve() has been called) has no effect. The routing model does not take ownership of the filter.

AddLocalSearchOperator

Return type: void

Arguments: LocalSearchOperator* ls_operator

Adds a local search operator to the set of operators used to solve the vehicle routing problem.

AddMatrixDimension

Return type: bool

Arguments: std::vector<std::vector<int64>> values, int64 capacity, bool fix_start_cumul_to_zero, const std::string& name

Creates a dimension where the transit variable is constrained to be equal to 'values[i][next(i)]' for node i; 'capacity' is the upper bound of the cumul variables. 'name' is the name used to reference the dimension; this name is used to get cumul and transit variables from the routing model. Returns false if a dimension with the same name has already been created (and doesn't create the new dimension).

AddPickupAndDelivery

Return type: void

Arguments: NodeIndex node1, NodeIndex node2

Notifies that node1 and node2 form a pair of nodes which should belong to the same route. This methods helps the search find better solutions, especially in the local search phase. It should be called each time you have an equality constraint linking the vehicle variables of two node (including for instance pickup and delivery problems): Solver* const solver = routing.solver(); solver->AddConstraint(solver->MakeEquality( routing.VehicleVar(routing.NodeToIndex(node1)), routing.VehicleVar(routing.NodeToIndex(node2)))); solver->AddPickupAndDelivery(node1, node2); TODO(user): Remove this when model introspection detects linked nodes.

AddSearchMonitor

Return type: void

Arguments: SearchMonitor* const monitor

Adds a search monitor to the search used to solve the routing model.

AddSoftSameVehicleConstraint

Return type: void

Arguments: const std::vector<NodeIndex>& nodes, int64 cost

Adds a soft contraint to force a set of nodes to be on the same vehicle. If all nodes are not on the same vehicle, each extra vehicle used adds 'cost' to the cost function.

AddToAssignment

Return type: void

Arguments: IntVar* const var

Adds an extra variable to the vehicle routing assignment.

AddVariableMaximizedByFinalizer

Return type: void

Arguments: IntVar* var

Adds a variable to maximize in the solution finalizer (see above for information on the solution finalizer).

AddVariableMinimizedByFinalizer

Return type: void

Arguments: IntVar* var

Adds a variable to minimize in the solution finalizer. The solution finalizer is called each time a solution is found during the search and allows to instantiate secondary variables (such as dimension cumul variables).

AddVectorDimension

Return type: bool

Arguments: std::vector<int64> values, int64 capacity, bool fix_start_cumul_to_zero, const std::string& name

Creates a dimension where the transit variable is constrained to be equal to 'values[i]' for node i; 'capacity' is the upper bound of the cumul variables. 'name' is the name used to reference the dimension; this name is used to get cumul and transit variables from the routing model. Returns false if a dimension with the same name has already been created (and doesn't create the new dimension).

ApplyLocks

Return type: IntVar*

Arguments: const std::vector<int>& locks

Applies a lock chain to the next search. 'locks' represents an ordered vector of nodes representing a partial route which will be fixed during the next search; it will constrain next variables such that: next[locks[i]] == locks[i+1]. Returns the next variable at the end of the locked chain; this variable is not locked. An assignment containing the locks can be obtained by calling PreAssignment().

ApplyLocksToAllVehicles

Return type: bool

Arguments: const std::vector<std::vector<NodeIndex>>& locks, bool close_routes

Applies lock chains to all vehicles to the next search, such that locks[p] is the lock chain for route p. Returns false if the locks do not contain valid routes; expects that the routes do not contain the depots, i.e. there are empty vectors in place of empty routes. If close_routes is set to true, adds the end nodes to the route of each vehicle and deactivates other nodes. An assignment containing the locks can be obtained by calling PreAssignment().

ArcIsMoreConstrainedThanArc

Return type: bool

Arguments: int64 from, int64 to1, int64 to2

Returns whether the arc from->to1 is more constrained than from->to2, taking into account, in order: - whether the destination node isn't an end node - whether the destination node is mandatory - whether the destination node is bound to the same vehicle as the source - the "primary constrained" dimension (see SetPrimaryConstrainedDimension) It then breaks ties using, in order: - the arc cost (taking unperformed penalties into account) - the size of the vehicle vars of "to1" and "to2" (lowest size wins) - the value: the lowest value of the indices to1 and to2 wins. See the .cc for details. The more constrained arc is typically preferable when building a first solution. This method is intended to be used as a callback for the BestValueByComparisonSelector value selector. Args: from: the variable index of the source node to1: the variable index of the first candidate destination node. to2: the variable index of the second candidate destination node.

AssignmentToRoutes

Return type: void

Arguments: const Assignment& assignment, std::vector<std::vector<NodeIndex>>* const routes

Converts the solution in the given assignment to routes for all vehicles. Expects that assignment contains a valid solution (i.e. routes for all vehicles end with an end node for that vehicle).

CloseModel

Return type: void

Closes the current routing model; after this method is called, no modification to the model can be done, but RoutesToAssignment becomes available. Note that CloseModel() is automatically called by Solve() and other methods that produce solution. This is equivalent to calling CloseModelWithParameters(DefaultSearchParameters()).

CloseModelWithParameters

Return type: void

Arguments: const RoutingSearchParameters& search_parameters

Same as above taking search parameters (as of 10/2015 some the parameters have to be set when closing the model).

CompactAndCheckAssignment

Return type: Assignment*

Arguments: const Assignment& assignment

Same as CompactAssignment() but also checks the validity of the final compact solution; if it is not valid, no attempts to repair it are made (instead, the method returns nullptr).

CompactAssignment

Return type: Assignment*

Arguments: const Assignment& assignment

Returns a compacted version of the given assignment, in which all vehicles with id lower or equal to some N have non-empty routes, and all vehicles with id greater than N have empty routes. Does not take ownership of the returned object. If found, the cost of the compact assignment is the same as in the original assignment and it preserves the values of 'active' variables. Returns nullptr if a compact assignment was not found. This method only works in homogenous mode, and it only swaps equivalent vehicles (vehicles with the same start and end nodes). When creating the compact assignment, the empty plan is replaced by the route assigned to the compatible vehicle with the highest id. Note that with more complex constraints on vehicle variables, this method might fail even if a compact solution exists. This method changes the vehicle and dimension variables as necessary. While compacting the solution, only basic checks on vehicle variables are performed; if one of these checks fails no attempts to repair it are made (instead, the method returns nullptr).

ComputeLowerBound

Return type: int64

Computes a lower bound to the routing problem solving a linear assignment problem. The routing model must be closed before calling this method. Note that problems with node disjunction constraints (including optional nodes) and non-homogenous costs are not supported (the method returns 0 in these cases). TODO(user): Add support for non-homogeneous costs and disjunctions.

CostClass

Return type: explicit

Arguments: NodeEvaluator2* arc_cost_evaluator

CostsAreHomogeneousAcrossVehicles

Return type: bool

Whether costs are homogeneous across all vehicles.

CostVar

Return type: IntVar*

Returns the global cost variable which is being minimized.

CumulVar

Return type: IntVar*

Arguments: int64 index, const std::string& dimension_name

All the methods below are replaced by public methods with the same name on the RoutingDimension class. See those.

CumulVars

Return type: const std::vector<IntVar*>&

Arguments: const std::string& dimension_name

DebugOutputAssignment

Return type: std::string

Arguments: const Assignment& solution_assignment, const std::string& dimension_to_print

Print some debugging information about an assignment, including the feasible intervals of the CumulVar for dimension "dimension_to_print" at each step of the routes. If "dimension_to_print" is omitted, all dimensions will be printed.

DefaultModelParameters

Return type: static RoutingModelParameters

DefaultSearchParameters

Return type: static RoutingSearchParameters

End

Return type: int64

Arguments: int vehicle

Returns the variable index of the ending node of a vehicle route.

first_solution_evaluator

Return type: const Solver::IndexEvaluator2&

ForEachNodeInDisjunctionWithMaxCardinalityFromIndex

Return type: void

Arguments: int64 index, int64 max_cardinality, F f

GetAllDimensionNames

Return type: std::vector<::std::string>

Outputs the names of all dimensions added to the routing engine. TODO(user): rename.

GetArcCostForClass

Return type: int64

Arguments: int64 from_index, int64 to_index, int64 /*CostClassIndex*/ cost_class_index

Returns the cost of the segment between two nodes for a given cost class. Input are variable indices of nodes and the cost class. Unlike GetArcCostForVehicle(), if cost_class is kNoCost, then the returned cost won't necessarily be zero: only some of the components of the cost that depend on the cost class will be omited. See the code for details.

GetArcCostForFirstSolution

Return type: int64

Arguments: int64 from_index, int64 to_index

Returns the cost of the arc in the context of the first solution strategy. This is typically a simplification of the actual cost; see the .cc.

GetArcCostForVehicle

Return type: int64

Arguments: int64 from_index, int64 to_index, int64 vehicle

Returns the cost of the transit arc between two nodes for a given vehicle. Input are variable indices of node. This returns 0 if vehicle < 0.

GetCost

Return type: int64

Arguments: int64 i, int64 j, int64 v

GetCostClassesCount

Return type: int

Returns the number of different cost classes in the model.

GetCostClassIndexOfVehicle

Return type: CostClassIndex

Arguments: int64 vehicle

Get the cost class index of the given vehicle.

GetCumulVarSoftUpperBound

Return type: int64

Arguments: NodeIndex, const std::string&

GetCumulVarSoftUpperBoundCoefficient

Return type: int64

Arguments: NodeIndex, const std::string&

GetDepot

Return type: int64

Returns the variable index of the first starting or ending node of all routes. If all routes start and end at the same node (single depot), this is the node returned.

GetDimensionOrDie

Return type: const RoutingDimension&

Arguments: const std::string& dimension_name

Returns a dimension from its name. Dies if the dimension does not exist.

GetDimensionSpanCost

Return type: int64

Arguments: const std::string& d

GetDimensionTransitCost

Return type: int64

Arguments: const std::string& d

GetDisjunctionIndices

Return type: const std::vector<int>&

Arguments: DisjunctionIndex index

Returns the variable indices of the nodes in the disjunction of index 'index'.

GetDisjunctionIndicesFromNode

Return type: const std::vector<DisjunctionIndex>&

Arguments: NodeIndex node

Returns the indices of the disjunctions to which a node belongs.

GetDisjunctionIndicesFromVariableIndex

Return type: const std::vector<DisjunctionIndex>&

Arguments: int64 index

GetDisjunctionMaxCardinality

Return type: int64

Arguments: DisjunctionIndex index

Returns the maximum number of possible active nodes of the node disjunction of index 'index'.

GetDisjunctionPenalty

Return type: int64

Arguments: DisjunctionIndex index

Returns the penalty of the node disjunction of index 'index'.

GetEndCumulVarSoftUpperBound

Return type: int64

Arguments: int, const std::string&

GetEndCumulVarSoftUpperBoundCoefficient

Return type: int64

Arguments: int, const std::string&

GetFixedCostOfVehicle

Return type: int64

Arguments: int vehicle

Returns the route fixed cost taken into account if the route of the vehicle is not empty, aka there's at least one node on the route other than the first and last nodes.

GetHomogeneousCost

Return type: int64

Arguments: int64 from_index, int64 to_index

Returns the cost of the segment between two nodes supposing all vehicle costs are the same (returns the cost for the first vehicle otherwise).

GetMutableDimension

Return type: RoutingDimension*

Arguments: const std::string& dimension_name

Returns a dimension from its name. Returns nullptr if the dimension does not exist.

GetNonZeroCostClassesCount

Return type: int

Ditto, minus the 'always zero', built-in cost class.

GetNumberOfDecisionsInFirstSolution

Return type: int64

Arguments: const RoutingSearchParameters& search_parameters

Returns statistics on first solution search, number of decisions sent to filters, number of decisions rejected by filters.

GetNumberOfDisjunctions

Return type: int

Returns the number of node disjunctions in the model.

GetNumberOfRejectsInFirstSolution

Return type: int64

Arguments: const RoutingSearchParameters& search_parameters

GetPickupAndDeliveryPairs

Return type: const NodePairs&

Returns pickup and delivery pairs currently in the model.

GetPrimaryConstrainedDimension

Return type: const std::string&

Get the primary constrained dimension, or an empty std::string if it is unset.

GetRouteFixedCost

Return type: int64

GetSameVehicleIndicesOfIndex

Return type: const std::vector<int>&

Arguments: int node

Returns variable indices of nodes constrained to be on the same route.

GetStartCumulVarSoftUpperBound

Return type: int64

Arguments: int, const std::string&

GetStartCumulVarSoftUpperBoundCoefficient

Return type: int64

Arguments: int, const std::string&

GetTransitValue

Return type: int64

Arguments: const std::string& d, int64 from, int64 to, int64 vehicle

GetVehicleClassCost

Return type: int64

Arguments: int64 i, int64 j, int64 c

GetVehicleClassesCount

Return type: int

Returns the number of different vehicle classes in the model.

GetVehicleClassIndexOfVehicle

Return type: VehicleClassIndex

Arguments: int64 vehicle

GetVehicleCostCount

Return type: int

GetVehicleFixedCost

Return type: int64

Arguments: int v

HasCumulVarSoftUpperBound

Return type: bool

Arguments: NodeIndex, const std::string&

HasDimension

Return type: bool

Arguments: const std::string& dimension_name

Returns true if a dimension exists for a given dimension name.

HasEndCumulVarSoftUpperBound

Return type: bool

Arguments: int, const std::string&

HasIndex

Return type: bool

Arguments: NodeIndex node

Returns true if the node can be safely converted to variable index. All nodes that are not end of a route are safe.

HasStartCumulVarSoftUpperBound

Return type: bool

Arguments: int, const std::string&

homogeneous_costs

Return type: bool

IgnoreDisjunctionsAlreadyForcedToZero

Return type: void

SPECIAL: Makes the solver ignore all the disjunctions whose active variables are all trivially zero (i.e. Max() == 0), by setting their max_cardinality to 0. This can be useful when using the BaseBinaryDisjunctionNeighborhood operators, in the context of arc-based routing.

IndexToNode

Return type: NodeIndex

Arguments: int64 index

Returns the node index from an index value resulting from a next variable.

InitializeBuilders

Return type: static void

Arguments: Solver* solver

Internal only: initializes the builders used to build a solver model from CpModels.

IsEnd

Return type: bool

Arguments: int64 index

Returns true if 'index' represents the last node of a route.

IsStart

Return type: bool

Arguments: int64 index

Returns true if 'index' represents the first node of a route.

IsVehicleUsed

Return type: bool

Arguments: const Assignment& assignment, int vehicle

Returns true if the route of 'vehicle' is non empty in 'assignment'.

MakeGreedyDescentLSOperator

Return type: static std::unique_ptr<LocalSearchOperator>

Arguments: std::vector<IntVar*> variables

TODO(user): MakeGreedyDescentLSOperator is too general for routing.h. Perhaps move it to constraint_solver.h. MakeGreedyDescentLSOperator creates a local search operator that tries to improve the initial assignment by moving a logarithmically decreasing step away in each possible dimension.

MakeGuidedSlackFinalizer

Return type: DecisionBuilder*

Arguments: const RoutingDimension* dimension, std::function<int64(int64)> initializer

The next few members are in the public section only for testing purposes. TODO(user): Find a way to test and restrict the access at the same time. MakeGuidedSlackFinalizer creates a DecisionBuilder for the slacks of a dimension using a callback to choose which values to start with. The finalizer works only when all next variables in the model have been fixed. It has the following two characteristics: 1. It follows the routes defined by the nexts variables when choosing a variable to make a decision on. 2. When it comes to choose a value for the slack of node i, the decision builder first calls the callback with argument i, and supposingly the returned value is x it creates decisions slack[i] = x, slack[i] = x + 1, slack[i] = x - 1, slack[i] = x + 2, etc.

MakeSelfDependentDimensionFinalizer

Return type: DecisionBuilder*

Arguments: const RoutingDimension* dimension

MakeSelfDependentDimensionFinalizer is a finalizer for the slacks of a self-dependent dimension. It makes an extensive use of the caches of the state dependent transits. In detail, MakeSelfDependentDimensionFinalizer returns a composition of a local search decision builder with a greedy descent operator for the cumul of the start of each route and a guided slack finalizer. Provided there are no time windows and the maximum slacks are large enough, once the cumul of the start of route is fixed, the guided finalizer can find optimal values of the slacks for the rest of the route in time proportional to the length of the route. Therefore the composed finalizer generally works in time O(log(t)*n*m), where t is the latest possible departute time, n is the number of nodes in the network and m is the number of vehicles.

MakeStateDependentTransit

Return type: static RoutingModel::StateDependentTransit

Arguments: const std::function<int64(int64)>& f, int64 domain_start, int64 domain_end

Creates a cached StateDependentTransit from an std::function.

MutablePreAssignment

Return type: Assignment*

Next

Return type: int64

Arguments: const Assignment& assignment, int64 index

Assignment inspection Returns the variable index of the node directly after the node corresponding to 'index' in 'assignment'.

Nexts

Return type: const std::vector<IntVar*>&

Returns all next variables of the model, such that Nexts(i) is the next variable of the node corresponding to i.

NextVar

Return type: IntVar*

Arguments: int64 index

Returns the next variable of the node corresponding to index. Note that NextVar(index) == index is equivalent to ActiveVar(index) == 0.

nodes

Return type: int

Sizes and indices Returns the number of nodes in the model.

NodeToIndex

Return type: int64

Arguments: NodeIndex node

Returns the variable index from a node value. Should not be used for nodes at the start / end of a route, because of node multiplicity. These cases return -1, which is considered a failure case. Clients who need start and end variable indices should use RoutingModel::Start and RoutingModel::End.

PreAssignment

Return type: const Assignment* const

Returns an assignment used to fix some of the variables of the problem. In practice, this assignment locks partial routes of the problem. This can be used in the context of locking the parts of the routes which have already been driven in online routing problems.

ReadAssignment

Return type: Assignment*

Arguments: const std::string& file_name

Reads an assignment from a file and returns the current solution. Returns nullptr if the file cannot be opened or if the assignment is not valid.

ReadAssignmentFromRoutes

Return type: Assignment*

Arguments: const std::vector<std::vector<NodeIndex>>& routes, bool ignore_inactive_nodes

Restores the routes as the current solution. Returns nullptr if the solution cannot be restored (routes do not contain a valid solution). Note that calling this method will run the solver to assign values to the dimension variables; this may take considerable amount of time, especially when using dimensions with slack.

RestoreAssignment

Return type: Assignment*

Arguments: const Assignment& solution

Restores an assignment as a solution in the routing model and returns the new solution. Returns nullptr if the assignment is not valid.

RoutesToAssignment

Return type: bool

Arguments: const std::vector<std::vector<NodeIndex>>& routes, bool ignore_inactive_nodes, bool close_routes, Assignment* const assignment

Fills an assignment from a specification of the routes of the vehicles. The routes are specified as lists of nodes that appear on the routes of the vehicles. The indices of the outer vector in 'routes' correspond to vehicles IDs, the inner vector contain the nodes on the routes for the given vehicle. The inner vectors must not contain the start and end nodes, as these are determined by the routing model. Sets the value of NextVars in the assignment, adding the variables to the assignment if necessary. The method does not touch other variables in the assignment. The method can only be called after the model is closed. With ignore_inactive_nodes set to false, this method will fail (return nullptr) in case some of the route contain nodes that are deactivated in the model; when set to true, these nodes will be skipped. Returns true if routes were successfully loaded. However, such assignment still might not be a valid solution to the routing problem due to more complex constraints; it is advisible to call solver()->CheckSolution() afterwards.

RoutingModel

Arguments: int nodes, int vehicles, NodeIndex depot

In the following constructors, the versions which do not take RoutingModelParameters are equivalent to passing DefaultModelParameters. A depot is the start and end node of the route of a vehicle. Constructor taking a single depot node which is used as the start and end node for all vehicles.

RoutingModel

Arguments: int nodes, int vehicles, NodeIndex depot, const RoutingModelParameters& parameters

RoutingModel

Arguments: int nodes, int vehicles, const std::vector<std::pair<NodeIndex, NodeIndex>>& start_end

Constructor taking a vector of (start node, end node) pairs for each vehicle route. Used to model multiple depots.

RoutingModel

Arguments: int nodes, int vehicles, const std::vector<std::pair<NodeIndex, NodeIndex>>& start_end, const RoutingModelParameters& parameters

RoutingModel

Arguments: int nodes, int vehicles, const std::vector<NodeIndex>& starts, const std::vector<NodeIndex>& ends

Constructor taking vectors of start nodes and end nodes for each vehicle route. Used to model multiple depots. TODO(user): added to simplify SWIG wrapping. Remove when swigging std::vector > is ok.

RoutingModel

Arguments: int nodes, int vehicles, const std::vector<NodeIndex>& starts, const std::vector<NodeIndex>& ends, const RoutingModelParameters& parameters

~RoutingModel

SetArcCostEvaluatorOfAllVehicles

Return type: void

Arguments: NodeEvaluator2* evaluator

Sets the cost function of the model such that the cost of a segment of a route between node 'from' and 'to' is evaluator(from, to), whatever the route or vehicle performing the route. Takes ownership of the callback 'evaluator'.

SetArcCostEvaluatorOfVehicle

Return type: void

Arguments: NodeEvaluator2* evaluator, int vehicle

Sets the cost function for a given vehicle route. Takes ownership of the callback 'evaluator'.

SetCost

Return type: void

Arguments: NodeEvaluator2* e

DEPRECATED METHODS. Don't use these methods; instead use their proposed replacement (in comments). TODO(user): only keep those for the open-source export.

SetCumulVarSoftUpperBound

Return type: void

Arguments: NodeIndex, const std::string&, int64, int64

SetDimensionSpanCost

Return type: void

Arguments: const std::string& d, int64 c

SetDimensionTransitCost

Return type: void

Arguments: const std::string& d, int64 c

All the methods below are replaced by public methods of the RoutingDimension class. See that class.

SetEndCumulVarSoftUpperBound

Return type: void

Arguments: int, const std::string&, int64, int64

SetFirstSolutionEvaluator

Return type: void

Arguments: Solver::IndexEvaluator2 evaluator

Takes ownership of evaluator.

SetFixedCostOfAllVehicles

Return type: void

Arguments: int64 cost

Sets the fixed cost of all vehicle routes. It is equivalent to calling SetFixedCostOfVehicle on all vehicle routes.

SetFixedCostOfVehicle

Return type: void

Arguments: int64 cost, int vehicle

Sets the fixed cost of one vehicle route.

SetPrimaryConstrainedDimension

Return type: void

Arguments: const std::string& dimension_name

Set the given dimension as "primary constrained". As of August 2013, this is only used by ArcIsMoreConstrainedThanArc(). "dimension" must be the name of an existing dimension, or be empty, in which case there will not be a primary dimension after this call.

SetRouteFixedCost

Return type: void

Arguments: int64 c

SetStartCumulVarSoftUpperBound

Return type: void

Arguments: int, const std::string&, int64, int64

SetSweepArranger

Return type: void

Arguments: SweepArranger* sweep_arranger

TODO(user): Revisit if coordinates are added to the RoutingModel class.

SetVehicleCost

Return type: void

Arguments: int v, NodeEvaluator2* e

SetArcCostEvaluatorOfVehicle()

SetVehicleFixedCost

Return type: void

Arguments: int v, int64 c

Size

Return type: int64

Returns the number of next variables in the model.

SlackVar

Return type: IntVar*

Arguments: int64 index, const std::string& dimension_name

Solve

Return type: const Assignment*

Arguments: const Assignment* assignment = nullptr

Solves the current routing model; closes the current model. This is equivalent to calling SolveWithParameters(DefaultSearchParameters()) or SolveFromAssignmentWithParameters(assignment, DefaultSearchParameters()).

SolveFromAssignmentWithParameters

Return type: const Assignment*

Arguments: const Assignment* assignment, const RoutingSearchParameters& search_parameters

solver

Return type: Solver*

Returns the underlying constraint solver. Can be used to add extra constraints and/or modify search algoithms.

SolveWithParameters

Return type: const Assignment*

Arguments: const RoutingSearchParameters& search_parameters

Solves the current routing model with the given parameters.

Start

Return type: int64

Arguments: int vehicle

Model inspection. Returns the variable index of the starting node of a vehicle route.

status

Return type: Status

Returns the current status of the routing model.

sweep_arranger

Return type: SweepArranger*

Returns the sweep arranger to be used by routing heuristics.

TransitVar

Return type: IntVar*

Arguments: int64 index, const std::string& dimension_name

UnperformedPenalty

Return type: int64

Arguments: int64 var_index

Get the "unperformed" penalty of a node. This is only well defined if the node is only part of a single Disjunction involving only itself, and that disjunction has a penalty. In all other cases, including forced active nodes, this returns 0.

UnperformedPenaltyOrValue

Return type: int64

Arguments: int64 default_value, int64 var_index

Same as above except that it returns default_value instead of 0 when penalty is not well defined (default value is passed as first argument to simplify the usage of the method in a callback).

vehicles

Return type: int

Returns the number of vehicle routes in the model.

VehicleVar

Return type: IntVar*

Arguments: int64 index

Returns the vehicle variable of the node corresponding to index. Note that VehicleVar(index) == -1 is equivalent to ActiveVar(index) == 0.

VehicleVars

Return type: const std::vector<IntVar*>&

Returns all vehicle variables of the model, such that VehicleVars(i) is the vehicle variable of the node corresponding to i.

WriteAssignment

Return type: bool

Arguments: const std::string& file_name

Writes the current solution to a file containing an AssignmentProto. Returns false if the file cannot be opened or if there is no current solution.

Send feedback about...