C++ Reference: class RoutingDimension

Note: This documentation is automatically generated.


Dimensions represent quantities accumulated at nodes along the routes. They represent quantities such as weights or volumes carried along the route, or distance or times.

Quantities at a node are represented by "cumul" variables and the increase or decrease of quantities between nodes are represented by "transit" variables. These variables are linked as follows:
  /// if j == next(i), cumul(j) = cumul(i) + transit(i) + slack(i)
where slack is a positive slack variable (can represent waiting times for a time dimension), and state_dependent_transits is a non-purely functional version of transits_. Favour transits over state_dependent_transits when possible, because purely functional callbacks allow more optimisations and make the model faster and easier to solve. TODO(user): Break constraints need to know the service time of nodes for a given vehicle, it is passed as an external vector, it would be better to have this information here.
Method
AddNodePrecedence

Return type: void

Arguments: NodePrecedence precedence

AddNodePrecedence

Return type: void

Arguments: int64_t first_node, int64_t second_node, int64_t offset

AreVehicleTransitsPositive

Return type: bool

Arguments: int vehicle

Returns true iff the transit evaluator of 'vehicle' is positive for all arcs.

base_dimension

Return type: const RoutingDimension*

Returns the parent in the dependency tree if any or nullptr otherwise.

class_transit_evaluator

Return type: const RoutingModel::TransitCallback2&

Arguments: RoutingVehicleClassIndex vehicle_class

Returns the callback evaluating the transit value between two node indices for a given vehicle class.

cumuls

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

Like CumulVar(), TransitVar(), SlackVar() but return the whole variable vectors instead (indexed by int64_t var index).

CumulVar

Return type: IntVar*

Arguments: int64_t index

Get the cumul, transit and slack variables for the given node (given as int64_t var index).

fixed_transits

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

FixedTransitVar

Return type: IntVar*

Arguments: int64_t index

forbidden_intervals

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

Returns forbidden intervals for each node.

GetAllowedIntervalsInRange

Return type: SortedDisjointIntervalList

Arguments: int64_t index, int64_t min_value, int64_t max_value

Returns allowed intervals for a given node in a given interval.

GetBreakIntervalsOfVehicle

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

Arguments: int vehicle

Returns the break intervals set by SetBreakIntervalsOfVehicle().

GetCumulVarPiecewiseLinearCost

Return type: const PiecewiseLinearFunction*

Arguments: int64_t index

Returns the piecewise linear cost of a cumul variable for a given variable index. The returned pointer has the same validity as this class.

GetCumulVarSoftLowerBound

Return type: int64_t

Arguments: int64_t index

Returns the soft lower bound of a cumul variable for a given variable index. The "hard" lower bound of the variable is returned if no soft lower bound has been set.

GetCumulVarSoftLowerBoundCoefficient

Return type: int64_t

Arguments: int64_t index

Returns the cost coefficient of the soft lower bound of a cumul variable for a given variable index. If no soft lower bound has been set, 0 is returned.

GetCumulVarSoftUpperBound

Return type: int64_t

Arguments: int64_t index

Returns the soft upper bound of a cumul variable for a given variable index. The "hard" upper bound of the variable is returned if no soft upper bound has been set.

GetCumulVarSoftUpperBoundCoefficient

Return type: int64_t

Arguments: int64_t index

Returns the cost coefficient of the soft upper bound of a cumul variable for a given variable index. If no soft upper bound has been set, 0 is returned.

GetFirstPossibleGreaterOrEqualValueForNode

Return type: int64_t

Arguments: int64_t index, int64_t min_value

Returns the smallest value outside the forbidden intervals of node 'index' that is greater than or equal to a given 'min_value'.

GetGlobalOptimizerOffset

Return type: int64_t

GetLastPossibleLessOrEqualValueForNode

Return type: int64_t

Arguments: int64_t index, int64_t max_value

Returns the largest value outside the forbidden intervals of node 'index' that is less than or equal to a given 'max_value'. NOTE: If this method is called with a max_value lower than the node's cumul min, it will return -1.

