C++ Reference

C++ Reference: Routing

routing_index_manager.h
Go to the documentation of this file.
1 // Copyright 2010-2018 Google LLC
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13 
14 #ifndef OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_INDEX_MANAGER_H_
15 #define OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_INDEX_MANAGER_H_
16 
17 #include <tuple>
18 #include <vector>
19 
20 #include "ortools/base/int_type_indexed_vector.h"
21 #include "ortools/base/logging.h"
23 
24 namespace operations_research {
25 
43  public:
44  typedef RoutingNodeIndex NodeIndex;
45  static const int64 kUnassigned;
46 
53  const std::vector<NodeIndex>& starts,
54  const std::vector<NodeIndex>& ends);
56  int num_nodes, int num_vehicles,
57  const std::vector<std::pair<NodeIndex, NodeIndex> >& starts_ends);
59 
60  int num_nodes() const { return num_nodes_; }
61  int num_vehicles() const { return num_vehicles_; }
62  int num_indices() const { return index_to_node_.size(); }
63  int64 GetStartIndex(int vehicle) const { return vehicle_to_start_[vehicle]; }
64  int64 GetEndIndex(int vehicle) const { return vehicle_to_end_[vehicle]; }
65  int64 NodeToIndex(NodeIndex node) const {
66  DCHECK_GE(node.value(), 0);
67  DCHECK_LT(node.value(), node_to_index_.size());
68  return node_to_index_[node];
69  }
70  std::vector<int64> NodesToIndices(const std::vector<NodeIndex>& nodes) const;
71  NodeIndex IndexToNode(int64 index) const {
72  DCHECK_GE(index, 0);
73  DCHECK_LT(index, index_to_node_.size());
74  return index_to_node_[index];
75  }
76  // TODO(user): Remove when removal of NodeIndex from RoutingModel is
77  // complete.
78  int num_unique_depots() const { return num_unique_depots_; }
79  std::vector<NodeIndex> GetIndexToNodeMap() const { return index_to_node_; }
80  gtl::ITIVector<NodeIndex, int64> GetNodeToIndexMap() const {
81  return node_to_index_;
82  }
83 
84  private:
85  void Initialize(
86  int num_nodes, int num_vehicles,
87  const std::vector<std::pair<NodeIndex, NodeIndex> >& starts_ends);
88 
89  std::vector<NodeIndex> index_to_node_;
90  gtl::ITIVector<NodeIndex, int64> node_to_index_;
91  std::vector<int64> vehicle_to_start_;
92  std::vector<int64> vehicle_to_end_;
93  int num_nodes_;
94  int num_vehicles_;
95  int num_unique_depots_;
96 };
97 
98 } // namespace operations_research
99 
100 #endif // OR_TOOLS_CONSTRAINT_SOLVER_ROUTING_INDEX_MANAGER_H_
RoutingNodeIndex NodeIndex
Manager for any NodeIndex <-> variable index conversion.
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
int num_indices() const
RoutingIndexManager(int num_nodes, int num_vehicles, NodeIndex depot)
Creates a NodeIndex to variable index mapping for a problem containing 'num_nodes',...
int64 NodeToIndex(NodeIndex node) const
~RoutingIndexManager()
int64 GetEndIndex(int vehicle) const
gtl::ITIVector< NodeIndex, int64 > GetNodeToIndexMap() const
static const int64 kUnassigned
RoutingIndexManager(int num_nodes, int num_vehicles, const std::vector< NodeIndex > &starts, const std::vector< NodeIndex > &ends)
std::vector< int64 > NodesToIndices(const std::vector< NodeIndex > &nodes) const
int num_unique_depots() const
std::vector< NodeIndex > GetIndexToNodeMap() const
int num_vehicles() const
RoutingIndexManager(int num_nodes, int num_vehicles, const std::vector< std::pair< NodeIndex, NodeIndex > > &starts_ends)
int64 GetStartIndex(int vehicle) const
int num_nodes() const
NodeIndex IndexToNode(int64 index) const