示例#1
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);
  }
}
示例#2
0
/*
 * Full header: includes the learned clauses
 */
static void dimacs_print_full_header(FILE *f, smt_core_t *core) {
  uint32_t num_clauses;

  num_clauses = num_empty_clauses(core) + num_unit_clauses(core) + num_binary_clauses(core) +
    num_prob_clauses(core) + num_learned_clauses(core) + 1;

  fprintf(f, "p cnf %"PRIu32" %"PRIu32"\n", core->nvars, num_clauses);
}
示例#3
0
/*
 * Name and size of the problem + core settings
 * and construction_time
 */
static void print_problem_size(FILE *f, smt_core_t *core, char *filename, double construction_time) {
  fprintf(f, "Problem: %s\n\n", basename(filename));
  fprintf(f, "Construction time       : %.4f s\n", construction_time);
  fprintf(f, "nb. of vars             : %"PRIu32"\n", num_vars(core));
  fprintf(f, "nb. of unit clauses     : %"PRIu32"\n", num_unit_clauses(core));
  fprintf(f, "nb. of bin clauses      : %"PRIu32"\n", num_binary_clauses(core));
  fprintf(f, "nb. of big clauses      : %"PRIu32"\n", num_prob_clauses(core));
  fprintf(f, "clause decay            : %g\n", clause_decay_factor(core));
  fprintf(f, "var decay               : %g\n", var_decay_factor(core));
  fprintf(f, "randomness factor       : %g\n\n", randomness_factor(core));
}
示例#4
0
/*
 * Print some statistic data + header if requested (on stdout)
 */
static void show_progress(smt_core_t *core,
			  uint32_t restart_threshold, uint32_t reduce_threshold, bool show_header) {

  if (show_header) {
    printf("---------------------------------------------------------------------------------\n");
    printf("|     Thresholds    |  Binary   |      Original     |          Learned          |\n");
    printf("|   Conf.      Del. |  Clauses  |   Clauses   Lits. |   Clauses  Lits. Lits/Cl. |\n");
    printf("---------------------------------------------------------------------------------\n");
  }

  printf("| %7"PRIu32"  %8"PRIu32" |  %8"PRIu32" | %8"PRIu32" %8"PRIu64" | %8"PRIu32" %8"PRIu64" %7.1f |\n",
	 restart_threshold, reduce_threshold,
	 num_binary_clauses(core),
	 num_prob_clauses(core), num_prob_literals(core),
	 num_learned_clauses(core), num_learned_literals(core),
	 ((double) num_learned_literals(core)/num_learned_clauses(core)));
  fflush(stdout);
}