Class RoutingIndexManager
java.lang.Object
com.google.ortools.constraintsolver.RoutingIndexManager
Manager for any NodeIndex <-> variable index conversion. The routing solver
uses variable indices internally and through its API. These variable indices
are tricky to manage directly because one Node can correspond to a multitude
of variables, depending on the number of times they appear in the model, and
if they're used as start and/or end points. This class aims to simplify
variable index usage, allowing users to use NodeIndex instead.
Usage:
Then, use 'manager.NodeToIndex(node)' whenever model requires a variable
index.
Note: the mapping between node indices and variables indices is subject to
change so no assumption should be made on it. The only guarantee is that
indices range between 0 and n-1, where n = number of vehicles * 2 (for start
and end nodes) + number of non-start or end nodes.
uses variable indices internally and through its API. These variable indices
are tricky to manage directly because one Node can correspond to a multitude
of variables, depending on the number of times they appear in the model, and
if they're used as start and/or end points. This class aims to simplify
variable index usage, allowing users to use NodeIndex instead.
Usage:
auto starts_ends = ...; /// These are NodeIndex.
RoutingIndexManager manager(10, 4, starts_ends); // 10 nodes, 4 vehicles.
RoutingModel model(manager);
Then, use 'manager.NodeToIndex(node)' whenever model requires a variable
index.
Note: the mapping between node indices and variables indices is subject to
change so no assumption should be made on it. The only guarantee is that
indices range between 0 and n-1, where n = number of vehicles * 2 (for start
and end nodes) + number of non-start or end nodes.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRoutingIndexManager
(int num_nodes, int num_vehicles, int depot) Creates a NodeIndex to variable index mapping for a problem containing
'num_nodes', 'num_vehicles' and the given starts and ends for each
vehicle.RoutingIndexManager
(int num_nodes, int num_vehicles, int[] starts, int[] ends) RoutingIndexManager
(long cPtr, boolean cMemoryOwn) -
Method Summary
Modifier and TypeMethodDescriptionvoid
delete()
protected void
finalize()
static long
long
getEndIndex
(int vehicle) int
int
int
long
getStartIndex
(int vehicle) int
indexToNode
(long index) long[]
nodesToIndices
(int[] nodes) long
nodeToIndex
(int node) static long
-
Field Details
-
swigCMemOwn
protected transient boolean swigCMemOwn
-
-
Constructor Details
-
RoutingIndexManager
public RoutingIndexManager(long cPtr, boolean cMemoryOwn) -
RoutingIndexManager
public RoutingIndexManager(int num_nodes, int num_vehicles, int depot) Creates a NodeIndex to variable index mapping for a problem containing
'num_nodes', 'num_vehicles' and the given starts and ends for each
vehicle. If used, any start/end arrays have to have exactly 'num_vehicles'
elements. -
RoutingIndexManager
public RoutingIndexManager(int num_nodes, int num_vehicles, int[] starts, int[] ends)
-
-
Method Details
-
getCPtr
-
swigRelease
-
finalize
-
delete
public void delete() -
getNumberOfNodes
public int getNumberOfNodes() -
getNumberOfVehicles
public int getNumberOfVehicles() -
getNumberOfIndices
public int getNumberOfIndices() -
getStartIndex
public long getStartIndex(int vehicle) -
getEndIndex
public long getEndIndex(int vehicle) -
nodeToIndex
public long nodeToIndex(int node) -
nodesToIndices
public long[] nodesToIndices(int[] nodes) -
indexToNode
public int indexToNode(long index)
-