Actual source code: PreSieve.hh
1: #ifndef included_ALE_PreSieve_hh
2: #define included_ALE_PreSieve_hh
4: #ifndef included_ALE_Coaster_hh
5: #include <Coaster.hh>
6: #endif
8: #include <map>
10: namespace ALE {
12: class Stack;
13: class PreSieve : public Coaster {
14: protected:
15: Point_set _roots;
16: Point_set _leaves;
17: Point__Point_set _cone;
18: Point__Point_set _support;
19: // The following two functions are used by Stack also.
20: void __computeBaseExclusion(Point_set& base, PreSieve *s);
21: void __computeCapExclusion(Point_set& cap, PreSieve *s);
22: void __determinePointOwners(Point_set& points, int32_t *LeaseData, std::map<Point,int32_t,Point::Cmp>& owner);
23: static const int completedSetCap = 0;
24: static const int completedSetBase = 1;
25: Stack *__computeCompletion(int32_t completedSet, int32_t completionType, int32_t footprintType, PreSieve *c);
27: public:
28: //
29: PreSieve();
30: PreSieve(MPI_Comm comm);
31: virtual ~PreSieve();
32: virtual PreSieve& clear();
33: virtual void view(const char *name);
34: //----------------------------------------------------------------------
35: // IMPROVE: implement deep copy when internals become Obj<X>
36: virtual PreSieve& copy(const PreSieve& s){*this = s; return *this;};
37: virtual PreSieve& addArrow(const Point& i, const Point& j);
38: virtual PreSieve& removeArrow(const Point& i, const Point& j, bool removeSingleton = false);
39: virtual PreSieve& addBasePoint(const Point& p);
40: virtual PreSieve& removeBasePoint(const Point& p, bool removeSingleton = false);
41: virtual PreSieve& addPoint(const Point& p) {this->addBasePoint(p); this->addCapPoint(p); return *this;};
42: virtual PreSieve& removePoint(const Point& p) {this->removeBasePoint(p); this->removeCapPoint(p); return *this;};
43: virtual PreSieve& addCapPoint(const Point& q);
44: virtual PreSieve& removeCapPoint(const Point& q, bool removeSingleton = false);
45: virtual PreSieve& addSupport(Point& i, Obj<Point_set>& suppSet) {
46: return this->addSupport(i, *(suppSet.objPtr));
47: }
48: virtual PreSieve& addSupport(Point& i, Point_set& suppSet) {
49: CHKCOMM(*this);
50: this->__checkLock();
51: // Add i to the cap in case the supp set is empty and no addArrow are executed
52: this->addCapPoint(i);
53: for(Point_set::iterator supp_itor = suppSet.begin(); supp_itor != suppSet.end(); supp_itor++) {
54: Point j = (*supp_itor);
55: this->addArrow(i,j);
56: }
57: return *this;
58: };
59: virtual PreSieve& addSupport(Point& i, Point& supp) {
60: CHKCOMM(*this);
61: this->__checkLock();
62: // Add i to the cap in case the supp set is empty and no addArrow are executed
63: this->addCapPoint(i);
64: this->addArrow(i,supp);
65: return *this;
66: };
67: virtual PreSieve& setSupport(Point& i, Point_set& supp) {
68: CHKCOMM(*this);
69: this->__checkLock();
70: // IMPROVE: use support iterator
71: Point_set support = this->support(i);
72: for(Point_set::iterator support_itor = support.begin(); support_itor != support.end(); support_itor++) {
73: Point j = (*support_itor);
74: this->removeArrow(i,j);
75: }
76: this->addSupport(i,supp);
77: return *this;
78: };
79: virtual PreSieve& setSupport(Point& i, Point& s) {
80: CHKCOMM(*this);
81: this->__checkLock();
82: // IMPROVE: use support iterator
83: Point_set support = this->support(i);
84: for(Point_set::iterator support_itor = support.begin(); support_itor != support.end(); support_itor++) {
85: Point j = (*support_itor);
86: this->removeArrow(i,j);
87: }
88: this->addSupport(i,s);
89: return *this;
90: };
91: virtual void addCone(Obj<Point_set> coneSet, const Point& j);
92: virtual void addCone(const Point& cone, const Point& j);
93: virtual PreSieve& setCone(Point_set& coneSet, Point& j) {
94: CHKCOMM(*this);
95: this->__checkLock();
96: // IMPROVE: use support iterator
97: Point_set cone = this->cone(j);
98: for(Point_set::iterator cone_itor = cone.begin(); cone_itor != cone.end(); cone_itor++) {
99: Point i = (*cone_itor);
100: this->removeArrow(i,j);
101: }
102: this->addCone(coneSet,j);
103: return *this;
104: };
105: virtual PreSieve& setCone(Point& i, Point& j) {
106: CHKCOMM(*this);
107: this->__checkLock();
108: // IMPROVE: use support iterator
109: Point_set cone = this->cone(j);
110: for(Point_set::iterator cone_itor = cone.begin(); cone_itor != cone.end(); cone_itor++) {
111: Point i = (*cone_itor);
112: this->removeArrow(i,j);
113: }
114: this->addCone(i,j);
115: return *this;
116: };
117: virtual Obj<Point_set> space();
118: virtual int32_t spaceSize();
119: virtual int32_t *spaceSizes();
120: virtual int32_t baseSize();
121: virtual int32_t *baseSizes();
122: virtual Point_set base();
123: virtual int32_t capSize();
124: virtual int32_t *capSizes();
125: virtual Point_set cap();
127: virtual PreSieve& stackAbove(PreSieve& s);
128: virtual PreSieve& stackBelow(PreSieve& s);
129: virtual PreSieve& invert();
130: virtual PreSieve& restrictBase(Point_set& base);
131: virtual PreSieve& restrictCap(Point_set& cap);
132: virtual PreSieve* baseRestriction(Point_set& base);
133: virtual PreSieve* capRestriction(Point_set& cap);
134: virtual PreSieve& excludeBase(Point_set& base);
135: virtual PreSieve& excludeCap(Point_set& cap);
136: virtual PreSieve* baseExclusion(Point_set& base);
137: virtual PreSieve* capExclusion(Point_set& cap);
138: virtual int spaceContains(Point point);
139: virtual int baseContains(Point point);
140: virtual bool capContains(const Point& point);
141: virtual int coneContains(Point& p, Point point);
142: virtual int supportContains(Point& q, Point point);
143: virtual Point_set roots(){return this->_roots;};
144: virtual Point_set leaves(){return this->_leaves;};
145: Obj<Point_set> cone(Obj<Point_set> chain) {return this->nCone(chain,1);};
146: Point_set cone(Point_set& chain) {return this->nCone(chain,1);};
147: Obj<Point_set> cone(const Point& point);
148: int32_t coneSize(const Point& p) {
149: Point_set pSet; pSet.insert(p);
150: return coneSize(pSet);
151: };
152: int32_t coneSize(Point_set& chain);
153: // Compute the point set obtained by taking the cone recursively on a point in the base
154: // (i.e., the set of cap points resulting after each iteration is used again as the base for the next cone computation).
155: // Note: a 0-cone is the point itself.
156: Obj<Point_set> nCone(Obj<Point_set> chain, int32_t n);
157: Point_set nCone(Point_set& chain, int32_t n) {return this->nCone(Obj<Point_set>(chain),n);};
158: Obj<Point_set> nCone(const Point& point, int32_t n) {return this->nCone(Obj<Point_set>(Point_set(point)),n);};
159: Obj<Point_set> nClosure(Obj<Point_set> chain, int32_t n);
160: Obj<Point_set> nClosure(const Point& point, int32_t n) {return this->nClosure(Obj<Point_set>(Point_set(point)),n);};
161: Obj<PreSieve> nClosurePreSieve(Obj<Point_set> chain, int32_t n, Obj<PreSieve> closure = Obj<PreSieve>());
162: //
163: Obj<Point_set> support(const Obj<Point_set>& chain) {return this->nSupport(chain,1);};
164: Point_set support(const Point_set& chain) {return this->nSupport(chain,1);};
165: Obj<Point_set> support(const Point& point);
166: int32_t supportSize(const Point_set& chain);
167: int32_t supportSize(const Point& p) {
168: Point_set pSet; pSet.insert(p);
169: return supportSize(pSet);
170: };
171: // Compute the point set obtained by taking the support recursively on a point in the cap
172: // (i.e., the set of base points resulting after each iteration is used again as the cap for the next support computation).
173: // Note: a 0-support is the point itself.
174: Obj<Point_set> nSupport(const Obj<Point_set>& chain, int32_t n);
175: Point_set nSupport(const Point_set& chain, int32_t n) {return this->nSupport(Obj<Point_set>(chain),n);};
176: Obj<Point_set> nSupport(const Point& point, int32_t n) {return this->nSupport(Obj<Point_set>(Point_set(point)),n);};
177: Obj<Point_set> nStar(const Obj<Point_set>& chain, int32_t n);
178: Point_set nStar(const Point_set& chain, int32_t n);
179: Point_set nStar(const Point& point, int32_t n) {
180: CHKCOMM(*this);
181: // Compute the point set obtained by accumulating the recursively-computed support of a point in the cap
182: // (i.e., the set of base points resulting after each iteration is accumulated in the star AND used again as
183: // the cap for the next support computation).
184: // Note: a 0-star is the point itself.
185: Point_set chain; chain.insert(point);
186: return this->nStar(chain,n);
187: };
188: Obj<PreSieve> nStarPreSieve(Obj<Point_set> chain, int32_t n, Obj<PreSieve> star = Obj<PreSieve>());
189: //
190: Point_set nMeet(Point_set c1, Point_set c2, int32_t n);
191: Point_set nJoin(Point_set c1, Point_set c2, int32_t n);
192: Point_set nMeetAll(Point_set& chain, int32_t n);
193: Point_set nJoinAll(Point_set& chain, int32_t n);
194: PreSieve* add(PreSieve& s);
195: PreSieve& add(Obj<PreSieve> s);
196: //
197: static const int completionTypePoint = 0;
198: static const int completionTypeArrow = 1;
199: static const int footprintTypeNone = 0;
200: static const int footprintTypeCone = 1;
201: static const int footprintTypeSupport = 2;
202: virtual Stack* coneCompletion( const int completionType, const int footprintType, PreSieve *c = NULL);
203: virtual Stack* supportCompletion(const int completionType, const int footprintType, PreSieve *c = NULL);
204: virtual Stack* baseFootprint( int completionType, int footprintType, PreSieve *f = NULL);
205: virtual Stack* capFootprint( int completionType, int footprintType, PreSieve *f = NULL);
206: virtual Stack* spaceFootprint(int completionType, int footprintType, PreSieve *f = NULL);
207: };
209: } // namespace ALE
213: #endif