44 #include "print_macros.h" 48 #define DBG_SORTOR_PRT(prm1, prm2) ; 50 #define SORTER_DBG(prm) DBG(prm) 51 #define SORTER_CK(prm) DBG_CK(prm) 52 #define SORTER_CK_PRT(prm, comms1) DBG_CK_2(prm, comms1) 54 #define SORTER_CK_1(prm) DBG_CK(prm) 55 #define SORTER_CK_2(prm) DBG_CK(prm) 57 #define PHASE_1_COMMENT "phase_one\n" 58 #define PHASE_2_COMMENT "phase_two\n" 59 #define PHASE_3_COMMENT "phase_three\n" 61 #define FINAL_COMMENT "final\n" 62 #define MUTUAL_COMMENT "mutual_stab\n" 78 typedef bj_big_int_t sort_id_t;
79 typedef row<sort_id_t> row_sort_id_t;
85 DECLARE_PRINT_FUNCS(
sortee)
86 DECLARE_PRINT_FUNCS(
sorset)
91 sortee& as_sortee(binder* bdr);
93 template<class obj_t1>
94 obj_t1& as_srt_of(binder* bdr);
113 row<sortee*> so_mates;
123 void init_sortrel(
bool free_mem =
false){
124 so_mates.clear(free_mem, free_mem);
125 so_opposite = NULL_PT;
128 bool ck_related(
long tee_cons);
142 comparison cmp_sortees(
sortee*
const & srt1,
sortee*
const & srt2);
158 char* get_cls_name(){
159 return sortee::CL_NAME;
165 long so_sorset_consec;
170 char so_dbg_me_class;
171 long so_dbg_extrn_id;
185 DBG(so_ccl.cc_in_free =
true);
188 void init_sortee(
bool free_mem =
false){
190 so_cmp_val = NULL_PT;
192 so_sorset_consec = INVALID_NATURAL;
193 so_walk_consec = INVALID_NATURAL;
195 so_related = NULL_PT;
201 so_wlk_consec = INVALID_NATURAL;
202 so_tee_consec = INVALID_NATURAL;
203 so_ccl.cc_clear(free_mem);
208 template<
class obj_t1>
211 SORTER_CK_1(so_me != NULL_PT);
212 obj_t1& obj = *((obj_t1*)(so_me));
213 SORTER_CK_1(obj.get_cls_name() == obj_t1::CL_NAME);
218 return (is_alone() && ! has_vessel());
224 return (so_vessel != NULL_PT);
229 void sort_from(
sort_glb& srg, sort_id_t curr_nid,
void* id_src = NULL_PT);
236 void update_totals(
sort_glb& srg,
long tgt_sz);
242 SORTER_CK(so_me != NULL_PT);
243 SORTER_CK(so_related != NULL_PT);
244 SORTER_CK(so_related->so_opposite != NULL_PT);
245 return *(so_related->so_opposite);
248 long get_target_sz(tgt_ccl_t tt){
249 SORTER_CK(so_me != NULL_PT);
250 SORTER_CK(so_related != NULL_PT);
252 SORTER_CK(tt != tc_none);
255 the_sz = so_related->so_mates.size();
260 void reset_sort_info(){
261 SORTER_CK(is_unsorted());
265 if(so_related != NULL_PT){
267 SORTER_CK(quar.so_opposite != NULL_PT);
268 quar.so_mates.clear();
271 so_ccl.cc_clear(
false);
275 bool is_next_choice(
sort_glb& srg1);
277 bj_ostream& print_sortee(bj_ostream& os,
bool from_pt =
false);
280 template<
class obj_t1>
282 tees_row_as(row<sortee*>& rr1, row<obj_t1*>& rr2){
283 long last_item_id = INVALID_NATURAL;
284 bool all_consec =
true;
286 rr2.set_cap(rr1.size());
287 for(
long ii = 0; ii < rr1.size(); ii++){
293 all_consec = all_consec && (last_item_id != srt.so_sorset_consec);
294 last_item_id = srt.so_sorset_consec;
296 obj_t1& obj_1 = srt.me_as<obj_t1>();
302 template<
class obj_t1>
304 srt_row_as_colors(
sort_glb& srg, row<sortee*>& rr1, row<obj_t1*>& rr2, row<long>& cols,
305 tee_id_t consec_kk,
bool unique_ccls);
317 typedef bool (
sorset::*cond_mth)();
319 typedef receptor<sorset> ss_srs_t;
327 char* get_cls_name(){
328 return sorset::CL_NAME;
337 sort_id_t ss_curr_id;
351 ss_parent_set = NULL_PT;
352 ss_sub_rcp.re_me =
this;
353 SORTER_CK(ss_sub_rcp.is_alone());
355 SORTER_CK(ss_items.is_alone());
356 SORTER_CK(ss_subsets.is_alone());
368 bool is_ss_virgin(
bool ck_items =
true);
370 sorset& get_next_vessel(
sort_glb& srg, sort_id_t curr_id,
void* id_src);
373 void fill_srs_trails(row_sort_id_t& id_trl, row<void*>& src_trl);
375 bool has_ss_parent(){
376 return (ss_parent_set != NULL_PT);
380 return ! ss_items.is_alone();
384 return ! ss_subsets.is_alone();
388 return ! ss_sub_rcp.is_alone();
392 return ss_items.is_single();
396 return ss_items.is_multiple();
400 return ss_subsets.is_single();
403 bool can_sort_in_me(){
404 bool ok = (! has_subsets() ||
405 (one_subset() && (first_subset().ss_curr_id == ss_curr_id)));
410 bool c1 = ! has_subsets();
411 bool c2 = ! has_ss_parent();
412 bool c3 = has_items();
413 return (c1 && c2 && c3);
417 bool c1 = (! has_ss_parent());
418 bool c2 = (! has_items());
419 bool c3 = (! ss_has_val);
420 bool c4 = (! has_brothers());
421 bool all_c = (c1 && c2 && c3 && c4);
426 SORTER_CK(has_subsets());
427 sorset& fst = rcp_as<sorset>(ss_subsets.bn_right);
432 SORTER_CK(has_items());
433 sortee& fst = as_sortee(ss_items.bn_right);
438 SORTER_CK(has_items());
439 sortee& lst = as_sortee(ss_items.bn_left);
449 bool is_single_leaf(){
450 return (! has_subsets() && ss_items.is_single());
453 void set_item_id(sort_id_t the_val,
void* val_src){
454 SORTER_CK(the_val > 0);
455 SORTER_CK(! ss_has_val);
457 ss_curr_id = the_val;
461 bool in_item_id(sort_id_t target_id){
465 SORTER_CK(target_id > 0);
466 SORTER_CK(ss_curr_id != 0);
467 SORTER_CK(target_id >= ss_curr_id);
468 bool in_the_id = (ss_curr_id == target_id);
475 while(srs != NULL_PT){
477 srs = srs->ss_parent_set;
482 bool contained_by(
sorset& vsl_srs){
484 while(srs != NULL_PT){
488 srs = srs->ss_parent_set;
495 void step_stabilize_rec(
sort_glb& srg);
498 void unsort_all_items(
sort_glb& srg);
500 void walk_reset_values(
sort_glb& srg, grip& flat_ss);
515 void walk_to_srs_row(row<sorset*>& sorted){
518 walk_to_srs_row_rec(consec, sorted);
521 void walk_to_srs_row_rec(
long& consec, row<sorset*>& sorted);
523 bool ck_all_items_same_qua_id();
524 void set_all_items_qua_id(
long qu_id);
526 void print_data_sorset(bj_ostream& os);
527 void print_tree_sorset(bj_ostream& os,
long level);
528 bj_ostream& print_sorset(bj_ostream& os,
bool from_pt =
false);
533 cmp_sorset_trails(row_sort_id_t& ids1, row_sort_id_t& ids2);
539 srs_row_as_clauses(
sort_glb& srg, row<sorset*>& rr1, row<canon_clause*>& rr2);
543 srs_row_get_first_tees(row<sorset*>& rr1, row<sortee*>& rr2){
545 rr2.set_cap(rr1.size());
547 for(
long ii = 0; ii < rr1.size(); ii++){
549 SORTER_CK(srs.has_items());
551 sortee& srt = srs.first_item();
571 enum step_mutual_op_t {
589 bool sg_dbg_always_find_filled;
591 k_row<sorset> sg_sorsets;
592 row<sorset*> sg_free_sorsets;
596 row<sortee*> sg_prt_srts;
598 long sg_num_active_ss;
603 sort_id_t sg_tot_stab_steps;
604 sort_id_t sg_curr_stab_consec;
605 bool sg_one_ccl_per_ss;
608 step_op_t sg_step_op;
609 bool sg_step_has_confl;
611 bool sg_step_has_diff;
612 bool sg_step_all_consec;
613 row<sortee*> sg_step_sortees;
614 row<sorset*> sg_step_sorsets;
615 row<sorset*> sg_step_prv_sorsets;
616 sorset* sg_step_first_multiple;
617 sortee* sg_step_next_choice;
619 row<sorset*> sg_step_neg_sorsets;
620 row<sorset*> sg_step_pos_sorsets;
622 step_mutual_op_t sg_step_mutual_op;
623 row<canon_clause*> sg_step_mutual_clauses;
625 long sg_tot_ss_marks;
632 long sg_dbg_fst_num_items;
633 long sg_dbg_num_items;
635 long sg_dbg_num_saved_consec;
636 bool sg_dbg_has_repeated_ids;
638 sort_id_t sg_dbg_last_id;
642 row<sortee*> sg_tmp_srts;
643 row<sorset*> sg_tmp_srss;
645 row_long_t sg_tmp_id_trail;
649 dima_dims sg_cnf_dims;
650 row<canon_clause*> sg_cnf_clauses;
653 long sg_dbg_cnf_tot_onelit;
663 brain* get_dbg_brn(){
664 brain* the_brn = NULL;
665 DBG(the_brn = sg_pt_brn);
669 brain& get_dbg_brain();
671 solver* get_dbg_slv();
673 ch_string dbg_prt_margin(bj_ostream& os,
bool is_ck =
false);
675 void set_dbg_brn(
brain* the_brn){
678 sg_cnf_step.set_dbg_brn(the_brn);
682 void init_sort_glb(){
683 DBG(sg_pt_brn = NULL);
685 sg_name =
"INVALID_SG_NAM";
687 sg_quick_find =
true;
688 sg_dbg_always_find_filled =
false;
694 sg_num_active_ss = 0;
696 sg_tot_stab_steps = 0;
697 sg_curr_stab_consec = 0;
698 sg_one_ccl_per_ss =
true;
701 sg_step_op = po_full;
702 sg_step_has_confl =
false;
704 sg_step_has_diff =
false;
705 sg_step_all_consec =
false;
706 sg_step_sortees.clear();
707 sg_step_sorsets.clear();
708 sg_step_prv_sorsets.clear();
709 sg_step_first_multiple = NULL_PT;
710 sg_step_next_choice = NULL_PT;
712 sg_step_mutual_op = sm_walk;
713 sg_step_mutual_clauses.clear();
718 sg_dbg_nmp = NULL_PT;
720 sg_dbg_fst_num_items = 0;
721 sg_dbg_num_items = 0;
723 sg_dbg_num_saved_consec = 0;
725 sg_dbg_has_repeated_ids =
false;
730 sg_cnf_dims.init_dima_dims();
732 sg_dbg_cnf_tot_onelit = 0;
735 void sort_all_from(row<sortee*>& tees, sort_id_t curr_id,
736 bool add_ccl_id,
long ccl_id,
bool sort_opps,
737 tgt_ccl_t tgt,
sort_glb* dbg_srg = NULL_PT,
sortee* dbg_srt = NULL_PT);
740 return (sg_head != NULL_PT);
744 SORTER_CK(! has_head());
745 if(sg_head == NULL_PT){
746 sorset& n_hd = add_sorset();
748 SORTER_CK(&n_hd == sg_head);
749 SORTER_CK(n_hd.can_be_head());
755 SORTER_CK(has_head());
760 SORTER_CK(hd.can_be_head());
766 if(! sg_free_sorsets.is_empty()){
767 pt_srs = sg_free_sorsets.pop();
769 pt_srs = &(sg_sorsets.inc_sz());
772 SORTER_CK(srs.is_ss_virgin());
774 if(sg_head == NULL_PT){ sg_head = &srs; }
780 void release_sorset(
sorset& srs);
782 void release_head_sorsets();
784 void init_counters();
785 void step_stabilize(step_op_t op,
bool ck_consecs =
false);
786 void step_mutual_stabilize(
sort_glb& mates_srg, step_mutual_op_t op);
788 void step_neus(
sort_glb& mates_srg);
789 void step_opps(
sort_glb& mates_srg);
790 void step_quas(
sort_glb& mates_srg);
792 sortee& get_sortee_of_ccl_id(
long ccl_id);
795 row<canon_clause*>& the_ccls,
bool sorted_cnf);
800 void stab_choose_one();
801 void stab_release_all_sorsets();
805 bool all_flags_ccl(canon_clause& ccl,
bool val);
806 bool ck_step_sortees();
810 bool ck_stab_inited();
812 void stab_mutual_init();
813 void stab_mutual_core(
sort_glb& mates_srg);
814 void stab_mutual(
sort_glb& mates_srg,
bool one_ccl_per_ss);
816 void stab_mutual_choose_one(
sort_glb& srg2);
817 void stab_mutual_end(
sort_glb& mates_srg,
bool unique_ccls);
818 void stab_mutual_walk();
821 long precalc_tot_vars = 0);
823 bool ck_all_tees_related();
826 void reset_head_values();
828 void clear_consecs();
830 bool sort_to_tmp_srts(
bool set_consecs =
false){
833 sg_step_sortees.copy_to(sg_tmp_srts);
834 return sg_step_has_diff;
849 void sort_to_tmp_srss(){
852 DBG(sg_tmp_srss.set_cap(sg_dbg_num_items));
854 sorset& hd = get_head_ss();
855 hd.walk_to_srs_row(sg_tmp_srss);
859 bool ck_srss_sorted(){
861 bool ck1 = sg_tmp_srss.is_sorted(cmp_sorsets);
865 bool ck_sorted_sorsets(row<sorset*>& dest_ss);
867 void add_neg_and_pos_to(row<sorset*>& dest_ss);
868 void join_all_tees_in_head();
870 bj_ostream& print_sort_glb(bj_ostream& os,
bool from_pt =
false);
872 template<
class obj_t1>
873 bool sort_to_row_and_all_consec(row<obj_t1*>& sorted,
bool& all_consec){
874 bool set_consecs =
true;
875 bool has_diff = sort_to_tmp_srts(set_consecs);
877 all_consec = tees_row_as<obj_t1>(sg_tmp_srts, sorted);
884 DBG_SORTOR_PRT(56, os <<
"sort_to_row " << obj_t1::CL_NAME);
894 template<
class obj_t1>
896 as_srt_of(binder* bdr){
897 sortee& srt = as_sortee(bdr);
898 return srt.me_as<obj_t1>();
903 sortee::get_vessel(){
904 SORTER_CK(has_vessel());
931 SORTER_CK(! ss_mark);
933 srg.sg_tot_ss_marks++;
938 sorset::reset_ss_mark(
sort_glb& srg){
941 srg.sg_tot_ss_marks--;
948 DEFINE_PRINT_FUNCS(
sorset);
949 DEFINE_PRINT_FUNCS(
sortee);
952 template<
class obj_t1>
954 srt_row_as_colors(
sort_glb& srg, row<sortee*>& rr1, row<obj_t1*>& rr2, row<long>& cols,
955 tee_id_t consec_kk,
bool unique_ccls)
957 sorset* last_ss = NULL_PT;
958 long last_item_consec = INVALID_NATURAL;
959 bool all_consec =
true;
961 rr2.set_cap(rr1.size());
963 cols.set_cap(rr1.size());
964 for(
long ii = 0; ii < rr1.size(); ii++){
966 SORTER_CK(srt.has_vessel());
968 long the_consec = srt.so_tee_consec;
969 if(consec_kk == tid_wlk_consec){
970 the_consec = srt.so_wlk_consec;
972 if(consec_kk == tid_qua_id){
973 the_consec = srt.so_qua_id;
975 if(consec_kk == tid_sset_consec){
976 the_consec = srt.so_sorset_consec;
978 SORTER_CK(the_consec != 0);
980 (last_item_consec == INVALID_NATURAL) || (last_item_consec <= the_consec),
986 if(unique_ccls && (last_ss != NULL_PT) && (srt.so_vessel == last_ss)){
990 all_consec = all_consec && (last_item_consec != the_consec);
991 last_item_consec = the_consec;
992 last_ss = srt.so_vessel;
994 cols.push(last_item_consec);
996 obj_t1& obj_1 = srt.me_as<obj_t1>();
A canon_cnf is a BCFF. An stabilized sub-formula.
Definition: skeleton.h:386
Class that holds all data used to solve a particular CNF instance.
Definition: brain.h:3085
Class that is an item to be stabilized.
Definition: sortor.h:152
A neuromap is a CNF sub-formula.
Definition: brain.h:2191
A skeleton_glb is a directory holding a database.
Definition: skeleton.h:761
A sorset is a group of sortee s.
Definition: sortor.h:321
Class that holds all global data used to stabilize a group of items.
Definition: sortor.h:579
A sortrel is a relation between two sortee s.
Definition: sortor.h:111