Changeset 217
- Timestamp:
- 02/07/07 21:35:35 (1 year ago)
- Files:
-
- 06/libkombilo/cpptest.cpp (modified) (1 diff)
- 06/libkombilo/process.py (modified) (2 diffs)
- 06/libkombilo/search.cpp (modified) (28 diffs)
- 06/libkombilo/search.h (modified) (2 diffs)
- 06/libkombilo/testsearch.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
06/libkombilo/cpptest.cpp
r214 r217 29 29 gl.start_processing(); 30 30 directory_iterator end_itr; 31 string path = "/home/ug/go/kombilo/06/libkombilo";31 // string path = "/home/ug/go/kombilo/06/libkombilo"; 32 32 // string path = "/home/ug/go/gtl/reviews"; 33 // string path = "/home/ug/go/gogod06/1999";33 string path = "/home/ug/go/gogod06/2000"; 34 34 for(directory_iterator it(path); it != end_itr; ++it) { 35 35 string n = it->string(); 06/libkombilo/process.py
r212 r217 10 10 11 11 try: 12 os.system('rm t1.db ')12 os.system('rm t1.db*') 13 13 except: 14 14 pass … … 45 45 print 'Processed %d games in %.2f seconds' % (counter, time.time()-starttime) 46 46 47 filelist = glob.glob('./*.sgf')48 #filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf')47 # filelist = glob.glob('./*.sgf') 48 filelist = glob.glob('/home/ug/go/gogod06/*/*.sgf') 49 49 # filelist = glob.glob('/home/ug/go/KGS2005/*.sgf') 50 50 06/libkombilo/search.cpp
r216 r217 969 969 970 970 void Algo_finalpos::initialize_process(sqlite3* DB) throw(DBError) { 971 // printf("init Algo_finalpos\n"); 971 972 db = DB; 972 973 char sql[100]; 973 974 sprintf(sql, "create table if not exists algo_finalpos_%d ( id integer primary key, data blob );", boardsize); 974 975 int rc = sqlite3_exec(db, sql, 0, 0, 0); 975 if (rc != SQLITE_OK) throw DBError(); 976 if (rc != SQLITE_OK) { 977 printf("error %d\n", rc); 978 throw DBError(); 979 } 980 // printf("init Algo_finalpos\n"); 976 981 } 977 982 … … 1030 1035 } 1031 1036 data = new vector<char* >; 1037 int rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 1038 if (rc) throw DBError(); 1032 1039 sqlite3_stmt *ppStmt=0; 1033 1040 char sql[100]; 1034 1041 sprintf(sql, "select data from algo_finalpos_%d order by id", boardsize); 1035 intrc = sqlite3_prepare(db, sql, -1, &ppStmt, 0);1042 rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 1036 1043 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 1037 1044 while (sqlite3_step(ppStmt) == SQLITE_ROW) { … … 1048 1055 rc = sqlite3_finalize(ppStmt); 1049 1056 if (rc != SQLITE_OK) return rc; 1057 rc = sqlite3_exec(db, "commit;", 0, 0, 0); 1058 if (rc != SQLITE_OK) throw DBError(); 1050 1059 return 0; 1051 1060 } … … 1207 1216 1208 1217 void Algo_movelist::initialize_process(sqlite3* DB) throw(DBError) { 1218 // printf("init Algo_movelist\n"); 1209 1219 db = DB; 1210 1220 char sql[100]; … … 1212 1222 int rc = sqlite3_exec(db, sql, 0, 0, 0); 1213 1223 if (rc != SQLITE_OK) throw DBError(); 1224 // printf("init Algo_movelist\n"); 1214 1225 } 1215 1226 … … 1322 1333 db = DB; 1323 1334 1335 int rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 1336 if (rc) throw DBError(); 1337 1324 1338 sqlite3_stmt *ppStmt=0; 1325 1339 char sql[100]; 1326 1340 sprintf(sql, "select movelist,fpC from algo_movelist_%d order by id", boardsize); 1327 intrc = sqlite3_prepare(db, sql, -1, &ppStmt, 0);1341 rc = sqlite3_prepare(db, sql, -1, &ppStmt, 0); 1328 1342 if (rc != SQLITE_OK || ppStmt==0) return rc; // FIXME: catch certain errors, (and/or throw DBError?) 1329 1343 while (sqlite3_step(ppStmt) == SQLITE_ROW) { … … 1349 1363 if (rc != SQLITE_OK) return rc; 1350 1364 1365 rc = sqlite3_exec(db, "commit;", 0, 0, 0); 1366 if (rc != SQLITE_OK) throw DBError(); 1351 1367 // printf("data sizes %d, %d, %d\n", data1->size(), data1l->size(), data2->size()); 1352 1368 return 0; … … 3365 3381 labels = 0; 3366 3382 continuations = 0; 3367 dbname = new char[strlen(DBNAME)+ 1];3383 dbname = new char[strlen(DBNAME)+2]; 3368 3384 strcpy(dbname, DBNAME); 3385 db = algo_db1 = algo_db2 = 0; 3386 3387 dbname[strlen(DBNAME)] = '1'; 3388 dbname[strlen(DBNAME)+1] = 0; 3389 int rc = sqlite3_open(dbname, &algo_db1); 3390 if (rc) { 3391 sqlite3_close(algo_db1); 3392 algo_db1 = 0; 3393 throw DBError(); 3394 } 3395 rc = sqlite3_busy_timeout(algo_db1, 200); 3396 if (rc) throw DBError(); 3397 rc = sqlite3_exec(algo_db1, "pragma synchronous = off;", 0, 0, 0); 3398 if (rc) throw DBError(); 3399 rc = sqlite3_exec(algo_db1, "pragma cache_size = 100000;", 0, 0, 0); 3400 if (rc) throw DBError(); 3401 dbname[strlen(DBNAME)] = '2'; 3402 dbname[strlen(DBNAME)+1] = 0; 3403 rc = sqlite3_open(dbname, &algo_db2); 3404 if (rc) { 3405 sqlite3_close(algo_db2); 3406 algo_db2 = 0; 3407 throw DBError(); 3408 } 3409 rc = sqlite3_busy_timeout(algo_db2, 200); 3410 if (rc) throw DBError(); 3411 rc = sqlite3_exec(algo_db2, "pragma synchronous = off;", 0, 0, 0); 3412 if (rc) throw DBError(); 3413 rc = sqlite3_exec(algo_db2, "pragma cache_size = 700000;", 0, 0, 0); 3414 if (rc) throw DBError(); 3369 3415 3370 3416 // try to retrieve basic options from database 3371 int rc = sqlite3_open(dbname, &db); 3417 dbname[strlen(DBNAME)] = 0; 3418 rc = sqlite3_open(dbname, &db); 3372 3419 if (rc) { 3373 3420 sqlite3_close(db); … … 3379 3426 rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0); 3380 3427 if (rc) throw DBError(); 3381 rc = sqlite3_exec(db, "pragma cache_size = 700000;", 0, 0, 0);3428 rc = sqlite3_exec(db, "pragma cache_size = 100000;", 0, 0, 0); 3382 3429 if (rc) throw DBError(); 3383 3430 … … 3423 3470 if (rc != SQLITE_OK) throw DBError(); 3424 3471 } 3425 // rc = sqlite3_close(db);3426 // if (rc != SQLITE_OK) throw DBError();3427 // db = 0;3428 3429 3472 3430 3473 // printf("set up Algorithm instances\n"); … … 3482 3525 int ctr = algo_ps.size()/20; 3483 3526 // printf("add algos %d %d %d\n", bs, ctr, p_op->algos); 3484 for(int i=0; i<20; i++) algo_ps.push_back(0); 3527 for(int i=0; i<20; i++) { 3528 algo_ps.push_back(0); 3529 algo_dbs.push_back(0); 3530 } 3485 3531 3486 3532 algo_ps[20*ctr] = new Algo_signature(bs); 3487 if (p_op->algos & ALGO_FINALPOS) 3533 algo_dbs[20*ctr] = db; 3534 if (p_op->algos & ALGO_FINALPOS) { 3488 3535 algo_ps[algo_finalpos+20*ctr] = new Algo_finalpos(bs); 3489 if (p_op->algos & ALGO_MOVELIST) 3536 algo_dbs[algo_finalpos+20*ctr] = algo_db1; 3537 } 3538 if (p_op->algos & ALGO_MOVELIST) { 3490 3539 algo_ps[algo_movelist+20*ctr] = new Algo_movelist(bs); 3491 if (p_op->algos & ALGO_HASH_FULL) 3540 algo_dbs[algo_movelist+20*ctr] = algo_db1; 3541 } 3542 if (p_op->algos & ALGO_HASH_FULL) { 3492 3543 algo_ps[algo_hash_full+20*ctr] = new Algo_hash_full(bs, p_op->algo_hash_corner_maxNumStones); 3493 if (p_op->algos & ALGO_HASH_CORNER) 3544 algo_dbs[algo_hash_full+20*ctr] = algo_db2; 3545 } 3546 if (p_op->algos & ALGO_HASH_CORNER) { 3494 3547 algo_ps[algo_hash_corner+20*ctr] = new Algo_hash_corner(bs, 7, p_op->algo_hash_corner_maxNumStones); 3548 algo_dbs[algo_hash_corner+20*ctr] = algo_db2; 3549 } 3495 3550 // for(int a=20*ctr; a<20*(ctr+1); a++) printf("aa %d %p\n", a, algo_ps[a]); 3496 3551 // if (algos & ALGO_HASH_SIDE) … … 3513 3568 3514 3569 int rc; 3515 // db = 0;3516 // rc = sqlite3_open(dbname, &db);3517 // if (rc) {3518 // fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));3519 // sqlite3_close(db);3520 // db = 0;3521 // throw DBError();3522 // }3523 3570 rc = sqlite3_exec(db, "begin transaction;", 0, 0, 0); 3524 3571 if (rc) throw DBError(); … … 3538 3585 3539 3586 readPlayersList(); 3587 rc = sqlite3_exec(db, "commit;", 0, 0, 0); 3588 if (rc != SQLITE_OK) throw DBError(); 3540 3589 3541 3590 if (rc == SQLITE_OK && !readDBs) { 3542 3591 for(unsigned int a=0; a < 20*boardsizes.size(); a++) { 3543 if (algo_ps[a]) algo_ps[a]->readDB( db);3592 if (algo_ps[a]) algo_ps[a]->readDB(algo_dbs[a]); 3544 3593 } 3545 3594 readDBs = 1; 3546 3595 } 3547 rc = sqlite3_exec(db, "commit;", 0, 0, 0);3548 if (rc != SQLITE_OK) throw DBError();3549 3596 // printf("read.\n"); 3550 3597 3551 // rc = sqlite3_close(db);3552 // if (rc != SQLITE_OK) throw DBError();3553 // db = 0;3554 3598 reset(); 3555 3599 // printf("leave readDB\n"); … … 3793 3837 3794 3838 void GameList::gisearch(char* sql, int complete) throw(DBError) { 3795 bool dbWasOpen = false;3796 if (!db) {3797 int rc = sqlite3_open(dbname, &db);3798 if (rc) {3799 sqlite3_close(db);3800 db = 0;3801 throw DBError();3802 }3803 } else dbWasOpen = true;3804 3839 if (start_sorted() == 0) { 3805 if (!dbWasOpen) {3806 int rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0);3807 if (rc) throw DBError();3808 rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0);3809 if (rc) throw DBError();3810 }3811 3840 string query; 3812 3841 if (!complete) query = "select id from games where "; … … 3817 3846 if( rc!=SQLITE_OK ) throw DBError(); 3818 3847 3819 if (!dbWasOpen) {3820 rc = sqlite3_close(db);3821 if( rc!=SQLITE_OK ) throw DBError();3822 db = 0;3823 }3824 3848 end_sorted(); 3825 3849 } … … 3897 3921 } 3898 3922 int index = (*all)[(*currentList)[i].second]->id; 3899 // int rc = sqlite3_open(dbname, &db);3900 // if (rc) {3901 // sqlite3_close(db);3902 // db = 0;3903 // throw DBError();3904 // }3905 3923 char* prop = 0; 3906 3924 char sql[200]; … … 3909 3927 int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 3910 3928 if (rc != SQLITE_OK) throw DBError(); 3911 // sqlite3_close(db);3912 // db = 0;3913 3929 3914 3930 if (!prop) return ""; … … 3929 3945 } 3930 3946 int index = (*all)[(*currentList)[i].second]->id; 3931 // int rc = sqlite3_open(dbname, &db);3932 // if (rc) {3933 // sqlite3_close(db);3934 // db = 0;3935 // throw DBError();3936 // }3937 3947 char* prop = 0; 3938 3948 char sql[200]; … … 3941 3951 int rc = sqlite3_exec(db, sql, getpropcallback, &prop, 0); 3942 3952 if (rc != SQLITE_OK) throw DBError(); 3943 // sqlite3_close(db);3944 // db = 0;3945 3953 3946 3954 if (!prop) return ""; … … 3956 3964 sizeX = pattern.sizeX; // need this in lookupLabel 3957 3965 PatternList pl(pattern, searchOptions->fixedColor, searchOptions->nextMove); 3958 // int rc = sqlite3_open(dbname, &db);3959 // if (rc) {3960 // sqlite3_close(db);3961 // db = 0;3962 // throw DBError();3963 // }3964 // rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0);3965 // if (rc) throw DBError();3966 // rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0);3967 // if (rc) throw DBError();3968 3966 3969 3967 if (boardsizes.size() != 1 || boardsizes[0] != pattern.boardsize) { … … 3973 3971 } 3974 3972 if (!readDBs) { 3975 for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->readDB( db);3973 for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->readDB(algo_dbs[a]); 3976 3974 readDBs = 1; 3977 3975 } … … 3980 3978 // FULL BOARD PATTERN? 3981 3979 if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX == pattern.boardsize && pattern.sizeY == pattern.boardsize && algo_ps[algo_hash_full]) { 3982 hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full])->search(pl, *this, *searchOptions, db);3980 hash_result = ((Algo_hash_full*)algo_ps[algo_hash_full])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_full]); 3983 3981 if (hash_result == 1) { 3984 3982 } else if (hash_result == 0) { … … 3991 3989 // CORNER PATTERN? 3992 3990 if ((searchOptions->algos & ALGO_HASH_FULL) && pattern.sizeX >= 7 && pattern.sizeY >= 7 && algo_ps[algo_hash_corner]) { 3993 hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner])->search(pl, *this, *searchOptions, db);3991 hash_result = ((Algo_hash_corner*)algo_ps[algo_hash_corner])->search(pl, *this, *searchOptions, algo_dbs[algo_hash_corner]); 3994 3992 if (hash_result == 0) { 3995 3993 if (searchOptions->algos & ALGO_MOVELIST && algo_ps[algo_movelist]) … … 4005 4003 } 4006 4004 } 4007 // sqlite3_close(db);4008 // db = 0;4009 4005 if (labels) delete [] labels; 4010 4006 labels = pl.sortContinuations(); … … 4120 4116 4121 4117 int rc; 4122 // rc = sqlite3_open(dbname, &db);4123 // if (rc) {4124 // sqlite3_close(db);4125 // db = 0;4126 // throw DBError();4127 // }4128 // rc = sqlite3_exec(db, "pragma synchronous = off;", 0, 0, 0);4129 // if (rc) throw DBError();4130 // rc = sqlite3_exec(db, "pragma cache_size = 300000;", 0, 0, 0);4131 // if (rc) throw DBError();4132 4118 4133 4119 createGamesDB(); … … 4135 4121 char* sql = "begin transaction;"; 4136 4122 rc = sqlite3_exec(db, sql, 0, 0, 0); 4137 if (rc) throw DBError(); 4123 if (rc) { throw DBError(); } 4124 rc = sqlite3_exec(algo_db1, sql, 0, 0, 0); 4125 if (rc) { throw DBError(); } 4126 rc = sqlite3_exec(algo_db2, sql, 0, 0, 0); 4127 if (rc) { throw DBError(); } 4138 4128 current = 0; 4139 for(unsigned int a=0; a < 20*boardsizes.size(); a++) if (algo_ps[a]) algo_ps[a]->initialize_process(db); 4129 for(unsigned int a=0; a < 20*boardsizes.size(); a++) { 4130 if (algo_ps[a]) algo_ps[a]->initialize_process(algo_dbs[a]); 4131 } 4140 4132 } 4141 4133 … … 4147 4139 sqlite3_close(db); 4148 4140 db = 0; 4141 throw DBError(); 4142 } 4143 rc = sqlite3_exec(algo_db1, "commit;", 0, 0, 0); 4144 if (rc != SQLITE_OK) { 4145 sqlite3_close(algo_db1); 4146 algo_db1 = 0; 4147 throw DBError(); 4148 } 4149 rc = sqlite3_exec(algo_db2, "commit;", 0, 0, 0); 4150 if (rc != SQLITE_OK) { 4151 sqlite3_close(algo_db2); 4152 algo_db2 = 0; 4149 4153 throw DBError(); 4150 4154 } … … 4223 4227 // printf("a %d\n", a); 4224 4228 // printf("%p\n", algo_ps[a]); 4225 if (algo_ps[a]) algo_ps[a]->initialize_process( db);4229 if (algo_ps[a]) algo_ps[a]->initialize_process(algo_dbs[a]); 4226 4230 } 4227 4231 } 06/libkombilo/search.h
r211 r217 574 574 std::vector<int> boardsizes; 575 575 std::vector<algo_p> algo_ps; 576 std::vector<sqlite3*> algo_dbs; 576 577 std::vector<GameListEntry* > * all; 577 578 std::vector<std::pair<int,int> > * currentList; // pair of game id and position within all … … 655 656 int SGFtagsSize; 656 657 int sizeX; // keeps track of width of search pattern during search 658 sqlite3* algo_db1; 659 sqlite3* algo_db2; 657 660 ProcessOptions* p_op; 658 661 std::vector<std::string>* SGFtags; 06/libkombilo/testsearch.py
r216 r217 14 14 # print gl.size(), 'games in the database' 15 15 16 p = Pattern(CORNER_SW_PATTERN, 19, 7, 7, '........................X........................') 16 # p = Pattern(CENTER_PATTERN, 19, 3,4,"..O.....OX..") 17 # p = Pattern(CORNER_SW_PATTERN, 19, 7, 7, '........................X........................') 17 18 # p = Pattern(CENTER_PATTERN, 19, 3, 3, '.X.XXXXOX') 18 #p = Pattern(CENTER_PATTERN, 19, 3, 5, '.X.' + '.OX' + '.OX' + '.OX' + 'OXO')19 p = Pattern(CENTER_PATTERN, 19, 3, 5, '.X.' + '.OX' + '.OX' + '.OX' + 'OXO') 19 20 # p = Pattern(CENTER_PATTERN, 19, 5, 4, '..XOO'+ '...XX'+ '.....'+ '..X..') 20 21 so = SearchOptions()
