23 #include "SheafSystem/poset_joiner.h" 24 #include "SheafSystem/assert_contract.h" 26 #include "SheafSystem/abstract_poset_member.h" 27 #include "SheafSystem/error_message.h" 28 #include "SheafSystem/unordered_set_filter.h" 29 #include "SheafSystem/total_poset_member.h" 30 #include "SheafSystem/poset_state_handle.h" 31 #include "SheafSystem/scoped_index.h" 32 #include "SheafSystem/set_filter.h" 33 #include "SheafSystem/std_algorithm.h" 34 #include "SheafSystem/std_unordered_set.h" 35 #include "SheafSystem/std_set.h" 36 #include "SheafSystem/tern.h" 37 #include "SheafSystem/triorder_itr.h" 39 using namespace sheaf;
54 #undef USE_IS_IMPLICIT 65 typedef unordered_set<pod_index_type> uset_type;
70 typedef set<pod_index_type> oset_type;
80 bool is_singleton(
const uset_type& xset)
82 return (++xset.begin() == xset.end());
92 crg_itr_type& xdown_itr)
96 require(xdown_itr.is_initialized());
102 xdown_itr.put_anchor(xindex);
105 while(!xdown_itr.is_done())
107 if(xdown_itr.action() == crg_itr_type::POSTVISIT_ACTION)
109 xgdown.insert(xdown_itr.index().hub_pod());
110 if(lhost->is_atom(xdown_itr.index()))
112 xatoms.insert(xdown_itr.index().hub_pod());
134 crg_itr_type& xdown_itr,
139 require(xdown_itr.is_initialized());
143 #ifdef USE_IS_IMPLICIT 147 xdown_itr.put_anchor(xindex);
150 while(!xdown_itr.is_done())
152 switch(xdown_itr.action())
154 case crg_itr_type::LINK_ACTION:
156 xall_implicit = xall_implicit && xdown_itr.link_is_implicit();
159 case crg_itr_type::POSTVISIT_ACTION:
161 xgdown.insert(xdown_itr.index().hub_pod());
162 if(lhost->is_atom(xdown_itr.index()))
164 xatoms.insert(xdown_itr.index().hub_pod());
196 crg_itr_type& xdown_itr)
202 require(xgdown.empty());
203 require(xatoms.empty());
204 require(xdown_itr.is_initialized());
215 xdown_itr.clear_has_visited();
217 for(
int i = 0; i < xexpansion_ct; i++)
219 compute_atoms(xexpansion[i], xgdown, xatoms, xdown_itr);
222 #ifdef DIAGNOSTIC_OUTPUT 223 cout <<
"compute_atoms(): " << endl;
224 cout <<
"joinands: ";
226 for(
int i = 0; i < xexpansion_ct; i++)
228 cout << xexpansion[i];
233 for(uset_type::iterator i=xgdown.begin(); i!=xgdown.end(); ++i)
235 cout << setw(6) << *i;
240 for(uset_type::iterator i=xatoms.begin(); i!=xatoms.end(); ++i)
242 cout << setw(6) << *i;
249 ensure(unexecutable(
"xgdown contains the downset of xexpansion"));
250 ensure(unexecutable(
"xatoms contains the atoms in the downset of xexpansion"));
255 require(unexecutable(
"for all m in down set of xexpansion: xdown_itr.has_visited(m)"));
274 crg_itr_type& xdown_itr,
281 require(xgdown.empty());
282 require(xatoms.empty());
283 require(xdown_itr.is_initialized());
294 xdown_itr.clear_has_visited();
296 for(
int i = 0; i < xexpansion_ct; i++)
298 compute_atoms(xexpansion[i], xgdown, xatoms, xdown_itr, xall_implicit);
301 #ifdef DIAGNOSTIC_OUTPUT 302 cout <<
"compute_atoms(): " << endl;
303 cout <<
"joinands: ";
305 for(
int i = 0; i < xexpansion_ct; i++)
307 cout << xexpansion[i];
312 for(uset_type::iterator i=xgdown.begin(); i!=xgdown.end(); ++i)
314 cout << setw(6) << *i;
319 for(uset_type::iterator i=xatoms.begin(); i!=xatoms.end(); ++i)
321 cout << setw(6) << *i;
328 ensure(unexecutable(
"xgdown contains the downset of xexpansion"));
329 ensure(unexecutable(
"xatoms contains the atoms in the downset of xexpansion"));
334 require(unexecutable(
"for all m in down set of xexpansion: xdown_itr.has_visited(m)"));
351 crg_itr_type& xdown_itr)
357 require(xgdown.empty());
358 require(xatoms.empty());
359 require(xdown_itr.is_initialized());
370 xdown_itr.clear_has_visited();
375 compute_atoms(litr.
index(), xgdown, xatoms, xdown_itr);
379 #ifdef DIAGNOSTIC_OUTPUT 380 cout <<
"compute_atoms(): " << endl;
381 cout <<
"joinands: ";
386 cout << litr.
index();
392 for(uset_type::iterator i=xgdown.begin(); i!=xgdown.end(); ++i)
394 cout << setw(6) << *i;
399 for(uset_type::iterator i=xatoms.begin(); i!=xatoms.end(); ++i)
401 cout << setw(6) << *i;
409 ensure(unexecutable(
"gdown() contains the downset of xexpansion"));
410 ensure(unexecutable(
"atoms() contains the atoms in the downset of xexpansion"));
415 require(unexecutable(
"for all m in down set of xexpansion: xdown_itr.has_visited(m)"));
432 crg_itr_type& xdown_itr,
439 require(xgdown.empty());
440 require(xatoms.empty());
441 require(xdown_itr.is_initialized());
452 xdown_itr.clear_has_visited();
457 compute_atoms(litr.
index(), xgdown, xatoms, xdown_itr, xall_implicit);
461 #ifdef DIAGNOSTIC_OUTPUT 462 cout <<
"compute_atoms(): " << endl;
463 cout <<
"joinands: ";
468 cout << litr.
index();
474 for(uset_type::iterator i=xgdown.begin(); i!=xgdown.end(); ++i)
476 cout << setw(6) << *i;
481 for(uset_type::iterator i=xatoms.begin(); i!=xatoms.end(); ++i)
483 cout << setw(6) << *i;
491 ensure(unexecutable(
"gdown() contains the downset of xexpansion"));
492 ensure(unexecutable(
"atoms() contains the atoms in the downset of xexpansion"));
497 require(unexecutable(
"for all m in down set of xexpansion: xdown_itr.has_visited(m)"));
513 update_gdown(
const scoped_index& xindex, uset_type& xgdown, crg_itr_type& xdown_itr)
523 result = (xgdown.find(xindex.
hub_pod()) != xgdown.end());
525 if(!result && !lhost->
is_jim(xindex) && !xdown_itr.has_visited(xindex))
531 stack<bool> ladd_to_gdown;
533 xdown_itr.put_anchor(xindex);
536 while(!xdown_itr.is_done())
538 bool lforce_is_done =
false;
539 bool ltruncate =
false;
541 switch(xdown_itr.action())
543 case crg_itr_type::PREVISIT_ACTION:
556 bool lis_jim = lhost->
is_jim(xdown_itr.index());
558 ladd_to_gdown.push(!lis_jim);
563 case crg_itr_type::LINK_ACTION:
567 ladd_to_gdown.top() =
568 ladd_to_gdown.top() &&
569 (xgdown.find(xdown_itr.lesser_index().hub_pod()) != xgdown.end());
573 case crg_itr_type::POSTVISIT_ACTION:
575 if(ladd_to_gdown.top())
579 xgdown.insert(xdown_itr.index().hub_pod());
588 lforce_is_done =
true;
600 xdown_itr.force_is_done();
604 xdown_itr.next(ltruncate);
620 compute_mlb(uset_type& xgdown,
622 crg_itr_type& xdown_itr,
623 crg_itr_type& xup_itr,
630 require(xdown_itr.is_initialized());
635 require(unexecutable(
"for all m in down set of joinands: xdown_itr.has_visited(m)"));
637 require(xup_itr.is_initialized());
638 require(xmlb.empty());
642 stack<bool> lis_maximal;
648 xup_itr.clear_has_visited();
650 for(uset_type::iterator itr = xatoms.begin(); itr != xatoms.end(); itr++)
653 xup_itr.put_anchor(litem);
656 while(!xup_itr.is_done())
658 bool ltruncate =
false;
660 switch(xup_itr.action())
662 case crg_itr_type::PREVISIT_ACTION:
668 bool lis_in_gdown = update_gdown(xup_itr.index(), xgdown, xdown_itr);
675 lis_maximal.push(lis_in_gdown);
680 ltruncate = !lis_in_gdown;
685 case crg_itr_type::LINK_ACTION:
693 (xgdown.find(xup_itr.lesser_index().hub_pod()) == xgdown.end());
697 case crg_itr_type::POSTVISIT_ACTION:
699 if(lis_maximal.top())
703 xmlb.insert(xup_itr.index().hub_pod());
714 xup_itr.next(ltruncate);
718 #ifdef DIAGNOSTIC_OUTPUT 719 cout <<
"compute_mlb:" << endl;
721 for(uset_type::iterator i=xgdown.begin(); i!=xgdown.end(); ++i)
723 cout << setw(6) << *i;
728 for(uset_type::iterator i=xmlb.begin(); i!=xmlb.end(); ++i)
730 cout << setw(6) << *i;
737 ensure(unexecutable(
"result contains mlb(g) in internal scope"));
749 compute_minimals(crg_itr_type& xup_itr, oset_type& xmub)
753 require(unexecutable(
"xmub is in internal scope"));
759 xup_itr.put_visit_once(
true);
760 xup_itr.put_strict(
true);
761 xup_itr.clear_has_visited();
765 for(oset_type::iterator litr = xmub.begin(); litr != xmub.end(); litr++)
771 xup_itr.put_anchor(litem);
776 while(!xup_itr.is_done())
778 if(xup_itr.action() == crg_itr_type::POSTVISIT_ACTION)
783 assertion(xup_itr.index().hub_pod() != *litr);
785 xmub.erase(xup_itr.index().hub_pod());
794 xup_itr.put_has_visited(litem,
false);
809 intersect(
const oset_type& xset, oset_type& xresult)
817 oset_type::iterator ritr = xresult.begin();
818 oset_type::const_iterator sitr = xset.begin();
819 oset_type::iterator tmp;
822 oset_type::value_type rmbr, smbr;
824 while(ritr != xresult.end() && sitr != xset.end())
841 else if( rmbr == smbr )
862 if(ritr != xresult.end())
864 xresult.erase(ritr, xresult.end());
879 compute_mub(uset_type& xmlb, crg_itr_type& xup_itr, oset_type& xmub)
885 require(xup_itr.is_initialized());
886 require(xmub.empty());
893 xup_itr.put_strict(
true);
894 xup_itr.put_visit_once(
false);
895 xup_itr.clear_has_visited();
898 for(uset_type::iterator itr = xmlb.begin(); itr != xmlb.end(); ++itr)
902 xup_itr.put_anchor(litem);
909 while(!xup_itr.is_done())
911 if(xup_itr.action() == crg_itr_type::POSTVISIT_ACTION)
913 xmub.insert(xup_itr.index().hub_pod());
925 while(!xup_itr.is_done())
927 if(xup_itr.action() == crg_itr_type::POSTVISIT_ACTION)
929 ltmp_set.insert(xup_itr.index().hub_pod());
934 intersect(ltmp_set, xmub);
938 #ifdef DIAGNOSTIC_OUTPUT 939 cout <<
"compute_mub:" << endl;
941 for(oset_type::iterator i=xmub.begin(); i!=xmub.end(); ++i)
943 cout << setw(6) << *i;
950 compute_minimals(xup_itr, xmub);
952 #ifdef DIAGNOSTIC_OUTPUT 953 cout <<
"xmub after compute_minimals: ";
954 for(oset_type::iterator i=xmub.begin(); i!=xmub.end(); ++i)
956 cout << setw(6) << *i;
963 ensure(unexecutable(
"result contains mub(g) in internal scope"));
977 link_result(
const uset_type& xresult_lc,
const oset_type& xresult_uc,
abstract_poset_member& xresult)
985 #ifdef DIAGNOSTIC_OUTPUT 986 cout <<
"link_result:" << endl;
987 cout <<
"xresult_lc: ";
988 for(uset_type::iterator i=xresult_lc.begin(); i!=xresult_lc.end(); ++i)
990 cout << setw(6) << *i;
994 cout <<
"xresult_uc: ";
995 for(oset_type::iterator i=xresult_uc.begin(); i!=xresult_uc.end(); ++i)
997 cout << setw(6) << *i;
1010 for(oset_type::const_iterator litr = xresult_uc.begin(); litr != xresult_uc.end(); ++litr)
1032 for(uset_type::const_iterator litr = xresult_lc.begin(); litr != xresult_lc.end(); ++litr)
1108 const uset_type& xmlb,
1109 const tern& xgreatest,
1117 require(is_singleton(xmlb));
1161 const uset_type& xmlb,
1162 const oset_type& xmub,
1163 const tern& xgreatest,
1171 require(!xmlb.empty());
1172 require(!is_singleton(xmlb));
1173 require(!xmub.empty());
1186 link_result(xmlb, xmub, xresult);
1211 require(xhost != 0);
1220 ensure(host() == xhost);
1237 const tern& xgreatest,
1284 uset_type lmax_gdown;
1292 #ifdef USE_IS_IMPLICIT 1294 bool lall_implicit =
true;
1298 compute_atoms(xexpansion, xexpansion_ct, lgdown, latoms, ldown_itr, lall_implicit);
1309 for(
int i=0; i<xexpansion_ct; ++i)
1311 lmlb.insert(xexpansion[i].hub_pod());
1318 compute_mlb(lgdown, latoms, ldown_itr, lup_itr, lmlb);
1325 compute_atoms(xexpansion, xexpansion_ct, lgdown, latoms, ldown_itr);
1329 compute_mlb(lgdown, latoms, ldown_itr, lup_itr, lmlb);
1338 attach_result(host(), xgreatest, xresult);
1340 else if(is_singleton(lmlb))
1346 attach_result(host(), lmlb, xgreatest, xresult);
1353 compute_mub(lmlb, lup_itr, lmub);
1357 attach_result(host(), lmlb, lmub, xgreatest, xresult);
1363 ensure(unexecutable(
"result is join of xexpansion"));
1383 uset_type lmax_gdown;
1391 #ifdef USE_IS_IMPLICIT 1393 bool lall_implicit =
true;
1397 compute_atoms(xexpansion, lgdown, latoms, ldown_itr, lall_implicit);
1411 lmlb.insert(litr.
index());
1419 compute_mlb(lgdown, latoms, ldown_itr, lup_itr, lmlb);
1426 compute_atoms(xexpansion, lgdown, latoms, ldown_itr);
1430 compute_mlb(lgdown, latoms, ldown_itr, lup_itr, lmlb);
1439 attach_result(host(), xgreatest, xresult);
1441 else if(is_singleton(lmlb))
1447 attach_result(host(), lmlb, xgreatest, xresult);
1454 compute_mub(lmlb, lup_itr, lmub);
1458 attach_result(host(), lmlb, lmub, xgreatest, xresult);
1463 ensure(unexecutable(
"result is join of xexpansion"));
poset_state_handle * host() const
The poset which this is a handle to a component of.
void remove_cover_members(const filter_type &xfilter, bool xlower, pod_index_type xmbr_hub_id)
Removes all members for which functor xfilter(xmbr.index().hub_pod()) is true from the lower (xlower ...
A client handle for a subposet.
void insert_cover_member(pod_index_type xother_mbr_hub_id, bool xlower, pod_index_type xmbr_hub_id)
Inserts hub id xother_mbr_hub id in the lower (xlower true) or upper (xlower false) cover set of the ...
bool state_is_read_accessible() const
True if this is attached and if the state is accessible for read or access control is disabled...
bool is_true() const
True if thi has value true.
A three state "bool". Does not provide the operations of ternary logic and is intended for use mostly...
A client handle for a general, abstract partially order set.
void insert_cover_member(pod_index_type xother_mbr_index, bool xlower)
Inserts xother_mbr_index in the lower (xlower true) or upper (xlower false) cover set of this...
const scoped_index & index() const
The current item in the subset.
Set implementation of filter concept.
const scoped_index & index() const
The index of the component state this handle is attached to.
abstract_poset_member & bottom()
The bottom member of the poset (mutable version)
namespace_poset * host() const
The namespace this poset resides in. Obsolete; use name_space() instead.
virtual pod_index_type new_member(bool xis_jim, pod_index_type xtuple_hub_id)
Create a disconnected member with is_jim == xis_jim and the dof tuple identified by hub id xtuple_hub...
void next()
Makes item the next member of the subset.
~poset_joiner()
Destructor; not virtual, can not be base class.
Hash set implementation of filter concept.
const bool NOT_STRICT
Iteration strictness control.
const bool DOWN
Iteration directions.
Specialization of the filtered depth-first iterator which exposes all three actions to the client; th...
bool state_is_read_write_accessible() const
True if this is attached and if the state is accessible for read and write or access control is disab...
poset_state_handle * host() const
The host poset.
poset_joiner(const poset_state_handle *xhost)
Creates a joiner for poset xhost.
An index within the external ("client") scope of a given id space.
virtual bool is_attached() const
True if this handle is attached to a non-void state.
void join(const scoped_index *xexpansion, int xexpansion_ct, const tern &xgreatest, abstract_poset_member &xresult)
The join of the members of xexpansion.
const bool UPPER
Selector for upper cover.
const bool UP
Iteration directions.
const bool NO_RESET
Iteration marker reset control.
Iterates over the subset of Zn defined by the characteristic function host().
const bool LOWER
Selector for lower cover.
bool is_false() const
True if this has value false.
int_type pod_index_type
The plain old data index type.
bool is_done() const
True if iteration finished.
Namespace for the sheaves component of the sheaf system.
virtual bool is_jim(pod_index_type xmbr_hub_id, bool xin_current_version=true) const
True if the member with hub id xmbr_hub_id is a jim in the current version (xin_current_version == tr...
void attach_to_state(const namespace_poset *xns, const poset_path &xpath, bool xauto_access=true)
Attach to the state specified by path xpath in the namespace xns.
An abstract client handle for a member of a poset.
virtual void new_jem_state(abstract_poset_member *xother, bool xgreatest, bool xauto_access)
Creates a new jrm state in host() which is the greatest jem (xgreatest true) or least jem (xgreatest ...
void reset()
Restarts the iteration, makes item the first member of the subset.
virtual index_iterator indexed_member_iterator() const
An iterator for members of this poset; index version.
virtual const scoped_index & member_id(bool xauto_access) const
An id in the member hub id space; intended for copying to initialize ids to the member id space...
pod_type hub_pod() const
The pod value of this mapped to the unglued hub id space.