Manager for any NodeIndex <-> variable index conversion.
More...
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 = ...;
RoutingIndexManager manager(10, 4, starts_ends);
RoutingIndexManager(int num_nodes, int num_vehicles, NodeIndex depot)
Creates a NodeIndex to variable index mapping for a problem containing 'num_nodes',...
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.
Definition at line 57 of file routing_index_manager.h.
#include <routing_index_manager.h>
|
| | RoutingIndexManager (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.
|
| | RoutingIndexManager (int num_nodes, int num_vehicles, const std::vector< NodeIndex > &starts, const std::vector< NodeIndex > &ends) |
| | Creates a NodeIndex to variable index mapping.
|
| | RoutingIndexManager (int num_nodes, int num_vehicles, const std::vector< std::pair< NodeIndex, NodeIndex > > &starts_ends) |
| | Creates a NodeIndex to variable index mapping.
|
| int | num_nodes () const |
| int | num_vehicles () const |
| int | num_indices () const |
| int64_t | GetStartIndex (int vehicle) const |
| int64_t | GetEndIndex (int vehicle) const |
| int64_t | NodeToIndex (NodeIndex node) const |
| std::vector< int64_t > | NodesToIndices (const std::vector< NodeIndex > &nodes) const |
| NodeIndex | IndexToNode (int64_t index) const |
| std::vector< NodeIndex > | IndicesToNodes (absl::Span< const int64_t > indices) const |
| int | num_unique_depots () const |
| std::vector< NodeIndex > | GetIndexToNodeMap () const |
◆ NodeIndex
| operations_research::RoutingIndexManager::RoutingIndexManager |
( |
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.
- Parameters
-
| num_nodes | Number of nodes in the problem. |
| num_vehicles | Number of vehicles in the problem. |
| depot | start and end NodeIndex for all vehicles. |
Definition at line 29 of file routing_index_manager.cc.
◆ RoutingIndexManager() [2/3]
| operations_research::RoutingIndexManager::RoutingIndexManager |
( |
int | num_nodes, |
|
|
int | num_vehicles, |
|
|
const std::vector< NodeIndex > & | starts, |
|
|
const std::vector< NodeIndex > & | ends ) |
Creates a NodeIndex to variable index mapping.
- Parameters
-
| num_nodes | Number of nodes in the problem. |
| num_vehicles | Number of vehicles in the problem. |
| starts | Array containing the start NodeIndex for each vehicle. |
| ends | Array containing the end NodeIndex for each vehicle. |
- Note
- starts and ends arrays must have exactly num_vehicles elements.
Definition at line 35 of file routing_index_manager.cc.
◆ RoutingIndexManager() [3/3]
| operations_research::RoutingIndexManager::RoutingIndexManager |
( |
int | num_nodes, |
|
|
int | num_vehicles, |
|
|
const std::vector< std::pair< NodeIndex, NodeIndex > > & | starts_ends ) |
Creates a NodeIndex to variable index mapping.
- Parameters
-
| num_nodes | Number of nodes in the problem. |
| num_vehicles | Number of vehicles in the problem. |
| starts_ends | Array containing a pair [start,end] NodeIndex for each vehicle. |
- Note
- starts_ends arrays must have exactly num_vehicles elements.
Definition at line 47 of file routing_index_manager.cc.
◆ GetEndIndex()
| int64_t operations_research::RoutingIndexManager::GetEndIndex |
( |
int | vehicle | ) |
const |
|
inline |
◆ GetIndexToNodeMap()
| std::vector< NodeIndex > operations_research::RoutingIndexManager::GetIndexToNodeMap |
( |
| ) |
const |
|
inline |
◆ GetStartIndex()
| int64_t operations_research::RoutingIndexManager::GetStartIndex |
( |
int | vehicle | ) |
const |
|
inline |
◆ IndexToNode()
| NodeIndex operations_research::RoutingIndexManager::IndexToNode |
( |
int64_t | index | ) |
const |
|
inline |
◆ IndicesToNodes()
◆ NodesToIndices()
| std::vector< int64_t > operations_research::RoutingIndexManager::NodesToIndices |
( |
const std::vector< NodeIndex > & | nodes | ) |
const |
◆ NodeToIndex()
| int64_t operations_research::RoutingIndexManager::NodeToIndex |
( |
NodeIndex | node | ) |
const |
|
inline |
◆ num_indices()
| int operations_research::RoutingIndexManager::num_indices |
( |
| ) |
const |
|
inline |
◆ num_nodes()
| int operations_research::RoutingIndexManager::num_nodes |
( |
| ) |
const |
|
inline |
◆ num_unique_depots()
| int operations_research::RoutingIndexManager::num_unique_depots |
( |
| ) |
const |
|
inline |
◆ num_vehicles()
| int operations_research::RoutingIndexManager::num_vehicles |
( |
| ) |
const |
|
inline |
◆ kUnassigned
|
const int64_t operations_research::RoutingIndexManager::kUnassigned = -1
|
static |
The documentation for this class was generated from the following files: