/* * Full solver: * - params: heuristic parameters. * If params is NULL, the default settings are used. * - verbose: if true, prints some data after each outer restart */ static void sat_solve(smt_core_t *core, core_param_t *params, bool verbose) { uint32_t c_threshold, d_threshold; // Picosat-style uint32_t reduce_threshold; assert(smt_status(core) == STATUS_IDLE); if (params == NULL) { params = &default_settings; } set_randomness(core, params->randomness); set_var_decay_factor(core, params->var_decay); set_clause_decay_factor(core, params->clause_decay); c_threshold = params->c_threshold; d_threshold = params->d_threshold; reduce_threshold = (uint32_t) (num_prob_clauses(core) * params->r_fraction); if (reduce_threshold < params->r_threshold) { reduce_threshold = params->r_threshold; } // initialize then do a propagation + simplification step. start_search(core); smt_process(core); if (verbose) { show_progress(core, d_threshold, reduce_threshold, true); } if (smt_status(core) == STATUS_SEARCHING) { // loop for (;;) { sat_search(core, c_threshold, &reduce_threshold, params->r_factor); if (smt_status(core) != STATUS_SEARCHING) break; smt_restart(core); // inner restart: increase c_threshold c_threshold = (uint32_t) (c_threshold * params->c_factor); if (c_threshold >= d_threshold) { d_threshold = c_threshold; if (params->fast_restart) { // outer restart: reset c_threshold and increase d_threshold c_threshold = params->c_threshold; d_threshold = (uint32_t) (d_threshold * params->d_factor); } if (verbose) { show_progress(core, d_threshold, reduce_threshold, false); } } } } if (verbose) { printf("---------------------------------------------------------------------------------\n\n"); fflush(stdout); } }
static void search_monitor_add (NautilusDirectory *directory, gconstpointer client, gboolean monitor_hidden_files, NautilusFileAttributes file_attributes, NautilusDirectoryCallback callback, gpointer callback_data) { GList *list; SearchMonitor *monitor; NautilusSearchDirectory *search; NautilusFile *file; search = NAUTILUS_SEARCH_DIRECTORY (directory); monitor = g_new0 (SearchMonitor, 1); monitor->monitor_hidden_files = monitor_hidden_files; monitor->monitor_attributes = file_attributes; monitor->client = client; search->details->monitor_list = g_list_prepend (search->details->monitor_list, monitor); if (callback != NULL) { (* callback) (directory, search->details->files, callback_data); } for (list = search->details->files; list != NULL; list = list->next) { file = list->data; /* Add monitors */ nautilus_file_monitor_add (file, monitor, file_attributes); } start_search (search); }
static void activate_cb (GtkEntry *entry, GtkButton *button) { if (search_progress_id != 0) return; start_search (button, entry); }
static void search_call_when_ready (NautilusDirectory *directory, NautilusFileAttributes file_attributes, gboolean wait_for_file_list, NautilusDirectoryCallback callback, gpointer callback_data) { NautilusSearchDirectory *search; SearchCallback *search_callback; search = NAUTILUS_SEARCH_DIRECTORY (directory); search_callback = search_callback_find (search, callback, callback_data); if (search_callback == NULL) { search_callback = search_callback_find_pending (search, callback, callback_data); } if (search_callback) { g_warning ("tried to add a new callback while an old one was pending"); return; } search_callback = g_new0 (SearchCallback, 1); search_callback->search_directory = search; search_callback->callback = callback; search_callback->callback_data = callback_data; search_callback->wait_for_attributes = file_attributes; search_callback->wait_for_file_list = wait_for_file_list; if (wait_for_file_list && !search->details->search_ready_and_valid) { /* Add it to the pending callback list, which will be * processed when the directory has valid data from the new * search and all data and signals from previous searchs is removed. */ search->details->pending_callback_list = g_list_prepend (search->details->pending_callback_list, search_callback); /* We might need to start the search engine */ start_search (search); } else { search_callback->file_list = nautilus_file_list_copy (search->details->files); search_callback->non_ready_hash = file_list_to_hash_table (search->details->files); if (!search_callback->non_ready_hash) { /* If there are no ready files, we invoke the callback with an empty list. */ search_callback_invoke_and_destroy (search_callback); } else { search->details->callback_list = g_list_prepend (search->details->callback_list, search_callback); search_callback_add_file_callbacks (search_callback); } } }
bool ContestDijkstra::Solve(bool exhaustive) { if (dijkstra.empty()) { set_weightings(); dijkstra.reserve(CONTEST_QUEUE_SIZE); } assert(num_stages <= MAX_STAGES); if (dijkstra.empty()) { update_trace(); if (n_points < num_stages) return true; // don't re-start search unless we have had new data appear if (!trace_dirty) { return true; } } else if (exhaustive) { update_trace(); if (n_points < num_stages) return true; } else if (n_points < num_stages) { update_trace(); return true; } if (trace_dirty) { trace_dirty = false; dijkstra.restart(ScanTaskPoint(0, 0)); start_search(); add_start_edges(); if (dijkstra.empty()) { return true; } } #ifdef INSTRUMENT_TASK count_olc_solve++; count_olc_size = max(count_olc_size, dijkstra.queue_size()); #endif if (distance_general(exhaustive ? 0 - 1 : 25)) { SaveSolution(); update_trace(); return true; } return !dijkstra.empty(); }
int Flat<Obj>::count_routes() { return start_search(); }
/* Process uki commmands from input buffer */ void uci() { while( 1 ) { usleep(200); string s; string tokens[1024]; s = getInput(); int token_count = parseString(s, tokens); if(token_count == 0) { continue; } if(tokens[0].compare("uki") == 0) { cout << "id name Khet "<< version << endl; cout << "id author YOUR NAME" << endl; cout << "ukiok" << endl; continue; } else if(tokens[0].compare("isready") == 0) { cout << "readyok" << endl; continue;; } else if(tokens[0].compare("ukinewgame") == 0) { continue; } else if(tokens[0].compare("setoption") == 0) { continue; } else if(tokens[0].compare("position")== 0) { ply = 0; if(gameHis[ply].init(tokens[1]) != 0) { cout << "invalid input position" << endl; exit(1); } //make all moves inlist if(token_count > 2 && tokens[2].compare("moves") != 0) { cout << "invalid input position" << endl; exit(1); } for(int i = 3; i < token_count; i++) { if(uciMakeMove(&gameHis[ply], &gameHis[ply + 1], tokens[i]) != 0) { cout << s <<" Invalid move:" << tokens[i] << endl; exit(1); } ply++; } } else if(tokens[0].compare("go")== 0) { best_move_buf = ""; //clear buf int search_time = -1; //indicates infintie int increment = 0; int depth = 10; for(int i = 1; i < token_count; i ++) { if(tokens[i].compare("wtime") == 0) { search_time = strtol(tokens[i+1].c_str(), NULL, 10) ; i++; } else if(tokens[i].compare("btime") == 0) { search_time = strtol(tokens[i+1].c_str(), NULL, 10) ; i++; } else if(tokens[i].compare("infinite") == 0) { search_time = -1; } else if(tokens[i].compare("winc") == 0) { increment = strtol(tokens[i+1].c_str(), NULL, 10); i++; } else if(tokens[i].compare("binc") == 0) { increment = strtol(tokens[i+1].c_str(), NULL, 10); i++; } else if(tokens[i].compare("depth") == 0) { depth = atoi(tokens[i+1].c_str()); i++; } } //try to use only a bit of your remaining time per move if(search_time != -1) search_time = search_time * .02 + increment * 0.8; cilk_spawn start_search(search_time, depth); continue; } else if(tokens[0].compare("stop")== 0) { _ABSEARCH::abortSearch(); } //prints out string format of board else if(tokens[0].compare("display")== 0) { string bd = gameHis[ply].getBoardPrettyStr(); cout << bd << endl ; } //forces a move generation of current board else if(tokens[0].compare("gen")== 0) { cout << gameHis[ply].gen() << endl; } else if(tokens[0].compare("quit")== 0) { exit(0); } //Not part of uki, prints out list of all possible moves form current state else if(tokens[0].compare("debug")== 0) { gameHis[ply].debugMoves(); } else if(tokens[0].compare("eval")== 0) { cout << gameHis[ply].evaluate() <<endl; } //The perft command is not part of UKI //prints out the counts of possible moves at from current position at depth i //ie the leaves of the game tree. Good move gen debug method else if(tokens[0].compare("perft")== 0) { int depth = 1; for(;depth < atoi(tokens[1].c_str()); depth++) { uint64_t nodec = gameHis[ply].perft(depth); cout << "Node count for depth " << depth << " is " << nodec << endl; } } else { cout << "Unrecognized UCI command: "<< tokens[0] << endl; } } }
/* * Test 1: construct simple terms, push/pop */ static void test1(void) { eterm_t tx, ty; occ_t x, y; type_t u; printf("***********************\n" "* TEST 1 *\n" "***********************\n\n"); init_solver(&egraph, &core); u = yices_new_uninterpreted_type(); // create x and y printf("---> building x and y\n"); tx = egraph_make_variable(&egraph, u); x = pos_occ(tx); ty = egraph_make_variable(&egraph, u); y = pos_occ(ty); // test push/pop printf("---> push\n"); smt_push(&core); // create (eq x y) printf("---> building (eq x y)\n"); (void) egraph_make_eq(&egraph, x, y); // create (eq y y) printf("---> building (eq x x)\n"); (void) egraph_make_eq(&egraph, y, y); print_solver(&egraph, &core); // empty push printf("---> push\n"); smt_push(&core); // start search + propagate + end_search printf("---> propagation test 1\n"); start_search(&core); smt_process(&core); end_search_unknown(&core); print_solver(&egraph, &core); printf("---> pop 1\n"); smt_pop(&core); print_solver(&egraph, &core); // start search + propagate + end_search printf("---> propagation test 2\n"); start_search(&core); smt_process(&core); end_search_unknown(&core); print_solver(&egraph, &core); printf("---> pop 2\n"); smt_pop(&core); print_solver(&egraph, &core); // reset reset_solver(&egraph, &core); print_solver(&egraph, &core); delete_solver(&egraph, &core); }