OR-Tools  9.6
graphs.h
Go to the documentation of this file.
1 // Copyright 2010-2022 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 
20 #include <vector>
21 
23 
24 namespace operations_research {
25 
26 // Since StarGraph does not have exactly the same interface as the other
27 // graphs, we define a correspondence there.
28 template <typename Graph>
29 struct Graphs {
30  typedef typename Graph::ArcIndex ArcIndex;
31  typedef typename Graph::NodeIndex NodeIndex;
32  static ArcIndex OppositeArc(const Graph& graph, ArcIndex arc) {
33  return graph.OppositeArc(arc);
34  }
35  static bool IsArcValid(const Graph& graph, ArcIndex arc) {
36  return graph.IsArcValid(arc);
37  }
38  static NodeIndex NodeReservation(const Graph& graph) {
39  return graph.node_capacity();
40  }
41  static ArcIndex ArcReservation(const Graph& graph) {
42  return graph.arc_capacity();
43  }
44  static void Build(Graph* graph) { graph->Build(); }
45  static void Build(Graph* graph, std::vector<ArcIndex>* permutation) {
46  graph->Build(permutation);
47  }
48 };
49 
50 template <>
53 #if defined(_MSC_VER)
54  typedef Graph::ArcIndex ArcIndex;
56 #else
57  typedef typename Graph::ArcIndex ArcIndex;
58  typedef typename Graph::NodeIndex NodeIndex;
59 #endif
60  static ArcIndex OppositeArc(const Graph& graph, ArcIndex arc) {
61  return graph.Opposite(arc);
62  }
63  static bool IsArcValid(const Graph& graph, ArcIndex arc) {
64  return graph.CheckArcValidity(arc);
65  }
66  static NodeIndex NodeReservation(const Graph& graph) {
67  return graph.max_num_nodes();
68  }
69  static ArcIndex ArcReservation(const Graph& graph) {
70  return graph.max_num_arcs();
71  }
72  static void Build(Graph* graph) {}
73  static void Build(Graph* graph, std::vector<ArcIndex>* permutation) {
74  permutation->clear();
75  }
76 };
77 
78 } // namespace operations_research
79 
80 #endif // OR_TOOLS_GRAPH_GRAPHS_H_
bool CheckArcValidity(const ArcIndexType arc) const
Definition: ebert_graph.h:1372
ArcIndexType Opposite(const ArcIndexType arc) const
Definition: ebert_graph.h:1410
NodeIndexType max_num_nodes() const
Definition: ebert_graph.h:256
ArcIndexType max_num_arcs() const
Definition: ebert_graph.h:260
int arc
Collection of objects used to extend the Constraint Solver library.
ListGraph Graph
Definition: graph.h:2398
static ArcIndex ArcReservation(const Graph &graph)
Definition: graphs.h:69
static NodeIndex NodeReservation(const Graph &graph)
Definition: graphs.h:66
static void Build(Graph *graph, std::vector< ArcIndex > *permutation)
Definition: graphs.h:73
static bool IsArcValid(const Graph &graph, ArcIndex arc)
Definition: graphs.h:63
static ArcIndex OppositeArc(const Graph &graph, ArcIndex arc)
Definition: graphs.h:60
static void Build(Graph *graph)
Definition: graphs.h:44
static ArcIndex ArcReservation(const Graph &graph)
Definition: graphs.h:41
Graph::ArcIndex ArcIndex
Definition: graphs.h:30
Graph::NodeIndex NodeIndex
Definition: graphs.h:31
static NodeIndex NodeReservation(const Graph &graph)
Definition: graphs.h:38
static void Build(Graph *graph, std::vector< ArcIndex > *permutation)
Definition: graphs.h:45
static bool IsArcValid(const Graph &graph, ArcIndex arc)
Definition: graphs.h:35
static ArcIndex OppositeArc(const Graph &graph, ArcIndex arc)
Definition: graphs.h:32