C++ Reference

C++ Reference: Routing

Detailed Description

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); // 10 nodes, 4 vehicles.
RoutingModel model(manager);
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 48 of file routing_index_manager.h.

Public Types

typedef RoutingNodeIndex NodeIndex
 

Public Member Functions

 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. More...
 
 RoutingIndexManager (int num_nodes, int num_vehicles, const std::vector< NodeIndex > &starts, const std::vector< NodeIndex > &ends)
 
 RoutingIndexManager (int num_nodes, int num_vehicles, const std::vector< std::pair< NodeIndex, NodeIndex > > &starts_ends)
 
 ~RoutingIndexManager ()
 
int num_nodes () const
 
int num_vehicles () const
 
int num_indices () const
 
int64 GetStartIndex (int vehicle) const
 
int64 GetEndIndex (int vehicle) const
 
int64 NodeToIndex (NodeIndex node) const
 
std::vector< int64 > NodesToIndices (const std::vector< NodeIndex > &nodes) const
 
NodeIndex IndexToNode (int64 index) const
 
std::vector< NodeIndexIndicesToNodes (const std::vector< int64 > &indices) const
 
int num_unique_depots () const
 complete. More...
 
std::vector< NodeIndexGetIndexToNodeMap () const
 
absl::StrongVector< NodeIndex, int64 > GetNodeToIndexMap () const
 

Static Public Attributes

static const int64 kUnassigned
 

Member Typedef Documentation

◆ NodeIndex

typedef RoutingNodeIndex NodeIndex

Definition at line 50 of file routing_index_manager.h.

Constructor & Destructor Documentation

◆ RoutingIndexManager() [1/3]

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() [2/3]

RoutingIndexManager ( int  num_nodes,
int  num_vehicles,
const std::vector< NodeIndex > &  starts,
const std::vector< NodeIndex > &  ends 
)

◆ RoutingIndexManager() [3/3]

RoutingIndexManager ( int  num_nodes,
int  num_vehicles,
const std::vector< std::pair< NodeIndex, NodeIndex > > &  starts_ends 
)

◆ ~RoutingIndexManager()

~RoutingIndexManager ( )
inline

Definition at line 64 of file routing_index_manager.h.

Member Function Documentation

◆ GetEndIndex()

int64 GetEndIndex ( int  vehicle) const
inline

Definition at line 74 of file routing_index_manager.h.

◆ GetIndexToNodeMap()

std::vector<NodeIndex> GetIndexToNodeMap ( ) const
inline

Definition at line 100 of file routing_index_manager.h.

◆ GetNodeToIndexMap()

absl::StrongVector<NodeIndex, int64> GetNodeToIndexMap ( ) const
inline

Definition at line 101 of file routing_index_manager.h.

◆ GetStartIndex()

int64 GetStartIndex ( int  vehicle) const
inline

Definition at line 73 of file routing_index_manager.h.

◆ IndexToNode()

NodeIndex IndexToNode ( int64  index) const
inline

Definition at line 88 of file routing_index_manager.h.

◆ IndicesToNodes()

std::vector<NodeIndex> IndicesToNodes ( const std::vector< int64 > &  indices) const

◆ NodesToIndices()

std::vector<int64> NodesToIndices ( const std::vector< NodeIndex > &  nodes) const

◆ NodeToIndex()

int64 NodeToIndex ( NodeIndex  node) const
inline

Definition at line 79 of file routing_index_manager.h.

◆ num_indices()

int num_indices ( ) const
inline

Definition at line 71 of file routing_index_manager.h.

◆ num_nodes()

int num_nodes ( ) const
inline

Definition at line 67 of file routing_index_manager.h.

◆ num_unique_depots()

int num_unique_depots ( ) const
inline

complete.

Definition at line 99 of file routing_index_manager.h.

◆ num_vehicles()

int num_vehicles ( ) const
inline

Definition at line 69 of file routing_index_manager.h.

Member Data Documentation

◆ kUnassigned

const int64 kUnassigned
static

Definition at line 51 of file routing_index_manager.h.


The documentation for this class was generated from the following file: