Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Hypergraph.h
Go to the documentation of this file.
1
34#pragma once
35
37#include <ogdf/basic/List.h>
38
40#define forall_adj_elements(adj, ge) for ((adj) = (v)->firstAdj(); (adj); (adj) = (adj)->succ())
41
43#define forall_hypernodes(v, H) for ((v) = (H).firstHypernode(); (v); (v) = (v)->succ())
44
46#define forall_rev_hypernodes(v, H) for ((v) = (H).lastHypernode(); (v); (v) = (v)->pred())
47
49#define forall_hyperedges(e, H) for ((e) = (H).firstHyperedge(); (e); (e) = (e)->succ())
50
52#define forall_rev_hyperedges(e, H) for ((e) = (H).lastHyperedge(); (e); (e) = (e)->pred())
53
54namespace ogdf {
55
56class OGDF_EXPORT Hypergraph;
57class OGDF_EXPORT HypernodeElement;
58class OGDF_EXPORT HyperedgeElement;
59class OGDF_EXPORT AdjHypergraphElement;
60
63
66
69
71
76 friend class Hypergraph;
77 friend class GraphListBase;
79
80private:
82 GraphElement* m_element;
83
85
92
95
97 explicit AdjHypergraphElement(GraphElement* pElement)
98 : m_element(pElement), m_twin(nullptr), m_index(0) { }
99
102 : m_element(pElement), m_twin(nullptr), m_index(pIndex) { }
103
104public:
106 int index() const { return m_index; }
107
109
114 GraphElement* element() const { return m_element; }
115
117 adjHypergraphEntry twin() const { return m_twin; }
118
120 adjHypergraphEntry succ() const { return static_cast<adjHypergraphEntry>(m_next); }
121
123 adjHypergraphEntry pred() const { return static_cast<adjHypergraphEntry>(m_prev); }
124
127
130
132};
133
136 friend class Hypergraph;
137 friend class GraphListBase;
139
140private:
143
146
149
152
154
158 : m_index(pIndex), m_cardinality(0), m_hypergraph(nullptr) { }
159
160public:
162 int index() const { return m_index; }
163
165 int cardinality() const { return m_cardinality; }
166
168 Hypergraph* hypergraph() const { return m_hypergraph; }
169
171 adjHypergraphEntry firstAdj() const { return m_adjHypernodes.head(); }
172
174 adjHypergraphEntry lastAdj() const { return m_adjHypernodes.tail(); }
175
178
180 template<class NODELIST>
181 void allHypernodes(NODELIST& hypernodes) const {
182 hypernodes.clear();
183 for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ()) {
184 hypernodes.pushBack(reinterpret_cast<hypernode>(adj->element()));
185 }
186 }
187
189 bool incident(hypernode v) const {
190 for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ()) {
191 if (reinterpret_cast<hypernode>(adj->element()) == v) {
192 return true;
193 }
194 }
195 return false;
196 }
197
199 hyperedge succ() const { return static_cast<hyperedge>(m_next); }
200
202 hyperedge pred() const { return static_cast<hyperedge>(m_prev); }
203
205 bool operator==(const hyperedge e) const {
206 return e->index() == m_index && e->hypergraph() == m_hypergraph;
207 }
208
209 friend std::ostream& operator<<(std::ostream& os, ogdf::hyperedge e);
210
212};
213
216 friend class Hypergraph;
217 friend class GraphListBase;
219
220public:
222 enum class Type {
223 normal = 0x0000001,
224 dummy = 0x0000002,
225 OR = 0x0000003,
226 BUF = 0x0000004,
227 AND = 0x0000005,
228 NOR = 0x0000006,
229 NOT = 0x0000007,
230 XOR = 0x0000008,
231 DFF = 0x0000009,
232 NAND = 0x0000010,
233 INPUT = 0x0000011,
234 OUTPUT = 0x0000012
235 };
236
237private:
240
243
246
249
252
255 : m_index(pIndex), m_degree(0), m_type(Type::normal), m_hypergraph(nullptr) { }
256
259 : m_index(pIndex), m_degree(0), m_type(pType), m_hypergraph(nullptr) { }
260
261public:
263 int index() const { return m_index; }
264
266 int degree() const { return m_degree; }
267
269 Hypergraph* hypergraph() const { return m_hypergraph; }
270
272 Type type() const { return m_type; }
273
275 void type(Type pType) { m_type = pType; }
276
278 adjHypergraphEntry firstAdj() const { return m_adjHyperedges.head(); }
279
281 adjHypergraphEntry lastAdj() const { return m_adjHyperedges.tail(); }
282
284 template<class NODELIST>
285 void allHyperedges(NODELIST& hyperedges) const {
286 hyperedges.clear();
287 for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ()) {
288 hyperedges.pushBack(reinterpret_cast<hyperedge>(adj->element()));
289 }
290 }
291
293 bool adjacent(hypernode v) const {
294 for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ()) {
295 if (reinterpret_cast<hyperedge>(adj->element())->incident(v)) {
296 return true;
297 }
298 }
299 return false;
300 }
301
303 hypernode succ() const { return static_cast<hypernode>(m_next); }
304
306 hypernode pred() const { return static_cast<hypernode>(m_prev); }
307
309 bool operator==(const hypernode v) const {
310 return v->index() == m_index && v->hypergraph() == m_hypergraph;
311 }
312
314};
315
317template<class T>
318class HypernodeArray;
319template<class T>
320class HyperedgeArray;
322
326
329
332
335
338
341
344
347
352
353public:
356
359
362
364 bool empty() const { return m_nHypernodes == 0; }
365
367 internal::GraphList<HypernodeElement> hypernodes() const { return m_hypernodes; }
368
370 internal::GraphList<HyperedgeElement> hyperedges() const { return m_hyperedges; }
371
373 int numberOfHypernodes() const { return m_nHypernodes; }
374
376 int numberOfHyperedges() const { return m_nHyperedges; }
377
379 int maxHypernodeIndex() const { return m_hypernodeIdCount - 1; }
380
382 int maxHyperedgeIndex() const { return m_hyperedgeIdCount - 1; }
383
385 hypernode firstHypernode() const { return m_hypernodes.head(); }
386
388 hypernode lastHypernode() const { return m_hypernodes.tail(); }
389
391 hyperedge firstHyperedge() const { return m_hyperedges.head(); }
392
394 hyperedge lastHyperEdge() const { return m_hyperedges.tail(); }
395
397 int hypernodeArrayTableSize() const { return m_hypernodeArrayTableSize; }
398
400 int hyperedgeArrayTableSize() const { return m_hyperedgeArrayTableSize; }
401
404
407
410
413
415
420
422
428
430
434
436
440
442 void clear();
443
446
449
451 template<class LIST>
453 hypernodeList.clear();
454 for (hypernode v = m_hypernodes.head(); v; v = v->succ()) {
455 hypernodeList.pushBack(v);
456 }
457 }
458
460 template<class LIST>
462 hyperedgeList.clear();
463 for (hyperedge e = m_hyperedges.head(); e; e = e->succ()) {
464 hyperedgeList.pushBack(e);
465 }
466 }
467
469 void readBenchHypergraph(std::istream& is);
470
472 void readBenchHypergraph(const char* filename);
473
475 void readPlaHypergraph(std::istream& is);
476
478 void loadPlaHypergraph(const char* fileName);
479
481 bool consistency() const;
482
486
489
492
495
498
501
503
504 friend std::ostream& operator<<(std::ostream& os, ogdf::Hypergraph& H);
505
506 friend std::istream& operator>>(std::istream& is, ogdf::Hypergraph& H);
507
509
510private:
512
514
515 int nextEntry(char* buffer, int from, string stop);
516
518};
519
520}
Decralation of GraphElement and GraphList classes.
Declaration of doubly linked lists and iterators.
Class for adjacency list elements.
Definition Hypergraph.h:75
GraphElement * m_element
The associated hyperedge or hypernode.
Definition Hypergraph.h:82
adjHypergraphEntry cyclicSucc() const
Returns the cyclic successor in the adjacency list.
adjHypergraphEntry succ() const
Returns the successor in the adjacency list.
Definition Hypergraph.h:120
int index() const
Returns the index of this adjacency element.
Definition Hypergraph.h:106
adjHypergraphEntry twin() const
Returns the pointer to a twin adjacency list.
Definition Hypergraph.h:117
adjHypergraphEntry m_twin
The corresponding adjacency entry.
Definition Hypergraph.h:91
int m_index
The (unique) index of the adjacency entry.
Definition Hypergraph.h:94
adjHypergraphEntry pred() const
Returns the predecessor in the adjacency list.
Definition Hypergraph.h:123
adjHypergraphEntry cyclicPred() const
Returns the cyclic predecessor in the adjacency list.
AdjHypergraphElement(GraphElement *pElement, int pIndex)
Constructs an adjacency entry for a given hyper{node,edge} and index.
Definition Hypergraph.h:101
GraphElement * element() const
Returns the element associated with this adjacency entry.
Definition Hypergraph.h:114
AdjHypergraphElement(GraphElement *pElement)
Constructs an adjacency element for a given hyper{node,edge}.
Definition Hypergraph.h:97
Dynamic arrays indexed with nodes.
Class for the representation of hyperedges.
Definition Hypergraph.h:135
internal::GraphList< AdjHypergraphElement > m_adjHypernodes
The adjacency list of the hyperedge.
Definition Hypergraph.h:142
void allHypernodes(NODELIST &hypernodes) const
Returns a list with all incident hypernodes of the hyperedge.
Definition Hypergraph.h:181
Hypergraph * hypergraph() const
Returns the hypergraph containing the hyperedge.
Definition Hypergraph.h:168
adjHypergraphEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition Hypergraph.h:174
int cardinality() const
Returns the number of incident hypernodes.
Definition Hypergraph.h:165
hyperedge pred() const
Returns the predecessor in the list of all hyperedges.
Definition Hypergraph.h:202
int m_cardinality
The number of incidend hypernodes.
Definition Hypergraph.h:148
bool incident(hypernode v) const
Returns true iff v is incident to the hyperedge.
Definition Hypergraph.h:189
friend std::ostream & operator<<(std::ostream &os, ogdf::hyperedge e)
internal::GraphList< AdjHypergraphElement > incidentHypernodes() const
Returns the incident hypernodes of the hyperedge.
Definition Hypergraph.h:177
hyperedge succ() const
Returns the successor in the list of all hyperedges.
Definition Hypergraph.h:199
Hypergraph * m_hypergraph
The hypergraph containing the hyperedge (if any).
Definition Hypergraph.h:151
adjHypergraphEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Hypergraph.h:171
bool operator==(const hyperedge e) const
Equality operator.
Definition Hypergraph.h:205
int index() const
Returns the index of a hyperedge.
Definition Hypergraph.h:162
int m_index
The (unique) index of the hyperedge.
Definition Hypergraph.h:145
HyperedgeElement(int pIndex)
Constructs an hyperedge element between hypernodes.
Definition Hypergraph.h:157
Abstract base class for hypergraph arrays.
void unregisterHypernodeArray(ListIterator< HypergraphArrayBase * > it) const
Unregisters a hypernode array.
~Hypergraph()
Destructor.
void delHyperedge(hyperedge e)
Removes hyperedge e from the hypergraph.
void loadPlaHypergraph(const char *fileName)
Reads hypergraph in pla format from the file.
hyperedge lastHyperEdge() const
Returns the last hyperedge in the list of all hyperedges.
Definition Hypergraph.h:394
ListIterator< HypergraphArrayBase * > registerHypernodeArray(HypergraphArrayBase *pHypernodeArray) const
Registers a node array.
ListPure< HypergraphObserver * > m_observers
Definition Hypergraph.h:351
int hypernodeArrayTableSize() const
Returns the table size of hypernode arrays with the hypergraph.
Definition Hypergraph.h:397
hyperedge randomHyperedge() const
Returns a randomly chosen hyperedge.
internal::GraphList< HypernodeElement > hypernodes() const
Returns the list of all hypernodes.
Definition Hypergraph.h:367
void clear()
Removes all hypernodes and all hyperedges from the hypergraph.
hyperedge firstHyperedge() const
Returns the first hyperedge in the list of all hyperedges.
Definition Hypergraph.h:391
int maxHyperedgeIndex() const
Returns the largest used hyperedge index.
Definition Hypergraph.h:382
hypernode newHypernode(int pIndex, HypernodeElement::Type pType)
Creates a new hypernode with given pIndex and pType and returns it.
int m_hyperedgeIdCount
The Index that will be assigned to the next created hyperedge.
Definition Hypergraph.h:340
int m_hypernodeIdCount
The Index that will be assigned to the next created hypernode.
Definition Hypergraph.h:337
internal::GraphList< HyperedgeElement > m_hyperedges
The list of all hyperedges.
Definition Hypergraph.h:328
void unregisterHyperedgeArray(ListIterator< HypergraphArrayBase * > it) const
Unregisters an hyperedge array.
int m_nHypernodes
The number of hypernodes in the hypergraph.
Definition Hypergraph.h:331
ListPure< HypergraphArrayBase * > m_hyperedgeArrays
Definition Hypergraph.h:350
void allHyperedges(LIST &hyperedgeList) const
Returns a list with all hyperedges of the hypergraph.
Definition Hypergraph.h:461
int m_hyperedgeArrayTableSize
The current table size of hyperedge arrays within the hypergraph.
Definition Hypergraph.h:346
bool empty() const
Returns true iff the hypergraph is empty (ie. contains no hypernodes).
Definition Hypergraph.h:364
hypernode newHypernode(HypernodeElement::Type pType)
Creates a new hypernode with given pType and returns it.
int numberOfHyperedges() const
Returns the number of hyperedges in the hypergraph.
Definition Hypergraph.h:376
internal::GraphList< HypernodeElement > m_hypernodes
The list of all hypernodes.
Definition Hypergraph.h:325
friend std::istream & operator>>(std::istream &is, ogdf::Hypergraph &H)
int m_hypernodeArrayTableSize
The current table size of hypernode arrays within the hypergraph.
Definition Hypergraph.h:343
void readBenchHypergraph(std::istream &is)
Reads hypergraph in bench format from the input stream.
bool consistency() const
Checks the consistency of the data structure.
Hypergraph & operator=(const Hypergraph &H)
friend std::ostream & operator<<(std::ostream &os, ogdf::Hypergraph &H)
Hypergraph(const Hypergraph &H)
Constructs a hypergraph that is a copy of H.
hypernode lastHypernode() const
Returns the last hypernode in the list of all hypernodes.
Definition Hypergraph.h:388
int nextEntry(char *buffer, int from, string stop)
void allHypernodes(LIST &hypernodeList) const
Returns a list with all hypernodes of the hypergraph.
Definition Hypergraph.h:452
hypernode newHypernode()
Creates a new hypernode and returns it.
int maxHypernodeIndex() const
Returns the largest used hypernode index.
Definition Hypergraph.h:379
int numberOfHypernodes() const
Returns the number of hypernodes in the hypergraph.
Definition Hypergraph.h:373
HypernodeElement::Type gateType(string gate)
ListIterator< HypergraphArrayBase * > registerHyperedgeArray(HypergraphArrayBase *pHyperedgeArray) const
hyperedge newHyperedge(int pIndex, List< hypernode > &hypernodes)
Creates a new hyperedge between hypernodes and returns it.
void readPlaHypergraph(std::istream &is)
Reads hypergraph in pla format from the input stream.
void readBenchHypergraph(const char *filename)
Reads hypergraph in bench format from the file.
hypernode firstHypernode() const
Returns the first hypernode in the list of all hypernodes.
Definition Hypergraph.h:385
ListPure< HypergraphArrayBase * > m_hypernodeArrays
The registered hypergraph arrays & observers.
Definition Hypergraph.h:349
Hypergraph()
Constructs an empty hypergraph.
internal::GraphList< HyperedgeElement > hyperedges() const
Returns the list of all hyperedges.
Definition Hypergraph.h:370
void delHypernode(hypernode v)
Removes hypernode v and all incident hyperedges from the hypergraph.
hyperedge newHyperedge(List< hypernode > &hypernodes)
Creates a new hyperedge btween hypernodes and returns it.
hypernode randomHypernode() const
Returns a randomly chosen hypergraph.
int hyperedgeArrayTableSize() const
Returns the table size of hyperedge arrays within the hypergraph.
Definition Hypergraph.h:400
hypernode newHypernode(int pIndex)
Creates a new hypernode with given pIndex and returns it.
int m_nHyperedges
The number of hyperedges in the hypergraph.
Definition Hypergraph.h:334
ListIterator< HypergraphObserver * > registerObserver(HypergraphObserver *pObserver) const
Registers a hypergraph observer (e.g. a EdgeStandardRep).
void unregisterObserver(ListIterator< HypergraphObserver * > it) const
Unregisters a hypergraph observer.
Dynamic arrays indexed with hypernodes.
Class for the representation of hypernodes.
Definition Hypergraph.h:215
HypernodeElement(int pIndex, Type pType)
Constructor.
Definition Hypergraph.h:258
int index() const
Returns the (unique) hypernode index.
Definition Hypergraph.h:263
void type(Type pType)
Sets the type of hypernode.
Definition Hypergraph.h:275
int m_degree
The number of incident hyperedges.
Definition Hypergraph.h:245
int m_index
The (unique) index of the hypernode.
Definition Hypergraph.h:242
hypernode pred() const
Returns the predecessor in the list of all hypernodes.
Definition Hypergraph.h:306
hypernode succ() const
Returns the successor in the list of all hypernodes.
Definition Hypergraph.h:303
Type m_type
The type of the hypernode.
Definition Hypergraph.h:248
adjHypergraphEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition Hypergraph.h:281
HypernodeElement(int pIndex)
Constructor.
Definition Hypergraph.h:254
adjHypergraphEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition Hypergraph.h:278
Hypergraph * hypergraph() const
Returns the hypergraph containing the hypernode.
Definition Hypergraph.h:269
void allHyperedges(NODELIST &hyperedges) const
Returns a list with all incident hyperedges of the hypernode.
Definition Hypergraph.h:285
Type type() const
Returns the type of hypernode.
Definition Hypergraph.h:272
bool adjacent(hypernode v) const
Returns true iff v is adjacent to the hypernode.
Definition Hypergraph.h:293
internal::GraphList< AdjHypergraphElement > m_adjHyperedges
The adjacency list of the hypernode.
Definition Hypergraph.h:239
int degree() const
Returns the hypernode degree.
Definition Hypergraph.h:266
Hypergraph * m_hypergraph
The hypergraph containing the hypernode (if any).
Definition Hypergraph.h:251
Type
The type of hypernodes.
Definition Hypergraph.h:222
bool operator==(const hypernode v) const
Equality operator.
Definition Hypergraph.h:309
Doubly linked lists (maintaining the length of the list).
Definition List.h:1435
Encapsulates a pointer to a list element.
Definition List.h:103
Doubly linked lists.
Definition List.h:217
The base class for objects used by (hyper)graphs.
Definition GraphList.h:55
Lists of graph objects (like nodes, edges, etc.).
Definition GraphList.h:288
T * head() const
Returns the first element in the list.
Definition GraphList.h:304
T * tail() const
Returns the last element in the list.
Definition GraphList.h:307
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.