Пример #1
0
/*
 * Delete the whole thing
 */
void delete_ef_solver(ef_solver_t *solver) {
  if (solver->exists_context != NULL) {
    delete_context(solver->exists_context);
    safe_free(solver->exists_context);
    solver->exists_context = NULL;
  }
  if (solver->forall_context != NULL) {
    delete_context(solver->forall_context);
    safe_free(solver->forall_context);
    solver->forall_context = NULL;
  }
  if (solver->exists_model != NULL) {
    yices_free_model(solver->exists_model);
    solver->exists_model = NULL;
  }

  safe_free(solver->evalue);
  safe_free(solver->uvalue);
  solver->evalue = NULL;
  solver->uvalue = NULL;

  if (solver->full_model != NULL) {
    yices_free_model(solver->full_model);
    solver->full_model = NULL;
  }
  yices_delete_term_vector(&solver->implicant);

  delete_ivector(&solver->evalue_aux);
  delete_ivector(&solver->uvalue_aux);
  delete_ivector(&solver->all_vars);
  delete_ivector(&solver->all_values);
}
/*
 * Run a test:
 * - show the constraint 
 * - check feasibility
 * - print the result
 */
static void run_test(int_constraint_t *cnstr) {
  ivector_t v;
  bool feasible;

  init_ivector(&v, 10);

  printf("Constraint: ");
  show_constraint(stdout, cnstr);
  show_fixed_vars(stdout, cnstr);

  feasible = int_constraint_is_feasible(cnstr, &v);
  if (feasible) {
    printf("Feasible\n");
  } else {
    printf("Not feasible\n");
    printf("conflict vars: ");
    show_varnames(stdout, v.data, v.size);
  }
  show_constraint_details(stdout, cnstr);

  if (feasible) {
    test_periods_and_phases(cnstr);
  }

  fflush(stdout);
  
  delete_ivector(&v);
}
Пример #3
0
static void check_propagation(test_bench_t *bench) {
  equality_queue_t *queue;
  ivector_t expl;
  uint32_t i, n;
  int32_t x, y;

  init_ivector(&expl, 10);

  queue = &bench->equeue;
  n = queue->top;
  for (i=0; i<n; i++) {
    x = queue->data[i].lhs;
    y = queue->data[i].rhs;
    if (x >= 0) {
      assert(y >= 0);

      offset_manager_explain_equality(&bench->manager, x, y, &expl);
      check_equality(bench, x, y, &expl);
      if (bench->show_details) {
	printf("Explanation for x%"PRId32" == x%"PRId32":\n", x, y);
	print_poly_def(bench->ptable, x);
	print_poly_def(bench->ptable, y);
	print_explanation(bench, &expl);
      }

      ivector_reset(&expl);
    }
  }

  delete_ivector(&expl);
}
Пример #4
0
/*
 * Check that s and c are equal
 */
static void check_equal_sets(bset_t *s, cset_t *c) {
  ivector_t aux;
  uint32_t i, n;

  n = s->card;
  for (i=0; i<n; i++) {
    if (! cset_member(c, s->data[i])) {
      goto bug;
    }
  }

  init_ivector(&aux, 10);
  cset_extract(c, &aux);
  n = aux.size;
  for (i=0; i<n; i++) {
    if (! bset_member(s, aux.data[i])) {
      goto bug;
    }
  }
  delete_ivector(&aux);
  return;

 bug:
  printf("*** BUG ***\n");
  printf(" bset: ");
  show_bset(s);
  printf("\n");
  printf(" cset: ");
  show_cset(c);
  printf("\n");
  printf("should be equal\b");
  fflush(stdout);
  exit(1);
}
/*
 * Test the period/phase computation
 */
static void test_periods_and_phases(int_constraint_t *cnstr) {
  ivector_t v;
  rational_t *p, *q;
  uint32_t i, n;
  int32_t x;

  init_ivector(&v, 10);

  n = int_constraint_num_terms(cnstr);
  for (i=0; i<n; i++) {
    ivector_reset(&v);
    int_constraint_period_of_var(cnstr, i, &v);
    x = int_constraint_get_var(cnstr, i);
    p = int_constraint_period(cnstr);
    q = int_constraint_phase(cnstr);
    printf("Variable %s: period = ", var[x].name);
    q_print(stdout, p);
    printf(", phase = ");
    q_print(stdout, q);
    printf("\n");
    printf("  antecedents: ");
    show_varnames(stdout, v.data, v.size);
    check_period_and_phase(cnstr, i, p, q);
  }

  delete_ivector(&v);
}
Пример #6
0
/*
 * Print model, including the aliased terms
 * - one line per term
 * - if model->has_alias is true, then the value of all terms in
 *   the alias table is displayed
 * - if model->has_alias is false, then this is the same as model_print
 */
