Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

Hypergraph.h
Go to the documentation of this file.
1 
34 #pragma once
35 
36 #include <ogdf/basic/List.h>
37 #include <ogdf/basic/GraphList.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 
54 namespace ogdf {
55 
56 class OGDF_EXPORT Hypergraph;
57 class OGDF_EXPORT HypernodeElement;
58 class OGDF_EXPORT HyperedgeElement;
59 class OGDF_EXPORT AdjHypergraphElement;
60 
62 using hypernode = HypernodeElement*;
63 
65 using hyperedge = HyperedgeElement*;
66 
68 using adjHypergraphEntry = AdjHypergraphElement*;
69 
71 
75 class OGDF_EXPORT AdjHypergraphElement : private internal::GraphElement
76 {
77  friend class Hypergraph;
78  friend class GraphListBase;
79  friend class internal::GraphList<AdjHypergraphElement>;
80 
81 private:
82 
84  GraphElement *m_element;
85 
87 
94 
96  int m_index;
97 
99  explicit AdjHypergraphElement(GraphElement *pElement)
100  : m_element(pElement)
101  { }
102 
104  AdjHypergraphElement(GraphElement *pElement, int pIndex)
105  : m_element(pElement), m_index(pIndex)
106  { }
107 
108 public:
109 
111  int index() const
112  {
113  return m_index;
114  }
115 
117 
122  GraphElement * element() const
123  {
124  return m_element;
125  }
126 
129  {
130  return m_twin;
131  }
132 
135  {
136  return static_cast<adjHypergraphEntry>(m_next);
137  }
138 
141  {
142  return static_cast<adjHypergraphEntry>(m_prev);
143  }
144 
146  adjHypergraphEntry cyclicSucc() const;
147 
149  adjHypergraphEntry cyclicPred() const;
150 
152 
153 }; // class AdjHypegraphElement
154 
156 class OGDF_EXPORT HyperedgeElement : private internal::GraphElement
157 {
158  friend class Hypergraph;
159  friend class GraphListBase;
160  friend class internal::GraphList<HyperedgeElement>;
161 
162 private:
163 
166 
168  int m_index;
169 
172 
174  Hypergraph *m_hypergraph;
175 
177 
180  explicit HyperedgeElement(int pIndex)
181  : m_index(pIndex), m_cardinality(0), m_hypergraph(nullptr) { }
182 
183 public:
184 
186  int index() const
187  {
188  return m_index;
189  }
190 
192  int cardinality() const
193  {
194  return m_cardinality;
195  }
196 
198  Hypergraph * hypergraph() const
199  {
200  return m_hypergraph;
201  }
202 
205  {
206  return m_adjHypernodes.head();
207  }
208 
211  {
212  return m_adjHypernodes.tail();
213  }
214 
217  {
218  return m_adjHypernodes;
219  }
220 
222  template<class NODELIST> void allHypernodes(NODELIST &hypernodes) const
223  {
224  hypernodes.clear();
225  for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ())
226  hypernodes.pushBack(reinterpret_cast<hypernode>(adj->element()));
227  }
228 
230  bool incident(hypernode v) const
231  {
232  for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ()) {
233  if (reinterpret_cast<hypernode>(adj->element()) == v) {
234  return true;
235  }
236  }
237  return false;
238  }
239 
241  hyperedge succ() const
242  {
243  return static_cast<hyperedge>(m_next);
244  }
245 
247  hyperedge pred() const
248  {
249  return static_cast<hyperedge>(m_prev);
250  }
251 
253  bool operator==(const hyperedge e) const
254  {
255  return e->index() == m_index && e->hypergraph() == m_hypergraph;
256  }
257 
258  friend ostream & operator<<(ostream &os, ogdf::hyperedge e);
259 
261 
262 }; // class EdgeElement
263 
265 class OGDF_EXPORT HypernodeElement : private internal::GraphElement
266 {
267  friend class Hypergraph;
268  friend class GraphListBase;
269  friend class internal::GraphList<HypernodeElement>;
270 
271 public:
272 
274  enum class Type {
275  normal = 0x0000001,
276  dummy = 0x0000002,
277  OR = 0x0000003,
278  BUF = 0x0000004,
279  AND = 0x0000005,
280  NOR = 0x0000006,
281  NOT = 0x0000007,
282  XOR = 0x0000008,
283  DFF = 0x0000009,
284  NAND = 0x0000010,
285  INPUT = 0x0000011,
286  OUTPUT = 0x0000012
287  };
288 
289 private:
290 
293 
295  int m_index;
296 
298  int m_degree;
299 
302 
304  Hypergraph * m_hypergraph;
305 
307  explicit HypernodeElement(int pIndex)
308  : m_index(pIndex), m_degree(0), m_type(Type::normal), m_hypergraph(nullptr)
309  {
310  }
311 
313  HypernodeElement(int pIndex, Type pType)
314  : m_index(pIndex), m_degree(0), m_type(pType), m_hypergraph(nullptr)
315  {
316  }
317 
318 public:
319 
321  int index() const
322  {
323  return m_index;
324  }
325 
327  int degree() const
328  {
329  return m_degree;
330  }
331 
333  Hypergraph * hypergraph() const
334  {
335  return m_hypergraph;
336  }
337 
339  Type type() const
340  {
341  return m_type;
342  }
343 
345  void type(Type pType)
346  {
347  m_type = pType;
348  }
349 
352  {
353  return m_adjHyperedges.head();
354  }
355 
358  {
359  return m_adjHyperedges.tail();
360  }
361 
363  template<class NODELIST> void allHyperedges(NODELIST &hyperedges) const
364  {
365  hyperedges.clear();
366  for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ())
367  hyperedges.pushBack(reinterpret_cast<hyperedge>(adj->element()));
368  }
369 
371  bool adjacent(hypernode v) const
372  {
373  for (adjHypergraphEntry adj = firstAdj(); adj; adj = adj->succ()) {
374  if (reinterpret_cast<hyperedge>(adj->element())->incident(v)) {
375  return true;
376  }
377  }
378  return false;
379  }
380 
382  hypernode succ() const
383  {
384  return static_cast<hypernode>(m_next);
385  }
386 
388  hypernode pred() const
389  {
390  return static_cast<hypernode>(m_prev);
391  }
392 
394  bool operator==(const hypernode v) const
395  {
396  return v->index() == m_index && v->hypergraph() == m_hypergraph;
397  }
398 
400 
401 }; // class HypernodeElement
402 
403 class HypergraphArrayBase;
404 template<class T> class HypernodeArray;
405 template<class T> class HyperedgeArray;
407 
408 class OGDF_EXPORT Hypergraph
409 {
412 
415 
418 
421 
424 
427 
430 
433 
438 
439 public:
440 
442  Hypergraph();
443 
445  Hypergraph(const Hypergraph &H);
446 
448  ~Hypergraph();
449 
451  bool empty() const
452  {
453  return m_nHypernodes == 0;
454  }
455 
458  {
459  return m_hypernodes;
460  }
461 
464  {
465  return m_hyperedges;
466  }
467 
469  int numberOfHypernodes() const
470  {
471  return m_nHypernodes;
472  }
473 
475  int numberOfHyperedges() const
476  {
477  return m_nHyperedges;
478  }
479 
481  int maxHypernodeIndex() const
482  {
483  return m_hypernodeIdCount - 1;
484  }
485 
487  int maxHyperedgeIndex() const
488  {
489  return m_hyperedgeIdCount - 1;
490  }
491 
494  {
495  return m_hypernodes.head();
496  }
497 
500  {
501  return m_hypernodes.tail();
502  }
503 
506  {
507  return m_hyperedges.head();
508  }
509 
512  {
513  return m_hyperedges.tail();
514  }
515 
518  {
519  return m_hypernodeArrayTableSize;
520  }
521 
524  {
525  return m_hyperedgeArrayTableSize;
526  }
527 
529  hypernode newHypernode();
530 
532  hypernode newHypernode(int pIndex);
533 
535  hypernode newHypernode(HypernodeElement::Type pType);
536 
538  hypernode newHypernode(int pIndex, HypernodeElement::Type pType);
539 
541 
545  hyperedge newHyperedge(List<hypernode> &hypernodes);
546 
548 
553  hyperedge newHyperedge(int pIndex, List<hypernode> &hypernodes);
554 
556 
559  void delHypernode(hypernode v);
560 
562 
565  void delHyperedge(hyperedge e);
566 
568  void clear();
569 
571  hypernode randomHypernode() const;
572 
574  hyperedge randomHyperedge() const;
575 
577  template<class LIST> void allHypernodes(LIST &hypernodeList) const
578  {
579  hypernodeList.clear();
580  for (hypernode v = m_hypernodes.head(); v; v = v->succ())
581  hypernodeList.pushBack(v);
582  }
583 
585  template<class LIST> void allHyperedges(LIST &hyperedgeList) const
586  {
587  hyperedgeList.clear();
588  for (hyperedge e = m_hyperedges.head(); e; e = e->succ())
589  hyperedgeList.pushBack(e);
590  }
591 
593  void readBenchHypergraph(istream &is);
594 
596  void readBenchHypergraph(const char *filename);
597 
599  void readPlaHypergraph(istream &is);
600 
602  void loadPlaHypergraph(const char *fileName);
603 
605  bool consistency() const;
606 
609  registerHypernodeArray(HypergraphArrayBase *pHypernodeArray) const;
610 
612  registerHyperedgeArray(HypergraphArrayBase *pHyperedgeArray) const;
613 
616  registerObserver(HypergraphObserver *pObserver) const;
617 
619  void unregisterHypernodeArray(ListIterator<HypergraphArrayBase *> it) const;
620 
622  void unregisterHyperedgeArray(ListIterator<HypergraphArrayBase *> it) const;
623 
625  void unregisterObserver(ListIterator<HypergraphObserver *> it) const;
626 
627  Hypergraph &operator=(const Hypergraph &H);
628 
629  friend ostream & operator<<(ostream &os, ogdf::Hypergraph &H);
630 
631  friend istream & operator>>(istream &is, ogdf::Hypergraph &H);
632 
634 
635 private:
636 
637  void initArrays();
638 
639  void initObservers();
640 
641  int nextEntry(char *buffer, int from, string stop);
642 
643  HypernodeElement::Type gateType(string gate);
644 
645 }; // class Hypergraph
646 
647 } // end of namespace ogdf
Hypergraph * m_hypergraph
The hypergraph containing the hyperedge (if any).
Definition: Hypergraph.h:174
int m_hypernodeArrayTableSize
The current table size of hypernode arrays within the hypergraph.
Definition: Hypergraph.h:429
internal::GraphList< AdjHypergraphElement > incidentHypernodes() const
Returns the incident hypernodes of the hyperedge.
Definition: Hypergraph.h:216
bool adjacent(hypernode v) const
Returns true iff v is adjacent to the hypernode.
Definition: Hypergraph.h:371
internal::GraphList< HypernodeElement > m_hypernodes
The list of all hypernodes.
Definition: Hypergraph.h:411
hypernode firstHypernode() const
Returns the first hypernode in the list of all hypernodes.
Definition: Hypergraph.h:493
adjHypergraphEntry twin() const
Returns the pointer to a twin adjacency list.
Definition: Hypergraph.h:128
int index() const
Returns the (unique) hypernode index.
Definition: Hypergraph.h:321
Type type() const
Returns the type of hypernode.
Definition: Hypergraph.h:339
void allHyperedges(NODELIST &hyperedges) const
Returns a list with all incident hyperedges of the hypernode.
Definition: Hypergraph.h:363
adjHypergraphEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition: Hypergraph.h:210
void allHypernodes(NODELIST &hypernodes) const
Returns a list with all incident hypernodes of the hyperedge.
Definition: Hypergraph.h:222
ListPure< HypergraphObserver * > m_observers
Definition: Hypergraph.h:437
GraphElement * element() const
Returns the element associated with this adjacency entry.
Definition: Hypergraph.h:122
static std::istream & operator>>(std::istream &inStream, HyperGraph::NodeArray< T > &array)
Definition: HyperGraph.h:814
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
HypernodeElement(int pIndex, Type pType)
Constructor.
Definition: Hypergraph.h:313
int m_cardinality
The number of incidend hypernodes.
Definition: Hypergraph.h:171
void allHypernodes(LIST &hypernodeList) const
Returns a list with all hypernodes of the hypergraph.
Definition: Hypergraph.h:577
hyperedge lastHyperEdge() const
Returns the last hyperedge in the list of all hyperedges.
Definition: Hypergraph.h:511
Doubly linked lists.
Definition: List.h:40
hyperedge pred() const
Returns the predecessor in the list of all hyperedges.
Definition: Hypergraph.h:247
hypernode succ() const
Returns the successor in the list of all hypernodes.
Definition: Hypergraph.h:382
int index() const
Returns the index of a hyperedge.
Definition: Hypergraph.h:186
Hypergraph * m_hypergraph
The hypergraph containing the hypernode (if any).
Definition: Hypergraph.h:304
adjHypergraphEntry succ() const
Returns the successor in the adjacency list.
Definition: Hypergraph.h:134
Class for adjacency list elements.
Definition: Hypergraph.h:75
T * tail() const
Returns the last element in the list.
Definition: GraphList.h:272
internal::GraphList< HypernodeElement > hypernodes() const
Returns the list of all hypernodes.
Definition: Hypergraph.h:457
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:764
Decralation of GraphElement and GraphList classes.
int m_hypernodeIdCount
The Index that will be assigned to the next created hypernode.
Definition: Hypergraph.h:423
internal::GraphList< HyperedgeElement > hyperedges() const
Returns the list of all hyperedges.
Definition: Hypergraph.h:463
ListPure< HypergraphArrayBase * > m_hypernodeArrays
The registered hypergraph arrays & observers.
Definition: Hypergraph.h:435
int maxHypernodeIndex() const
Returns the largest used hypernode index.
Definition: Hypergraph.h:481
int degree() const
Returns the hypernode degree.
Definition: Hypergraph.h:327
int hyperedgeArrayTableSize() const
Returns the table size of hyperedge arrays within the hypergraph.
Definition: Hypergraph.h:523
AdjHypergraphElement(GraphElement *pElement, int pIndex)
Constructs an adjacency entry for a given hyper{node,edge} and index.
Definition: Hypergraph.h:104
adjHypergraphEntry lastAdj() const
Returns the last entry in the adjacency list.
Definition: Hypergraph.h:357
AdjHypergraphElement(GraphElement *pElement)
Constructs an adjacency element for a given hyper{node,edge}.
Definition: Hypergraph.h:99
Type m_type
The type of the hypernode.
Definition: Hypergraph.h:301
int numberOfHypernodes() const
Returns the number of hypernodes in the hypergraph.
Definition: Hypergraph.h:469
T * head() const
Returns the first element in the list.
Definition: GraphList.h:269
hypernode lastHypernode() const
Returns the last hypernode in the list of all hypernodes.
Definition: Hypergraph.h:499
Doubly linked lists (maintaining the length of the list).
Definition: List.h:39
int m_hyperedgeIdCount
The Index that will be assigned to the next created hyperedge.
Definition: Hypergraph.h:426
int hypernodeArrayTableSize() const
Returns the table size of hypernode arrays with the hypergraph.
Definition: Hypergraph.h:517
Class for the representation of hypernodes.
Definition: Hypergraph.h:265
hyperedge firstHyperedge() const
Returns the first hyperedge in the list of all hyperedges.
Definition: Hypergraph.h:505
HypernodeElement(int pIndex)
Constructor.
Definition: Hypergraph.h:307
bool operator==(const hyperedge e) const
Equality operator.
Definition: Hypergraph.h:253
int m_index
The (unique) index of the hyperedge.
Definition: Hypergraph.h:168
int m_degree
The number of incident hyperedges.
Definition: Hypergraph.h:298
The base class for objects used by (hyper)graphs.
Definition: GraphList.h:54
void type(Type pType)
Sets the type of hypernode.
Definition: Hypergraph.h:345
adjHypergraphEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Hypergraph.h:204
Encapsulates a pointer to a list element.
Definition: List.h:41
internal::GraphList< AdjHypergraphElement > m_adjHyperedges
The adjacency list of the hypernode.
Definition: Hypergraph.h:292
bool incident(hypernode v) const
Returns true iff v is incident to the hyperedge.
Definition: Hypergraph.h:230
Hypergraph * hypergraph() const
Returns the hypergraph containing the hypernode.
Definition: Hypergraph.h:333
int m_nHypernodes
The number of hypernodes in the hypergraph.
Definition: Hypergraph.h:417
bool empty() const
Returns true iff the hypergraph is empty (ie. contains no hypernodes).
Definition: Hypergraph.h:451
ListPure< HypergraphArrayBase * > m_hyperedgeArrays
Definition: Hypergraph.h:436
void allHyperedges(LIST &hyperedgeList) const
Returns a list with all hyperedges of the hypergraph.
Definition: Hypergraph.h:585
adjHypergraphEntry m_twin
The corresponding adjacency entry.
Definition: Hypergraph.h:93
int m_nHyperedges
The number of hyperedges in the hypergraph.
Definition: Hypergraph.h:420
internal::GraphList< HyperedgeElement > m_hyperedges
The list of all hyperedges.
Definition: Hypergraph.h:414
bool operator==(const hypernode v) const
Equality operator.
Definition: Hypergraph.h:394
int m_index
The (unique) index of the hypernode.
Definition: Hypergraph.h:295
int m_hyperedgeArrayTableSize
The current table size of hyperedge arrays within the hypergraph.
Definition: Hypergraph.h:432
int numberOfHyperedges() const
Returns the number of hyperedges in the hypergraph.
Definition: Hypergraph.h:475
Abstract base class for hypergraph arrays.
adjHypergraphEntry pred() const
Returns the predecessor in the adjacency list.
Definition: Hypergraph.h:140
HyperedgeElement(int pIndex)
Constructs an hyperedge element between hypernodes.
Definition: Hypergraph.h:180
hypernode pred() const
Returns the predecessor in the list of all hypernodes.
Definition: Hypergraph.h:388
GraphElement * m_element
The associated hyperedge or hypernode.
Definition: Hypergraph.h:84
Class for the representation of hyperedges.
Definition: Hypergraph.h:156
The namespace for all OGDF objects.
int index() const
Returns the index of this adjacency element.
Definition: Hypergraph.h:111
hyperedge succ() const
Returns the successor in the list of all hyperedges.
Definition: Hypergraph.h:241
int maxHyperedgeIndex() const
Returns the largest used hyperedge index.
Definition: Hypergraph.h:487
Lists of graph objects (like nodes, edges, etc.).
Definition: GraphList.h:252
int cardinality() const
Returns the number of incident hypernodes.
Definition: Hypergraph.h:192
Type
The type of hypernodes.
Definition: Hypergraph.h:274
internal::GraphList< AdjHypergraphElement > m_adjHypernodes
The adjacency list of the hyperedge.
Definition: Hypergraph.h:165
int m_index
The (unique) index of the adjacency entry.
Definition: Hypergraph.h:96
adjHypergraphEntry firstAdj() const
Returns the first entry in the adjaceny list.
Definition: Hypergraph.h:351
Dynamic arrays indexed with nodes.
Definition: Hypergraph.h:405
Declaration of doubly linked lists and iterators.
Dynamic arrays indexed with hypernodes.
Definition: Hypergraph.h:404
Hypergraph * hypergraph() const
Returns the hypergraph containing the hyperedge.
Definition: Hypergraph.h:198