Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
operations_research::RoutingIndexManager Class Reference

#include <routing_index_manager.h>

Public Types

typedef RoutingNodeIndex NodeIndex
 

Public Member Functions

 RoutingIndexManager (int num_nodes, int num_vehicles, NodeIndex depot)
 
 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)
 
int num_nodes () const
 Returns the number of nodes in the manager.
 
int num_vehicles () const
 Returns the number of vehicles in the manager.
 
int num_indices () const
 Returns the number of indices mapped to nodes.
 
int64_t GetStartIndex (int vehicle) const
 Returns start and end indices of the given vehicle.
 
int64_t GetEndIndex (int vehicle) const
 
int64_t NodeToIndex (NodeIndex node) const
 
std::vector< int64_t > NodesToIndices (const std::vector< NodeIndex > &nodes) const
 Same as NodeToIndex but for a given vector of nodes.
 
NodeIndex IndexToNode (int64_t index) const
 
std::vector< NodeIndexIndicesToNodes (const std::vector< int64_t > &indices) const
 Same as IndexToNode but for a given vector of indices.
 
int num_unique_depots () const
 
std::vector< NodeIndexGetIndexToNodeMap () const
 

Static Public Attributes

static const int64_t kUnassigned = -1
 

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);
RoutingModel model(manager);
GRBmodel * model

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 54 of file routing_index_manager.h.

Member Typedef Documentation

◆ NodeIndex

Constructor & Destructor Documentation

◆ RoutingIndexManager() [1/3]

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.

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 )

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 )

Definition at line 47 of file routing_index_manager.cc.

Member Function Documentation

◆ GetEndIndex()

int64_t operations_research::RoutingIndexManager::GetEndIndex ( int vehicle) const
inline

Definition at line 81 of file routing_index_manager.h.

◆ GetIndexToNodeMap()

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

Definition at line 108 of file routing_index_manager.h.

◆ GetStartIndex()

int64_t operations_research::RoutingIndexManager::GetStartIndex ( int vehicle) const
inline

Returns start and end indices of the given vehicle.

Definition at line 78 of file routing_index_manager.h.

◆ IndexToNode()

NodeIndex operations_research::RoutingIndexManager::IndexToNode ( int64_t index) const
inline

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.

Definition at line 96 of file routing_index_manager.h.

◆ IndicesToNodes()

std::vector< RoutingIndexManager::NodeIndex > operations_research::RoutingIndexManager::IndicesToNodes ( const std::vector< int64_t > & indices) const

Same as IndexToNode but for a given vector of indices.

Definition at line 138 of file routing_index_manager.cc.

◆ NodesToIndices()

std::vector< int64_t > operations_research::RoutingIndexManager::NodesToIndices ( const std::vector< NodeIndex > & nodes) const

Same as NodeToIndex but for a given vector of nodes.

Definition at line 126 of file routing_index_manager.cc.

◆ NodeToIndex()

int64_t operations_research::RoutingIndexManager::NodeToIndex ( NodeIndex node) const
inline

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.

Definition at line 86 of file routing_index_manager.h.

◆ num_indices()

int operations_research::RoutingIndexManager::num_indices ( ) const
inline

Returns the number of indices mapped to nodes.

Definition at line 76 of file routing_index_manager.h.

◆ num_nodes()

int operations_research::RoutingIndexManager::num_nodes ( ) const
inline

Returns the number of nodes in the manager.

Definition at line 72 of file routing_index_manager.h.

◆ num_unique_depots()

int operations_research::RoutingIndexManager::num_unique_depots ( ) const
inline
Todo

(user) Add unit tests for NodesToIndices and IndicesToNodes.

(user): Remove when removal of NodeIndex from RoutingModel is complete.

Definition at line 107 of file routing_index_manager.h.

◆ num_vehicles()

int operations_research::RoutingIndexManager::num_vehicles ( ) const
inline

Returns the number of vehicles in the manager.

Definition at line 74 of file routing_index_manager.h.

Member Data Documentation

◆ kUnassigned

const int64_t operations_research::RoutingIndexManager::kUnassigned = -1
static

Definition at line 57 of file routing_index_manager.h.


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