Stay organized with collections
Save and categorize content based on your preferences.
C++ Reference: class RoutingIndexManager
Note: This documentation is automatically generated.
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:
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.
Returns the index of a node. A node can correspond to multiple indices if
it's a start or end node. As of 03/2020, kUnassigned will be returned for
all end nodes. If a node appears more than once as a start node, the index
of the first node in the list of start nodes is returned.
Arguments: int num_nodes, int num_vehicles, NodeIndex 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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-08-06 UTC."],[[["\u003cp\u003eThe RoutingIndexManager class simplifies the use of variable indices in the routing solver by allowing users to work with NodeIndex instead.\u003c/p\u003e\n"],["\u003cp\u003eIt manages the conversion between NodeIndex and the internal variable indices used by the routing solver.\u003c/p\u003e\n"],["\u003cp\u003eUsers can create a RoutingIndexManager instance by specifying the number of nodes, vehicles, and start/end locations.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eNodeToIndex\u003c/code\u003e method provides the variable index corresponding to a given NodeIndex, while \u003ccode\u003eIndexToNode\u003c/code\u003e performs the reverse operation.\u003c/p\u003e\n"],["\u003cp\u003eThe mapping between NodeIndex and variable indices is dynamic, but guarantees indices within a specific range.\u003c/p\u003e\n"]]],["The `RoutingIndexManager` class manages the conversion between `NodeIndex` and variable indices used in routing solvers. It simplifies index usage, as a node can map to multiple variable indices. Key actions include creating a manager with node, vehicle, and start/end information. Users then use `NodeToIndex(node)` to get the variable index. The class provides methods to convert between nodes and indices (`NodeToIndex`, `IndexToNode`, `NodesToIndices`, `IndicesToNodes`) and to get information about the problem setup (`num_nodes`, `num_vehicles`, etc.).\n"],null,["# RoutingIndexManager\n\nC++ Reference: class RoutingIndexManager\n========================================\n\n\nNote: This documentation is automatically generated.\nManager for any NodeIndex \\\u003c-\\\u003e 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. \n\nUsage: \n\n```\n auto starts_ends = ...; /// These are NodeIndex.\n RoutingIndexManager manager(10, 4, starts_ends); // 10 nodes, 4 vehicles.\n RoutingModel model(manager);\n```\n\n\u003cbr /\u003e\n\nThen, use 'manager.NodeToIndex(node)' whenever model requires a variable index. \n\nNote: 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. \n\n| Method ||\n|------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [`GetEndIndex`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L77) | Return type: `int64_t ` Arguments: `int vehicle` \u003cbr /\u003e |\n| [`GetIndexToNodeMap`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L104) | Return type: `std::vector\u003cNodeIndex\u003e ` \u003cbr /\u003e |\n| [`GetNodeToIndexMap`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L105) | Return type: `absl::StrongVector\u003cNodeIndex, int64_t\u003e ` \u003cbr /\u003e |\n| [`GetStartIndex`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L74) | Return type: `int64_t ` Arguments: `int vehicle` Returns start and end indices of the given vehicle. |\n| [`IndexToNode`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L92) | Return type: `NodeIndex ` Arguments: `int64_t index` Returns the node corresponding to an index. A node may appear more than once if it is used as the start or the end node of multiple vehicles. |\n| [`IndicesToNodes`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L98) | Return type: `std::vector\u003cNodeIndex\u003e ` Arguments: ` const std::vector\u003cint64_t\u003e& indices` Same as IndexToNode but for a given vector of indices. |\n| [`NodesToIndices`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L88) | Return type: `std::vector\u003cint64_t\u003e ` Arguments: ` const std::vector\u003cNodeIndex\u003e& nodes` Same as NodeToIndex but for a given vector of nodes. |\n| [`NodeToIndex`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L82) | Return type: `int64_t ` Arguments: `NodeIndex node` Returns the index of a node. A node can correspond to multiple indices if it's a start or end node. As of 03/2020, kUnassigned will be returned for all end nodes. If a node appears more than once as a start node, the index of the first node in the list of start nodes is returned. |\n| [`num_indices`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L72) | Return type: `int ` Returns the number of indices mapped to nodes. |\n| [`num_nodes`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L68) | Return type: `int ` Returns the number of nodes in the manager. |\n| [`num_unique_depots`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L103) | Return type: `int ` TODO(user) Add unit tests for NodesToIndices and IndicesToNodes. TODO(user): Remove when removal of NodeIndex from RoutingModel is complete. |\n| [`num_vehicles`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L70) | Return type: `int ` Returns the number of vehicles in the manager. |\n| [`RoutingIndexManager`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L58) | \u003cbr /\u003e Arguments: `int num_nodes, int num_vehicles, NodeIndex 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. |\n| [`RoutingIndexManager`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L59) | \u003cbr /\u003e Arguments: `int num_nodes, int num_vehicles, const std::vector\u003cNodeIndex\u003e& starts, const std::vector\u003cNodeIndex\u003e& ends` \u003cbr /\u003e |\n| [`RoutingIndexManager`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L62) | \u003cbr /\u003e Arguments: ` int num_nodes, int num_vehicles, const std::vector\u003cstd::pair\u003cNodeIndex, NodeIndex\u003e \u003e& starts_ends` \u003cbr /\u003e |\n| [`~RoutingIndexManager`](https://github.com/google/or-tools/blob/v9.4/ortools/constraint_solver/routing_index_manager.h#L65) | \u003cbr /\u003e |"]]