GetLocalOptimizerOffsetForVehicle

Return type: int64_t

Arguments: int vehicle

GetNodePrecedences

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

GetPathPrecedenceGraph

Return type: const ReverseArcListGraph<int, int>&

GetPickupToDeliveryLimitForPair

Return type: int64_t

Arguments: int pair_index, int pickup, int delivery

GetPostTravelEvaluatorOfVehicle

Return type: int

Arguments: int vehicle

GetPreTravelEvaluatorOfVehicle

Return type: int

Arguments: int vehicle

clang-format on

GetQuadraticCostSoftSpanUpperBoundForVehicle

Return type: SimpleBoundCosts::BoundCost

Arguments: int vehicle

GetSoftSpanUpperBoundForVehicle

Return type: SimpleBoundCosts::BoundCost

Arguments: int vehicle

GetSpanCostCoefficientForVehicle

Return type: int64_t

Arguments: int vehicle

GetSpanCostCoefficientForVehicleClass

Return type: int64_t

Arguments: RoutingVehicleClassIndex vehicle_class

GetSpanUpperBoundForVehicle

Return type: int64_t

Arguments: int vehicle

GetTransitValue

Return type: int64_t

Arguments: int64_t from_index, int64_t to_index, int64_t vehicle

Returns the transition value for a given pair of nodes (as var index); this value is the one taken by the corresponding transit variable when the 'next' variable for 'from_index' is bound to 'to_index'.

GetTransitValueFromClass

Return type: int64_t

Arguments: int64_t from_index, int64_t to_index, int64_t vehicle_class

Same as above but taking a vehicle class of the dimension instead of a vehicle (the class of a vehicle can be obtained with vehicle_to_class()).

GetUnaryTransitEvaluator

Return type: const RoutingModel::TransitCallback1&

Arguments: int vehicle

Returns the unary callback evaluating the transit value between two node indices for a given vehicle. If the corresponding callback is not unary, returns a null callback.

global_span_cost_coefficient

Return type: int64_t

HasBreakConstraints

Return type: bool

Returns true if any break interval or break distance was defined.

HasCumulVarPiecewiseLinearCost

Return type: bool

Arguments: int64_t index

Returns true if a piecewise linear cost has been set for a given variable index.

HasCumulVarSoftLowerBound

Return type: bool

Arguments: int64_t index

Returns true if a soft lower bound has been set for a given variable index.

HasCumulVarSoftUpperBound

Return type: bool

Arguments: int64_t index

Returns true if a soft upper bound has been set for a given variable index.

HasPickupToDeliveryLimits

Return type: bool

HasQuadraticCostSoftSpanUpperBounds

Return type: bool

HasSoftSpanUpperBounds

Return type: bool

InitializeBreaks

Return type: void

Sets up vehicle_break_intervals_, vehicle_break_distance_duration_, pre_travel_evaluators and post_travel_evaluators.

model

Return type: RoutingModel*

Returns the model on which the dimension was created.

name

Return type: const std::string&

Returns the name of the dimension.

~RoutingDimension

SetBreakDistanceDurationOfVehicle

Return type: void

Arguments: int64_t distance, int64_t duration, int vehicle

With breaks supposed to be consecutive, this forces the distance between breaks of size at least minimum_break_duration to be at most distance. This supposes that the time until route start and after route end are infinite breaks.

SetBreakIntervalsOfVehicle

Return type: void

Arguments: std::vector<IntervalVar*> breaks, int vehicle, int pre_travel_evaluator, int post_travel_evaluator

SetBreakIntervalsOfVehicle

Return type: void

Arguments: std::vector<IntervalVar*> breaks, int vehicle, std::vector<int64_t> node_visit_transits

Deprecated, sets pre_travel(i, j) = node_visit_transit[i].

SetBreakIntervalsOfVehicle

Return type: void

Arguments: std::vector<IntervalVar*> breaks, int vehicle, std::vector<int64_t> node_visit_transits, std::function<int64_t(int64_t, int64_t)> delays

Deprecated, sets pre_travel(i, j) = node_visit_transit[i] and post_travel(i, j) = delays(i, j).

