Class RoutingModel

java.lang.Object
com.google.ortools.constraintsolver.RoutingModel

public class RoutingModel
extends java.lang.Object
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  RoutingModel.VehicleTypeContainer
    Struct used to sort and store vehicles by their type.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int ADDED_TYPE_REMOVED_FROM_VEHICLE
    When visited, one instance of type 'T' previously added to the route
    (TYPE_ADDED_TO_VEHICLE), if any, is removed from the vehicle.
    If the type was not previously added to the route or all added instances
    have already been removed, this visit has no effect on the types.
    static int PICKUP_AND_DELIVERY_FIFO
    Deliveries must be performed in the same order as pickups.
    static int PICKUP_AND_DELIVERY_LIFO
    Deliveries must be performed in reverse order of pickups.
    static int PICKUP_AND_DELIVERY_NO_ORDER
    Any precedence is accepted.
    static int ROUTING_FAIL
    No solution found to the problem after calling RoutingModel::Solve().
    static int ROUTING_FAIL_TIMEOUT
    Time limit reached before finding a solution with RoutingModel::Solve().
    static int ROUTING_INVALID
    Model, model parameters or flags are not valid.
    static int ROUTING_NOT_SOLVED
    Problem not solved yet (before calling RoutingModel::Solve()).
    static int ROUTING_SUCCESS
    Problem solved successfully after calling RoutingModel::Solve().
    protected boolean swigCMemOwn  
    static int TYPE_ADDED_TO_VEHICLE
    When visited, the number of types 'T' on the vehicle increases by one.
    static int TYPE_ON_VEHICLE_UP_TO_VISIT
    With the following policy, the visit enforces that type 'T' is
    considered on the route from its start until this node is visited.
    static int TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED
    The visit doesn't have an impact on the number of types 'T' on the
    route, as it's (virtually) added and removed directly.
    This policy can be used for visits which are part of an incompatibility
    or requirement set without affecting the type count on the route.
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected RoutingModel​(long cPtr, boolean cMemoryOwn)  
      RoutingModel​(RoutingIndexManager index_manager)
    Constructor taking an index manager.
      RoutingModel​(RoutingIndexManager index_manager, RoutingModelParameters parameters)  
  • Method Summary

    Modifier and Type Method Description
    IntVar activeVar​(long index)
    Returns the active variable of the node corresponding to index.
    IntVar activeVehicleVar​(int vehicle)
    Returns the active variable of the vehicle.
    void addAtSolutionCallback​(java.lang.Runnable 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.
    IntBoolPair addConstantDimension​(long value, long capacity, boolean fix_start_cumul_to_zero, java.lang.String name)  
    IntBoolPair addConstantDimensionWithSlack​(long value, long capacity, long slack_max, boolean fix_start_cumul_to_zero, java.lang.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 a pair consisting of an index to the registered unary transit
    callback and a bool denoting whether the dimension has been created.
    It is false if a dimension with the same name has already been created
    (and doesn't create the new dimension but still register a new callback).
    boolean addDimension​(int evaluator_index, long slack_max, long capacity, boolean fix_start_cumul_to_zero, java.lang.String name)
    Model creation
    Methods to add dimensions to routes; dimensions represent quantities
    accumulated at nodes along the routes.
    boolean addDimensionWithVehicleCapacity​(int evaluator_index, long slack_max, long[] vehicle_capacities, boolean fix_start_cumul_to_zero, java.lang.String name)  
    boolean addDimensionWithVehicleTransitAndCapacity​(int[] evaluator_indices, long slack_max, long[] vehicle_capacities, boolean fix_start_cumul_to_zero, java.lang.String name)  
    boolean addDimensionWithVehicleTransits​(int[] evaluator_indices, long slack_max, long capacity, boolean fix_start_cumul_to_zero, java.lang.String name)  
    int addDisjunction​(long[] indices)
    Adds a disjunction constraint on the indices: exactly 'max_cardinality' of
    the indices are active.
    int addDisjunction​(long[] indices, long penalty)
    Adds a disjunction constraint on the indices: exactly 'max_cardinality' of
    the indices are active.
    int addDisjunction​(long[] indices, long penalty, long max_cardinality)
    Adds a disjunction constraint on the indices: exactly 'max_cardinality' of
    the indices are active.
    void addHardTypeIncompatibility​(int type1, int type2)
    Incompatibilities:
    Two nodes with "hard" incompatible types cannot share the same route at
    all, while with a "temporal" incompatibility they can't be on the same
    route at the same time.
    void addIntervalToAssignment​(IntervalVar interval)  
    void addLocalSearchFilter​(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.
    void addLocalSearchOperator​(LocalSearchOperator ls_operator)
    Adds a local search operator to the set of operators used to solve the
    vehicle routing problem.
    IntBoolPair addMatrixDimension​(long[][] values, long capacity, boolean fix_start_cumul_to_zero, java.lang.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.
    void addPickupAndDelivery​(long pickup, long delivery)
    Notifies that index1 and index2 form a pair of nodes which should belong
    to the same route.
    void addPickupAndDeliverySets​(int pickup_disjunction, int delivery_disjunction)
    Same as AddPickupAndDelivery but notifying that the performed node from
    the disjunction of index 'pickup_disjunction' is on the same route as the
    performed node from the disjunction of index 'delivery_disjunction'.
    void addRequiredTypeAlternativesWhenAddingType​(int dependent_type, SWIGTYPE_p_absl__flat_hash_setT_int_t required_type_alternatives)
    If type_D depends on type_R when adding type_D, any node_D of type_D and
    VisitTypePolicy TYPE_ADDED_TO_VEHICLE or
    TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED requires at least one type_R on its
    vehicle at the time node_D is visited.
    void addRequiredTypeAlternativesWhenRemovingType​(int dependent_type, SWIGTYPE_p_absl__flat_hash_setT_int_t required_type_alternatives)
    The following requirements apply when visiting dependent nodes that remove
    their type from the route, i.e.
    void addSearchMonitor​(SearchMonitor monitor)
    Adds a search monitor to the search used to solve the routing model.
    void addSoftSameVehicleConstraint​(long[] indices, long cost)
    Adds a soft constraint to force a set of variable indices to be on the
    same vehicle.
    void addTemporalTypeIncompatibility​(int type1, int type2)  
    void addToAssignment​(IntVar var)
    Adds an extra variable to the vehicle routing assignment.
    void addVariableMaximizedByFinalizer​(IntVar var)
    Adds a variable to maximize in the solution finalizer (see above for
    information on the solution finalizer).
    void addVariableMinimizedByFinalizer​(IntVar var)
    Adds a variable to minimize in the solution finalizer.
    void addVariableTargetToFinalizer​(IntVar var, long target)
    Add a variable to set the closest possible to the target value in the
    solution finalizer.
    IntBoolPair addVectorDimension​(long[] values, long capacity, boolean fix_start_cumul_to_zero, java.lang.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.
    void AddWeightedVariableMinimizedByFinalizer​(IntVar var, long cost)
    Adds a variable to minimize in the solution finalizer, with a weighted
    priority: the higher the more priority it has.
    IntVar applyLocks​(long[] locks)
    Applies a lock chain to the next search.
    boolean applyLocksToAllVehicles​(long[][] locks, boolean close_routes)
    Applies lock chains to all vehicles to the next search, such that locks[p]
    is the lock chain for route p.
    boolean arcIsMoreConstrainedThanArc​(long from, long to1, long 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.
    boolean AreEmptyRouteCostsConsideredForVehicle​(int vehicle)  
    void assignmentToRoutes​(Assignment assignment, long[][] routes)
    Converts the solution in the given assignment to routes for all vehicles.
    Expects that assignment contains a valid solution (i.e.
    boolean checkLimit()
    Returns true if the search limit has been crossed.
    void closeModel()
    Closes the current routing model; after this method is called, no
    modification to the model can be done, but RoutesToAssignment becomes
    available.
    void closeModelWithParameters​(RoutingSearchParameters search_parameters)
    Same as above taking search parameters (as of 10/2015 some the parameters
    have to be set when closing the model).
    void closeVisitTypes()
    This function should be called once all node visit types have been set and
    prior to adding any incompatibilities/requirements.
    "close" types.
    Assignment compactAndCheckAssignment​(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).
    Assignment compactAssignment​(Assignment assignment)
    Converts the solution in the given assignment to routes for all vehicles.
    If the returned vector is route_indices, route_indices[i][j] is the index
    for jth location visited on route i.
    long computeLowerBound()
    Computes a lower bound to the routing problem solving a linear assignment
    problem.
    void ConsiderEmptyRouteCostsForVehicle​(boolean consider_costs, int vehicle)  
    boolean costsAreHomogeneousAcrossVehicles()
    Whether costs are homogeneous across all vehicles.
    IntVar costVar()
    Returns the global cost variable which is being minimized.
    java.lang.String debugOutputAssignment​(Assignment solution_assignment, java.lang.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.
    void delete()  
    long end​(int vehicle)
    Returns the variable index of the ending node of a vehicle route.
    protected void finalize()  
    long[] getAmortizedLinearCostFactorOfVehicles()  
    long[] getAmortizedQuadraticCostFactorOfVehicles()  
    long getArcCostForClass​(long from_index, long to_index, long cost_class_index)
    Returns the cost of the segment between two nodes for a given cost
    class.
    long getArcCostForFirstSolution​(long from_index, long 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.
    long getArcCostForVehicle​(long from_index, long to_index, long vehicle)
    Returns the cost of the transit arc between two nodes for a given vehicle.
    Input are variable indices of node.
    int getCostClassesCount()
    Returns the number of different cost classes in the model.
    int getCostClassIndexOfVehicle​(long vehicle)
    Get the cost class index of the given vehicle.
    protected static long getCPtr​(RoutingModel obj)  
    long getDepot()
    Returns the variable index of the first starting or ending node of all
    routes.
    RoutingDimension getDimensionOrDie​(java.lang.String dimension_name)
    Returns a dimension from its name.
    long[] getDisjunctionIndices​(int index)
    Returns the variable indices of the nodes in the disjunction of index
    'index'.
    int[] getDisjunctionIndices​(long index)
    Returns the indices of the disjunctions to which an index belongs.
    long getDisjunctionMaxCardinality​(int index)
    Returns the maximum number of possible active nodes of the node
    disjunction of index 'index'.
    long getDisjunctionPenalty​(int index)
    Returns the penalty of the node disjunction of index 'index'.
    long getFixedCostOfVehicle​(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.
    long getHomogeneousCost​(long from_index, long 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).
    static int getKNoDimension()
    Constant used to express the "no dimension" index, returned when a
    dimension name does not correspond to an actual dimension.
    static int getKNoDisjunction()
    Constant used to express the "no disjunction" index, returned when a node
    does not appear in any disjunction.
    static long getKNoPenalty()
    Constant used to express a hard constraint instead of a soft penalty.
    int GetMaximumNumberOfActiveVehicles()
    Returns the maximum number of active vehicles.
    RoutingDimension getMutableDimension​(java.lang.String dimension_name)
    Returns a dimension from its name.
    int getNonZeroCostClassesCount()
    Ditto, minus the 'always zero', built-in cost class.
    long getNumberOfDecisionsInFirstSolution​(RoutingSearchParameters search_parameters)
    Returns statistics on first solution search, number of decisions sent to
    filters, number of decisions rejected by filters.
    int getNumberOfDisjunctions()
    Returns the number of node disjunctions in the model.
    long getNumberOfRejectsInFirstSolution​(RoutingSearchParameters search_parameters)  
    int getNumberOfVisitTypes()  
    int getNumOfSingletonNodes()
    Returns the number of non-start/end nodes which do not appear in a
    pickup/delivery pair.
    int[] GetPairIndicesOfType​(int type)  
    int getPickupAndDeliveryPolicyOfVehicle​(int vehicle)  
    java.lang.String getPrimaryConstrainedDimension()
    Get the primary constrained dimension, or an empty string if it is unset.
    SWIGTYPE_p_std__vectorT_absl__flat_hash_setT_int_t_t GetRequiredTypeAlternativesWhenAddingType​(int type)
    Returns the set of requirement alternatives when adding the given type.
    SWIGTYPE_p_std__vectorT_absl__flat_hash_setT_int_t_t GetRequiredTypeAlternativesWhenRemovingType​(int type)
    Returns the set of requirement alternatives when removing the given type.
    int[] getSameVehicleIndicesOfIndex​(int node)
    Returns variable indices of nodes constrained to be on the same route.
    int[] GetSingleNodesOfType​(int type)  
    SWIGTYPE_p_absl__flat_hash_setT_int_t getTemporalTypeIncompatibilitiesOfType​(int type)  
    int getVehicleClassesCount()
    Returns the number of different vehicle classes in the model.
    int getVehicleClassIndexOfVehicle​(long vehicle)  
    RoutingModel.VehicleTypeContainer GetVehicleTypeContainer()  
    int getVisitType​(long index)  
    int GetVisitTypePolicy​(long index)  
    boolean hasDimension​(java.lang.String dimension_name)
    Returns true if a dimension exists for a given dimension name.
    boolean hasHardTypeIncompatibilities()
    Returns true iff any hard (resp.
    boolean hasSameVehicleTypeRequirements()
    Returns true iff any same-route (resp.
    boolean hasTemporalTypeIncompatibilities()  
    boolean hasTemporalTypeRequirements()  
    boolean hasVehicleWithCostClassIndex​(int cost_class_index)
    Returns true iff the model contains a vehicle with the given
    cost_class_index.
    void ignoreDisjunctionsAlreadyForcedToZero()
    SPECIAL: Makes the solver ignore all the disjunctions whose active
    variables are all trivially zero (i.e.
    boolean isEnd​(long index)
    Returns true if 'index' represents the last node of a route.
    boolean isMatchingModel()
    Returns true if a vehicle/node matching problem is detected.
    boolean isStart​(long index)
    Returns true if 'index' represents the first node of a route.
    boolean isVehicleAllowedForIndex​(int vehicle, long index)
    Returns true if a vehicle is allowed to visit a given node.
    boolean isVehicleUsed​(Assignment assignment, int vehicle)
    Returns true if the route of 'vehicle' is non empty in 'assignment'.
    DecisionBuilder makeGuidedSlackFinalizer​(RoutingDimension dimension, java.util.function.LongUnaryOperator initializer)
    The next few members are in the public section only for testing purposes.

    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.
    Constraint MakePathSpansAndTotalSlacks​(RoutingDimension dimension, IntVar[] spans, IntVar[] total_slacks)
    For every vehicle of the routing model:
    - if total_slacks[vehicle] is not nullptr, constrains it to be the sum of
    slacks on that vehicle, that is,
    dimension->CumulVar(end) - dimension->CumulVar(start) -
    sum_{node in path of vehicle} dimension->FixedTransitVar(node).
    - if spans[vehicle] is not nullptr, constrains it to be
    dimension->CumulVar(end) - dimension->CumulVar(start)
    This does stronger propagation than a decomposition, and takes breaks into
    account.
    DecisionBuilder makeSelfDependentDimensionFinalizer​(RoutingDimension dimension)
    MakeSelfDependentDimensionFinalizer is a finalizer for the slacks of a
    self-dependent dimension.
    Assignment mutablePreAssignment()  
    long next​(Assignment assignment, long index)
    Assignment inspection
    Returns the variable index of the node directly after the node
    corresponding to 'index' in 'assignment'.
    IntVar[] nexts()
    Returns all next variables of the model, such that Nexts(i) is the next
    variable of the node corresponding to i.
    IntVar nextVar​(long index)
    Returns the next variable of the node corresponding to index.
    int nodes()
    Sizes and indices
    Returns the number of nodes in the model.
    Assignment preAssignment()
    Returns an assignment used to fix some of the variables of the problem.
    In practice, this assignment locks partial routes of the problem.
    Assignment readAssignment​(java.lang.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.
    Assignment readAssignmentFromRoutes​(long[][] routes, boolean ignore_inactive_indices)
    Restores the routes as the current solution.
    int registerPositiveTransitCallback​(java.util.function.LongBinaryOperator callback)  
    int registerPositiveUnaryTransitCallback​(java.util.function.LongUnaryOperator callback)  
    int registerTransitCallback​(java.util.function.LongBinaryOperator callback)  
    int registerTransitMatrix​(long[][] values)  
    int registerUnaryTransitCallback​(java.util.function.LongUnaryOperator callback)  
    int registerUnaryTransitVector​(long[] values)
    Registers 'callback' and returns its index.
    Assignment restoreAssignment​(Assignment solution)
    Restores an assignment as a solution in the routing model and returns the
    new solution.
    boolean routesToAssignment​(long[][] routes, boolean ignore_inactive_indices, boolean close_routes, Assignment assignment)
    Fills an assignment from a specification of the routes of the
    vehicles.
    void setAllowedVehiclesForIndex​(int[] vehicles, long index)
    Sets the vehicles which can visit a given node.
    void setAmortizedCostFactorsOfAllVehicles​(long linear_cost_factor, long quadratic_cost_factor)
    The following methods set the linear and quadratic cost factors of
    vehicles (must be positive values).
    void setAmortizedCostFactorsOfVehicle​(long linear_cost_factor, long quadratic_cost_factor, int vehicle)
    Sets the linear and quadratic cost factor of the given vehicle.
    void setArcCostEvaluatorOfAllVehicles​(int evaluator_index)
    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.
    void setArcCostEvaluatorOfVehicle​(int evaluator_index, int vehicle)
    Sets the cost function for a given vehicle route.
    void setAssignmentFromOtherModelAssignment​(Assignment target_assignment, RoutingModel source_model, Assignment source_assignment)
    Given a "source_model" and its "source_assignment", resets
    "target_assignment" with the IntVar variables (nexts_, and vehicle_vars_
    if costs aren't homogeneous across vehicles) of "this" model, with the
    values set according to those in "other_assignment".
    The objective_element of target_assignment is set to this->cost_.
    void setFirstSolutionEvaluator​(java.util.function.LongBinaryOperator evaluator)
    Gets/sets the evaluator used during the search.
    void setFixedCostOfAllVehicles​(long cost)
    Sets the fixed cost of all vehicle routes.
    void setFixedCostOfVehicle​(long cost, int vehicle)
    Sets the fixed cost of one vehicle route.
    void SetMaximumNumberOfActiveVehicles​(int max_active_vehicles)
    Constrains the maximum number of active vehicles, aka the number of
    vehicles which do not have an empty route.
    void setPickupAndDeliveryPolicyOfAllVehicles​(int policy)
    Sets the Pickup and delivery policy of all vehicles.
    void setPickupAndDeliveryPolicyOfVehicle​(int policy, int vehicle)  
    void setPrimaryConstrainedDimension​(java.lang.String dimension_name)
    Set the given dimension as "primary constrained".
    void setVisitType​(long index, int type, int type_policy)  
    long size()
    Returns the number of next variables in the model.
    Assignment solve()
    Solves the current routing model; closes the current model.
    This is equivalent to calling
    SolveWithParameters(DefaultRoutingSearchParameters())
    or
    SolveFromAssignmentWithParameters(assignment,
    DefaultRoutingSearchParameters()).
    Assignment solve​(Assignment assignment)
    Solves the current routing model; closes the current model.
    This is equivalent to calling
    SolveWithParameters(DefaultRoutingSearchParameters())
    or
    SolveFromAssignmentWithParameters(assignment,
    DefaultRoutingSearchParameters()).
    Assignment SolveFromAssignmentsWithParameters​(SWIGTYPE_p_std__vectorT_operations_research__Assignment_const_p_t assignments, RoutingSearchParameters search_parameters)
    Same as above but will try all assignments in order as first solutions
    until one succeeds.
    Assignment SolveFromAssignmentsWithParameters​(SWIGTYPE_p_std__vectorT_operations_research__Assignment_const_p_t assignments, RoutingSearchParameters search_parameters, SWIGTYPE_p_std__vectorT_operations_research__Assignment_const_p_t solutions)
    Same as above but will try all assignments in order as first solutions
    until one succeeds.
    Assignment solveFromAssignmentWithParameters​(Assignment assignment, RoutingSearchParameters search_parameters)
    Same as above, except that if assignment is not null, it will be used as
    the initial solution.
    Solver solver()
    Returns a vector cumul_bounds, for which cumul_bounds[i][j] is a pair
    containing the minimum and maximum of the CumulVar of the jth node on
    route i.
    - cumul_bounds[i][j].first is the minimum.
    - cumul_bounds[i][j].second is the maximum.
    Returns the underlying constraint solver.
    Assignment solveWithParameters​(RoutingSearchParameters search_parameters)
    Solves the current routing model with the given parameters.
    long start​(int vehicle)
    Model inspection.
    Returns the variable index of the starting node of a vehicle route.
    int status()
    Returns the current status of the routing model.
    long unperformedPenalty​(long var_index)
    Get the "unperformed" penalty of a node.
    long unperformedPenaltyOrValue​(long default_value, long 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).
    IntVar VehicleCostsConsideredVar​(int vehicle)
    Returns the variable specifying whether or not costs are considered for
    vehicle.
    int VehicleIndex​(long index)
    Returns the vehicle of the given start/end index, and -1 if the given
    index is not a vehicle start/end.
    int vehicles()
    Returns the number of vehicle routes in the model.
    IntVar vehicleVar​(long index)
    Returns the vehicle variable of the node corresponding to index.
    IntVar[] vehicleVars()
    Returns all vehicle variables of the model, such that VehicleVars(i) is
    the vehicle variable of the node corresponding to i.
    boolean writeAssignment​(java.lang.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.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • swigCMemOwn

      protected transient boolean swigCMemOwn
    • ROUTING_NOT_SOLVED

      public static final int ROUTING_NOT_SOLVED
      Problem not solved yet (before calling RoutingModel::Solve()).
    • ROUTING_SUCCESS

      public static final int ROUTING_SUCCESS
      Problem solved successfully after calling RoutingModel::Solve().
    • ROUTING_FAIL

      public static final int ROUTING_FAIL
      No solution found to the problem after calling RoutingModel::Solve().
    • ROUTING_FAIL_TIMEOUT

      public static final int ROUTING_FAIL_TIMEOUT
      Time limit reached before finding a solution with RoutingModel::Solve().
    • ROUTING_INVALID

      public static final int ROUTING_INVALID
      Model, model parameters or flags are not valid.
    • PICKUP_AND_DELIVERY_NO_ORDER

      public static final int PICKUP_AND_DELIVERY_NO_ORDER
      Any precedence is accepted.
    • PICKUP_AND_DELIVERY_LIFO

      public static final int PICKUP_AND_DELIVERY_LIFO
      Deliveries must be performed in reverse order of pickups.
    • PICKUP_AND_DELIVERY_FIFO

      public static final int PICKUP_AND_DELIVERY_FIFO
      Deliveries must be performed in the same order as pickups.
    • TYPE_ADDED_TO_VEHICLE

      public static final int TYPE_ADDED_TO_VEHICLE
      When visited, the number of types 'T' on the vehicle increases by one.
    • ADDED_TYPE_REMOVED_FROM_VEHICLE

      public static final int ADDED_TYPE_REMOVED_FROM_VEHICLE
      When visited, one instance of type 'T' previously added to the route
      (TYPE_ADDED_TO_VEHICLE), if any, is removed from the vehicle.
      If the type was not previously added to the route or all added instances
      have already been removed, this visit has no effect on the types.
    • TYPE_ON_VEHICLE_UP_TO_VISIT

      public static final int TYPE_ON_VEHICLE_UP_TO_VISIT
      With the following policy, the visit enforces that type 'T' is
      considered on the route from its start until this node is visited.
    • TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED

      public static final int TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED
      The visit doesn't have an impact on the number of types 'T' on the
      route, as it's (virtually) added and removed directly.
      This policy can be used for visits which are part of an incompatibility
      or requirement set without affecting the type count on the route.
  • Constructor Details

    • RoutingModel

      protected RoutingModel​(long cPtr, boolean cMemoryOwn)
    • RoutingModel

      public RoutingModel​(RoutingIndexManager index_manager)
      Constructor taking an index manager. The version which does not take
      RoutingModelParameters is equivalent to passing
      DefaultRoutingModelParameters().
    • RoutingModel

      public RoutingModel​(RoutingIndexManager index_manager, RoutingModelParameters parameters)
  • Method Details

    • getCPtr

      protected static long getCPtr​(RoutingModel obj)
    • finalize

      protected void finalize()
      Overrides:
      finalize in class java.lang.Object
    • delete

      public void delete()
    • getKNoPenalty

      public static long getKNoPenalty()
      Constant used to express a hard constraint instead of a soft penalty.
    • getKNoDisjunction

      public static int getKNoDisjunction()
      Constant used to express the "no disjunction" index, returned when a node
      does not appear in any disjunction.
    • getKNoDimension

      public static int getKNoDimension()
      Constant used to express the "no dimension" index, returned when a
      dimension name does not correspond to an actual dimension.
    • registerUnaryTransitVector

      public int registerUnaryTransitVector​(long[] values)
      Registers 'callback' and returns its index.
    • registerUnaryTransitCallback

      public int registerUnaryTransitCallback​(java.util.function.LongUnaryOperator callback)
    • registerPositiveUnaryTransitCallback

      public int registerPositiveUnaryTransitCallback​(java.util.function.LongUnaryOperator callback)
    • registerTransitMatrix

      public int registerTransitMatrix​(long[][] values)
    • registerTransitCallback

      public int registerTransitCallback​(java.util.function.LongBinaryOperator callback)
    • registerPositiveTransitCallback

      public int registerPositiveTransitCallback​(java.util.function.LongBinaryOperator callback)
    • addDimension

      public boolean addDimension​(int evaluator_index, long slack_max, long capacity, boolean fix_start_cumul_to_zero, java.lang.String name)
      Model creation
      Methods to add dimensions to routes; 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).
      Setting the value of fix_start_cumul_to_zero to true will force the
      "cumul" variable of the start node of all vehicles to be equal to 0.
      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'.
    • addDimensionWithVehicleTransits

      public boolean addDimensionWithVehicleTransits​(int[] evaluator_indices, long slack_max, long capacity, boolean fix_start_cumul_to_zero, java.lang.String name)
    • addDimensionWithVehicleCapacity

      public boolean addDimensionWithVehicleCapacity​(int evaluator_index, long slack_max, long[] vehicle_capacities, boolean fix_start_cumul_to_zero, java.lang.String name)
    • addDimensionWithVehicleTransitAndCapacity

      public boolean addDimensionWithVehicleTransitAndCapacity​(int[] evaluator_indices, long slack_max, long[] vehicle_capacities, boolean fix_start_cumul_to_zero, java.lang.String name)
    • addConstantDimensionWithSlack

      public IntBoolPair addConstantDimensionWithSlack​(long value, long capacity, long slack_max, boolean fix_start_cumul_to_zero, java.lang.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 a pair consisting of an index to the registered unary transit
      callback and a bool denoting whether the dimension has been created.
      It is false if a dimension with the same name has already been created
      (and doesn't create the new dimension but still register a new callback).
    • addConstantDimension

      public IntBoolPair addConstantDimension​(long value, long capacity, boolean fix_start_cumul_to_zero, java.lang.String name)
    • addVectorDimension

      public IntBoolPair addVectorDimension​(long[] values, long capacity, boolean fix_start_cumul_to_zero, java.lang.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 a pair consisting of an index to the registered unary transit
      callback and a bool denoting whether the dimension has been created.
      It is false if a dimension with the same name has already been created
      (and doesn't create the new dimension but still register a new callback).
    • addMatrixDimension

      public IntBoolPair addMatrixDimension​(long[][] values, long capacity, boolean fix_start_cumul_to_zero, java.lang.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 a pair consisting of an index to the registered transit callback
      and a bool denoting whether the dimension has been created.
      It is false if a dimension with the same name has already been created
      (and doesn't create the new dimension but still register a new callback).
    • MakePathSpansAndTotalSlacks

      public Constraint MakePathSpansAndTotalSlacks​(RoutingDimension dimension, IntVar[] spans, IntVar[] total_slacks)
      For every vehicle of the routing model:
      - if total_slacks[vehicle] is not nullptr, constrains it to be the sum of
      slacks on that vehicle, that is,
      dimension->CumulVar(end) - dimension->CumulVar(start) -
      sum_{node in path of vehicle} dimension->FixedTransitVar(node).
      - if spans[vehicle] is not nullptr, constrains it to be
      dimension->CumulVar(end) - dimension->CumulVar(start)
      This does stronger propagation than a decomposition, and takes breaks into
      account.
    • hasDimension

      public boolean hasDimension​(java.lang.String dimension_name)
      Returns true if a dimension exists for a given dimension name.
    • getDimensionOrDie

      public RoutingDimension getDimensionOrDie​(java.lang.String dimension_name)
      Returns a dimension from its name. Dies if the dimension does not exist.
    • getMutableDimension

      public RoutingDimension getMutableDimension​(java.lang.String dimension_name)
      Returns a dimension from its name. Returns nullptr if the dimension does
      not exist.
    • setPrimaryConstrainedDimension

      public void setPrimaryConstrainedDimension​(java.lang.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.
    • getPrimaryConstrainedDimension

      public java.lang.String getPrimaryConstrainedDimension()
      Get the primary constrained dimension, or an empty string if it is unset.
    • addDisjunction

      public int addDisjunction​(long[] indices, long penalty, long max_cardinality)
      Adds a disjunction constraint on the indices: exactly 'max_cardinality' of
      the indices are active. Start and end indices of any vehicle cannot be
      part of a disjunction.

      If a penalty is given, at most 'max_cardinality' of the indices can be
      active, and if less are active, 'penalty' is payed per inactive index.
      This is equivalent to adding the constraint:
      p + Sum(i)active[i] == max_cardinality
      where p is an integer 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 'max_cardinality' indices of the disjunction to be
      performed, and therefore p == 0.
      Note: passing a vector with a single index will model an optional index
      with a penalty cost if it is not visited.
    • addDisjunction

      public int addDisjunction​(long[] indices, long penalty)
      Adds a disjunction constraint on the indices: exactly 'max_cardinality' of
      the indices are active. Start and end indices of any vehicle cannot be
      part of a disjunction.

      If a penalty is given, at most 'max_cardinality' of the indices can be
      active, and if less are active, 'penalty' is payed per inactive index.
      This is equivalent to adding the constraint:
      p + Sum(i)active[i] == max_cardinality
      where p is an integer 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 'max_cardinality' indices of the disjunction to be
      performed, and therefore p == 0.
      Note: passing a vector with a single index will model an optional index
      with a penalty cost if it is not visited.
    • addDisjunction

      public int addDisjunction​(long[] indices)
      Adds a disjunction constraint on the indices: exactly 'max_cardinality' of
      the indices are active. Start and end indices of any vehicle cannot be
      part of a disjunction.

      If a penalty is given, at most 'max_cardinality' of the indices can be
      active, and if less are active, 'penalty' is payed per inactive index.
      This is equivalent to adding the constraint:
      p + Sum(i)active[i] == max_cardinality
      where p is an integer 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 'max_cardinality' indices of the disjunction to be
      performed, and therefore p == 0.
      Note: passing a vector with a single index will model an optional index
      with a penalty cost if it is not visited.
    • getDisjunctionIndices

      public int[] getDisjunctionIndices​(long index)
      Returns the indices of the disjunctions to which an index belongs.
    • getDisjunctionIndices

      public long[] getDisjunctionIndices​(int index)
      Returns the variable indices of the nodes in the disjunction of index
      'index'.
    • getDisjunctionPenalty

      public long getDisjunctionPenalty​(int index)
      Returns the penalty of the node disjunction of index 'index'.
    • getDisjunctionMaxCardinality

      public long getDisjunctionMaxCardinality​(int index)
      Returns the maximum number of possible active nodes of the node
      disjunction of index 'index'.
    • getNumberOfDisjunctions

      public int getNumberOfDisjunctions()
      Returns the number of node disjunctions in the model.
    • ignoreDisjunctionsAlreadyForcedToZero

      public void ignoreDisjunctionsAlreadyForcedToZero()
      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.
    • addSoftSameVehicleConstraint

      public void addSoftSameVehicleConstraint​(long[] indices, long cost)
      Adds a soft constraint to force a set of variable indices 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.
    • setAllowedVehiclesForIndex

      public void setAllowedVehiclesForIndex​(int[] vehicles, long index)
      Sets the vehicles which can visit a given node. If the node is in a
      disjunction, this will not prevent it from being unperformed.
      Specifying an empty vector of vehicles has no effect (all vehicles
      will be allowed to visit the node).
    • isVehicleAllowedForIndex

      public boolean isVehicleAllowedForIndex​(int vehicle, long index)
      Returns true if a vehicle is allowed to visit a given node.
    • addPickupAndDelivery

      public void addPickupAndDelivery​(long pickup, long delivery)
      Notifies that index1 and index2 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();
      int64_t index1 = manager.NodeToIndex(node1);
      int64_t index2 = manager.NodeToIndex(node2);
      solver->AddConstraint(solver->MakeEquality(
      routing.VehicleVar(index1),
      routing.VehicleVar(index2)));
      routing.AddPickupAndDelivery(index1, index2);
    • addPickupAndDeliverySets

      public void addPickupAndDeliverySets​(int pickup_disjunction, int delivery_disjunction)
      Same as AddPickupAndDelivery but notifying that the performed node from
      the disjunction of index 'pickup_disjunction' is on the same route as the
      performed node from the disjunction of index 'delivery_disjunction'.
    • setPickupAndDeliveryPolicyOfAllVehicles

      public void setPickupAndDeliveryPolicyOfAllVehicles​(int policy)
      Sets the Pickup and delivery policy of all vehicles. It is equivalent to
      calling SetPickupAndDeliveryPolicyOfVehicle on all vehicles.
    • setPickupAndDeliveryPolicyOfVehicle

      public void setPickupAndDeliveryPolicyOfVehicle​(int policy, int vehicle)
    • getPickupAndDeliveryPolicyOfVehicle

      public int getPickupAndDeliveryPolicyOfVehicle​(int vehicle)
    • getNumOfSingletonNodes

      public int getNumOfSingletonNodes()
      Returns the number of non-start/end nodes which do not appear in a
      pickup/delivery pair.
    • setVisitType

      public void setVisitType​(long index, int type, int type_policy)
    • getVisitType

      public int getVisitType​(long index)
    • GetSingleNodesOfType

      public int[] GetSingleNodesOfType​(int type)
    • GetPairIndicesOfType

      public int[] GetPairIndicesOfType​(int type)
    • GetVisitTypePolicy

      public int GetVisitTypePolicy​(long index)
    • closeVisitTypes

      public void closeVisitTypes()
      This function should be called once all node visit types have been set and
      prior to adding any incompatibilities/requirements.
      "close" types.
    • getNumberOfVisitTypes

      public int getNumberOfVisitTypes()
    • addHardTypeIncompatibility

      public void addHardTypeIncompatibility​(int type1, int type2)
      Incompatibilities:
      Two nodes with "hard" incompatible types cannot share the same route at
      all, while with a "temporal" incompatibility they can't be on the same
      route at the same time.
    • addTemporalTypeIncompatibility

      public void addTemporalTypeIncompatibility​(int type1, int type2)
    • getTemporalTypeIncompatibilitiesOfType

      public SWIGTYPE_p_absl__flat_hash_setT_int_t getTemporalTypeIncompatibilitiesOfType​(int type)
    • hasHardTypeIncompatibilities

      public boolean hasHardTypeIncompatibilities()
      Returns true iff any hard (resp. temporal) type incompatibilities have
      been added to the model.
    • hasTemporalTypeIncompatibilities

      public boolean hasTemporalTypeIncompatibilities()
    • addRequiredTypeAlternativesWhenAddingType

      public void addRequiredTypeAlternativesWhenAddingType​(int dependent_type, SWIGTYPE_p_absl__flat_hash_setT_int_t required_type_alternatives)
      If type_D depends on type_R when adding type_D, any node_D of type_D and
      VisitTypePolicy TYPE_ADDED_TO_VEHICLE or
      TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED requires at least one type_R on its
      vehicle at the time node_D is visited.
    • addRequiredTypeAlternativesWhenRemovingType

      public void addRequiredTypeAlternativesWhenRemovingType​(int dependent_type, SWIGTYPE_p_absl__flat_hash_setT_int_t required_type_alternatives)
      The following requirements apply when visiting dependent nodes that remove
      their type from the route, i.e. type_R must be on the vehicle when type_D
      of VisitTypePolicy ADDED_TYPE_REMOVED_FROM_VEHICLE,
      TYPE_ON_VEHICLE_UP_TO_VISIT or TYPE_SIMULTANEOUSLY_ADDED_AND_REMOVED is
      visited.
    • GetRequiredTypeAlternativesWhenAddingType

      public SWIGTYPE_p_std__vectorT_absl__flat_hash_setT_int_t_t GetRequiredTypeAlternativesWhenAddingType​(int type)
      Returns the set of requirement alternatives when adding the given type.
    • GetRequiredTypeAlternativesWhenRemovingType

      public SWIGTYPE_p_std__vectorT_absl__flat_hash_setT_int_t_t GetRequiredTypeAlternativesWhenRemovingType​(int type)
      Returns the set of requirement alternatives when removing the given type.
    • hasSameVehicleTypeRequirements

      public boolean hasSameVehicleTypeRequirements()
      Returns true iff any same-route (resp. temporal) type requirements have
      been added to the model.
    • hasTemporalTypeRequirements

      public boolean hasTemporalTypeRequirements()
    • unperformedPenalty

      public long unperformedPenalty​(long 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

      public long unperformedPenaltyOrValue​(long default_value, long 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).
    • getDepot

      public long getDepot()
      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.
    • SetMaximumNumberOfActiveVehicles

      public void SetMaximumNumberOfActiveVehicles​(int max_active_vehicles)
      Constrains the maximum number of active vehicles, aka the number of
      vehicles which do not have an empty route. For instance, this can be used
      to limit the number of routes in the case where there are fewer drivers
      than vehicles and that the fleet of vehicle is heterogeneous.
    • GetMaximumNumberOfActiveVehicles

      public int GetMaximumNumberOfActiveVehicles()
      Returns the maximum number of active vehicles.
    • setArcCostEvaluatorOfAllVehicles

      public void setArcCostEvaluatorOfAllVehicles​(int evaluator_index)
      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.
    • setArcCostEvaluatorOfVehicle

      public void setArcCostEvaluatorOfVehicle​(int evaluator_index, int vehicle)
      Sets the cost function for a given vehicle route.
    • setFixedCostOfAllVehicles

      public void setFixedCostOfAllVehicles​(long cost)
      Sets the fixed cost of all vehicle routes. It is equivalent to calling
      SetFixedCostOfVehicle on all vehicle routes.
    • setFixedCostOfVehicle

      public void setFixedCostOfVehicle​(long cost, int vehicle)
      Sets the fixed cost of one vehicle route.
    • getFixedCostOfVehicle

      public long getFixedCostOfVehicle​(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.
    • setAmortizedCostFactorsOfAllVehicles

      public void setAmortizedCostFactorsOfAllVehicles​(long linear_cost_factor, long quadratic_cost_factor)
      The following methods set the linear and quadratic cost factors of
      vehicles (must be positive values). The default value of these parameters
      is zero for all vehicles.

      When set, the cost_ of the model will contain terms aiming at reducing the
      number of vehicles used in the model, by adding the following to the
      objective for every vehicle v:
      INDICATOR(v used in the model) *
      [linear_cost_factor_of_vehicle_[v]
      - quadratic_cost_factor_of_vehicle_[v]*(square of length of route v)]
      i.e. for every used vehicle, we add the linear factor as fixed cost, and
      subtract the square of the route length multiplied by the quadratic
      factor. This second term aims at making the routes as dense as possible.

      Sets the linear and quadratic cost factor of all vehicles.
    • setAmortizedCostFactorsOfVehicle

      public void setAmortizedCostFactorsOfVehicle​(long linear_cost_factor, long quadratic_cost_factor, int vehicle)
      Sets the linear and quadratic cost factor of the given vehicle.
    • getAmortizedLinearCostFactorOfVehicles

      public long[] getAmortizedLinearCostFactorOfVehicles()
    • getAmortizedQuadraticCostFactorOfVehicles

      public long[] getAmortizedQuadraticCostFactorOfVehicles()
    • ConsiderEmptyRouteCostsForVehicle

      public void ConsiderEmptyRouteCostsForVehicle​(boolean consider_costs, int vehicle)
    • AreEmptyRouteCostsConsideredForVehicle

      public boolean AreEmptyRouteCostsConsideredForVehicle​(int vehicle)
    • setFirstSolutionEvaluator

      public void setFirstSolutionEvaluator​(java.util.function.LongBinaryOperator evaluator)
      Gets/sets the evaluator used during the search. Only relevant when
      RoutingSearchParameters.first_solution_strategy = EVALUATOR_STRATEGY.
      Takes ownership of evaluator.
    • addLocalSearchOperator

      public void addLocalSearchOperator​(LocalSearchOperator ls_operator)
      Adds a local search operator to the set of operators used to solve the
      vehicle routing problem.
    • addSearchMonitor

      public void addSearchMonitor​(SearchMonitor monitor)
      Adds a search monitor to the search used to solve the routing model.
    • addAtSolutionCallback

      public void addAtSolutionCallback​(java.lang.Runnable 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.
    • addVariableMinimizedByFinalizer

      public void addVariableMinimizedByFinalizer​(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).
    • addVariableMaximizedByFinalizer

      public void addVariableMaximizedByFinalizer​(IntVar var)
      Adds a variable to maximize in the solution finalizer (see above for
      information on the solution finalizer).
    • AddWeightedVariableMinimizedByFinalizer

      public void AddWeightedVariableMinimizedByFinalizer​(IntVar var, long cost)
      Adds a variable to minimize in the solution finalizer, with a weighted
      priority: the higher the more priority it has.
    • addVariableTargetToFinalizer

      public void addVariableTargetToFinalizer​(IntVar var, long target)
      Add a variable to set the closest possible to the target value in the
      solution finalizer.
    • closeModel

      public void closeModel()
      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(DefaultRoutingSearchParameters()).
    • closeModelWithParameters

      public void closeModelWithParameters​(RoutingSearchParameters search_parameters)
      Same as above taking search parameters (as of 10/2015 some the parameters
      have to be set when closing the model).
    • solve

      public Assignment solve​(Assignment assignment)
      Solves the current routing model; closes the current model.
      This is equivalent to calling
      SolveWithParameters(DefaultRoutingSearchParameters())
      or
      SolveFromAssignmentWithParameters(assignment,
      DefaultRoutingSearchParameters()).
    • solve

      public Assignment solve()
      Solves the current routing model; closes the current model.
      This is equivalent to calling
      SolveWithParameters(DefaultRoutingSearchParameters())
      or
      SolveFromAssignmentWithParameters(assignment,
      DefaultRoutingSearchParameters()).
    • solveWithParameters

      public Assignment solveWithParameters​(RoutingSearchParameters search_parameters)
      Solves the current routing model with the given parameters. If 'solutions'
      is specified, it will contain the k best solutions found during the search
      (from worst to best, including the one returned by this method), where k
      corresponds to the 'number_of_solutions_to_collect' in
      'search_parameters'. Note that the Assignment returned by the method and
      the ones in solutions are owned by the underlying solver and should not be
      deleted.
    • solveFromAssignmentWithParameters

      public Assignment solveFromAssignmentWithParameters​(Assignment assignment, RoutingSearchParameters search_parameters)
      Same as above, except that if assignment is not null, it will be used as
      the initial solution.
    • SolveFromAssignmentsWithParameters

      Same as above but will try all assignments in order as first solutions
      until one succeeds.
    • SolveFromAssignmentsWithParameters

      public Assignment SolveFromAssignmentsWithParameters​(SWIGTYPE_p_std__vectorT_operations_research__Assignment_const_p_t assignments, RoutingSearchParameters search_parameters)
      Same as above but will try all assignments in order as first solutions
      until one succeeds.
    • setAssignmentFromOtherModelAssignment

      public void setAssignmentFromOtherModelAssignment​(Assignment target_assignment, RoutingModel source_model, Assignment source_assignment)
      Given a "source_model" and its "source_assignment", resets
      "target_assignment" with the IntVar variables (nexts_, and vehicle_vars_
      if costs aren't homogeneous across vehicles) of "this" model, with the
      values set according to those in "other_assignment".
      The objective_element of target_assignment is set to this->cost_.
    • computeLowerBound

      public long computeLowerBound()
      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).
    • status

      public int status()
      Returns the current status of the routing model.
    • applyLocks

      public IntVar applyLocks​(long[] 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

      public boolean applyLocksToAllVehicles​(long[][] locks, boolean 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().
    • preAssignment

      public Assignment preAssignment()
      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.
    • mutablePreAssignment

      public Assignment mutablePreAssignment()
    • writeAssignment

      public boolean writeAssignment​(java.lang.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.
    • readAssignment

      public Assignment readAssignment​(java.lang.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.
    • restoreAssignment

      public Assignment restoreAssignment​(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.
    • readAssignmentFromRoutes

      public Assignment readAssignmentFromRoutes​(long[][] routes, boolean ignore_inactive_indices)
      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.
    • routesToAssignment

      public boolean routesToAssignment​(long[][] routes, boolean ignore_inactive_indices, boolean close_routes, Assignment assignment)
      Fills an assignment from a specification of the routes of the
      vehicles. The routes are specified as lists of variable indices that
      appear on the routes of the vehicles. The indices of the outer vector in
      'routes' correspond to vehicles IDs, the inner vector contains the
      variable indices on the routes for the given vehicle. The inner vectors
      must not contain the start and end indices, 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_indices set to false, this method will
      fail (return nullptr) in case some of the route contain indices that are
      deactivated in the model; when set to true, these indices 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.
    • assignmentToRoutes

      public void assignmentToRoutes​(Assignment assignment, long[][] 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 index for that vehicle).
    • compactAssignment

      public Assignment compactAssignment​(Assignment assignment)
      Converts the solution in the given assignment to routes for all vehicles.
      If the returned vector is route_indices, route_indices[i][j] is the index
      for jth location visited on route i. Note that contrary to
      AssignmentToRoutes, the vectors do include start and end locations.
      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).
    • compactAndCheckAssignment

      public Assignment compactAndCheckAssignment​(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).
    • addToAssignment

      public void addToAssignment​(IntVar var)
      Adds an extra variable to the vehicle routing assignment.
    • addIntervalToAssignment

      public void addIntervalToAssignment​(IntervalVar interval)
    • addLocalSearchFilter

      public void addLocalSearchFilter​(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.
    • start

      public long start​(int vehicle)
      Model inspection.
      Returns the variable index of the starting node of a vehicle route.
    • end

      public long end​(int vehicle)
      Returns the variable index of the ending node of a vehicle route.
    • isStart

      public boolean isStart​(long index)
      Returns true if 'index' represents the first node of a route.
    • isEnd

      public boolean isEnd​(long index)
      Returns true if 'index' represents the last node of a route.
    • VehicleIndex

      public int VehicleIndex​(long index)
      Returns the vehicle of the given start/end index, and -1 if the given
      index is not a vehicle start/end.
    • next

      public long next​(Assignment assignment, long index)
      Assignment inspection
      Returns the variable index of the node directly after the node
      corresponding to 'index' in 'assignment'.
    • isVehicleUsed

      public boolean isVehicleUsed​(Assignment assignment, int vehicle)
      Returns true if the route of 'vehicle' is non empty in 'assignment'.
    • nexts

      public IntVar[] nexts()
      Returns all next variables of the model, such that Nexts(i) is the next
      variable of the node corresponding to i.
    • vehicleVars

      public IntVar[] vehicleVars()
      Returns all vehicle variables of the model, such that VehicleVars(i) is
      the vehicle variable of the node corresponding to i.
    • nextVar

      public IntVar nextVar​(long index)
      Returns the next variable of the node corresponding to index. Note that
      NextVar(index) == index is equivalent to ActiveVar(index) == 0.
    • activeVar

      public IntVar activeVar​(long index)
      Returns the active variable of the node corresponding to index.
    • activeVehicleVar

      public IntVar activeVehicleVar​(int vehicle)
      Returns the active variable of the vehicle. It will be equal to 1 iff the
      route of the vehicle is not empty, 0 otherwise.
    • VehicleCostsConsideredVar

      public IntVar VehicleCostsConsideredVar​(int vehicle)
      Returns the variable specifying whether or not costs are considered for
      vehicle.
    • vehicleVar

      public IntVar vehicleVar​(long index)
      Returns the vehicle variable of the node corresponding to index. Note that
      VehicleVar(index) == -1 is equivalent to ActiveVar(index) == 0.
    • costVar

      public IntVar costVar()
      Returns the global cost variable which is being minimized.
    • getArcCostForVehicle

      public long getArcCostForVehicle​(long from_index, long to_index, long 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.
    • costsAreHomogeneousAcrossVehicles

      public boolean costsAreHomogeneousAcrossVehicles()
      Whether costs are homogeneous across all vehicles.
    • getHomogeneousCost

      public long getHomogeneousCost​(long from_index, long 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).
    • getArcCostForFirstSolution

      public long getArcCostForFirstSolution​(long from_index, long 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.
    • getArcCostForClass

      public long getArcCostForClass​(long from_index, long to_index, long 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.
    • getCostClassIndexOfVehicle

      public int getCostClassIndexOfVehicle​(long vehicle)
      Get the cost class index of the given vehicle.
    • hasVehicleWithCostClassIndex

      public boolean hasVehicleWithCostClassIndex​(int cost_class_index)
      Returns true iff the model contains a vehicle with the given
      cost_class_index.
    • getCostClassesCount

      public int getCostClassesCount()
      Returns the number of different cost classes in the model.
    • getNonZeroCostClassesCount

      public int getNonZeroCostClassesCount()
      Ditto, minus the 'always zero', built-in cost class.
    • getVehicleClassIndexOfVehicle

      public int getVehicleClassIndexOfVehicle​(long vehicle)
    • getVehicleClassesCount

      public int getVehicleClassesCount()
      Returns the number of different vehicle classes in the model.
    • getSameVehicleIndicesOfIndex

      public int[] getSameVehicleIndicesOfIndex​(int node)
      Returns variable indices of nodes constrained to be on the same route.
    • GetVehicleTypeContainer

      public RoutingModel.VehicleTypeContainer GetVehicleTypeContainer()
    • arcIsMoreConstrainedThanArc

      public boolean arcIsMoreConstrainedThanArc​(long from, long to1, long 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.
    • debugOutputAssignment

      public java.lang.String debugOutputAssignment​(Assignment solution_assignment, java.lang.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.
    • solver

      public Solver solver()
      Returns a vector cumul_bounds, for which cumul_bounds[i][j] is a pair
      containing the minimum and maximum of the CumulVar of the jth node on
      route i.
      - cumul_bounds[i][j].first is the minimum.
      - cumul_bounds[i][j].second is the maximum.
      Returns the underlying constraint solver. Can be used to add extra
      constraints and/or modify search algoithms.
    • checkLimit

      public boolean checkLimit()
      Returns true if the search limit has been crossed.
    • nodes

      public int nodes()
      Sizes and indices
      Returns the number of nodes in the model.
    • vehicles

      public int vehicles()
      Returns the number of vehicle routes in the model.
    • size

      public long size()
      Returns the number of next variables in the model.
    • getNumberOfDecisionsInFirstSolution

      public long getNumberOfDecisionsInFirstSolution​(RoutingSearchParameters search_parameters)
      Returns statistics on first solution search, number of decisions sent to
      filters, number of decisions rejected by filters.
    • getNumberOfRejectsInFirstSolution

      public long getNumberOfRejectsInFirstSolution​(RoutingSearchParameters search_parameters)
    • isMatchingModel

      public boolean isMatchingModel()
      Returns true if a vehicle/node matching problem is detected.
    • makeGuidedSlackFinalizer

      public DecisionBuilder makeGuidedSlackFinalizer​(RoutingDimension dimension, java.util.function.LongUnaryOperator initializer)
      The next few members are in the public section only for testing purposes.

      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

      public DecisionBuilder makeSelfDependentDimensionFinalizer​(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.