void model_pp_full(yices_pp_t *printer, model_t *model) {
  evaluator_t eval;
  ivector_t v;
  term_t *a;
  uint32_t n;

  if (model->has_alias && model->alias_map != NULL) {
    init_evaluator(&eval, model);

    // collect all terms that have a value
    init_ivector(&v, 0);
    model_collect_terms(model, true, model->terms, term_to_print, &v);

    n = v.size;
    a = v.data;
    eval_pp_bool_assignments(printer, &eval, a, n);
    eval_pp_arithmetic_assignments(printer, &eval, a, n);
    eval_pp_bitvector_assignments(printer, &eval, a, n);
    eval_pp_constant_assignments(printer, &eval, a, n);
    eval_pp_tuple_assignments(printer, &eval, a, n);
    eval_pp_function_assignments(printer, &eval, a, n);
    vtbl_pp_queued_functions(printer, &model->vtbl, true);
    delete_evaluator(&eval);
    delete_ivector(&v);
  } else {
    model_pp(printer, model);
  }
}
Пример #7
0
/*
 * Undo assert_var/keep record poly
 * - stop on the top-most 'INCREASE_DLEVEL'
 */
static void op_stack_backtrack(test_bench_t *bench) {
  op_stack_t *stack;
  ivector_t saved_polys;
  uint32_t i;
  int32_t id;

  stack = &bench->stack;

  init_ivector(&saved_polys, 10);
  i = stack->top;
  for (;;) {
    assert(i > 0);
    i --;
    switch (stack->data[i].tag) {
    case RECORD_POLY:
      id = stack->data[i].arg.rec_id;
      ivector_push(&saved_polys, id);
      break;

    case ASSERT_EQ: // undo
    case PROPAGATE: // undo
      break;

    case INCREASE_DLEVEL:
      goto done;

    case PUSH:
    default:
      assert(false);
      break;
    }
  }

 done:
  stack->top = i;

  if (bench->conflict) {
    // check whether the conflict equality has been removed
    assert(bench->conflict_eq >= 0);
    if (i <= bench->conflict_eq) {
      bench->conflict_eq = -1;
      bench->conflict = false;
      bench->mngr_conflict = false;
      printf("---> Conflict resolved\n");
      fflush(stdout);
    }
  }


  // redo the record poly operations
  i = saved_polys.size;
  while (i > 0) {
    i --;
    id = saved_polys.data[i];
    push_record_poly(stack, id);
  }

  delete_ivector(&saved_polys);
}
Пример #8
0
static void test_propagate(test_bench_t *bench) {
  ivector_t expl;

  printf("[%"PRIu32"]: TEST_PROPAGATE: decision level = %"PRIu32", base level = %"PRIu32"\n", ctr, bench->decision_level, bench->base_level);
  push_propagate(&bench->stack);
  normalize_all(bench);

  if (bench->show_details) {
    printf("Active polys\n");
    print_active_polys(bench);
    printf("Assertions\n");
    print_all_equalities(bench);
    printf("Normal forms\n");
    print_normal_forms(bench);
  }

  if (bench->conflict) {
    printf("Expected result: conflict\n\n");
  } else {
    printf("Expected classes\n");
    print_expected_classes(bench);
  }

  if (offset_manager_propagate(&bench->manager)) {
    bench->mngr_conflict = false;
    printf("Propagated classes\n");
    print_infered_classes(bench);
    check_propagation(bench);
    check_all_propagated(bench);
    if (bench->conflict) {
      printf("BUG: conflict expected\n");
      fflush(stdout);
      exit(1);
    }

  } else {
    bench->mngr_conflict = true;
    printf("Conflict\n");
    init_ivector(&expl, 10);
    offset_manager_explain_conflict(&bench->manager, &expl);
    print_explanation(bench, &expl);
    check_conflict(bench, &expl);
    delete_ivector(&expl);

    if (! bench->conflict) {
      printf("BUG: conflict unexpected\n");
      fflush(stdout);
      exit(1);
    }
  }

  ctr ++;
}
Пример #9
0
/*
 * Delete the store
 */
static void delete_type_store(type_store_t *store) {
  uint32_t i, n;

  n = store->ntypes;
  for (i=0; i<n; i++) {
    delete_ivector(store->terms + i);
  }
  safe_free(store->type);
  safe_free(store->terms);

  store->type = NULL;
  store->terms = NULL;
}
Пример #10
0
/*
 * Delete all allocated memory
 */
