Changeset 243

Show
Ignore:
Timestamp:
03/22/07 22:41:18 (1 year ago)
Author:
ug
Message:

Fixed bug w.r.t. pattern anchors in hash_center search. Further small changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 06/libkombilo-branches/hash_center/cpptest.cpp

    r242 r243  
    2929    gl.start_processing(); 
    3030    directory_iterator end_itr; 
    31     // string path = "/home/ug/go/kombilo/06/hash_center"; 
     31    string path = "/home/ug/go/kombilo/06/hash_center"; 
    3232    // string path = "/home/ug/go/gtl/reviews"; 
    33     string path = "/home/ug/go/gogod06/2001"; 
     33    // string path = "/home/ug/go/gogod06/2001"; 
    3434    int counter = 0; 
    3535    for(directory_iterator it(path); it != end_itr; ++it) { 
  • 06/libkombilo-branches/hash_center/process.py

    r242 r243  
    1010 
    1111try:  
    12     os.system('rm t1.db*') 
     12    # os.system('rm t1.db*') 
    1313    pass 
    1414except:  
     
    5151 
    5252# filelist = glob.glob('./*.sgf') 
    53 filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 
     53# filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 
    5454# filelist = glob.glob('/home/ug/go/KGS/*/*.sgf') 
    55 # filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 
     55filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 
    5656 
    5757filelist.sort() 
  • 06/libkombilo-branches/hash_center/search.cpp

    r242 r243  
    26532653} 
    26542654 
    2655 void HashCTREntry::add(int gameid, int pos, char ori, bool cs) { 
     2655void HashCTREntry::add(int gameid, int pos, char ori, bool cs, bool do_sort) { 
    26562656  data.push_back(new HashhitCS(gameid, pos, ori, cs)); 
    26572657//   printf("HashCTREntry::add 1 gid: %d, ori: %d, pos: %d,l: %d\n", gameid, ori, pos, data.size()); 
    2658   if (data.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS); 
    2659 } 
    2660  
    2661 void HashCTREntry::add(int gameid, int position, bool cs) { 
     2658  if (do_sort && data.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS); 
     2659} 
     2660 
     2661void HashCTREntry::add(int gameid, int position, bool cs, bool do_sort) { 
    26622662  data.push_back(new HashhitCS(gameid, position, cs)); 
    26632663//   printf("HashCTREntry::add 2 gid: %d, position: %d, l:%d\n", gameid, position, data.size()); 
    2664   if (data.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS); 
    2665 } 
    2666  
    2667 char* HashCTREntry::to_charp() { 
     2664  if (do_sort && data.size() > 1) sort(data.begin(), data.end(), cmp_HashhitCS); 
     2665} 
     2666 
     2667unsigned char* HashCTREntry::to_charp() { 
    26682668//   printf("to charp\n"); 
    2669   char* c = new char[7*data.size()]; 
     2669  unsigned char* c = new unsigned char[7*data.size()]; 
    26702670  unsigned int i=0; 
    26712671  for(vector<HashhitCS* >::iterator it = data.begin(); it != data.end(); it++) { 
     
    27332733    // else printf("ok 3\n"); 
    27342734  } 
    2735    
    2736   for(set<pair<hashtype, int> >::iterator it = hash_vector.begin(); it != hash_vector.end(); it++) { 
     2735 
     2736  int counter = 0; 
     2737  for(map<hashtype, HashCTREntry* >::iterator it = all_hashes.begin(); it != all_hashes.end(); it++) { 
     2738    if (!(counter++ % 100)) printf("ctr %d\n", counter); 
    27372739    // printf("enter loop\n"); 
    2738     HashCTREntry* he = 0; 
    27392740    rc = sqlite3_bind_int64(selStmt, 1, it->first); 
    27402741    if (rc != SQLITE_OK) printf("error 4a: %d\n", rc); // return rc; 
    27412742    rc = sqlite3_step(selStmt); 
    27422743    if (rc != SQLITE_DONE && rc != SQLITE_ROW) printf("error 4: %d\n", rc); // throw DBError(); 
    2743     // else printf("ok 4\n")
     2744    HashCTREntry* he = it->second
    27442745    if (rc == SQLITE_ROW) { 
    27452746//       printf("update %lld\n", it->first); 
    2746       he = new HashCTREntry((unsigned char*)sqlite3_column_blob(selStmt, 0), sqlite3_column_bytes(selStmt, 0)); 
    2747 //       if (he->get_length() != sqlite3_column_bytes(selStmt, 0)) 
    2748 //         printf("ouch %d %d\n", he->get_length(), sqlite3_column_bytes(selStmt, 0)); 
    2749       he->add(gid, it->second); 
    2750       char* he_charp = he->to_charp(); 
     2747      he->add((unsigned char*)sqlite3_column_blob(selStmt, 0), sqlite3_column_bytes(selStmt, 0), false, true); 
     2748      unsigned char* he_charp = he->to_charp(); 
    27512749      rc = sqlite3_bind_blob(updStmt, 1, he_charp, he->get_length(), SQLITE_TRANSIENT); 
    27522750      if (rc != SQLITE_OK) printf("error 5: %d\n", rc); // return rc; 
    2753       // else printf("ok 5\n"); 
    27542751      delete [] he_charp; 
    27552752      rc = sqlite3_bind_int64(updStmt, 2, it->first); 
    27562753      if (rc != SQLITE_OK) printf("error 6: %d\n", rc); // return rc; 
    2757       // else printf("ok 6\n"); 
    27582754      rc = sqlite3_step(updStmt); 
    27592755      if (rc != SQLITE_DONE) printf("error 7: %d\n", rc); // return rc; 
    2760       // else printf("ok 7\n"); 
    27612756      rc = sqlite3_reset(updStmt); 
    27622757      if (rc != SQLITE_OK) printf("error 8: %d\n", rc); // return rc; 
    2763       // else printf("ok 8\n"); 
    2764 //       sqlite3_reset(selStmt); 
    2765 //       rc = sqlite3_step(selStmt); 
    2766 //       printf("new length %d\n", sqlite3_column_bytes(selStmt, 0)); 
    2767       delete he; 
    27682758    } else { 
    2769 //       printf("insert %lld\n", it->first); 
    2770       he = new HashCTREntry(); 
    2771       he->add(gid, it->second); 
    27722759      rc = sqlite3_bind_int64(insStmt, 1, it->first); 
    27732760      if (rc != SQLITE_OK) printf("error 9: %d\n", rc); // return rc; 
    2774       // else printf("ok 9\n"); 
    2775       char* he_charp = he->to_charp(); 
     2761      unsigned char* he_charp = he->to_charp(); 
    27762762      rc = sqlite3_bind_blob(insStmt, 2, he_charp, he->get_length(), SQLITE_TRANSIENT); 
    27772763      if (rc != SQLITE_OK) printf("error 10: %d\n", rc); // return rc; 
    2778       // else printf("ok 10\n"); 
    27792764      delete [] he_charp; 
    27802765      rc = sqlite3_step(insStmt); 
    27812766      if (rc != SQLITE_DONE) printf("error 11: %d\n", rc); // return rc; 
    2782       // else printf("ok 11\n"); 
    27832767      rc = sqlite3_reset(insStmt); 
    27842768      if (rc != SQLITE_OK) printf("error 12: %d\n", rc); // return rc; 
    2785       // else printf("ok 12\n");       
    2786 //       sqlite3_reset(selStmt); 
    2787 //       rc = sqlite3_step(selStmt); 
    2788 //       printf("new length %d\n", sqlite3_column_bytes(selStmt, 0)); 
    2789       delete he; 
    2790     } 
     2769    } 
     2770    delete he; 
    27912771    rc = sqlite3_reset(selStmt); 
    27922772    if (rc != SQLITE_OK) printf("error 13: %d\n", rc); // throw DBError(); 
    2793     // else printf("ok 13\n"); 
    2794   } 
     2773  } 
     2774  all_hashes.clear(); 
    27952775  return 0; // success 
    27962776} 
     
    27992779  // printf("enter algo_hash::initialize_processing\n"); 
    28002780  db = DB; 
     2781  all_hashes.clear(); 
    28012782  char buf[200]; 
    28022783  sprintf(buf, "create table if not exists algo_hash_%d_%s ( hash integer, data blob );", boardsize, dbnameext.c_str()); 
     
    28732854    (*it)->finalize(); 
    28742855  if (commit) { 
    2875     int rc = insert_all_hashes(); 
    2876     if (rc) printf("ouch %d\n",rc); 
    2877     hash_vector.clear(); 
    2878   } else hash_vector.clear(); 
     2856    for(set<pair<hashtype, int> >::iterator it = hash_vector.begin(); it != hash_vector.end(); it++) { 
     2857      HashCTREntry* he = 0; 
     2858      map<hashtype, HashCTREntry* >::iterator ah_it = all_hashes.find(it->first); 
     2859      if (ah_it != all_hashes.end()) { 
     2860        ah_it->second->add(gid, it->second, false, false); 
     2861      } else { 
     2862        he = new HashCTREntry(); 
     2863        he->add(gid, it->second); 
     2864        all_hashes[it->first] = he; 
     2865      } 
     2866    } 
     2867  } 
     2868  hash_vector.clear(); 
    28792869} 
    28802870  
    28812871void Algo_hash::finalize_process() { 
    2882   int rc; 
     2872  int rc = insert_all_hashes(); 
     2873  if (rc) printf("ouch %d\n",rc); 
     2874 
    28832875  rc = sqlite3_finalize(insStmt); 
    28842876  if (rc != SQLITE_OK) printf("error 14: %d\n", rc); // return rc; 
     
    30233015          else index = patternList.flipTable[*flip + 8]; 
    30243016//           printf("%d %d %d %d make cand %d, %d, %d\n", pos, ori, fl, *flip, pos_left, pos_top, index); 
    3025           candidates->push_back(new Candidate(pos_left, pos_top, index)); 
     3017          if (patternList.data[index].left <= pos_left && pos_left <= patternList.data[index].right && patternList.data[index].top <= pos_top && pos_top <= patternList.data[index].bottom) 
     3018            candidates->push_back(new Candidate(pos_left, pos_top, index)); 
    30263019        } 
    30273020        delete f_list; 
     
    31423135  string sql = buf; 
    31433136 
    3144   PatternList* sub_pl1
     3137  PatternList* sub_pl1 = 0
    31453138  int fl2 = fl; 
    31463139  if (patternList.data[patternList.size()-1].colorSwitch) { 
     
    48904883      hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner+20*bs_index])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_corner+20*bs_index]); 
    48914884      if (hash_result == 0) { 
     4885//         printf("hash_corner\n"); 
    48924886        if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 
    4893 //           printf("movelist 0\n"); 
    48944887          algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 
    48954888      } 
     
    49014894        hash_result = ((Algo_hash_center*)algo_ps[algo_hash_center+20*bs_index])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_center+20*bs_index]); 
    49024895        if (hash_result == 0) { 
    4903 //           printf("movelist after center hash\n"); 
     4896//           printf("hash_center\n"); 
    49044897          if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 
    49054898            algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 
     
    49074900      } 
    49084901      if (hash_result == -1) { 
     4902//           printf("finalpos\n"); 
    49094903          if (searchOptions->algos & ALGO_FINALPOS && algo_ps[algo_finalpos+20*bs_index]) 
    49104904              algo_ps[algo_finalpos+20*bs_index]->search(pl, *this, *searchOptions); 
    4911 //           printf("movelist\n"); 
    49124905          if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist+20*bs_index]) 
    49134906            algo_ps[algo_movelist+20*bs_index]->search(pl, *this, *searchOptions); 
  • 06/libkombilo-branches/hash_center/search.h

    r242 r243  
    524524 
    525525    void add(unsigned char* c, int l, bool cs, bool do_sort = true); 
    526     void add(int gameid, int pos, char ori, bool cs = false); 
    527     void add(int gameid, int position, bool cs = false); 
    528     char* to_charp(); 
     526    void add(int gameid, int pos, char ori, bool cs = false, bool do_sort = true); 
     527    void add(int gameid, int position, bool cs = false, bool do_sort = true); 
     528    unsigned char* to_charp(); 
    529529    int get_length(); 
    530530}; 
     
    558558    int maxNumStones; 
    559559    std::set<std::pair<hashtype, int> > hash_vector; 
     560    std::map<hashtype, HashCTREntry* > all_hashes; 
    560561    virtual int insert_hash(hashtype hashCod, int pos); 
    561562    int insert_all_hashes(); 
  • 06/libkombilo-branches/hash_center/test_hash_center2.py

    r242 r243  
    5252                      (gl.lookupLabel(x,y), cont.B, cont.wB, cont.lB, cont.W, cont.wW, cont.lW)) 
    5353 
    54     if nh_result != h_result: 
    55         print nh_result 
    56         print h_result 
    57         raise Exception() 
     54    if ''.join(nh_result) != ''.join(h_result): 
     55        out1 = open('nh_result', 'ab') 
     56        out1.write(''.join(nh_result)) 
     57        out1.close() 
     58        out2 = open('h_result', 'ab') 
     59        out2.write(''.join(h_result)) 
     60        out1.close() 
    5861    return (nohash_time, hash_time)  
    5962 
     
    102105 
    103106start = time.time() 
    104 gl = GameList('t1.db') 
     107gl = GameList(sys.argv[1] + '.db') 
    105108end = time.time() 
    106109print gl.size(), 'games in the database' 
     
    108111for pattern in pl: 
    109112    print pattern.printPattern() 
    110     print 'nh, h:', timed_search(gl, pattern) 
     113    print timed_search(gl, pattern) 
     114    print 'num hits:', gl.num_hits 
     115    print '..................................................................' 
     116    print 
    111117