Exemple #1
0
/*
 * Bounded search: search until the conflict bound is reached
 * or until the problem is solved.
 * - reduce_threshold: number of learned clauses above which reduce_clause_database is called
 * - r_factor = increment factor for reduce threshold
 */
static void sat_search(smt_core_t *core, uint32_t conflict_bound, uint32_t *reduce_threshold, double r_factor) {
  uint64_t max_conflicts;
  uint32_t r_threshold;
  literal_t l;

  assert(smt_status(core) == STATUS_SEARCHING || smt_status(core) == STATUS_INTERRUPTED);

  max_conflicts = num_conflicts(core) + conflict_bound;
  r_threshold = *reduce_threshold;

  smt_process(core);
  while (smt_status(core) == STATUS_SEARCHING && num_conflicts(core) <= max_conflicts) {
    // reduce heuristic
    if (num_learned_clauses(core) >= r_threshold) {
      reduce_clause_database(core);
      r_threshold = (uint32_t) (r_threshold * r_factor);
    }

    // decision
    l = select_unassigned_literal(core);
    if (l == null_literal) {
      // all variables assigned: the problem is satisfiable
      end_search_sat(core);
      break;
    }
    // propagation
    decide_literal(core, l);
    smt_process(core);
  }

  *reduce_threshold = r_threshold;
}
Exemple #2
0
/*
 * 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);
  }
}
/*
 * 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);
}