void delete_epartition_manager(epartition_manager_t *m) {
    safe_free(m->label);
    safe_free(m->next);
    safe_free(m->root);
    safe_free(m->subclass);
    delete_ivector(&m->buffer);
    safe_free(m->empty);
    m->label = NULL;
    m->next = NULL;
    m->root = NULL;
    m->subclass = NULL;
    m->empty = NULL;
}
Пример #11
0
static void show_cset(cset_t *c) {
  ivector_t aux;
  uint32_t i, n;

  init_ivector(&aux, 10);
  cset_extract(c, &aux);
  int_array_sort(aux.data, aux.size);
  printf("{");
  n = aux.size;
  for (i=0; i<n; i++) {
    printf(" %"PRIu32, aux.data[i]);
  }
  printf(" }");
  delete_ivector(&aux);
}
Пример #12
0
/*
 * Print the model->map table
 */
void model_pp(yices_pp_t *printer, model_t *model) {
  ivector_t v;
  term_t *a;
  uint32_t n;

  init_ivector(&v, 0);
  model_collect_terms(model, false, model->terms, term_to_print, &v);

  n = v.size;
  a = v.data;
  model_pp_bool_assignments(printer, model, a, n);
  model_pp_arithmetic_assignments(printer, model, a, n);
  model_pp_bitvector_assignments(printer, model, a, n);
  model_pp_constant_assignments(printer, model, a, n);
  model_pp_tuple_assignments(printer, model, a, n);
  model_pp_function_assignments(printer, model, a, n);
  vtbl_pp_queued_functions(printer, &model->vtbl, true);
  delete_ivector(&v);
}
Пример #13
0
/*
 * Get explanation for t1 == t2
 */
static void test_eq_explanation(eterm_t t1, eterm_t t2) {
  ivector_t v;
  uint32_t i, n;
  int32_t x1, x2;

  init_ivector(&v, 10);

  x1 = var_of_term(t1);
  x2 = var_of_term(t2);
  offset_manager_explain_equality(&mngr, x1, x2, &v);

  printf("---> Explanation:");
  n = v.size;
  for (i=0; i<n; i++) {
    printf(" eq[%"PRId32"]", v.data[i]);
  }
  printf("\n\n");

  delete_ivector(&v);
}
Пример #14
0
/*
 * Delete
 */
void delete_flattener(flattener_t *flat) {
  delete_int_queue(&flat->queue);
  delete_int_hset(&flat->cache);
  delete_ivector(&flat->resu);
}
Пример #15
0
static int build_instance(char *filename, smt_core_t *core) {
  int l, n, c_idx, literal, nvars, nclauses;
  char *s;
  FILE *f;
  ivector_t buffer;

  f = fopen(filename, "r");
  if (f == NULL) {
    perror(filename);
    return OPEN_ERROR;
  }

  s = fgets(line, MAX_LINE, f);
  l = 1; /* line number */

  if (s == NULL) {
    fprintf(stderr, "%s: empty file\n", filename);
    fclose(f);
    return FORMAT_ERROR;
  }

  /* skip empty and comment lines */
  while (*s == 'c' || *s == '\n') {
    s = fgets(line, MAX_LINE, f);
    l ++;

    if (s == NULL) {
      fprintf(stderr, "Format error: file %s, line %d\n", filename, l);
      fclose(f);
      return FORMAT_ERROR;
    }
  }

  /* read problem size */
  n = sscanf(s, "p cnf %d %d", &nvars, &nclauses);
  if (n != 2 || nvars < 0 || nclauses < 0) {
    fprintf(stderr, "Format error: file %s, line %d\n", filename, l);
    fclose(f);
    return FORMAT_ERROR;
  }

  /* initialize core for nvars */
  init_sat_solver(core, nvars);

  /* initialize the clause buffer */
  init_ivector(&buffer, 10);

  /* now read the clauses and translate them */
  c_idx = 0;

  while (c_idx < nclauses) {
    for (;;) {
      literal = read_literal(f, nvars);
      if (literal < 0) break;
      ivector_push(&buffer, literal);
    }

    if (literal != END_OF_CLAUSE) {
      fprintf(stderr, "Format error: file %s\n", filename);
      fclose(f);
      return FORMAT_ERROR;
    }

    add_clause(core, buffer.size, buffer.data);
    c_idx ++;
    ivector_reset(&buffer);
  }

  delete_ivector(&buffer);
  fclose(f);

  return 0;
}
Пример #16
0
void clause_db_destruct(clause_db_t* db) {
  delete_ivector(&db->clauses);
  safe_free(db->memory);
}