Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
OGDFGraphWrapper.h
Go to the documentation of this file.
1
31#pragma once
32
33#ifdef OGDF_INCLUDE_CGAL
34
35# include <ogdf/basic/Graph.h>
41
42# include <algorithm>
43# include <iostream>
44# include <map>
45# include <vector>
46
47namespace ogdf {
48namespace internal {
49namespace gcm {
50namespace graph {
51
54class OGDFGraphWrapper {
55public:
56 using Node = node;
57 using Edge = edge;
58 using AdjEntry = adjEntry;
59
60protected:
61 std::shared_ptr<Graph> self_generated_graph;
62 const Graph& graph;
63
64 static void id_sg_handle_node(Node, Node) { }
65
66 static void id_sg_handle_edge(Edge, Edge) { }
67
68
69public:
71 /*nothing to do*/
72 }
73
75 /*nothing to do*/
76 }
77
79
80 inline const Graph& get_graph() { return graph; }
81
82 inline const Graph& get_ogdf_graph() { return graph; }
83
84 inline size_t number_of_nodes() const { return graph.numberOfNodes(); }
85
86 inline size_t number_of_edges() const { return graph.numberOfEdges(); }
87
88 inline size_t max_node_index() const { return graph.maxNodeIndex(); }
89
90 inline size_t max_edge_index() const { return graph.maxEdgeIndex(); }
91
92 inline Node get_node(unsigned int i) const {
93 for (auto w : nodes()) {
94 if (w->index() == (int)i) {
95 return w;
96 }
97 }
98 return nullptr;
99 }
100
107 inline Edge search_edge(Node v, Node w) const {
108 if (v->degree() < w->degree()) {
109 for (auto e : edges(v)) {
110 if (e->opposite(v) == w) {
111 return e;
112 }
113 }
114 return nullptr;
115 } else {
116 for (auto e : edges(w)) {
117 if (e->opposite(w) == v) {
118 return e;
119 }
120 }
121 return nullptr;
122 }
123 }
124
130 inline bool are_adjacent(Node v, Node w) const { return search_edge(v, w) != nullptr; }
131
135 inline datastructure::IteratorRange<NodeIterator> nodes() const {
136 if (number_of_nodes() > 0) {
137 return datastructure::IteratorRange<NodeIterator>(NodeIterator(graph.firstNode()),
138 NodeIterator(graph.lastNode()->succ()));
139 } else {
140 return datastructure::IteratorRange<NodeIterator>(Node(0), Node(0));
141 }
142 }
143
147 inline datastructure::IteratorRange<EdgeIterator> edges() const {
148 if (number_of_edges() > 0) {
149 return datastructure::IteratorRange<EdgeIterator>(EdgeIterator(graph.firstEdge()),
150 EdgeIterator(graph.lastEdge()->succ()));
151 } else {
152 return datastructure::IteratorRange<EdgeIterator>(Edge(0), Edge(0));
153 }
154 }
155
160 inline datastructure::IteratorRange<IncidentEdgeIterator> edges(const Node w) const {
161 if (w->degree() == 0) {
162 return datastructure::IteratorRange<IncidentEdgeIterator>(
163 IncidentEdgeIterator(adjEntry(0)), IncidentEdgeIterator(adjEntry(0)));
164 } else {
165 return datastructure::IteratorRange<IncidentEdgeIterator>(
166 IncidentEdgeIterator(w->firstAdj()), IncidentEdgeIterator(w->lastAdj()->succ()));
167 }
168 }
169
175 inline datastructure::IteratorRange<AdjEntryIterator> adj(const Node w) const {
176 if (w->degree() == 0) {
177 return datastructure::IteratorRange<AdjEntryIterator>(AdjEntryIterator(adjEntry(0)),
179 } else {
180 return datastructure::IteratorRange<AdjEntryIterator>(AdjEntryIterator(w->firstAdj()),
181 AdjEntryIterator(w->lastAdj()->succ()));
182 }
183 }
184
189 inline datastructure::IteratorRange<AdjacentNodeIterator> neighbors(const Node w) const {
190 if (w->degree() == 0) {
191 return datastructure::IteratorRange<AdjacentNodeIterator>(
192 AdjacentNodeIterator(adjEntry(0)), AdjacentNodeIterator(adjEntry(0)));
193
194 } else {
195 return datastructure::IteratorRange<AdjacentNodeIterator>(
196 AdjacentNodeIterator(w->firstAdj()), AdjacentNodeIterator(w->lastAdj()->succ()));
197 }
198 }
199};
200
201}
202}
203}
204}
205
206
207#endif
Includes declaration of graph class.
Declares class GraphIO which provides access to all graph read and write functionality.
AdjElement * adjEntry
The type of adjacency entries.
Definition Graph_d.h:72
NodeElement * node
The type of nodes.
Definition Graph_d.h:64
EdgeElement * edge
The type of edges.
Definition Graph_d.h:68
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
EntryIterator< edge > EdgeIterator
EntryIterator< adjEntry > AdjEntryIterator
EntryIterator< node > NodeIterator
The namespace for all OGDF objects.