Actual source code: Sieve.hh
2: #ifndef included_ALE_Sieve_hh
3: #define included_ALE_Sieve_hh
5: #include <boost/multi_index_container.hpp>
6: #include <boost/multi_index/member.hpp>
7: #include <boost/multi_index/ordered_index.hpp>
8: #include <boost/multi_index/composite_key.hpp>
9: #include <iostream>
11: #ifndef included_ALE_hh
12: #include <ALE.hh>
13: #endif
15: // ALE extensions
17: #ifndef included_ALE_Sifter_hh
18: #include <Sifter.hh>
19: #endif
22: namespace ALE {
24: namespace SieveDef {
25: //
26: // Rec & RecContainer definitions.
27: // Rec is intended to denote a graph point record.
28: //
29: template <typename Point_, typename Marker_>
30: struct Rec {
31: typedef Point_ point_type;
32: typedef Marker_ marker_type;
33: template<typename OtherPoint_, typename OtherMarker_ = Marker_>
34: struct rebind {
35: typedef Rec<OtherPoint_, OtherMarker_> type;
36: };
37: point_type point;
38: int degree;
39: int depth;
40: int height;
41: marker_type marker;
42: // Basic interface
43: Rec() : point(point_type()), degree(0), depth(0), height(0), marker(marker_type()) {};
44: Rec(const Rec& r) : point(r.point), degree(r.degree), depth(r.depth), height(r.height), marker(r.marker) {}
45: Rec(const point_type& p) : point(p), degree(0), depth(0), height(0), marker(marker_type()) {};
46: Rec(const point_type& p, const int degree) : point(p), degree(degree), depth(0), height(0), marker(marker_type()) {};
47: Rec(const point_type& p, const int degree, const int depth, const int height, const marker_type marker) : point(p), degree(degree), depth(depth), height(height), marker(marker) {};
48: // Printing
49: friend std::ostream& operator<<(std::ostream& os, const Rec& p) {
50: os << "<" << p.point << ", "<< p.degree << ", "<< p.depth << ", "<< p.height << ", "<< p.marker << ">";
51: return os;
52: };
54: struct degreeAdjuster {
55: degreeAdjuster(int newDegree) : _newDegree(newDegree) {};
56: void operator()(Rec& r) { r.degree = this->_newDegree; }
57: private:
58: int _newDegree;
59: };
60: };// class Rec
62: template <typename Point_, typename Rec_>
63: struct RecContainerTraits {
64: typedef Rec_ rec_type;
65: typedef typename rec_type::marker_type marker_type;
66: // Index tags
67: struct pointTag{};
68: struct degreeTag{};
69: struct markerTag{};
70: struct depthMarkerTag{};
71: struct heightMarkerTag{};
72: // Rec set definition
73: typedef ::boost::multi_index::multi_index_container<
74: rec_type,
75: ::boost::multi_index::indexed_by<
76: ::boost::multi_index::ordered_unique<
77: ::boost::multi_index::tag<pointTag>, BOOST_MULTI_INDEX_MEMBER(rec_type, typename rec_type::point_type, point)
78: >,
79: // ::boost::multi_index::ordered_non_unique<
80: // ::boost::multi_index::tag<degreeTag>, BOOST_MULTI_INDEX_MEMBER(rec_type, int, degree)
81: // >,
82: ::boost::multi_index::ordered_non_unique<
83: ::boost::multi_index::tag<markerTag>, BOOST_MULTI_INDEX_MEMBER(rec_type, marker_type, marker)
84: >,
85: ::boost::multi_index::ordered_non_unique<
86: ::boost::multi_index::tag<depthMarkerTag>,
87: ::boost::multi_index::composite_key<
88: rec_type, BOOST_MULTI_INDEX_MEMBER(rec_type,int,depth), BOOST_MULTI_INDEX_MEMBER(rec_type,marker_type,marker)>
89: >,
90: ::boost::multi_index::ordered_non_unique<
91: ::boost::multi_index::tag<heightMarkerTag>,
92: ::boost::multi_index::composite_key<
93: rec_type, BOOST_MULTI_INDEX_MEMBER(rec_type,int,height), BOOST_MULTI_INDEX_MEMBER(rec_type,marker_type,marker)>
94: >
95: >,
96: ALE_ALLOCATOR<rec_type>
97: > set_type;
98: //
99: // Return types
100: //
102: class PointSequence {
103: public:
104: typedef ALE::SifterDef::IndexSequenceTraits<typename ::boost::multi_index::index<set_type, pointTag>::type,
105: BOOST_MULTI_INDEX_MEMBER(rec_type, typename rec_type::point_type,point)>
106: traits;
107: protected:
108: const typename traits::index_type& _index;
109: public:
110:
111: // Need to extend the inherited iterator to be able to extract the degree
112: class iterator : public traits::iterator {
113: public:
114: iterator(const typename traits::iterator::itor_type& itor) : traits::iterator(itor) {};
115: virtual const int& degree() const {return this->_itor->degree;};
116: virtual const int& marker() const {return this->_itor->marker;};
117: virtual const int& depth() const {return this->_itor->depth;};
118: virtual const int& height() const {return this->_itor->height;};
119: //void setDegree(const int degree) {this->_index.modify(this->_itor, typename traits::rec_type::degreeAdjuster(degree));};
120: };
121:
122: PointSequence(const PointSequence& seq) : _index(seq._index) {};
123: PointSequence(typename traits::index_type& index) : _index(index) {};
124: virtual ~PointSequence(){};
125:
126: virtual bool empty(){return this->_index.empty();};
127:
128: virtual typename traits::index_type::size_type size() {return this->_index.size();};
130: virtual iterator begin() {
131: // Retrieve the beginning iterator of the index
132: return iterator(this->_index.begin());
133: };
134: virtual iterator end() {
135: // Retrieve the ending iterator of the index
136: // Since the elements in this index are ordered by degree, this amounts to the end() of the index.
137: return iterator(this->_index.end());
138: };
139: virtual bool contains(const typename rec_type::point_type& p) {
140: // Check whether a given point is in the index
141: return (this->_index.find(p) != this->_index.end());
142: };
143: }; // class PointSequence
145: template<typename Tag_, typename Value_>
146: class ValueSequence {
147: public:
148: typedef Value_ value_type;
149: typedef ALE::SifterDef::IndexSequenceTraits<typename ::boost::multi_index::index<set_type, Tag_>::type,
150: BOOST_MULTI_INDEX_MEMBER(rec_type, typename rec_type::point_type,point)>
151: traits;
152: protected:
153: const typename traits::index_type& _index;
154: const value_type _value;
155: public:
156: // Need to extend the inherited iterator to be able to extract the degree
157: class iterator : public traits::iterator {
158: public:
159: iterator(const typename traits::iterator::itor_type& itor) : traits::iterator(itor) {};
160: virtual const int& degree() const {return this->_itor->degree;};
161: virtual const int& marker() const {return this->_itor->marker;};
162: virtual const int& depth() const {return this->_itor->depth;};
163: virtual const int& height() const {return this->_itor->height;};
164: };
165:
166: ValueSequence(const PointSequence& seq) : _index(seq._index), _value(seq._value) {};
167: ValueSequence(typename traits::index_type& index, const value_type& value) : _index(index), _value(value) {};
168: virtual ~ValueSequence(){};
169:
170: virtual bool empty(){return this->_index.empty();};
171:
172: virtual typename traits::index_type::size_type size() {return this->_index.count(this->_value);};
174: virtual iterator begin() {
175: return iterator(this->_index.lower_bound(this->_value));
176: };
177: virtual iterator end() {
178: return iterator(this->_index.upper_bound(this->_value));
179: };
180: }; // class ValueSequence
182: template<typename Tag_, typename Value_>
183: class TwoValueSequence {
184: public:
185: typedef Value_ value_type;
186: typedef ALE::SifterDef::IndexSequenceTraits<typename ::boost::multi_index::index<set_type, Tag_>::type,
187: BOOST_MULTI_INDEX_MEMBER(rec_type, typename rec_type::point_type,point)>
188: traits;
189: protected:
190: const typename traits::index_type& _index;
191: const value_type _valueA, _valueB;
192: const bool _useTwoValues;
193: public:
194: // Need to extend the inherited iterator to be able to extract the degree
195: class iterator : public traits::iterator {
196: public:
197: iterator(const typename traits::iterator::itor_type& itor) : traits::iterator(itor) {};
198: virtual const int& degree() const {return this->_itor->degree;};
199: virtual const int& marker() const {return this->_itor->marker;};
200: };
201:
202: TwoValueSequence(const PointSequence& seq) : _index(seq._index), _valueA(seq._valueA), _valueB(seq._valueB), _useTwoValues(seq._useTwoValues) {};
203: TwoValueSequence(typename traits::index_type& index, const value_type& valueA) : _index(index), _valueA(valueA), _valueB(value_type()), _useTwoValues(false) {};
204: TwoValueSequence(typename traits::index_type& index, const value_type& valueA, const value_type& valueB) : _index(index), _valueA(valueA), _valueB(valueB), _useTwoValues(true) {};
205: virtual ~TwoValueSequence(){};
206:
207: virtual bool empty(){return this->_index.empty();};
208:
209: virtual typename traits::index_type::size_type size() {
210: if (this->_useTwoValues) {
211: return this->_index.count(::boost::make_tuple(this->_valueA,this->_valueB));
212: } else {
213: return this->_index.count(::boost::make_tuple(this->_valueA));
214: }
215: };
217: virtual iterator begin() {
218: if (this->_useTwoValues) {
219: return iterator(this->_index.lower_bound(::boost::make_tuple(this->_valueA,this->_valueB)));
220: } else {
221: return iterator(this->_index.lower_bound(::boost::make_tuple(this->_valueA)));
222: }
223: };
224: virtual iterator end() {
225: if (this->_useTwoValues) {
226: return iterator(this->_index.upper_bound(::boost::make_tuple(this->_valueA,this->_valueB)));
227: } else {
228: return iterator(this->_index.upper_bound(::boost::make_tuple(this->_valueA)));
229: }
230: };
231: }; // class TwoValueSequence
232: };// struct RecContainerTraits
234: template <typename Point_, typename Rec_>
235: struct RecContainer {
236: typedef RecContainerTraits<Point_, Rec_> traits;
237: typedef typename traits::set_type set_type;
238: template <typename OtherPoint_, typename OtherRec_>
239: struct rebind {
240: typedef RecContainer<OtherPoint_, OtherRec_> type;
241: };
242: set_type set;
244: void removePoint(const typename traits::rec_type::point_type& p) {
245: typename ::boost::multi_index::index<set_type, typename traits::pointTag>::type& index =
246: ::boost::multi_index::get<typename traits::pointTag>(this->set);
247: typename ::boost::multi_index::index<set_type, typename traits::pointTag>::type::iterator i = index.find(p);
248: if (i != index.end()) { // Point exists
249: index.erase(i);
250: }
251: };
252: void adjustDegree(const typename traits::rec_type::point_type& p, int delta) {
253: typename ::boost::multi_index::index<set_type, typename traits::pointTag>::type& index =
254: ::boost::multi_index::get<typename traits::pointTag>(this->set);
255: typename ::boost::multi_index::index<set_type, typename traits::pointTag>::type::iterator i = index.find(p);
256: if (i == index.end()) { // No such point exists
257: if(delta < 0) { // Cannot decrease degree of a non-existent point
258: ostringstream err;
259: err << "ERROR: adjustDegree: Non-existent point " << p;
260: std::cout << err << std::endl;
261: throw(Exception(err.str().c_str()));
262: }
263: else { // We CAN INCREASE the degree of a non-existent point: simply insert a new element with degree == delta
264: std::pair<typename ::boost::multi_index::index<set_type, typename traits::pointTag>::type::iterator, bool> ii;
265: typename traits::rec_type r(p,delta);
266: ii = index.insert(r);
267: if(ii.second == false) {
268: ostringstream err;
269: err << "ERROR: adjustDegree: Failed to insert a rec " << r;
270: std::cout << err << std::endl;
271: throw(Exception(err.str().c_str()));
272: }
273: }
274: }
275: else { // Point exists, so we try to modify its degree
276: // If the adjustment is zero, there is nothing to do, otherwise ...
277: if(delta != 0) {
278: int newDegree = i->degree + delta;
279: if(newDegree < 0) {
280: ostringstream ss;
281: ss << "adjustDegree: Adjustment of " << *i << " by " << delta << " would result in negative degree: " << newDegree;
282: throw Exception(ss.str().c_str());
283: }
284: index.modify(i, typename traits::rec_type::degreeAdjuster(newDegree));
285: }
286: }
287: }; // adjustDegree()
288: }; // struct RecContainer
289: };// namespace SieveDef
291: //
292: // Sieve:
293: // A Sieve is a set of {\emph arrows} connecting {\emph points} of type Point_. Thus we
294: // could realize a sieve, for instance, as a directed graph. In addition, we will often
295: // assume an acyclicity constraint, arriving at a DAG. Each arrow may also carry a label,
296: // or {\emph color} of type Color_, and the interface allows sets of arrows to be filtered
297: // by color.
298: //
299: template <typename Point_, typename Marker_, typename Color_>
300: class Sieve : public ALE::Sifter<Point_, Point_, Color_, ::boost::multi_index::composite_key_compare<std::less<Point_>, std::less<Color_>, std::less<Point_> >, SieveDef::RecContainer<Point_, SieveDef::Rec<Point_, Marker_> >, SieveDef::RecContainer<Point_, SieveDef::Rec<Point_, Marker_> > > {
301: public:
302: typedef Color_ color_type;
303: typedef Point_ point_type;
304: typedef Marker_ marker_type;
305: typedef struct {
306: typedef ALE::Sifter<Point_, Point_, Color_, ::boost::multi_index::composite_key_compare<std::less<Point_>, std::less<Color_>, std::less<Point_> >, SieveDef::RecContainer<Point_, SieveDef::Rec<Point_, Marker_> >, SieveDef::RecContainer<Point_, SieveDef::Rec<Point_, Marker_> > > baseType;
307: // Encapsulated container types
308: typedef typename baseType::traits::arrow_container_type arrow_container_type;
309: typedef typename baseType::traits::cap_container_type cap_container_type;
310: typedef typename baseType::traits::base_container_type base_container_type;
311: // Types associated with records held in containers
312: typedef typename baseType::traits::arrow_type arrow_type;
313: typedef typename baseType::traits::source_type source_type;
314: typedef typename baseType::traits::sourceRec_type sourceRec_type;
315: typedef typename baseType::traits::target_type target_type;
316: typedef typename baseType::traits::targetRec_type targetRec_type;
317: typedef typename baseType::traits::color_type color_type;
318: typedef Point_ point_type;
319: // Convenient tag names
320: typedef typename baseType::traits::supportInd supportInd;
321: typedef typename baseType::traits::coneInd coneInd;
322: typedef typename baseType::traits::arrowInd arrowInd;
323: typedef typename baseType::traits::baseInd baseInd;
324: typedef typename baseType::traits::capInd capInd;
326: //
327: // Return types
328: //
329: typedef typename baseType::traits::arrowSequence arrowSequence;
330: typedef typename baseType::traits::coneSequence coneSequence;
331: typedef typename baseType::traits::supportSequence supportSequence;
332: typedef typename baseType::traits::baseSequence baseSequence;
333: typedef typename baseType::traits::capSequence capSequence;
334: typedef typename base_container_type::traits::template TwoValueSequence<typename base_container_type::traits::depthMarkerTag,int> depthSequence;
335: typedef typename cap_container_type::traits::template TwoValueSequence<typename cap_container_type::traits::heightMarkerTag,int> heightSequence;
336: typedef typename cap_container_type::traits::template ValueSequence<typename cap_container_type::traits::markerTag,marker_type> markerSequence;
337: } traits;
338: typedef std::set<point_type> pointSet;
339: typedef ALE::array<point_type> pointArray;
340: typedef std::set<marker_type> markerSet;
341: typedef pointSet coneSet;
342: typedef pointSet supportSet;
343: typedef pointArray coneArray;
344: typedef pointArray supportArray;
345: public:
346: Sieve(MPI_Comm comm = PETSC_COMM_SELF, const int& debug = 0) : ALE::Sifter<Point_, Point_, Color_, ::boost::multi_index::composite_key_compare<std::less<Point_>, std::less<Color_>, std::less<Point_> >, SieveDef::RecContainer<Point_, SieveDef::Rec<Point_, Marker_> >, SieveDef::RecContainer<Point_, SieveDef::Rec<Point_, Marker_> > >(comm, debug), doStratify(false), maxDepth(-1), maxHeight(-1), graphDiameter(-1) {
347: this->_markers = new markerSet();
348: this->_meetSet = new coneSet();
349: };
350: virtual ~Sieve() {};
351: // Printing
352: friend std::ostream& operator<<(std::ostream& os, Obj<Sieve<Point_,Marker_,Color_> > s) {
353: os << *s;
354: return os;
355: };
356:
357: friend std::ostream& operator<<(std::ostream& os, Sieve<Point_,Marker_,Color_>& s) {
358: Obj<typename traits::baseSequence> base = s.base();
359: for(typename traits::baseSequence::iterator b_iter = base->begin(); b_iter != base->end(); ++b_iter) {
360: Obj<typename traits::coneSequence> cone = s.cone(*b_iter);
361: os << "Base point " << *b_iter << " with cone:" << std::endl;
362: for(typename traits::coneSequence::iterator c_iter = cone->begin(); c_iter != cone->end(); ++c_iter) {
363: os << " " << *c_iter << std::endl;
364: }
365: }
366: return os;
367: };
369: template<typename ostream_type>
370: void view(ostream_type& os, const char* label, bool rawData);
371: void view(const char* label, MPI_Comm comm);
373: Obj<Sieve> copy() {
374: Obj<Sieve> s = Sieve(this->comm(), this->debug);
375: Obj<typename traits::capSequence> cap = this->cap();
376: Obj<typename traits::baseSequence> base = this->base();
378: for(typename traits::capSequence::iterator c_iter = cap->begin(); c_iter != cap->end(); ++c_iter) {
379: s->addCapPoint(*c_iter);
380: }
381: for(typename traits::baseSequence::iterator b_iter = base->begin(); b_iter != base->end(); ++b_iter) {
382: Obj<typename traits::coneSequence> cone = this->cone(*b_iter);
384: for(typename traits::coneSequence::iterator c_iter = cone->begin(); c_iter != cone->end(); ++c_iter) {
385: s->addArrow(*c_iter, *b_iter, c_iter.color());
386: }
387: }
388: s->stratify();
389: return s;
390: };
391: bool hasPoint(const point_type& point) {
392: if (this->baseContains(point) || this->capContains(point)) return true;
393: return false;
394: };
395: private:
396: template<class InputSequence> Obj<coneSet> __nCone(Obj<InputSequence>& cone, int n, const Color_& color, bool useColor);
397: template<class pointSequence> void __nCone(const Obj<pointSequence>& points, int n, const Color_& color, bool useColor, Obj<coneArray> cone, Obj<coneSet> seen);
398: template<class pointSequence> void __nSupport(const Obj<pointSequence>& points, int n, const Color_& color, bool useColor, Obj<supportArray> cone, Obj<supportSet> seen);
399: public:
400: //
401: // The basic Sieve interface (extensions to Sifter)
402: //
403: Obj<coneArray> nCone(const Point_& p, int n);
404: Obj<coneArray> nCone(const Point_& p, int n, const Color_& color, bool useColor = true);
405: template<class InputSequence> Obj<coneSet> nCone(const Obj<InputSequence>& points, int n);
406: template<class InputSequence> Obj<coneSet> nCone(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor = true);
408: Obj<supportArray> nSupport(const Point_& p, int n);
409: Obj<supportArray> nSupport(const Point_& p, int n, const Color_& color, bool useColor = true);
410: template<class InputSequence> Obj<supportSet> nSupport(const Obj<InputSequence>& points, int n);
411: template<class InputSequence> Obj<supportSet> nSupport(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor = true);
412: public:
413: virtual bool checkArrow(const typename traits::arrow_type& a) {
414: if ((this->_cap.set.find(a.source) == this->_cap.set.end()) && (this->_base.set.find(a.source) == this->_base.set.end())) return false;
415: if ((this->_cap.set.find(a.target) == this->_cap.set.end()) && (this->_base.set.find(a.target) == this->_base.set.end())) return false;
416: return true;
417: };
418: //
419: // Iterated versions
420: //
421: Obj<coneSet> closure(const Point_& p);
423: Obj<coneSet> closure(const Point_& p, const Color_& color);
425: template<class InputSequence>
426: Obj<coneSet> closure(const Obj<InputSequence>& points);
428: template<class InputSequence>
429: Obj<coneSet> closure(const Obj<InputSequence>& points, const Color_& color);
431: Obj<coneSet> nClosure(const Point_& p, int n);
433: Obj<coneSet> nClosure(const Point_& p, int n, const Color_& color, bool useColor = true);
435: template<class InputSequence>
436: Obj<coneSet> nClosure(const Obj<InputSequence>& points, int n);
438: template<class InputSequence>
439: Obj<coneSet> nClosure(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor = true);
441: Obj<Sieve<Point_,Marker_,Color_> > closureSieve(const Point_& p);
443: Obj<Sieve<Point_,Marker_,Color_> > closureSieve(const Point_& p, const Color_& color);
445: template<class InputSequence>
446: Obj<Sieve<Point_,Marker_,Color_> > closureSieve(const Obj<InputSequence>& points);
448: template<class InputSequence>
449: Obj<Sieve<Point_,Marker_,Color_> > closureSieve(const Obj<InputSequence>& points, const Color_& color);
451: Obj<Sieve<Point_,Marker_,Color_> > nClosureSieve(const Point_& p, int n);
453: Obj<Sieve<Point_,Marker_,Color_> > nClosureSieve(const Point_& p, int n, const Color_& color, bool useColor = true);
455: template<class InputSequence>
456: Obj<Sieve<Point_,Marker_,Color_> > nClosureSieve(const Obj<InputSequence>& points, int n);
458: template<class InputSequence>
459: Obj<Sieve<Point_,Marker_,Color_> > nClosureSieve(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor = true);
461: Obj<supportSet> star(const Point_& p);
463: Obj<supportSet> star(const Point_& p, const Color_& color);
465: template<class InputSequence>
466: Obj<supportSet> star(const Obj<InputSequence>& points);
468: template<class InputSequence>
469: Obj<supportSet> star(const Obj<InputSequence>& points, const Color_& color);
471: Obj<supportSet> nStar(const Point_& p, int n);
473: Obj<supportSet> nStar(const Point_& p, int n, const Color_& color, bool useColor = true);
475: template<class InputSequence>
476: Obj<supportSet> nStar(const Obj<InputSequence>& points, int n);
478: template<class InputSequence>
479: Obj<supportSet> nStar(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor = true);
481: private:
482: template<class InputSequence>
483: Obj<coneSet> __nClosure(Obj<InputSequence>& cone, int n, const Color_& color, bool useColor);
485: template<class InputSequence>
486: Obj<Sieve<Point_,Marker_,Color_> > __nClosureSieve(Obj<InputSequence>& cone, int n, const Color_& color, bool useColor);
488: template<class InputSequence>
489: Obj<supportSet> __nStar(Obj<InputSequence>& support, int n, const Color_& color, bool useColor);
491: public:
492: //
493: // Lattice methods
494: //
495: const Obj<coneSet>& meet(const Point_& p, const Point_& q);
497: const Obj<coneSet>& meet(const Point_& p, const Point_& q, const Color_& color);
499: template<class InputSequence>
500: const Obj<coneSet>& meet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1);
502: template<class InputSequence>
503: const Obj<coneSet>& meet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, const Color_& color);
505: const Obj<coneSet>& nMeet(const Point_& p, const Point_& q, int n);
507: const Obj<coneSet>& nMeet(const Point_& p, const Point_& q, int n, const Color_& color, bool useColor = true);
509: template<class InputSequence>
510: const Obj<coneSet>& nMeet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, int n);
512: template<class InputSequence>
513: const Obj<coneSet>& nMeet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, int n,
514: const Color_& color, bool useColor = true);
516: Obj<supportSet> join(const Point_& p, const Point_& q);
518: Obj<supportSet> join(const Point_& p, const Point_& q, const Color_& color);
520: template<class InputSequence>
521: Obj<supportSet> join(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1);
523: template<class InputSequence>
524: Obj<supportSet> join(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, const Color_& color);
526: Obj<supportSet> nJoin(const Point_& p, const Point_& q, int n);
528: Obj<supportSet> nJoin(const Point_& p, const Point_& q, int n, const Color_& color, bool useColor = true);
530: template<class InputSequence>
531: Obj<supportSet> nJoin(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, int n);
533: template<class InputSequence>
534: Obj<supportSet> nJoin(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, int n, const Color_& color, bool useColor = true);
536: public:
537: Obj<typename traits::depthSequence> roots() {
538: return this->depthStratum(0);
539: };
540: Obj<typename traits::heightSequence> leaves() {
541: return this->heightStratum(0);
542: };
543: private:
544: bool doStratify;
545: int maxDepth, maxHeight, graphDiameter;
546: public:
547: //
548: // Structural queries
549: //
550: int depth();
551: int depth(const point_type& p);
552: template<typename InputSequence> int depth(const Obj<InputSequence>& points);
554: int height();
555: int height(const point_type& p);
556: template<typename InputSequence> int height(const Obj<InputSequence>& points);
558: int diameter();
559: int diameter(const point_type& p);
561: Obj<typename traits::depthSequence> depthStratum(int d);
562: Obj<typename traits::depthSequence> depthStratum(int d, marker_type m);
564: Obj<typename traits::heightSequence> heightStratum(int h);
565: Obj<typename traits::heightSequence> heightStratum(int h, marker_type m);
567: Obj<typename traits::markerSequence> markerStratum(marker_type m);
568:
569: void setStratification(bool doStratify) {this->doStratify = doStratify;};
571: bool getStratification() {return this->doStratify;};
573: void stratify(bool show = false);
574: protected:
575: Obj<markerSet> _markers;
576: Obj<coneSet> _meetSet;
577: public:
578: //
579: // Structural manipulation
580: //
582: struct changeMarker {
583: changeMarker(int newMarker) : newMarker(newMarker) {};
585: void operator()(typename traits::base_container_type::traits::rec_type& p) {
586: p.marker = newMarker;
587: }
588: private:
589: marker_type newMarker;
590: };
592: void setMarker(const point_type& p, const marker_type& marker);
593: template<class InputSequence> void setMarker(const Obj<InputSequence>& points, const marker_type& marker);
595: void clearMarkers() {this->_markers.clear();};
596: Obj<markerSet> markers() {return this->_markers;};
597: private:
598: struct changeHeight {
599: changeHeight(int newHeight) : newHeight(newHeight) {};
601: void operator()(typename traits::base_container_type::traits::rec_type& p) {
602: p.height = newHeight;
603: }
604: private:
605: int newHeight;
606: };
607:
608: template<class InputSequence> void __computeClosureHeights(const Obj<InputSequence>& points);
610: struct changeDepth {
611: changeDepth(int newDepth) : newDepth(newDepth) {};
613: void operator()(typename traits::base_container_type::traits::rec_type& p) {
614: p.depth = newDepth;
615: }
616: private:
617: int newDepth;
618: };
620: template<class InputSequence> void __computeStarDepths(const Obj<InputSequence>& points);
621: };
623: template <typename Point_, typename Marker_, typename Color_>
624: Obj<typename Sieve<Point_,Marker_,Color_>::coneArray> Sieve<Point_,Marker_,Color_>::nCone(const Point_& p, int n) {
625: return this->nCone(p, n, Color_(), false);
626: };
628: template <typename Point_, typename Marker_, typename Color_>
629: Obj<typename Sieve<Point_,Marker_,Color_>::coneArray> Sieve<Point_,Marker_,Color_>::nCone(const Point_& p, int n, const Color_& color, bool useColor) {
630: Obj<coneArray> cone = new coneArray();
631: Obj<coneSet> seen = new coneSet();
633: this->__nCone(this->cone(p), n-1, color, useColor, cone, seen);
634: return cone;
635: };
637: template <typename Point_, typename Marker_, typename Color_>
638: template<class pointSequence>
639: void Sieve<Point_,Marker_,Color_>::__nCone(const Obj<pointSequence>& points, int n, const Color_& color, bool useColor, Obj<coneArray> cone, Obj<coneSet> seen) {
640: if (n == 0) {
641: for(typename pointSequence::iterator p_itor = points->begin(); p_itor != points->end(); ++p_itor) {
642: if (seen->find(*p_itor) == seen->end()) {
643: cone->push_back(*p_itor);
644: seen->insert(*p_itor);
645: }
646: }
647: } else {
648: typename pointSequence::iterator end = points->end();
649: for(typename pointSequence::iterator p_itor = points->begin(); p_itor != end; ++p_itor) {
650: if (useColor) {
651: this->__nCone(this->cone(*p_itor, color), n-1, color, useColor, cone, seen);
652: } else {
653: this->__nCone(this->cone(*p_itor), n-1, color, useColor, cone, seen);
654: }
655: }
656: }
657: };
659: template <typename Point_, typename Marker_, typename Color_>
660: template<class InputSequence>
661: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::nCone(const Obj<InputSequence>& points, int n) {
662: return this->nCone(points, n, Color_(), false);
663: };
665: template <typename Point_, typename Marker_, typename Color_>
666: template<class InputSequence>
667: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::nCone(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor ) {
668: Obj<coneSet> cone = new coneSet();
669: cone->insert(points->begin(), points->end());
670: return this->__nCone(cone, n, color, useColor);
671: };
673: template <typename Point_, typename Marker_, typename Color_>
674: template<class InputSequence>
675: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::__nCone(Obj<InputSequence>& cone, int n, const Color_& color, bool useColor) {
676: Obj<coneSet> base = new coneSet();
678: for(int i = 0; i < n; ++i) {
679: Obj<coneSet> tmp = cone; cone = base; base = tmp;
680:
681: cone->clear();
682: for(typename coneSet::iterator b_itor = base->begin(); b_itor != base->end(); ++b_itor) {
683: Obj<typename traits::coneSequence> pCone;
684:
685: if (useColor) {
686: pCone = this->cone(*b_itor, color);
687: } else {
688: pCone = this->cone(*b_itor);
689: }
690: cone->insert(pCone->begin(), pCone->end());
691: }
692: }
693: return cone;
694: };
696: template <typename Point_, typename Marker_, typename Color_>
697: Obj<typename Sieve<Point_,Marker_,Color_>::supportArray> Sieve<Point_,Marker_,Color_>::nSupport(const Point_& p, int n) {
698: return this->nSupport(p, n, Color_(), false);
699: };
701: template <typename Point_, typename Marker_, typename Color_>
702: Obj<typename Sieve<Point_,Marker_,Color_>::supportArray> Sieve<Point_,Marker_,Color_>::nSupport(const Point_& p, int n, const Color_& color, bool useColor) {
703: Obj<supportArray> cone = new supportArray();
704: Obj<supportSet> seen = new supportSet();
706: this->__nSupport(this->support(p), n-1, color, useColor, cone, seen);
707: return cone;
708: };
710: template <typename Point_, typename Marker_, typename Color_>
711: template<class pointSequence>
712: void Sieve<Point_,Marker_,Color_>::__nSupport(const Obj<pointSequence>& points, int n, const Color_& color, bool useColor, Obj<supportArray> support, Obj<supportSet> seen) {
713: if (n == 0) {
714: for(typename pointSequence::iterator p_itor = points->begin(); p_itor != points->end(); ++p_itor) {
715: if (seen->find(*p_itor) == seen->end()) {
716: support->push_back(*p_itor);
717: seen->insert(*p_itor);
718: }
719: }
720: } else {
721: typename pointSequence::iterator end = points->end();
722: for(typename pointSequence::iterator p_itor = points->begin(); p_itor != end; ++p_itor) {
723: if (useColor) {
724: this->__nSupport(this->support(*p_itor, color), n-1, color, useColor, support, seen);
725: } else {
726: this->__nSupport(this->support(*p_itor), n-1, color, useColor, support, seen);
727: }
728: }
729: }
730: };
732: template <typename Point_, typename Marker_, typename Color_>
733: template<class InputSequence>
734: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nSupport(const Obj<InputSequence>& points, int n) {
735: return this->nSupport(points, n, Color_(), false);
736: };
738: template <typename Point_, typename Marker_, typename Color_>
739: template<class InputSequence>
740: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nSupport(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor ) {
741: Obj<supportSet> support = supportSet();
742: Obj<supportSet> cap = supportSet();
743:
744: support->insert(points->begin(), points->end());
745: for(int i = 0; i < n; ++i) {
746: Obj<supportSet> tmp = support; support = cap; cap = tmp;
747:
748: support->clear();
749: for(typename supportSet::iterator c_itor = cap->begin(); c_itor != cap->end(); ++c_itor) {
750: Obj<typename traits::supportSequence> pSupport;
751:
752: if (useColor) {
753: pSupport = this->support(*c_itor, color);
754: } else {
755: pSupport = this->support(*c_itor);
756: }
757: support->insert(pSupport->begin(), pSupport->end());
758: }
759: }
760: return support;
761: };
762: //
763: // Iterated versions
764: //
765:
766: template <typename Point_, typename Marker_, typename Color_>
767: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::closure(const Point_& p) {
768: return nClosure(p, this->depth());
769: };
770:
771: template <typename Point_, typename Marker_, typename Color_>
772: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::closure(const Point_& p, const Color_& color) {
773: return nClosure(p, this->depth(), color);
774: };
776: template <typename Point_, typename Marker_, typename Color_>
777: template<class InputSequence>
778: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::closure(const Obj<InputSequence>& points) {
779: return nClosure(points, this->depth());
780: };
781:
782: template <typename Point_, typename Marker_, typename Color_>
783: template<class InputSequence>
784: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::closure(const Obj<InputSequence>& points, const Color_& color) {
785: return nClosure(points, this->depth(), color);
786: };
787:
788: template <typename Point_, typename Marker_, typename Color_>
789: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::nClosure(const Point_& p, int n) {
790: return this->nClosure(p, n, Color_(), false);
791: };
793: template <typename Point_, typename Marker_, typename Color_>
794: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::nClosure(const Point_& p, int n, const Color_& color, bool useColor ) {
795: Obj<coneSet> cone = coneSet();
796: cone->insert(p);
797: return this->__nClosure(cone, n, color, useColor);
798: };
800: template <typename Point_, typename Marker_, typename Color_>
801: template<class InputSequence>
802: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::nClosure(const Obj<InputSequence>& points, int n) {
803: return this->nClosure(points, n, Color_(), false);
804: };
806: template <typename Point_, typename Marker_, typename Color_>
807: template<class InputSequence>
808: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::nClosure(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor ) {
809: Obj<coneSet> cone = coneSet();
810: cone->insert(points->begin(), points->end());
811: return this->__nClosure(cone, n, color, useColor);
812: };
814: template <typename Point_, typename Marker_, typename Color_>
815: template<class InputSequence>
816: Obj<typename Sieve<Point_,Marker_,Color_>::coneSet> Sieve<Point_,Marker_,Color_>::__nClosure(Obj<InputSequence>& cone, int n, const Color_& color, bool useColor) {
817: Obj<coneSet> base = coneSet();
818: Obj<coneSet> closure = coneSet();
819:
820: closure->insert(cone->begin(), cone->end());
821: for(int i = 0; i < n; ++i) {
822: Obj<coneSet> tmp = cone; cone = base; base = tmp;
823: cone->clear();
824: for(typename coneSet::iterator b_itor = base->begin(); b_itor != base->end(); ++b_itor) {
825: Obj<typename traits::coneSequence> pCone;
826: if (useColor) {
827: pCone = this->cone(*b_itor, color);
828: } else {
829: pCone = this->cone(*b_itor);
830: }
831: cone->insert(pCone->begin(), pCone->end());
832: closure->insert(pCone->begin(), pCone->end());
833: }
834: }
835: return closure;
836: };
838: template <typename Point_, typename Marker_, typename Color_>
839: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::closureSieve(const Point_& p) {
840: return nClosureSieve(p, this->depth());
841: };
843: template <typename Point_, typename Marker_, typename Color_>
844: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::closureSieve(const Point_& p, const Color_& color) {
845: return nClosureSieve(p, this->depth(), color);
846: };
847:
848: template <typename Point_, typename Marker_, typename Color_>
849: template<class InputSequence>
850: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::closureSieve(const Obj<InputSequence>& points) {
851: return nClosureSieve(points, this->depth());
852: };
853:
854: template <typename Point_, typename Marker_, typename Color_>
855: template<class InputSequence>
856: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::closureSieve(const Obj<InputSequence>& points, const Color_& color) {
857: return nClosureSieve(points, this->depth(), color);
858: };
859:
860: template <typename Point_, typename Marker_, typename Color_>
861: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::nClosureSieve(const Point_& p, int n) {
862: return this->nClosureSieve(p, n, Color_(), false);
863: };
864:
865: template <typename Point_, typename Marker_, typename Color_>
866: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::nClosureSieve(const Point_& p, int n, const Color_& color, bool useColor ) {
867: Obj<coneSet> cone = coneSet();
868: cone->insert(p);
869: return this->__nClosureSieve(cone, n, color, useColor);
870: };
871:
872: template <typename Point_, typename Marker_, typename Color_>
873: template<class InputSequence>
874: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::nClosureSieve(const Obj<InputSequence>& points, int n) {
875: return this->nClosureSieve(points, n, Color_(), false);
876: };
877:
878: template <typename Point_, typename Marker_, typename Color_>
879: template<class InputSequence>
880: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::nClosureSieve(const Obj<InputSequence>& points, int n,
881: const Color_& color, bool useColor ) {
882: Obj<coneSet> cone = coneSet();
883: cone->insert(points->begin(), points->end());
884: return this->__nClosureSieve(cone, n, color, useColor);
885: };
886:
887: template <typename Point_, typename Marker_, typename Color_>
888: template<class InputSequence>
889: Obj<Sieve<Point_,Marker_,Color_> > Sieve<Point_,Marker_,Color_>::__nClosureSieve(Obj<InputSequence>& cone,int n,const Color_& color,bool useColor) {
890: Obj<coneSet> base = coneSet();
891: Obj<Sieve<Point_,Marker_,Color_> > closure = Sieve<Point_,Marker_,Color_>();
892: // FIX: need to add initial stuff
893: for(int i = 0; i < n; ++i) {
894: Obj<coneSet> tmp = cone; cone = base; base = tmp;
895: cone->clear();
896: for(typename coneSet::iterator b_itor = base->begin(); b_itor != base->end(); ++b_itor) {
897: Obj<typename traits::coneSequence> pCone;
898:
899: if (useColor) {
900: pCone = this->cone(*b_itor, color);
901: } else {
902: pCone = this->cone(*b_itor);
903: }
904: cone->insert(pCone->begin(), pCone->end());
905: closure->addCone(pCone, *b_itor);
906: }
907: }
908: return closure;
909: };
910:
911: template <typename Point_, typename Marker_, typename Color_>
912: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::star(const Point_& p) {
913: return nStar(p, this->height());
914: };
915:
916: template <typename Point_, typename Marker_, typename Color_>
917: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::star(const Point_& p, const Color_& color) {
918: return nStar(p, this->depth(), color);
919: };
920:
921: template <typename Point_, typename Marker_, typename Color_>
922: template<class InputSequence>
923: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::star(const Obj<InputSequence>& points) {
924: return nStar(points, this->height());
925: };
926:
927: template <typename Point_, typename Marker_, typename Color_>
928: template<class InputSequence>
929: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::star(const Obj<InputSequence>& points, const Color_& color) {
930: return nStar(points, this->height(), color);
931: };
933: template <typename Point_, typename Marker_, typename Color_>
934: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nStar(const Point_& p, int n) {
935: return this->nStar(p, n, Color_(), false);
936: };
937:
938: template <typename Point_, typename Marker_, typename Color_>
939: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nStar(const Point_& p, int n, const Color_& color, bool useColor ) {
940: Obj<supportSet> support = supportSet();
941: support->insert(p);
942: return this->__nStar(support, n, color, useColor);
943: };
945: template <typename Point_, typename Marker_, typename Color_>
946: template<class InputSequence>
947: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nStar(const Obj<InputSequence>& points, int n) {
948: return this->nStar(points, n, Color_(), false);
949: };
951: template <typename Point_, typename Marker_, typename Color_>
952: template<class InputSequence>
953: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nStar(const Obj<InputSequence>& points, int n, const Color_& color, bool useColor ) {
954: Obj<supportSet> support = supportSet();
955: support->insert(points->begin(), points->end());
956: return this->__nStar(support, n, color, useColor);
957: };
958:
959: template <typename Point_, typename Marker_, typename Color_>
960: template<class InputSequence>
961: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::__nStar(Obj<InputSequence>& support, int n, const Color_& color, bool useColor) {
962: Obj<supportSet> cap = supportSet();
963: Obj<supportSet> star = supportSet();
964: star->insert(support->begin(), support->end());
965: for(int i = 0; i < n; ++i) {
966: Obj<supportSet> tmp = support; support = cap; cap = tmp;
967: support->clear();
968: for(typename supportSet::iterator c_itor = cap->begin(); c_itor != cap->end(); ++c_itor) {
969: Obj<typename traits::supportSequence> pSupport;
970: if (useColor) {
971: pSupport = this->support(*c_itor, color);
972: } else {
973: pSupport = this->support(*c_itor);
974: }
975: support->insert(pSupport->begin(), pSupport->end());
976: star->insert(pSupport->begin(), pSupport->end());
977: }
978: }
979: return star;
980: };
982: //
983: // Lattice methods
984: //
986: template <typename Point_, typename Marker_, typename Color_>
987: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::meet(const Point_& p, const Point_& q) {
988: return nMeet(p, q, this->depth());
989: };
990:
991: template <typename Point_, typename Marker_, typename Color_>
992: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::meet(const Point_& p, const Point_& q, const Color_& color) {
993: return nMeet(p, q, this->depth(), color);
994: };
996: template <typename Point_, typename Marker_, typename Color_>
997: template<class InputSequence>
998: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::meet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1) {
999: return nMeet(chain0, chain1, this->depth());
1000: };
1002: template <typename Point_, typename Marker_, typename Color_>
1003: template<class InputSequence>
1004: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::meet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, const Color_& color) {
1005: return nMeet(chain0, chain1, this->depth(), color);
1006: };
1008: template <typename Point_, typename Marker_, typename Color_>
1009: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::nMeet(const Point_& p, const Point_& q, int n) {
1010: if (n == 1) {
1011: std::set<point_type> intersect;
1012: const Obj<typename traits::coneSequence>& coneA = this->cone(p);
1013: const typename traits::coneSequence::iterator beginA = coneA->begin();
1014: const typename traits::coneSequence::iterator endA = coneA->end();
1015: const Obj<typename traits::coneSequence>& coneB = this->cone(q);
1016: const typename traits::coneSequence::iterator beginB = coneB->begin();
1017: const typename traits::coneSequence::iterator endB = coneB->end();
1019: std::set_intersection(beginA, endA, beginB, endB, std::insert_iterator<std::set<point_type> >(intersect, intersect.begin()));
1020: this->_meetSet->clear();
1021: this->_meetSet->insert(intersect.begin(), intersect.end());
1022: return this->_meetSet;
1023: }
1024: return nMeet(p, q, n, Color_(), false);
1025: };
1027: template <typename Point_, typename Marker_, typename Color_>
1028: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::nMeet(const Point_& p, const Point_& q, int n, const Color_& color, bool useColor ) {
1029: Obj<coneSet> chain0 = new coneSet();
1030: Obj<coneSet> chain1 = new coneSet();
1031: chain0->insert(p);
1032: chain1->insert(q);
1033: return this->nMeet(chain0, chain1, n, color, useColor);
1034: };
1036: template <typename Point_, typename Marker_, typename Color_>
1037: template<class InputSequence>
1038: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::nMeet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, int n) {
1039: return this->nMeet(chain0, chain1, n, Color_(), false);
1040: };
1041:
1042: template <typename Point_, typename Marker_, typename Color_>
1043: template<class InputSequence>
1044: const Obj<typename Sieve<Point_,Marker_,Color_>::coneSet>& Sieve<Point_,Marker_,Color_>::nMeet(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1,int n,const Color_& color, bool useColor){
1045: // The strategy is to compute the intersection of cones over the chains, remove the intersection
1046: // and use the remaining two parts -- two disjoined components of the symmetric difference of cones -- as the new chains.
1047: // The intersections at each stage are accumulated and their union is the meet.
1048: // The iteration stops after n steps in addition to the meet of the initial chains or sooner if at least one of the chains is empty.
1049: Obj<coneSet> cone;
1051: this->_meetSet->clear();
1052: if((chain0->size() != 0) && (chain1->size() != 0)) {
1053: for(int i = 0; i <= n; ++i) {
1054: // Compute the intersection of chains and put it in meet at the same time removing it from c and cc
1055: std::set<point_type> intersect;
1056: //std::set_intersection(chain0->begin(), chain0->end(), chain1->begin(), chain1->end(), std::insert_iterator<coneSet>(meet, meet->begin()));
1057: std::set_intersection(chain0->begin(), chain0->end(), chain1->begin(), chain1->end(), std::insert_iterator<std::set<point_type> >(intersect, intersect.begin()));
1058: this->_meetSet->insert(intersect.begin(), intersect.end());
1059: for(typename std::set<point_type>::iterator i_iter = intersect.begin(); i_iter != intersect.end(); ++i_iter) {
1060: chain0->erase(chain0->find(*i_iter));
1061: chain1->erase(chain1->find(*i_iter));
1062: }
1063: // Replace each of the cones with a cone over it, and check if either is empty; if so, return what's in meet at the moment.
1064: cone = this->cone(chain0);
1065: chain0->insert(cone->begin(), cone->end());
1066: if(chain0->size() == 0) {
1067: break;
1068: }
1069: cone = this->cone(chain1);
1070: chain1->insert(cone->begin(), cone->end());
1071: if(chain1->size() == 0) {
1072: break;
1073: }
1074: // If both cones are empty, we should quit
1075: }
1076: }
1077: return this->_meetSet;
1078: };
1079:
1080: template <typename Point_, typename Marker_, typename Color_>
1081: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::join(const Point_& p, const Point_& q) {
1082: return this->nJoin(p, q, this->depth());
1083: };
1084:
1085: template <typename Point_, typename Marker_, typename Color_>
1086: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::join(const Point_& p, const Point_& q, const Color_& color) {
1087: return this->nJoin(p, q, this->depth(), color);
1088: };
1090: template <typename Point_, typename Marker_, typename Color_>
1091: template<class InputSequence>
1092: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::join(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1) {
1093: return this->nJoin(chain0, chain1, this->depth());
1094: };
1095:
1096: template <typename Point_, typename Marker_, typename Color_>
1097: template<class InputSequence>
1098: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::join(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, const Color_& color) {
1099: return this->nJoin(chain0, chain1, this->depth(), color);
1100: };
1101:
1102: template <typename Point_, typename Marker_, typename Color_>
1103: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nJoin(const Point_& p, const Point_& q, int n) {
1104: return this->nJoin(p, q, n, Color_(), false);
1105: };
1106:
1107: template <typename Point_, typename Marker_, typename Color_>
1108: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nJoin(const Point_& p, const Point_& q, int n, const Color_& color, bool useColor) {
1109: Obj<supportSet> chain0 = supportSet();
1110: Obj<supportSet> chain1 = supportSet();
1111: chain0->insert(p);
1112: chain1->insert(q);
1113: return this->nJoin(chain0, chain1, n, color, useColor);
1114: };
1116: template <typename Point_, typename Marker_, typename Color_>
1117: template<class InputSequence>
1118: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nJoin(const Obj<InputSequence>& chain0, const Obj<InputSequence>& chain1, int n) {
1119: return this->nJoin(chain0, chain1, n, Color_(), false);
1120: };
1122: template <typename Point_, typename Marker_, typename Color_>
1123: template<class InputSequence>
1124: Obj<typename Sieve<Point_,Marker_,Color_>::supportSet> Sieve<Point_,Marker_,Color_>::nJoin(const Obj<InputSequence>& chain0,const Obj<InputSequence>& chain1,int n,const Color_& color,bool useColor){
1125: // The strategy is to compute the intersection of supports over the chains, remove the intersection
1126: // and use the remaining two parts -- two disjoined components of the symmetric difference of supports -- as the new chains.
1127: // The intersections at each stage are accumulated and their union is the join.
1128: // The iteration stops after n steps in addition to the join of the initial chains or sooner if at least one of the chains is empty.
1129: Obj<supportSet> join = supportSet();
1130: Obj<supportSet> support;
1131: if((chain0->size() != 0) && (chain1->size() != 0)) {
1132: for(int i = 0; i <= n; ++i) {
1133: // Compute the intersection of chains and put it in meet at the same time removing it from c and cc
1134: std::set<point_type> intersect;
1135: //std::set_intersection(chain0->begin(), chain0->end(), chain1->begin(), chain1->end(), std::insert_iterator<supportSet>(join.obj(), join->begin()));
1136: std::set_intersection(chain0->begin(), chain0->end(), chain1->begin(), chain1->end(), std::insert_iterator<std::set<point_type> >(intersect, intersect.begin()));
1137: join->insert(intersect.begin(), intersect.end());
1138: for(typename std::set<point_type>::iterator i_iter = intersect.begin(); i_iter != intersect.end(); ++i_iter) {
1139: chain0->erase(chain0->find(*i_iter));
1140: chain1->erase(chain1->find(*i_iter));
1141: }
1142: // Replace each of the supports with the support over it, and check if either is empty; if so, return what's in join at the moment.
1143: support = this->support(chain0);
1144: chain0->insert(support->begin(), support->end());
1145: if(chain0->size() == 0) {
1146: break;
1147: }
1148: support = this->support(chain1);
1149: chain1->insert(support->begin(), support->end());
1150: if(chain1->size() == 0) {
1151: break;
1152: }
1153: // If both supports are empty, we should quit
1154: }
1155: }
1156: return join;
1157: };
1159: template <typename Point_, typename Marker_, typename Color_>
1160: template<typename ostream_type>
1161: void Sieve<Point_,Marker_,Color_>::view(ostream_type& os, const char* label = NULL, bool rawData = false){
1162: if(label != NULL) {
1163: os << "Viewing Sieve '" << label << "':" << std::endl;
1164: }
1165: else {
1166: os << "Viewing a Sieve:" << std::endl;
1167: }
1168: if(!rawData) {
1169: os << "cap --> base:" << std::endl;
1170: Obj<typename traits::capSequence> cap = this->cap();
1171: for(typename traits::capSequence::iterator capi = cap->begin(); capi != cap->end(); ++capi) {
1172: Obj<typename traits::supportSequence> supp = this->support(*capi);
1173: for(typename traits::supportSequence::iterator suppi = supp->begin(); suppi != supp->end(); ++suppi) {
1174: os << *capi << "--(" << suppi.color() << ")-->" << *suppi << std::endl;
1175: }
1176: }
1177: os << "base <-- cap:" << std::endl;
1178: Obj<typename traits::baseSequence> base = this->base();
1179: for(typename traits::baseSequence::iterator basei = base->begin(); basei != base->end(); ++basei) {
1180: Obj<typename traits::coneSequence> cone = this->cone(*basei);
1181: for(typename traits::coneSequence::iterator conei = cone->begin(); conei != cone->end(); ++conei) {
1182: os << *basei << "<--(" << conei.color() << ")--" << *conei << std::endl;
1183: }
1184: }
1185: os << "cap --> (outdegree, marker, depth, height):" << std::endl;
1186: for(typename traits::capSequence::iterator capi = cap->begin(); capi != cap->end(); ++capi) {
1187: os << *capi << "-->" << capi.degree() << ", " << capi.marker() << ", " << capi.depth() << ", " << capi.height() << std::endl;
1188: }
1189: os << "base --> (indegree, marker, depth, height):" << std::endl;
1190: for(typename traits::baseSequence::iterator basei = base->begin(); basei != base->end(); ++basei) {
1191: os << *basei << "-->" << basei.degree() << ", " << basei.marker() << ", " << basei.depth() << ", " << basei.height() << std::endl;
1192: }
1193: }
1194: else {
1195: os << "'raw' arrow set:" << std::endl;
1196: for(typename traits::arrow_container_type::set_type::iterator ai = this->_arrows.set.begin(); ai != this->_arrows.set.end(); ai++)
1197: {
1198: typename traits::arrow_type arr = *ai;
1199: os << arr << std::endl;
1200: }
1201: os << "'raw' base set:" << std::endl;
1202: for(typename traits::base_container_type::set_type::iterator bi = this->_base.set.begin(); bi != this->_base.set.end(); bi++)
1203: {
1204: typename traits::base_container_type::traits::rec_type bp = *bi;
1205: os << bp << std::endl;
1206: }
1207: os << "'raw' cap set:" << std::endl;
1208: for(typename traits::cap_container_type::set_type::iterator ci = this->_cap.set.begin(); ci != this->_cap.set.end(); ci++)
1209: {
1210: typename traits::cap_container_type::traits::rec_type cp = *ci;
1211: os << cp << std::endl;
1212: }
1213: }
1214: };
1215: template <typename Point_, typename Marker_, typename Color_>
1216: void Sieve<Point_,Marker_,Color_>::view(const char* label = NULL, MPI_Comm comm = MPI_COMM_NULL) {
1217: ostringstream txt;
1219: if (this->debug) {
1220: std::cout << "viewing a Sieve, comm = " << this->comm() << ", commRank = " << this->commRank() << std::endl;
1221: }
1222: if(label != NULL) {
1223: if(this->commRank() == 0) {
1224: txt << "viewing Sieve :'" << label << "'" << std::endl;
1225: }
1226: }
1227: else {
1228: if(this->commRank() == 0) {
1229: txt << "viewing a Sieve" << std::endl;
1230: }
1231: }
1232: if(this->commRank() == 0) {
1233: txt << "cap --> base:\n";
1234: }
1235: typename traits::capSequence cap = this->cap();
1236: typename traits::baseSequence base = this->base();
1237: if(cap.empty()) {
1238: txt << "[" << this->commRank() << "]: empty" << std::endl;
1239: }
1240: for(typename traits::capSequence::iterator capi = cap.begin(); capi != cap.end(); capi++) {
1241: const Obj<typename traits::supportSequence>& supp = this->support(*capi);
1242: const typename traits::supportSequence::iterator suppEnd = supp->end();
1244: for(typename traits::supportSequence::iterator suppi = supp->begin(); suppi != suppEnd; suppi++) {
1245: txt << "[" << this->commRank() << "]: " << *capi << "--(" << suppi.color() << ")-->" << *suppi << std::endl;
1246: }
1247: }
1248: PetscSynchronizedPrintf(this->comm(), txt.str().c_str());
1249: PetscSynchronizedFlush(this->comm());
1250: //
1251: ostringstream txt1;
1252: if(this->commRank() == 0) {
1253: txt1 << "base --> cap:\n";
1254: }
1255: if(base.empty()) {
1256: txt1 << "[" << this->commRank() << "]: empty" << std::endl;
1257: }
1258: for(typename traits::baseSequence::iterator basei = base.begin(); basei != base.end(); basei++) {
1259: const Obj<typename traits::coneSequence>& cone = this->cone(*basei);
1260: const typename traits::coneSequence::iterator coneEnd = cone->end();
1262: for(typename traits::coneSequence::iterator conei = cone->begin(); conei != coneEnd; conei++) {
1263: txt1 << "[" << this->commRank() << "]: " << *basei << "<--(" << conei.color() << ")--" << *conei << std::endl;
1264: }
1265: }
1266: //
1267: PetscSynchronizedPrintf(this->comm(), txt1.str().c_str());
1268: PetscSynchronizedFlush(this->comm());
1269: //
1270: ostringstream txt2;
1271: if(this->commRank() == 0) {
1272: txt2 << "cap <point, outdegree, marker, depth, height>:\n";
1273: }
1274: txt2 << "[" << this->commRank() << "]: [";
1275: for(typename traits::capSequence::iterator capi = cap.begin(); capi != cap.end(); capi++) {
1276: txt2 << " <" << *capi << ", " << capi.degree() << ", " << capi.marker() << ", " << capi.depth() << ", " << capi.height() << ">";
1277: }
1278: txt2 << " ]" << std::endl;
1279: //
1280: PetscSynchronizedPrintf(this->comm(), txt2.str().c_str());
1281: PetscSynchronizedFlush(this->comm());
1282: //
1283: ostringstream txt3;
1284: if(this->commRank() == 0) {
1285: txt3 << "base <point, indegree, marker, depth, height>:\n";
1286: }
1287: txt3 << "[" << this->commRank() << "]: [";
1288: for(typename traits::baseSequence::iterator basei = base.begin(); basei != base.end(); basei++) {
1289: txt3 << " <" << *basei << "," << basei.degree() << ", " << basei.marker() << ", " << basei.depth() << ", " << basei.height() << ">";
1290: }
1291: txt3 << " ]" << std::endl;
1292: //
1293: PetscSynchronizedPrintf(this->comm(), txt3.str().c_str());
1294: PetscSynchronizedFlush(this->comm());
1295: };
1296: //
1297: // Structural queries
1298: //
1299: template <typename Point_, typename Marker_, typename Color_>
1300: void Sieve<Point_,Marker_,Color_>::setMarker(const point_type& p, const marker_type& marker) {
1301: typename ::boost::multi_index::index<typename traits::base_container_type::set_type,typename traits::base_container_type::traits::pointTag>::type& bIndex = ::boost::multi_index::get<typename traits::base_container_type::traits::pointTag>(this->_base.set);
1302: typename ::boost::multi_index::index<typename traits::cap_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& cIndex = ::boost::multi_index::get<typename traits::cap_container_type::traits::pointTag>(this->_cap.set);
1304: if (bIndex.find(p) != bIndex.end()) {
1305: bIndex.modify(bIndex.find(p), changeMarker(marker));
1306: }
1307: if (cIndex.find(p) != cIndex.end()) {
1308: cIndex.modify(cIndex.find(p), changeMarker(marker));
1309: }
1310: this->_markers->insert(marker);
1311: };
1313: template <typename Point_, typename Marker_, typename Color_>
1314: template <typename Sequence>
1315: void Sieve<Point_,Marker_,Color_>::setMarker(const Obj<Sequence>& points, const marker_type& marker) {
1316: for(typename Sequence::iterator p_iter = points->begin(); p_iter != points->end(); ++p_iter) {
1317: this->setMarker(*p_iter, marker);
1318: }
1319: };
1321: template <typename Point_, typename Marker_, typename Color_>
1322: int Sieve<Point_,Marker_,Color_>::depth() {
1323: return this->maxDepth;
1324: };
1325: template <typename Point_, typename Marker_, typename Color_>
1326: int Sieve<Point_,Marker_,Color_>::depth(const point_type& p) {
1327: const typename ::boost::multi_index::index<typename traits::base_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& i = ::boost::multi_index::get<typename traits::base_container_type::traits::pointTag>(this->_base.set);
1328: if (i.find(p) != i.end()) {
1329: return i.find(p)->depth;
1330: }
1331: return 0;
1332: };
1333: template <typename Point_, typename Marker_, typename Color_>
1334: template<typename InputSequence>
1335: int Sieve<Point_,Marker_,Color_>::depth(const Obj<InputSequence>& points) {
1336: const typename ::boost::multi_index::index<typename traits::base_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& i = ::boost::multi_index::get<typename traits::base_container_type::traits::pointTag>(this->_base.set);
1337: int maxDepth = 0;
1338:
1339: for(typename InputSequence::iterator iter = points->begin(); iter != points->end(); ++iter) {
1340: if (i.find(*iter) != i.end()) {
1341: maxDepth = std::max(maxDepth, i.find(*iter)->depth);
1342: }
1343: }
1344: return maxDepth;
1345: };
1346: template <typename Point_, typename Marker_, typename Color_>
1347: int Sieve<Point_,Marker_,Color_>::height() {
1348: return this->maxHeight;
1349: };
1350: template <typename Point_, typename Marker_, typename Color_>
1351: int Sieve<Point_,Marker_,Color_>::height(const point_type& p) {
1352: const typename ::boost::multi_index::index<typename traits::cap_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& i = ::boost::multi_index::get<typename traits::cap_container_type::traits::pointTag>(this->_cap.set);
1353: if (i.find(p) != i.end()) {
1354: return i.find(p)->height;
1355: }
1356: return 0;
1357: };
1358: template <typename Point_, typename Marker_, typename Color_>
1359: template<typename InputSequence>
1360: int Sieve<Point_,Marker_,Color_>::height(const Obj<InputSequence>& points) {
1361: const typename ::boost::multi_index::index<typename traits::cap_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& i = ::boost::multi_index::get<typename traits::cap_container_type::traits::pointTag>(this->_cap.set);
1362: int maxHeight = 0;
1363:
1364: for(typename InputSequence::iterator iter = points->begin(); iter != points->end(); ++iter) {
1365: if (i.find(*iter) != i.end()) {
1366: maxHeight = std::max(maxHeight, i.find(*iter)->height);
1367: }
1368: }
1369: return maxHeight;
1370: };
1372: template <typename Point_, typename Marker_, typename Color_>
1373: int Sieve<Point_,Marker_,Color_>::diameter() {
1374: int globalDiameter;
1375: int MPI_Allreduce(&this->graphDiameter, &globalDiameter, 1, MPI_INT, MPI_MAX, this->comm());
1376: CHKMPIERROR(ierr, ERRORMSG("Error in MPI_Allreduce"));
1377: return globalDiameter;
1378: };
1379: template <typename Point_, typename Marker_, typename Color_>
1380: int Sieve<Point_,Marker_,Color_>::diameter(const point_type& p) {
1381: return this->depth(p) + this->height(p);
1382: };
1384: template <typename Point_, typename Marker_, typename Color_>
1385: Obj<typename Sieve<Point_,Marker_,Color_>::traits::depthSequence> Sieve<Point_,Marker_,Color_>::depthStratum(int d) {
1386: if (d == 0) {
1387: return typename traits::depthSequence(::boost::multi_index::get<typename traits::cap_container_type::traits::depthMarkerTag>(this->_cap.set), d);
1388: } else {
1389: return typename traits::depthSequence(::boost::multi_index::get<typename traits::base_container_type::traits::depthMarkerTag>(this->_base.set), d);
1390: }
1391: };
1392: template <typename Point_, typename Marker_, typename Color_>
1393: Obj<typename Sieve<Point_,Marker_,Color_>::traits::depthSequence> Sieve<Point_,Marker_,Color_>::depthStratum(int d, marker_type m) {
1394: if (d == 0) {
1395: return typename traits::depthSequence(::boost::multi_index::get<typename traits::cap_container_type::traits::depthMarkerTag>(this->_cap.set), d, m);
1396: } else {
1397: return typename traits::depthSequence(::boost::multi_index::get<typename traits::base_container_type::traits::depthMarkerTag>(this->_base.set), d, m);
1398: }
1399: };
1400: template <typename Point_, typename Marker_, typename Color_>
1401: Obj<typename Sieve<Point_,Marker_,Color_>::traits::heightSequence> Sieve<Point_,Marker_,Color_>::heightStratum(int h) {
1402: if (h == 0) {
1403: return typename traits::heightSequence(::boost::multi_index::get<typename traits::base_container_type::traits::heightMarkerTag>(this->_base.set), h);
1404: } else {
1405: return typename traits::heightSequence(::boost::multi_index::get<typename traits::cap_container_type::traits::heightMarkerTag>(this->_cap.set), h);
1406: }
1407: };
1408: template <typename Point_, typename Marker_, typename Color_>
1409: Obj<typename Sieve<Point_,Marker_,Color_>::traits::heightSequence> Sieve<Point_,Marker_,Color_>::heightStratum(int h, marker_type m) {
1410: if (h == 0) {
1411: return typename traits::heightSequence(::boost::multi_index::get<typename traits::base_container_type::traits::heightMarkerTag>(this->_base.set), h, m);
1412: } else {
1413: return typename traits::heightSequence(::boost::multi_index::get<typename traits::cap_container_type::traits::heightMarkerTag>(this->_cap.set), h, m);
1414: }
1415: };
1416: template <typename Point_, typename Marker_, typename Color_>
1417: template<class InputSequence>
1418: void Sieve<Point_,Marker_,Color_>::__computeClosureHeights(const Obj<InputSequence>& points) {
1419: typename ::boost::multi_index::index<typename traits::cap_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& index = ::boost::multi_index::get<typename traits::cap_container_type::traits::pointTag>(this->_cap.set);
1420: typename ::boost::multi_index::index<typename traits::base_container_type::set_type,typename traits::base_container_type::traits::pointTag>::type& bIndex = ::boost::multi_index::get<typename traits::base_container_type::traits::pointTag>(this->_base.set);
1421: Obj<coneSet> modifiedPoints = coneSet();
1422:
1423: for(typename InputSequence::iterator p_itor = points->begin(); p_itor != points->end(); ++p_itor) {
1424: // Compute the max height of the points in the support of p, and add 1
1425: int h0 = this->height(*p_itor);
1426: int h1 = this->height(this->support(*p_itor)) + 1;
1427: if(h1 != h0) {
1428: typename ::boost::multi_index::index<typename traits::base_container_type::set_type,typename traits::base_container_type::traits::pointTag>::type::iterator bIter = bIndex.find(*p_itor);
1430: index.modify(index.find(*p_itor), changeHeight(h1));
1431: if (bIter != bIndex.end()) {
1432: bIndex.modify(bIter, changeHeight(h1));
1433: }
1434: if (h1 > this->maxHeight) this->maxHeight = h1;
1435: modifiedPoints->insert(*p_itor);
1436: }
1437: }
1438: // FIX: We would like to avoid the copy here with cone()
1439: if(modifiedPoints->size() > 0) {
1440: this->__computeClosureHeights(this->cone(modifiedPoints));
1441: }
1442: };
1443: template <typename Point_, typename Marker_, typename Color_>
1444: template<class InputSequence>
1445: void Sieve<Point_,Marker_,Color_>::__computeStarDepths(const Obj<InputSequence>& points) {
1446: typename ::boost::multi_index::index<typename traits::base_container_type::set_type,typename traits::base_container_type::traits::pointTag>::type& index = ::boost::multi_index::get<typename traits::base_container_type::traits::pointTag>(this->_base.set);
1447: typename ::boost::multi_index::index<typename traits::cap_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type& cIndex = ::boost::multi_index::get<typename traits::cap_container_type::traits::pointTag>(this->_cap.set);
1448: Obj<supportSet> modifiedPoints = supportSet();
1449: for(typename InputSequence::iterator p_itor = points->begin(); p_itor != points->end(); ++p_itor) {
1450: // Compute the max depth of the points in the support of p, and add 1
1451: int d0 = this->depth(*p_itor);
1452: int d1 = this->depth(this->cone(*p_itor)) + 1;
1453: if(d1 != d0) {
1454: typename ::boost::multi_index::index<typename traits::cap_container_type::set_type,typename traits::cap_container_type::traits::pointTag>::type::iterator cIter = cIndex.find(*p_itor);
1456: index.modify(index.find(*p_itor), changeDepth(d1));
1457: if (cIter != cIndex.end()) {
1458: cIndex.modify(cIter, changeDepth(d1));
1459: }
1460: if (d1 > this->maxDepth) this->maxDepth = d1;
1461: modifiedPoints->insert(*p_itor);
1462: }
1463: }
1464: // FIX: We would like to avoid the copy here with cone()
1465: if(modifiedPoints->size() > 0) {
1466: this->__computeStarDepths(this->support(modifiedPoints));
1467: }
1468: };
1471: template <typename Point_, typename Marker_, typename Color_>
1472: void Sieve<Point_,Marker_,Color_>::stratify(bool show) {
1473: ALE_LOG_EVENT_BEGIN;
1474: // FIX: We would like to avoid the copy here with cone() and support()
1475: this->__computeClosureHeights(this->cone(this->leaves()));
1476: this->__computeStarDepths(this->support(this->roots()));
1477:
1478: Obj<typename traits::capSequence> base = this->base();
1480: for(typename traits::baseSequence::iterator b_iter = base->begin(); b_iter != base->end(); ++b_iter) {
1481: maxDepth = std::max(maxDepth, b_iter.depth());
1482: //b_iter.setDegree(this->cone(*b_iter)->size());
1483: this->_base.adjustDegree(*b_iter, this->cone(*b_iter)->size());
1484: }
1485: Obj<typename traits::capSequence> cap = this->cap();
1487: for(typename traits::capSequence::iterator c_iter = cap->begin(); c_iter != cap->end(); ++c_iter) {
1488: maxHeight = std::max(maxHeight, c_iter.height());
1489: //c_iter.setDegree(this->support(*c_iter)->size());
1490: this->_cap.adjustDegree(*c_iter, this->support(*c_iter)->size());
1491: }
1492: if (this->debug || show) {
1493: // const typename ::boost::multi_index::index<StratumSet,point>::type& points = ::boost::multi_index::get<point>(this->strata);
1494: // for(typename ::boost::multi_index::index<StratumSet,point>::type::iterator i = points.begin(); i != points.end(); i++) {
1495: // std::cout << *i << std::endl;
1496: // }
1497: }
1498: ALE_LOG_EVENT_END;
1499: };
1500: //
1501: // Structural manipulation
1502: //
1503:
1504: } // namespace ALE
1506: #endif