OR-Tools  8.1
graphs.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 // Temporary utility class needed as long as we have two slightly
15 // different graph interface: The one in ebert_graph.h and the one in graph.h
16 
17 #ifndef OR_TOOLS_GRAPH_GRAPHS_H_
18 #define OR_TOOLS_GRAPH_GRAPHS_H_
19 
21 
22 namespace operations_research {
23 
24 // Since StarGraph does not have exactly the same interface as the other
25 // graphs, we define a correspondence there.
26 template <typename Graph>
27 struct Graphs {
28  typedef typename Graph::ArcIndex ArcIndex;
29  typedef typename Graph::NodeIndex NodeIndex;
30  static ArcIndex OppositeArc(const Graph& graph, ArcIndex arc) {
31  return graph.OppositeArc(arc);
32  }
33  static bool IsArcValid(const Graph& graph, ArcIndex arc) {
34  return graph.IsArcValid(arc);
35  }
36  static NodeIndex NodeReservation(const Graph& graph) {
37  return graph.node_capacity();
38  }
39  static ArcIndex ArcReservation(const Graph& graph) {
40  return graph.arc_capacity();
41  }
42  static void Build(Graph* graph) { graph->Build(); }
43  static void Build(Graph* graph, std::vector<ArcIndex>* permutation) {
44  graph->Build(permutation);
45  }
46 };
47 
48 template <>
51 #if defined(_MSC_VER)
52  typedef Graph::ArcIndex ArcIndex;
54 #else
55  typedef typename Graph::ArcIndex ArcIndex;
56  typedef typename Graph::NodeIndex NodeIndex;
57 #endif
58  static ArcIndex OppositeArc(const Graph& graph, ArcIndex arc) {
59  return graph.Opposite(arc);
60  }
61  static bool IsArcValid(const Graph& graph, ArcIndex arc) {
62  return graph.CheckArcValidity(arc);
63  }
64  static NodeIndex NodeReservation(const Graph& graph) {
65  return graph.max_num_nodes();
66  }
67  static ArcIndex ArcReservation(const Graph& graph) {
68  return graph.max_num_arcs();
69  }
70  static void Build(Graph* graph) {}
71  static void Build(Graph* graph, std::vector<ArcIndex>* permutation) {
72  permutation->clear();
73  }
74 };
75 
76 } // namespace operations_research
77 
78 #endif // OR_TOOLS_GRAPH_GRAPHS_H_
operations_research::Graphs< operations_research::StarGraph >::ArcIndex
Graph::ArcIndex ArcIndex
Definition: graphs.h:55
operations_research::Graphs::IsArcValid
static bool IsArcValid(const Graph &graph, ArcIndex arc)
Definition: graphs.h:33
operations_research::Graphs< operations_research::StarGraph >::Build
static void Build(Graph *graph)
Definition: graphs.h:70
operations_research::EbertGraph::Opposite
ArcIndexType Opposite(const ArcIndexType arc) const
Definition: ebert_graph.h:1409
operations_research::NodeIndex
int32 NodeIndex
Definition: ebert_graph.h:192
operations_research::Graphs< operations_research::StarGraph >::ArcReservation
static ArcIndex ArcReservation(const Graph &graph)
Definition: graphs.h:67
operations_research::Graphs::ArcIndex
Graph::ArcIndex ArcIndex
Definition: graphs.h:28
util::Graph
ListGraph Graph
Definition: graph.h:2354
operations_research::Graphs< operations_research::StarGraph >::Graph
operations_research::StarGraph Graph
Definition: graphs.h:50
operations_research::Graphs::OppositeArc
static ArcIndex OppositeArc(const Graph &graph, ArcIndex arc)
Definition: graphs.h:30
operations_research::Graphs
Definition: graphs.h:27
operations_research
The vehicle routing library lets one model and solve generic vehicle routing problems ranging from th...
Definition: dense_doubly_linked_list.h:21
operations_research::Graphs< operations_research::StarGraph >::OppositeArc
static ArcIndex OppositeArc(const Graph &graph, ArcIndex arc)
Definition: graphs.h:58
operations_research::EbertGraph
Definition: ebert_graph.h:1188
operations_research::EbertGraph::NodeIndex
NodeIndexType NodeIndex
Definition: ebert_graph.h:1223
operations_research::Graphs::ArcReservation
static ArcIndex ArcReservation(const Graph &graph)
Definition: graphs.h:39
operations_research::EbertGraph::ArcIndex
ArcIndexType ArcIndex
Definition: ebert_graph.h:1224
operations_research::Graphs< operations_research::StarGraph >::IsArcValid
static bool IsArcValid(const Graph &graph, ArcIndex arc)
Definition: graphs.h:61
operations_research::Graphs< operations_research::StarGraph >::Build
static void Build(Graph *graph, std::vector< ArcIndex > *permutation)
Definition: graphs.h:71
operations_research::Graphs::NodeReservation
static NodeIndex NodeReservation(const Graph &graph)
Definition: graphs.h:36
operations_research::ArcIndex
int32 ArcIndex
Definition: ebert_graph.h:201
operations_research::Graphs::Build
static void Build(Graph *graph, std::vector< ArcIndex > *permutation)
Definition: graphs.h:43
operations_research::EbertGraph::CheckArcValidity
bool CheckArcValidity(const ArcIndexType arc) const
Definition: ebert_graph.h:1371
operations_research::Graphs< operations_research::StarGraph >::NodeIndex
Graph::NodeIndex NodeIndex
Definition: graphs.h:56
ebert_graph.h
operations_research::Graphs::Build
static void Build(Graph *graph)
Definition: graphs.h:42
operations_research::Graphs< operations_research::StarGraph >::NodeReservation
static NodeIndex NodeReservation(const Graph &graph)
Definition: graphs.h:64
operations_research::Graphs::NodeIndex
Graph::NodeIndex NodeIndex
Definition: graphs.h:29