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

Manager for any NodeIndex <-> variable index conversion. More...

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);
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>

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. 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< NodeIndexIndicesToNodes (absl::Span< const int64_t > indices) const
int num_unique_depots () const
std::vector< NodeIndexGetIndexToNodeMap () const

Static Public Attributes

static const int64_t kUnassigned = -1

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.

Parameters
num_nodesNumber of nodes in the problem.
num_vehiclesNumber of vehicles in the problem.
depotstart 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_nodesNumber of nodes in the problem.
num_vehiclesNumber of vehicles in the problem.
startsArray containing the start NodeIndex for each vehicle.
endsArray 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_nodesNumber of nodes in the problem.
num_vehiclesNumber of vehicles in the problem.
starts_endsArray 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.

Member Function Documentation

◆ GetEndIndex()

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

Definition at line 102 of file routing_index_manager.h.

◆ GetIndexToNodeMap()

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

Definition at line 129 of file routing_index_manager.h.

◆ GetStartIndex()

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

Definition at line 99 of file routing_index_manager.h.

◆ IndexToNode()

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

Definition at line 117 of file routing_index_manager.h.

◆ IndicesToNodes()

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

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

Definition at line 126 of file routing_index_manager.cc.

◆ NodeToIndex()

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

Definition at line 107 of file routing_index_manager.h.

◆ num_indices()

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

Definition at line 97 of file routing_index_manager.h.

◆ num_nodes()

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

Definition at line 93 of file routing_index_manager.h.

◆ num_unique_depots()

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

Definition at line 128 of file routing_index_manager.h.

◆ num_vehicles()

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

Definition at line 95 of file routing_index_manager.h.

Member Data Documentation

◆ kUnassigned

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

Definition at line 60 of file routing_index_manager.h.


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