SetCumulVarPiecewiseLinearCost

Return type: void

Arguments: int64_t index, const PiecewiseLinearFunction& cost

Sets a piecewise linear cost on the cumul variable of a given variable index. If f is a piecewise linear function, the resulting cost at 'index' will be f(CumulVar(index)). As of 3/2017, only non-decreasing positive cost functions are supported.

SetCumulVarSoftLowerBound

Return type: void

Arguments: int64_t index, int64_t lower_bound, int64_t coefficient

Sets a soft lower bound to the cumul variable of a given variable index. If the value of the cumul variable is less than the bound, a cost proportional to the difference between this value and the bound is added to the cost function of the model: cumulVar > lower_bound -> cost = 0 cumulVar <= lower_bound -> cost = coefficient * (lower_bound - cumulVar). This is also handy to model earliness costs when the dimension represents time.

SetCumulVarSoftUpperBound

Return type: void

Arguments: int64_t index, int64_t upper_bound, int64_t coefficient

Sets a soft upper bound to the cumul variable of a given variable index. If the value of the cumul variable is greater than the bound, a cost proportional to the difference between this value and the bound is added to the cost function of the model: cumulVar <= upper_bound -> cost = 0 cumulVar > upper_bound -> cost = coefficient * (cumulVar - upper_bound) This is also handy to model tardiness costs when the dimension represents time.

SetGlobalSpanCostCoefficient

Return type: void

Arguments: int64_t coefficient

Sets a cost proportional to the *global* dimension span, that is the difference between the largest value of route end cumul variables and the smallest value of route start cumul variables. In other words: global_span_cost = coefficient * (Max(dimension end value) - Min(dimension start value)).

SetPickupToDeliveryLimitFunctionForPair

Return type: void

Arguments: PickupToDeliveryLimitFunction limit_function, int pair_index

SetQuadraticCostSoftSpanUpperBoundForVehicle

Return type: void

Arguments: SimpleBoundCosts::BoundCost bound_cost, int vehicle

If the span of vehicle on this dimension is larger than bound, the cost will be increased by cost * (span - bound)^2.

SetSoftSpanUpperBoundForVehicle

Return type: void

Arguments: SimpleBoundCosts::BoundCost bound_cost, int vehicle

If the span of vehicle on this dimension is larger than bound, the cost will be increased by cost * (span - bound).

SetSpanCostCoefficientForAllVehicles

Return type: void

Arguments: int64_t coefficient

SetSpanCostCoefficientForVehicle

Return type: void

Arguments: int64_t coefficient, int vehicle

Sets a cost proportional to the dimension span on a given vehicle, or on all vehicles at once. "coefficient" must be nonnegative. This is handy to model costs proportional to idle time when the dimension represents time. The cost for a vehicle is span_cost = coefficient * (dimension end value - dimension start value).

SetSpanUpperBoundForVehicle

Return type: void

Arguments: int64_t upper_bound, int vehicle

Sets an upper bound on the dimension span on a given vehicle. This is the preferred way to limit the "length" of the route of a vehicle according to a dimension.

ShortestTransitionSlack

Return type: int64_t

Arguments: int64_t node

It makes sense to use the function only for self-dependent dimension. For such dimensions the value of the slack of a node determines the transition cost of the next transit. Provided that 1. cumul[node] is fixed, 2. next[node] and next[next[node]] (if exists) are fixed, the value of slack[node] for which cumul[next[node]] + transit[next[node]] is minimized can be found in O(1) using this function.

slacks

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

SlackVar

Return type: IntVar*

Arguments: int64_t index

transit_evaluator

Return type: const RoutingModel::TransitCallback2&

Arguments: int vehicle

Returns the callback evaluating the transit value between two node indices for a given vehicle.

transits

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

TransitVar

Return type: IntVar*

Arguments: int64_t index

vehicle_capacities

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

Returns the capacities for all vehicles.

vehicle_span_cost_coefficients

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

vehicle_span_upper_bounds

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

vehicle_to_class

Return type: int

Arguments: int vehicle