Doxygen Generated Documentation of Ben-Jose Trainable SAT Solver Library
sortor.h
1 
2 
3 
4 /*************************************************************
5 
6 This file is part of ben-jose.
7 
8 ben-jose is free software: you can redistribute it and/or modify
9 it under the terms of the version 3 of the GNU General Public
10 License as published by the Free Software Foundation.
11 
12 ben-jose is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with ben-jose. If not, see <http://www.gnu.org/licenses/>.
19 
20 ------------------------------------------------------------
21 
22 Copyright (C) 2007-2012, 2014-2016. QUIROGA BELTRAN, Jose Luis.
23 Id (cedula): 79523732 de Bogota - Colombia.
24 See https://github.com/joseluisquiroga/ben-jose
25 
26 ben-jose is free software thanks to The Glory of Our Lord
27  Yashua Melej Hamashiaj.
28 Our Resurrected and Living, both in Body and Spirit,
29  Prince of Peace.
30 
31 ------------------------------------------------------------
32 
33 sortor.h
34 
35 classes to implement a sortor.
36 
37 --------------------------------------------------------------*/
38 
39 
40 #ifndef SORTOR_H
41 #define SORTOR_H
42 
43 #include "tools.h"
44 #include "print_macros.h"
45 #include "skeleton.h"
46 #include "binder.h"
47 
48 #define DBG_SORTOR_PRT(prm1, prm2) ;
49 
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)
53 
54 #define SORTER_CK_1(prm) DBG_CK(prm)
55 #define SORTER_CK_2(prm) DBG_CK(prm)
56 
57 #define PHASE_1_COMMENT "phase_one\n"
58 #define PHASE_2_COMMENT "phase_two\n"
59 #define PHASE_3_COMMENT "phase_three\n"
60 
61 #define FINAL_COMMENT "final\n"
62 #define MUTUAL_COMMENT "mutual_stab\n"
63 
64 class solver;
65 class brain;
66 class skeleton_glb;
67 class neuromap;
68 class elem_sor;
69 
70 //class binder;
71 class sortee;
72 class sorset;
73 class sort_glb;
74 
75 //=================================================================
76 // type defs
77 
78 typedef bj_big_int_t sort_id_t;
79 typedef row<sort_id_t> row_sort_id_t;
80 
81 
82 //=================================================================
83 // printing declarations
84 
85 DECLARE_PRINT_FUNCS(sortee)
86 DECLARE_PRINT_FUNCS(sorset)
87 
88 //=================================================================
89 // funtion declarations
90 
91 sortee& as_sortee(binder* bdr);
92 
93 template<class obj_t1>
94 obj_t1& as_srt_of(binder* bdr);
95 
96 
97 //=================================================================
106 enum tgt_ccl_t {
107  tc_none = 0,
108  tc_mates = 1
109 };
110 
111 class sortrel {
112 public:
113  row<sortee*> so_mates;
114  sortee* so_opposite;
115 
116  sortrel(){
117  init_sortrel();
118  }
119 
120  ~sortrel(){
121  }
122 
123  void init_sortrel(bool free_mem = false){
124  so_mates.clear(free_mem, free_mem);
125  so_opposite = NULL_PT;
126  }
127 
128  bool ck_related(long tee_cons);
129 
130 };
131 
132 
133 //=================================================================
142 comparison cmp_sortees(sortee* const & srt1, sortee* const & srt2);
143 
144 enum tee_id_t {
145  tid_none,
146  tid_wlk_consec,
147  tid_sset_consec,
148  tid_tee_consec,
149  tid_qua_id
150 };
151 
152 class sortee : public binder {
153 public:
154  static
155  char* CL_NAME;
156 
157  virtual
158  char* get_cls_name(){
159  return sortee::CL_NAME;
160  }
161 
162  void* so_me;
163  long* so_cmp_val;
164  sorset* so_vessel;
165  long so_sorset_consec;
166  long so_walk_consec;
167 
168  sortrel* so_related;
169 
170  char so_dbg_me_class;
171  long so_dbg_extrn_id;
172 
173  //long so_saved_tee_consec;
174  long so_wlk_consec;
175  long so_tee_consec;
176 
177  canon_clause so_ccl;
178  long so_qua_id;
179 
180  sortee(){
181  init_sortee();
182  }
183 
184  ~sortee(){
185  DBG(so_ccl.cc_in_free = true);
186  }
187 
188  void init_sortee(bool free_mem = false){
189  so_me = NULL_PT;
190  so_cmp_val = NULL_PT;
191  so_vessel = NULL_PT;
192  so_sorset_consec = INVALID_NATURAL;
193  so_walk_consec = INVALID_NATURAL;
194 
195  so_related = NULL_PT;
196 
197  so_dbg_me_class = 0;
198  so_dbg_extrn_id = 0;
199 
200  //so_saved_tee_consec = INVALID_NATURAL;
201  so_wlk_consec = INVALID_NATURAL;
202  so_tee_consec = INVALID_NATURAL;
203  so_ccl.cc_clear(free_mem);
204 
205  so_qua_id = 0;
206  }
207 
208  template<class obj_t1>
209  obj_t1&
210  me_as(){
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);
214  return obj;
215  }
216 
217  bool is_unsorted(){
218  return (is_alone() && ! has_vessel());
219  }
220 
221  sorset& get_vessel();
222 
223  bool has_vessel(){
224  return (so_vessel != NULL_PT);
225  }
226 
227  void unsort_me(sort_glb& srg);
228  void sort_me_to(sort_glb& srg, sorset& nsr);
229  void sort_from(sort_glb& srg, sort_id_t curr_nid, void* id_src = NULL_PT);
230 
231  //void save_consec(sort_glb& srg);
232  //long recover_consec(sort_glb& srg);
233 
234  long get_ccl_id(sort_glb& srg);
235  void close_ccl(sort_glb& srg);
236  void update_totals(sort_glb& srg, long tgt_sz);
237  bool is_confl(sort_glb& srg);
238  bool is_dual(sort_glb& srg);
239  long get_qua_id(sort_glb& srg);
240 
241  sortee& opposite(){
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);
246  }
247 
248  long get_target_sz(tgt_ccl_t tt){
249  SORTER_CK(so_me != NULL_PT);
250  SORTER_CK(so_related != NULL_PT);
251 
252  SORTER_CK(tt != tc_none);
253  long the_sz = 0;
254  if(tt == tc_mates){
255  the_sz = so_related->so_mates.size();
256  }
257  return the_sz;
258  }
259 
260  void reset_sort_info(){
261  SORTER_CK(is_unsorted());
262 
263  so_wlk_consec = 0;
264  so_tee_consec = 0;
265  if(so_related != NULL_PT){
266  sortrel& quar = *so_related;
267  SORTER_CK(quar.so_opposite != NULL_PT);
268  quar.so_mates.clear();
269  }
270 
271  so_ccl.cc_clear(false);
272  so_qua_id = 0;
273  }
274 
275  bool is_next_choice(sort_glb& srg1);
276 
277  bj_ostream& print_sortee(bj_ostream& os, bool from_pt = false);
278 };
279 
280 template<class obj_t1>
281 bool
282 tees_row_as(row<sortee*>& rr1, row<obj_t1*>& rr2){
283  long last_item_id = INVALID_NATURAL;
284  bool all_consec = true;
285  rr2.clear();
286  rr2.set_cap(rr1.size());
287  for(long ii = 0; ii < rr1.size(); ii++){
288  sortee& srt = *(rr1[ii]);
289 
290  //all_consec = all_consec && (last_item_id != srt.so_walk_consec);
291  //last_item_id = srt.so_walk_consec;
292 
293  all_consec = all_consec && (last_item_id != srt.so_sorset_consec);
294  last_item_id = srt.so_sorset_consec;
295 
296  obj_t1& obj_1 = srt.me_as<obj_t1>();
297  rr2.push(&obj_1);
298  }
299  return all_consec;
300 }
301 
302 template<class obj_t1>
303 bool
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);
306 
307 
308 //=================================================================
317 typedef bool (sorset::*cond_mth)();
318 
319 typedef receptor<sorset> ss_srs_t;
320 
321 class sorset {
322 public:
323  static
324  char* CL_NAME;
325 
326  virtual
327  char* get_cls_name(){
328  return sorset::CL_NAME;
329  }
330 
331  sorset* ss_parent_set;
332  ss_srs_t ss_sub_rcp;
333 
334  grip ss_items;
335  grip ss_subsets;
336 
337  sort_id_t ss_curr_id;
338  void* ss_id_src;
339  bool ss_has_val;
340 
341  bool ss_mark;
342 
343  sorset(){
344  init_sorset();
345  }
346 
347  ~sorset(){
348  }
349 
350  void init_sorset(){
351  ss_parent_set = NULL_PT;
352  ss_sub_rcp.re_me = this;
353  SORTER_CK(ss_sub_rcp.is_alone());
354 
355  SORTER_CK(ss_items.is_alone());
356  SORTER_CK(ss_subsets.is_alone());
357 
358  ss_curr_id = 0;
359  ss_id_src = NULL_PT;
360  ss_has_val = false;
361 
362  ss_mark = false;
363  }
364 
365  void set_ss_mark(sort_glb& srg);
366  void reset_ss_mark(sort_glb& srg);
367 
368  bool is_ss_virgin(bool ck_items = true);
369 
370  sorset& get_next_vessel(sort_glb& srg, sort_id_t curr_id, void* id_src);
371  sorset* last_sub();
372 
373  void fill_srs_trails(row_sort_id_t& id_trl, row<void*>& src_trl);
374 
375  bool has_ss_parent(){
376  return (ss_parent_set != NULL_PT);
377  }
378 
379  bool has_items(){
380  return ! ss_items.is_alone();
381  }
382 
383  bool has_subsets(){
384  return ! ss_subsets.is_alone();
385  }
386 
387  bool has_brothers(){
388  return ! ss_sub_rcp.is_alone();
389  }
390 
391  bool one_item(){
392  return ss_items.is_single();
393  }
394 
395  bool is_multitem(){
396  return ss_items.is_multiple();
397  }
398 
399  bool one_subset(){
400  return ss_subsets.is_single();
401  }
402 
403  bool can_sort_in_me(){
404  bool ok = (! has_subsets() ||
405  (one_subset() && (first_subset().ss_curr_id == ss_curr_id)));
406  return ok;
407  }
408 
409  bool is_final(){
410  bool c1 = ! has_subsets();
411  bool c2 = ! has_ss_parent();
412  bool c3 = has_items();
413  return (c1 && c2 && c3);
414  }
415 
416  bool can_be_head(){
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);
422  return all_c;
423  }
424 
425  sorset& first_subset(){
426  SORTER_CK(has_subsets());
427  sorset& fst = rcp_as<sorset>(ss_subsets.bn_right);
428  return fst;
429  }
430 
431  sortee& first_item(){
432  SORTER_CK(has_items());
433  sortee& fst = as_sortee(ss_items.bn_right);
434  return fst;
435  }
436 
437  sortee& last_item(){
438  SORTER_CK(has_items());
439  sortee& lst = as_sortee(ss_items.bn_left);
440  return lst;
441  }
442 
443  /*
444  bool is_leaf(){
445  bool is_lf = ! has_subsets();
446  return is_lf;
447  }*/
448 
449  bool is_single_leaf(){
450  return (! has_subsets() && ss_items.is_single());
451  }
452 
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);
456  ss_has_val = true;
457  ss_curr_id = the_val;
458  ss_id_src = val_src;
459  }
460 
461  bool in_item_id(sort_id_t target_id){
462  if(! ss_has_val){
463  return false;
464  }
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);
469  return in_the_id;
470  }
471 
472  long depth(){
473  long dd = 0;
474  sorset* srs = this;
475  while(srs != NULL_PT){
476  dd++;
477  srs = srs->ss_parent_set;
478  }
479  return dd;
480  }
481 
482  bool contained_by(sorset& vsl_srs){
483  sorset* srs = this;
484  while(srs != NULL_PT){
485  if(srs == &vsl_srs){
486  return true;
487  }
488  srs = srs->ss_parent_set;
489  }
490  return false;
491  }
492 
493  sorset& add_sub(sort_glb& srg, sort_id_t curr_id, void* id_src);
494 
495  void step_stabilize_rec(sort_glb& srg);
496  void step_mutual_stabilize_rec(sort_glb& srg1, sort_glb& srg2);
497 
498  void unsort_all_items(sort_glb& srg);
499  void walk_release(sort_glb& srg);
500  void walk_reset_values(sort_glb& srg, grip& flat_ss);
501 
502  /*bool walk_to_row(row<sortee*>& sorted, bool set_consecs){
503  long consec = 0;
504  bool has_diff = false;
505  sorted.clear();
506  walk_to_row_rec(set_consecs, consec, sorted, has_diff);
507 
508  return has_diff;
509  }
510 
511  void walk_to_row_rec(bool set_consecs, long& consec,
512  row<sortee*>& sorted, bool& has_diff);
513  */
514 
515  void walk_to_srs_row(row<sorset*>& sorted){
516  long consec = 0;
517  sorted.clear();
518  walk_to_srs_row_rec(consec, sorted);
519  }
520 
521  void walk_to_srs_row_rec(long& consec, row<sorset*>& sorted);
522 
523  bool ck_all_items_same_qua_id();
524  void set_all_items_qua_id(long qu_id);
525 
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);
529 
530 };
531 
532 comparison
533 cmp_sorset_trails(row_sort_id_t& ids1, row_sort_id_t& ids2);
534 
535 comparison
536 cmp_sorsets(sorset* const& srs1, sorset* const& srs2);
537 
538 bool
539 srs_row_as_clauses(sort_glb& srg, row<sorset*>& rr1, row<canon_clause*>& rr2);
540 
541 inline
542 void
543 srs_row_get_first_tees(row<sorset*>& rr1, row<sortee*>& rr2){
544  rr2.clear();
545  rr2.set_cap(rr1.size());
546 
547  for(long ii = 0; ii < rr1.size(); ii++){
548  sorset& srs = *(rr1[ii]);
549  SORTER_CK(srs.has_items());
550 
551  sortee& srt = srs.first_item();
552  rr2.push(&srt);
553  }
554 }
555 
556 //=================================================================
565 enum step_op_t {
566  po_full = 0,
567  po_walk = 1,
568  po_sort = 2
569 };
570 
571 enum step_mutual_op_t {
572  sm_walk = 0,
573  sm_with_neus = 1,
574  sm_with_opps = 2,
575  sm_with_quas = 3,
576  sm_get_ccls = 4
577 };
578 
579 class sort_glb {
580 public:
581 
582  DBG(
583  brain* sg_pt_brn;
584  )
585 
586  ch_string sg_name;
587 
588  bool sg_quick_find;
589  bool sg_dbg_always_find_filled;
590 
591  k_row<sorset> sg_sorsets;
592  row<sorset*> sg_free_sorsets;
593 
594  sorset* sg_head;
595 
596  row<sortee*> sg_prt_srts;
597 
598  long sg_num_active_ss;
599 
600  //bool sg_has_dual;
601  //sortee* sg_first_srt;
602 
603  sort_id_t sg_tot_stab_steps;
604  sort_id_t sg_curr_stab_consec;
605  bool sg_one_ccl_per_ss;
606  bool sg_got_ccls;
607 
608  step_op_t sg_step_op;
609  bool sg_step_has_confl;
610  long sg_step_consec;
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;
618 
619  row<sorset*> sg_step_neg_sorsets;
620  row<sorset*> sg_step_pos_sorsets;
621 
622  step_mutual_op_t sg_step_mutual_op;
623  row<canon_clause*> sg_step_mutual_clauses;
624 
625  long sg_tot_ss_marks;
626 
627  // dbg attrs
628 
629  SORTER_DBG(
630  neuromap* sg_dbg_nmp;
631 
632  long sg_dbg_fst_num_items;
633  long sg_dbg_num_items;
634  );
635  long sg_dbg_num_saved_consec;
636  bool sg_dbg_has_repeated_ids;
637 
638  sort_id_t sg_dbg_last_id;
639 
640  // tmp attrs
641 
642  row<sortee*> sg_tmp_srts;
643  row<sorset*> sg_tmp_srss;
644 
645  row_long_t sg_tmp_id_trail;
646 
647  // cnf data
648 
649  dima_dims sg_cnf_dims;
650  row<canon_clause*> sg_cnf_clauses;
651  canon_cnf sg_cnf_step;
652 
653  long sg_dbg_cnf_tot_onelit;
654 
655  sort_glb(){
656  init_sort_glb();
657  }
658 
659  ~sort_glb(){
660  release_all();
661  }
662 
663  brain* get_dbg_brn(){
664  brain* the_brn = NULL;
665  DBG(the_brn = sg_pt_brn);
666  return the_brn;
667  }
668 
669  brain& get_dbg_brain();
670 
671  solver* get_dbg_slv();
672 
673  ch_string dbg_prt_margin(bj_ostream& os, bool is_ck = false);
674 
675  void set_dbg_brn(brain* the_brn){
676  DBG(
677  sg_pt_brn = the_brn;
678  sg_cnf_step.set_dbg_brn(the_brn);
679  );
680  }
681 
682  void init_sort_glb(){
683  DBG(sg_pt_brn = NULL);
684 
685  sg_name = "INVALID_SG_NAM";
686 
687  sg_quick_find = true;
688  sg_dbg_always_find_filled = false;
689 
690  sg_prt_srts.clear();
691 
692  sg_head = NULL_PT;
693 
694  sg_num_active_ss = 0;
695 
696  sg_tot_stab_steps = 0;
697  sg_curr_stab_consec = 0;
698  sg_one_ccl_per_ss = true;
699  sg_got_ccls = false;
700 
701  sg_step_op = po_full;
702  sg_step_has_confl = false;
703  sg_step_consec = 0;
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;
711 
712  sg_step_mutual_op = sm_walk;
713  sg_step_mutual_clauses.clear();
714 
715  sg_tot_ss_marks = 0;
716 
717  SORTER_DBG(
718  sg_dbg_nmp = NULL_PT;
719 
720  sg_dbg_fst_num_items = 0;
721  sg_dbg_num_items = 0;
722  );
723  sg_dbg_num_saved_consec = 0;
724  sg_dbg_last_id = 0;
725  sg_dbg_has_repeated_ids = false;
726 
727  sg_tmp_srts.clear();
728  sg_tmp_srss.clear();
729 
730  sg_cnf_dims.init_dima_dims();
731 
732  sg_dbg_cnf_tot_onelit = 0;
733  }
734 
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);
738 
739  bool has_head(){
740  return (sg_head != NULL_PT);
741  }
742 
743  sorset& init_head_ss(){
744  SORTER_CK(! has_head());
745  if(sg_head == NULL_PT){
746  sorset& n_hd = add_sorset();
747  sg_head = &n_hd;
748  SORTER_CK(&n_hd == sg_head);
749  SORTER_CK(n_hd.can_be_head());
750  }
751  return *sg_head;
752  }
753 
754  sorset& get_head_ss(){
755  SORTER_CK(has_head());
756  if(! has_head()){
757  init_head_ss();
758  }
759  sorset& hd = *sg_head;
760  SORTER_CK(hd.can_be_head());
761  return hd;
762  }
763 
764  sorset& add_sorset(){
765  sorset* pt_srs = NULL_PT;
766  if(! sg_free_sorsets.is_empty()){
767  pt_srs = sg_free_sorsets.pop();
768  } else {
769  pt_srs = &(sg_sorsets.inc_sz());
770  }
771  sorset& srs = *pt_srs;
772  SORTER_CK(srs.is_ss_virgin());
773 
774  if(sg_head == NULL_PT){ sg_head = &srs; }
775 
776  sg_num_active_ss++;
777  return srs;
778  }
779 
780  void release_sorset(sorset& srs);
781 
782  void release_head_sorsets();
783 
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);
787 
788  void step_neus(sort_glb& mates_srg);
789  void step_opps(sort_glb& mates_srg);
790  void step_quas(sort_glb& mates_srg);
791 
792  sortee& get_sortee_of_ccl_id(long ccl_id);
793 
794  void build_cnf(skeleton_glb& skg, canon_cnf& the_cnf,
795  row<canon_clause*>& the_ccls, bool sorted_cnf);
796 
797  //void step_build_cnf(skeleton_glb& skg, ch_string ph_str = "",
798  // bool sorted_cnf = true);
799 
800  void stab_choose_one();
801  void stab_release_all_sorsets();
802  void stab_save_it();
803  //void stab_recover_it();
804 
805  bool all_flags_ccl(canon_clause& ccl, bool val);
806  bool ck_step_sortees();
807 
808  void stabilize();
809 
810  bool ck_stab_inited();
811 
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);
815  void stab_mutual_unique(sort_glb& mates_srg, neuromap* dbg_nmp = NULL_PT);
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();
819 
820  canon_cnf& get_final_cnf(skeleton_glb& skg, bool sorted_cnf,
821  long precalc_tot_vars = 0);
822 
823  bool ck_all_tees_related();
824 
825  void release_all();
826  void reset_head_values();
827 
828  void clear_consecs();
829 
830  bool sort_to_tmp_srts(bool set_consecs = false){
831  sg_tmp_srts.clear();
832  stab_mutual_walk();
833  sg_step_sortees.copy_to(sg_tmp_srts);
834  return sg_step_has_diff;
835  }
836 
837  /*bool sort_to_tmp_srts(bool set_consecs = false){
838  bool has_diff = false;
839  sg_tmp_srts.clear();
840  if(has_head()){
841  DBG(sg_tmp_srts.set_cap(sg_dbg_num_items));
842 
843  sorset& hd = get_head_ss();
844  has_diff = hd.walk_to_row(sg_tmp_srts, set_consecs);
845  }
846  return has_diff;
847  }*/
848 
849  void sort_to_tmp_srss(){
850  sg_tmp_srss.clear();
851  if(has_head()){
852  DBG(sg_tmp_srss.set_cap(sg_dbg_num_items));
853 
854  sorset& hd = get_head_ss();
855  hd.walk_to_srs_row(sg_tmp_srss);
856  }
857  }
858 
859  bool ck_srss_sorted(){
860  sort_to_tmp_srss();
861  bool ck1 = sg_tmp_srss.is_sorted(cmp_sorsets);
862  return ck1;
863  }
864 
865  bool ck_sorted_sorsets(row<sorset*>& dest_ss);
866 
867  void add_neg_and_pos_to(row<sorset*>& dest_ss);
868  void join_all_tees_in_head();
869 
870  bj_ostream& print_sort_glb(bj_ostream& os, bool from_pt = false);
871 
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);
876 
877  all_consec = tees_row_as<obj_t1>(sg_tmp_srts, sorted);
878 
879  //sort_glb& srg = *this;
880  //row<long> cols;
881  //all_consec = srt_row_as_colors<obj_t1>(srg, sg_tmp_srts, sorted, cols,
882  // tid_sset_consec, false);
883 
884  DBG_SORTOR_PRT(56, os << "sort_to_row " << obj_t1::CL_NAME);
885  return has_diff;
886  }
887 };
888 
889 //=================================================================
890 // INLINE DEFS
891 
892 //sortee& as_sortee(binder* bdr);
893 
894 template<class obj_t1>
895 obj_t1&
896 as_srt_of(binder* bdr){
897  sortee& srt = as_sortee(bdr);
898  return srt.me_as<obj_t1>();
899 }
900 
901 inline
902 sorset&
903 sortee::get_vessel(){
904  SORTER_CK(has_vessel());
905  return *so_vessel;
906 }
907 
908 /*
909 inline
910 void
911 sortee::save_consec(sort_glb& srg){
912  SORTER_CK(so_saved_tee_consec == INVALID_NATURAL);
913  so_saved_tee_consec = so_tee_consec;
914  SORTER_CK(so_saved_tee_consec != INVALID_NATURAL);
915  srg.sg_dbg_num_saved_consec++;
916 }
917 
918 inline
919 long
920 sortee::recover_consec(sort_glb& srg){
921  srg.sg_dbg_num_saved_consec--;
922  SORTER_CK(so_saved_tee_consec != INVALID_NATURAL);
923  long consec = so_saved_tee_consec;
924  so_saved_tee_consec = INVALID_NATURAL;
925  return consec;
926 }*/
927 
928 inline
929 void
930 sorset::set_ss_mark(sort_glb& srg){
931  SORTER_CK(! ss_mark);
932  ss_mark = true;
933  srg.sg_tot_ss_marks++;
934 }
935 
936 inline
937 void
938 sorset::reset_ss_mark(sort_glb& srg){
939  SORTER_CK(ss_mark);
940  ss_mark = false;
941  srg.sg_tot_ss_marks--;
942 }
943 
944 
945 //=================================================================
946 // printing operators
947 
948 DEFINE_PRINT_FUNCS(sorset);
949 DEFINE_PRINT_FUNCS(sortee);
950 DEFINE_PRINT_FUNCS(sort_glb);
951 
952 template<class obj_t1>
953 bool
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)
956 {
957  sorset* last_ss = NULL_PT;
958  long last_item_consec = INVALID_NATURAL;
959  bool all_consec = true;
960  rr2.clear();
961  rr2.set_cap(rr1.size());
962  cols.clear();
963  cols.set_cap(rr1.size());
964  for(long ii = 0; ii < rr1.size(); ii++){
965  sortee& srt = *(rr1[ii]);
966  SORTER_CK(srt.has_vessel());
967 
968  long the_consec = srt.so_tee_consec;
969  if(consec_kk == tid_wlk_consec){
970  the_consec = srt.so_wlk_consec;
971  }
972  if(consec_kk == tid_qua_id){
973  the_consec = srt.so_qua_id;
974  }
975  if(consec_kk == tid_sset_consec){
976  the_consec = srt.so_sorset_consec;
977  }
978  SORTER_CK(the_consec != 0);
979  SORTER_CK_PRT(
980  (last_item_consec == INVALID_NATURAL) || (last_item_consec <= the_consec),
981  DBG_PRT_ABORT(srg);
982  os << "sortees=\n";
983  os << rr1 << "\n";
984  );
985 
986  if(unique_ccls && (last_ss != NULL_PT) && (srt.so_vessel == last_ss)){
987  continue;
988  }
989 
990  all_consec = all_consec && (last_item_consec != the_consec);
991  last_item_consec = the_consec;
992  last_ss = srt.so_vessel;
993 
994  cols.push(last_item_consec);
995 
996  obj_t1& obj_1 = srt.me_as<obj_t1>();
997  rr2.push(&obj_1);
998  }
999  return all_consec;
1000 }
1001 
1002 
1003 #endif // SORTOR_H
1004 
1005 
1006 
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