42 #include "bj_stream.h"    44 #include "file_funcs.h"    47 #include "print_macros.h"    68 #define SKELETON_DBG(prm) DBG(prm)    69 #define SKELETON_CK(prm)    DBG_BJ_LIB_CK(prm)    70 #define SKELETON_CK_PRT(prm, comms1)  DBG_CK_2(prm, comms1)    76 #define SKG_NUM_DIGITS_IN_DIRNAM_OF_NUMBER_PATH 1    77 #define SKG_MAX_SAMPLE_NUM_LITS 1000    78 #define SKG_MAX_SAMPLE_NUM_CCLS 10    81 #define SKG_MAX_NUM_VARIANT 10    83 #define SKG_MAX_NUM_VARIANT 10    86 #define SKG_LOCK_SEP_STR "%"    87 #define SKG_LOCK_SEP '%'    88 #define SKG_VARIANT_DIR "vv/"    90 #define SKG_CANON_PATH_ENDING "oo"    92 #define SKG_CANON_HEADER_STR \    93         "c Yashua Melej Hamashiaj. \n" \    94         "c ben-jose dimacs unsat cnf generated file.\n" \    95         "c Any modification will make it useless for ben-jose. \n" \   105 #define SKG_INVALID_PTH     "skg_invalid_pth"   106 #define SKG_SKELETON_DIR    "/SKELETON"   107 #define SKG_CNF_DIR     "/SKELETON/CNF"   108 #define SKG_REF_DIR     "/SKELETON/REF"   109 #define SKG_LCK_DIR     "/SKELETON/LCK"   110 #define SKG_TMP_PROOF_DIR   "/SKELETON/TMP/PROOF"   111 #define SKG_JS_DIR          "/SKELETON/JS"   112 #define SKG_COLLISIONS_DIR  "/SKELETON/ERR/COLLISIONS"   113 #define SKG_MISSING_DIR     "/SKELETON/ERR/MISSING"   114 #define SKG_CORRUPTED_DIR   "/SKELETON/ERR/CORRUPTED"   115 #define SKG_OVERLAPED_DIR   "/SKELETON/ERR/OVERLAPED"   116 #define SKG_DEAD_DIR        "/SKELETON/ERR/DEAD"   117 #define SKG_BROKEN_DIR      "/SKELETON/ERR/BROKEN"   119 #define SKG_REF_SUF         ".ref"   121 #define SKG_CANON_NAME      "canon.skl"   122 #define SKG_DIFF_NAME       "diff.skl"   123 #define SKG_GUIDE_NAME      "guide.skl"   124 #define SKG_GUIDE_SHA_NAME  "guide_sha.skl"   125 #define SKG_COMMENT_NAME    "comment.skl"   126 #define SKG_ELAPSED_NAME    "elapsed.skl"   127 #define SKG_NUM_VNT_NAME    "numvariants.skl"   129 #define SKG_ERR_COUNT_NAME  "err_count.skl"   130 #define SKG_READY_NAME      "ready"   132 #define SKG_VERIFY_NAME     "/SKELETON/verify.skl"   134 #define SKG_DBG_COLLI_DIFF  "/dbg_colli_diff.skl"   135 #define SKG_DBG_COLLI_NEW   "/dbg_colli_new.skl"   137 #define SKG_PROOF_SUBDIR            "proof"   138 #define SKG_UNIRONS_SUBDIR          "unirons"   139 #define SKG_UNIRONS_REF_FNAM        "unirons_ref.txt"   140 #define SKG_SHOW_PROOF_JS_SUBDIR    "show_proof_js_lib"   141 #define SKG_SHOW_PROOF_TOP_HTM_NAME "Show_Proof.htm"   142 #define SKG_END_JSN_NAME            "cnf_proof.jsn"   147 DECLARE_PRINT_FUNCS(canon_clause)
   148 DECLARE_PRINT_FUNCS(variant)
   154 bool        print_str_long_map(bj_ostream& os, string_long_map_t& pmp);
   156 bool        not_skl_path(ch_string pth);
   158 ch_string   nam_subset_resp(cmp_is_sub rr);
   159 void        string_replace_char(ch_string& src_str, 
char orig, 
char repl);
   161 bool        path_is_dead_lock(ch_string the_pth);
   164 ch_string&  slice_str_to_path(ch_string& sha_txt);
   166 bool        all_digits(ch_string& the_str);
   169 void        delete_sha_skeleton(ch_string& sha_pth);
   171 bool        canon_save(
skeleton_glb& skg, ch_string& the_pth, row<
char>& cnn, 
   172                        bool write_once = true);
   173 bool        canon_load(
skeleton_glb& skg, ch_string& the_pth, row<
char>& cnn);
   174 bool        canon_equal(
skeleton_glb& skg, ch_string& the_pth, row<
char>& cnn);
   179 void        canon_print(bj_ostream& os, row<
char>& cnn);
   180 void        canon_sha(row<
char>& cnn, ch_string& sha_txt, ch_string& minisha_txt);
   182 ch_string   canon_header(ch_string& hd_str, 
long ccls, 
long vars);
   183 void        canon_long_append(row<
char>& cnn, 
long nn);
   184 void        canon_string_append(row<
char>& cnn, ch_string ss);
   185 long        canon_purge_clauses(
skeleton_glb& skg, row<canon_clause*>& all_ccl, 
long& tot_lits, 
long& tot_twolits);
   187 void        canon_count_tots(row<canon_clause*>& all_ccls, 
long& tot_vars, 
long& tot_lits, 
long& tot_twolits);
   193 class skeleton_exception : public top_exception {
   195     skeleton_exception(
long the_id = 0) : top_exception(the_id)
   204 class canon_clause : 
private row_long_t {
   218     brain*  get_dbg_brn(){
   219         brain* the_brn = NULL;
   220         SKELETON_DBG(the_brn = cc_pt_brn);
   224     solver* get_dbg_slv();
   226     void    set_dbg_brn(
brain* pt_brn){
   227         SKELETON_DBG(cc_pt_brn = pt_brn);
   231         bool c1 = is_empty();
   235     void    init_canon_clause(
bool free_mem){
   243         clear(free_mem, free_mem);
   246     template<
class obj_t1>
   249         SKELETON_CK(cc_me != NULL_PT);
   250         obj_t1& obj = *((obj_t1*)(cc_me));
   251         SKELETON_CK(obj.get_cls_name() == obj_t1::CL_NAME);
   256         SKELETON_CK(! cc_in_free);
   261         SKELETON_CK(! cc_in_free);
   266         SKELETON_CK(! cc_in_free);
   270     void    cc_push(
long the_lit){
   271         SKELETON_CK(! cc_in_free);
   275     void    cc_mix_sort(cmp_func_t cmp_fn){
   276         SKELETON_CK(! cc_in_free);
   280     bool    cc_is_sorted(cmp_func_t cmp_fn){
   281         SKELETON_CK(! cc_in_free);
   282         return is_sorted(cmp_fn);
   285     long    cc_pos(
long the_idx){
   286         SKELETON_CK(! cc_in_free);
   287         SKELETON_CK(is_valid_idx(the_idx));
   291         void    cc_copy_to(canon_clause& dest, 
   292                 row_index first_ii = 0, row_index last_ii = -1,
   295         copy_to(dest, first_ii, last_ii, inv);
   298     void    cc_clear(
bool free_mem);
   300     charge_t    cc_is_full();
   302     void        add_chars_to(row<char>& cnn);
   304     bj_ostream& print_canon_clause(bj_ostream& os, 
bool from_pt = 
false);
   308 cmp_canon_ids(
const long& id1, 
const long& id2);
   311 cmp_lit_rows(row_long_t& trl1, row_long_t& trl2);
   317 cmp_clauses(canon_clause* 
const& srt1, canon_clause* 
const& srt2);
   319 template<
class obj_t1>
   321 ccl_row_as(row<canon_clause*>& rr1, row<obj_t1*>& rr2, 
bool only_spotted = 
false){
   323     rr2.set_cap(rr1.size());
   324     for(
long ii = 0; ii < rr1.size(); ii++){
   325         SKELETON_CK(rr1[ii] != NULL_PT);        
   326         canon_clause& the_ccl = *(rr1[ii]);
   329         if(only_spotted){ add_it = the_ccl.cc_spot; }
   332             obj_t1& obj_1 = the_ccl.me_as<obj_t1>();
   343     ch_string   vn_real_path;
   355         vn_elap.init_average();
   358     bj_ostream& print_variant(bj_ostream& os, 
bool from_pt = 
false){    
   359         os << 
"vn[" << vn_real_path << 
" " << vn_elap << 
"]" << bj_eol;
   364 long        choose_variant(row<variant>& all_vnt, 
   365                            bj_big_float_t& avg_szs, 
bool in_dbg = 
false);
   368 cmp_variant(variant 
const & vnt1, variant 
const & vnt2);
   388     SKELETON_DBG(
brain*     cf_pt_brn;)
   396     row<canon_clause*>  cf_clauses;
   398     ch_string       cf_sha_str;
   399     ch_string       cf_minisha_str;
   400     ch_string       cf_diff_minisha_str;
   403     row<char>       cf_comment_chars;
   404     long            cf_num_cls_in_chars;
   406     ch_string       cf_phase_str;
   408     ch_string       cf_unique_path;
   414     ch_string       cf_quick_find_ref;
   415     row_str_t       cf_dbg_shas;
   419     ch_string       cf_tmp_sv_dir;
   420     ch_string       cf_tmp_pth1;
   421     ch_string       cf_tmp_pth2;
   424         void*   cf_dbg_orig_nmp;
   425         bool    cf_dbg_file_existed;
   435     brain*  get_dbg_brn(){
   436         brain* the_brn = NULL;
   437         SKELETON_DBG(the_brn = cf_pt_brn);
   441     solver* get_dbg_slv();
   443     void    set_dbg_brn(
brain* pt_brn){
   444         SKELETON_DBG(cf_pt_brn = pt_brn);
   447     void init_canon_cnf(
bool free_mem = 
false){
   448         SKELETON_DBG(cf_pt_brn = NULL);
   450         cf_kind = fk_invalid;
   454         cf_dims.init_dima_dims(INVALID_NATURAL);
   455         cf_dims.dd_tot_twolits = 0;
   457         SKELETON_CK(cf_clauses.is_empty());
   461         cf_diff_minisha_str = 
"";
   463         cf_chars.clear(free_mem, free_mem);
   464         cf_comment_chars.clear(free_mem, free_mem);
   465         cf_num_cls_in_chars = -1;
   473         cf_guide_cnf = NULL_PT;
   474         cf_tauto_cnf = NULL_PT;
   475         cf_quick_find_ref = 
"";
   476         cf_dbg_shas.clear(free_mem, free_mem);
   478         cf_inst_inf = NULL_PT;
   485             cf_dbg_orig_nmp = NULL_PT;
   486             cf_dbg_file_existed = 
false;
   489         SKELETON_CK(cf_unique_path.size() == 0);
   492     void    init_with_ccls(
skeleton_glb& skg, row<canon_clause*>& all_ccls, 
   493                 long tot_vars = INVALID_NATURAL, 
   494                 long tot_lits = INVALID_NATURAL, 
   495                 long tot_twolits = INVALID_NATURAL, 
   496                 bool sorted_cnf = 
true);
   498     void    release_and_init(
skeleton_glb& skg, 
bool free_mem = 
false){
   499         release_all_clauses(skg, free_mem);
   500         brain* old_dbg_brn = get_dbg_brn();
   501         init_canon_cnf(free_mem);
   502         set_dbg_brn(old_dbg_brn);
   505     void    clear_all_spots();
   507     bool    ck_full_dir(ch_string sv_dir){
   508         SKELETON_CK(! sv_dir.empty());
   509         SKELETON_CK(*(sv_dir.begin()) == 
'/');
   510         SKELETON_CK(*(sv_dir.rbegin()) == 
'/');
   514     bool    ck_all_can_release(row<canon_clause*>& rr, 
bool can_val){
   515         for(
long aa = 0; aa < rr.size(); aa++){
   516             SKELETON_CK(rr[aa] != NULL_PT);
   517             canon_clause& ccl = *(rr[aa]);
   519             SKELETON_CK(ccl.cc_can_release == can_val);
   525         SKELETON_CK(ck_all_can_release(cf_clauses, 
false));
   528         brain* old_dbg_brn = get_dbg_brn();
   529         init_canon_cnf(
false);
   530         set_dbg_brn(old_dbg_brn);
   536         SKELETON_CK(cf_dims.dd_tot_ccls == cf_clauses.size());
   537         bool is_e = cf_clauses.is_empty();
   541     ch_string   get_id_str();
   542     void        get_extreme_lits(row<long>& lits);
   544     ch_string   get_num_variants_file_name(
skeleton_glb& skg);
   546     void    release_all_clauses(
skeleton_glb& skg, 
bool free_mem = 
false);
   548     bool    has_phase_path(){
   553         bool c1 = (cf_guide_cnf != NULL_PT);
   554         bool c2 = (cf_tauto_cnf != NULL_PT);
   555         bool c_ok = (c1 && c2);
   556         SKELETON_CK(is_diff() == c_ok);
   561         SKELETON_CK(cf_guide_cnf != NULL_PT);
   562         return *cf_guide_cnf;
   566         SKELETON_CK(cf_tauto_cnf != NULL_PT);
   567         return *cf_tauto_cnf;
   570     ch_string   get_ref1_nam(){
   571         SKELETON_CK(has_cnfs());
   572         SKELETON_CK(is_diff());
   573         return cf_guide_cnf->get_ref_path();
   576     ch_string   get_ref2_nam(){
   577         SKELETON_CK(has_cnfs());
   578         SKELETON_CK(is_diff());
   579         return cf_guide_cnf->get_lck_path();
   582     ch_string   get_ref3_nam(){
   583         SKELETON_CK(has_cnfs());
   584         SKELETON_CK(is_diff());
   585         return cf_quick_find_ref;
   588     ch_string   get_vnt_nam(){
   589         return get_ref1_nam();
   592     ch_string   get_lck_nam(){
   593         return get_ref2_nam();
   597         return (cf_kind == fk_canon);
   601         return (cf_kind == fk_diff);
   605         return (cf_kind == fk_guide);
   608     void    update_diff_refs(
skeleton_glb& skg, ch_string sv_vpth);
   609     void    update_mng_verif_sys(
skeleton_glb& skg, ch_string sv_vpth);
   611     void    set_kind_from(ch_string the_pth){
   612         SKELETON_CK(cf_kind == fk_invalid);
   614         ch_string nm = path_get_name(the_pth);
   615         if(nm == SKG_GUIDE_NAME){
   618         if(nm == SKG_DIFF_NAME){
   621         if(nm == SKG_CANON_NAME){
   624         SKELETON_CK(cf_kind != fk_invalid);
   627     ch_string   get_kind_name(){
   629         SKELETON_CK(cf_kind != fk_invalid);
   632                 fnm = SKG_GUIDE_NAME;
   638                 fnm = SKG_CANON_NAME;
   643         SKELETON_CK(fnm != 
"");
   647     ch_string   get_all_variant_dir_name();
   648     ch_string   get_variant_ref_fname(
long num_vnt);
   649     ch_string   get_variant_path(
skeleton_glb& skg, 
long num_vnt, 
bool skip_report = 
false);
   651     bool    i_am_sub_of(
canon_cnf& the_cnf, 
bool& are_eq);
   652     bool    i_am_super_of(
canon_cnf& the_cnf, 
bool& are_eq);
   653     bool    i_sub_of_vnt(
skeleton_glb& skg, ch_string& vpth, 
bool& are_eq);
   654     bool    i_super_of_vnt(
skeleton_glb& skg, ch_string& vpth);
   655     bool    i_equal_to_vnt(
skeleton_glb& skg, ch_string& vpth);
   659     void        set_num_variants(
skeleton_glb& skg, bj_big_int_t num_vnts);
   661     bool    all_nxt_vnt(
skeleton_glb& skg, row<variant>& all_next, row<ch_string>& all_del);
   663     ch_string   first_vnt_i_super_of(
skeleton_glb& skg, row<neuron*>& all_found, 
   668     ch_string   get_cnf_path();
   670     ch_string   get_ref_path(){
   671         SKELETON_CK(cf_unique_path.size() > 0);
   672         ch_string ref_pth = SKG_REF_DIR + cf_unique_path;
   676     ch_string   get_lck_path(){
   677         SKELETON_CK(cf_unique_path.size() > 0);
   678         ch_string ref_pth = SKG_LCK_DIR + cf_unique_path;
   684     ch_string prepare_cnf(
skeleton_glb& skg, ch_string sv_base_pth);
   686     bool    save_canon_cnf(ch_string& the_pth, row<char>& cnn, 
bool write_once = 
true);
   688     void    update_parent_variants(
skeleton_glb& skg, ch_string sv_dir);
   690     void    update_chars_to_write();
   692     void    load_lits(
skeleton_glb& skg, row_long_t& all_lits, 
long& tot_lits, 
   694     void    calc_sha_in(ch_string& sha_str, ch_string& minisha_str);
   697     bool    ck_all_sup_leaf(row_str_t& all_pth);
   700         calc_sha_in(cf_sha_str, cf_minisha_str);
   708     bool    has_instance_info(){
   709         return (cf_inst_inf != NULL);
   713         SKELETON_CK(has_instance_info());
   714         return (*cf_inst_inf);
   720     bj_ostream& print_canon_cnf(bj_ostream& os, 
bool from_pt = 
false);
   722     bj_ostream& print_attrs_canon_cnf(bj_ostream& os){
   723         os << cf_dims << bj_eol;
   729         os << 
"cf_sha_str=" << cf_sha_str << bj_eol;
   730         os << 
"cf_minisha_str=" << cf_minisha_str << bj_eol;
   731         os << 
"cf_num_purged=" << cf_num_purged << bj_eol;
   763     SKELETON_DBG(
brain*         kg_pt_brn;)
   767     k_row<canon_clause> kg_clauses;
   768     row<canon_clause*>  kg_free_clauses;
   770     bool            kg_dbg_only_save;
   771     bool            kg_dbg_verifying_skeleton_tree;
   772     bool            kg_dbg_local_verifying;
   774     bool            kg_dbg_save_canon;
   775     bool            kg_keep_skeleton;
   776     bool            kg_find_cnn_pth;
   778     SKELETON_DBG(string_long_map_t  kg_dbg_all_wrt_paths);
   780     string_set_t    kg_cnf_new_paths;
   781     string_set_t    kg_cnf_paths_found;
   783     ch_string       kg_root_path;
   784     ch_string       kg_running_path;
   786     ch_string       kg_instance_file_nam;
   788     ch_string       kg_tmp_proof_path;
   790     ch_string       kg_cnfs_path;
   791     ch_string       kg_collisions_path;
   792     ch_string       kg_missing_path;
   793     ch_string       kg_corrupted_path;
   794     ch_string       kg_overlaped_path;
   795     ch_string       kg_dead_path;
   796     ch_string       kg_broken_path;
   797     ch_string       kg_show_proof_js_path;
   799     ch_string       kg_verify_path;
   800     time_t          kg_verify_mtime;
   804     row<long>       kg_tmp_lits;
   806     row<variant>        kg_tmp_all_nxt_vnts;
   807     row<ch_string>  kg_tmp_all_del_paths;
   817     brain*  get_dbg_brn(){
   818         brain* the_brn = NULL;
   819         SKELETON_DBG(the_brn = kg_pt_brn);
   823     solver* get_dbg_slv();
   825     solver& get_solver();
   827     void    set_dbg_brn(
brain* pt_brn){
   830             kg_tmp_cnf.set_dbg_brn(pt_brn);
   834     ch_string   as_full_path(ch_string sklroute){
   835         SKELETON_CK(kg_root_path != 
"");
   836         SKELETON_CK(path_begins_with(sklroute, SKG_SKELETON_DIR));
   837         return kg_root_path + sklroute;
   844         return (kg_dbg_verifying_skeleton_tree || kg_dbg_local_verifying); 
   847     canon_clause&   get_new_clause();
   848     void    release_clause(canon_clause& ccl, 
bool free_mem);
   850     void    init_skeleton_glb();
   852     void    report_err(ch_string pth, ch_string err_pth);
   854     void    reset_proof_path();
   856     bool    find_skl_path(ch_string the_pth, 
instance_info* iinfo = NULL);
   858     bool    in_skl(ch_string a_dir){
   859         ch_string skl_pth = as_full_path(SKG_SKELETON_DIR);
   860         return path_begins_with(a_dir, skl_pth);
   863     bool    ref_in_skl(ch_string a_ref){
   864         return path_begins_with(a_ref, SKG_SKELETON_DIR);
   867     bool    ref_exists(ch_string a_ref);
   869     bool    ref_create(ch_string a_ref);
   871     bool    ref_find(ch_string a_ref){
   872         ch_string f_pth = as_full_path(a_ref);
   873         return find_skl_path(f_pth);
   876     bool    ref_touch(ch_string a_ref);
   878     void    ref_remove(ch_string a_ref){
   879         ch_string f_pth = as_full_path(a_ref);
   880         unlink(f_pth.c_str());
   883     void    ref_write(ch_string nam_ref, ch_string val_ref);
   884     ch_string   ref_read(ch_string nam_ref);
   886     ch_string   ref_vnt_name(ch_string vpth, ch_string sub_nm);
   888     long num_new_paths(){
   889         return strset_size(kg_cnf_new_paths);
   893                                  ch_string sv_ref_pth, row<char>& cnn);
   895     int     get_write_lock(ch_string lk_dir);
   896     void    drop_write_lock(ch_string lk_dir, 
int fd_lock);
   898     ch_string   read_guide_sha_str(ch_string vpth);
   899     void        write_guide_sha_str(ch_string vpth, ch_string sha_str);
   901     bj_ostream& print_paths(bj_ostream& os);
   908 DEFINE_PRINT_FUNCS(canon_clause);
   909 DEFINE_PRINT_FUNCS(variant);
 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 holds an instance data. 
Definition: instance_info.h:96
 
A skeleton_glb is a directory holding a database. 
Definition: skeleton.h:761
 
Class for CNF clause behavior. So there is one neuron per clause. 
Definition: brain.h:1211