atlas  0.6
poset.h
Go to the documentation of this file.
1 
5 /*
6  Copyright (C) 2004,2005 Fokko du Cloux
7  part of the Atlas of Lie Groups and Representations
8 
9  For license information see the LICENSE file
10 */
11 
12 #ifndef POSET_H /* guard against multiple inclusions */
13 #define POSET_H
14 
15 #include <vector>
16 
17 #include "bitmap.h"
18 #include "tags.h"
19 
20 #include "poset_fwd.h"
21 #include "graph_fwd.h"
22 
23 
24 namespace atlas {
25 
26 namespace poset {
27 
28 
29 
30 /******** type definitions **************************************************/
31 
39 class Poset {
50  std::vector<bitmap::BitMap> d_below;
51 
53  void new_cover(unsigned long x,unsigned long y) // add $x<y$, $y$ maximal
54  { (d_below[y] |= d_below[x]).insert(x); }
55 
56 
57  public:
58 
59 // constructors and destructors
60  Poset() : d_below() {}
61 
62  explicit Poset(size_t n); // poset without any (nontrivial) comparabilities
63 
65  template<typename C> // |C| is some container of |set::Elt|
66  explicit Poset(const std::vector<C>& hasse);
67 
69  Poset(size_t n,const std::vector<Link>&);
70 
71  Poset(const Poset& p, tags::DualTag);
72 
73  ~Poset() {}
74 
75 // swap
76  void swap(Poset& other) {
77  d_below.swap(other.d_below);
78  }
79 
80 // accessors
81 
86  bool lesseq(set::Elt i, set::Elt j) const
87  { return i<j ? d_below[j].isMember(i) : i==j; }
88 
89  bool operator==(const Poset& other) const;
90 
91  size_t size() const { return d_below.size(); }
92 
93  const bitmap::BitMap& below(set::Elt y)const { return d_below[y]; }
94  bitmap::BitMap above(set::Elt x) const;
95 
96  set::EltList maxima(const bitmap::BitMap&) const;
97  set::EltList minima(const bitmap::BitMap&) const;
98 
99  set::EltList covered_by(set::Elt y) const { return maxima(d_below[y]); }
101 
102  graph::OrientedGraph hasseDiagram() const; // full Hasse diagram
103  graph::OrientedGraph hasseDiagram(set::Elt max) const; // part |<=max|
104 
106  unsigned long n_comparable() const;
107 
108 // manipulators
109  void resize(unsigned long);
110 
126  void extend(const std::vector<Link>& lks)
127  {
128  for (size_t i=0; i<lks.size(); ++i)
129  new_cover(lks[i].first,lks[i].second);
130  }
131 
132  // add a new maximal element, comparable with elements in |container|
133  template<typename C> void new_max(C container)
134  {
135  size_t y=d_below.size();
136  d_below.push_back(bitmap::BitMap(y));
137 
138  for (typename C::const_iterator
139  it=container.begin(); it!=container.end(); ++it)
140  new_cover(*it,y);
141  }
142 
143 }; // class Poset
144 
145 
146 /* ********************** Function(s) *****************************/
147 
148 // memory-efficient version of |Poset(hasse).n_comparable()|
149 unsigned long n_comparable_from_Hasse
150  (const std::vector<set::EltList>& hasse);
151 
161 template<typename C>
162 Poset::Poset(const std::vector<C>& hasse)
163 : d_below(hasse.size())
164 {
165  for (size_t i=0; i<hasse.size(); ++i)
166  {
167  d_below[i].set_capacity(i);
168  for (typename C::const_iterator
169  it=hasse[i].begin(); it!=hasse[i].end(); ++it)
170  new_cover(*it,i);
171  }
172 }
173 
174 
175 } // |namespace poset|
176 
177 } // |namespace atlas|
178 
179 #endif
size_t Elt
Definition: Atlas.h:52
bool operator==(const Poset &other) const
Definition: poset.cpp:79
size_t size() const
Definition: poset.h:91
uA p
Definition: lists.cpp:26
bitmap::BitMap above(set::Elt x) const
Definition: poset.cpp:91
std::vector< bitmap::BitMap > d_below
Matrix of order relations.
Definition: poset.h:50
set::EltList minima(const bitmap::BitMap &) const
Definition: poset.cpp:119
void swap(Poset &other)
Definition: poset.h:76
Poset()
Definition: poset.h:60
void extend(const std::vector< Link > &lks)
Transforms the poset into the weakest ordering containing the relations it previously contained...
Definition: poset.h:126
set::EltList covered_by(set::Elt y) const
Definition: poset.h:99
unsigned long n_comparable() const
Number of comparable pairs (including those on the diagonal)
Definition: poset.cpp:188
const bitmap::BitMap & below(set::Elt y) const
Definition: poset.h:93
bool lesseq(set::Elt i, set::Elt j) const
The order relation itself.
Definition: poset.h:86
Definition: graph.h:27
void new_cover(unsigned long x, unsigned long y)
The basic method to add elementary relations.
Definition: poset.h:53
Represents a poset by the matrix of order relations.
Definition: poset.h:39
graph::OrientedGraph hasseDiagram() const
Puts in h the Hasse diagram of the poset.
Definition: poset.cpp:156
Definitions and declarations for the BitMap class.
void new_max(C container)
Definition: poset.h:133
unsigned long n
Definition: axis.cpp:77
Definition: Atlas.h:38
Definition of dummy argument tags used for constructor overloading.
Definition: tags.h:51
~Poset()
Definition: poset.h:73
std::vector< Elt > EltList
Definition: Atlas.h:53
Container of a large (more than twice the machine word size) set of bits.
Definition: bitmap.h:52
set::EltList covers_of(set::Elt x) const
Definition: poset.cpp:130
void resize(unsigned long)
Resizes the poset to size n, adding only the diagonal for the new rows.
Definition: poset.cpp:203
unsigned long n_comparable_from_Hasse(const std::vector< set::EltList > &hasse)
Definition: poset.cpp:225
Definition: cweave.c:343
set::EltList maxima(const bitmap::BitMap &) const
Definition: poset.cpp:108