Example #1
0
/**Function********************************************************************

  Synopsis    [Adds a clause to the solver database.]

  Description [converts all CNF literals into the internal literals,
  adds a group id to every clause (if group is not permament) and then add
  obtained clauses to actual Minisat]

  SideEffects []

  SeeAlso     []

******************************************************************************/
void sat_minisat_add(const SatSolver_ptr solver,
                     const Be_Cnf_ptr cnfProb,
                     SatSolverGroup group)
{
  SatMinisat_ptr self = SAT_MINISAT(solver);

  int * clause = (int *)NULL;
  Siter genClause;
  int* minisatClause;

  /* just for efficiency */
  const int groupIsNotPermanent =
    SatSolver_get_permanent_group(SAT_SOLVER(self)) != group;


  SAT_MINISAT_CHECK_INSTANCE(self);

  minisatClause = sat_minisat_get_minisatClause(self);

  SLIST_FOREACH (Be_Cnf_GetClausesList(cnfProb), genClause) {
    clause = (int*) Siter_element(genClause);

    int literal, i;
    int clause_size = _get_clause_size(clause);
    int literalNumber = 0;

    if (sat_minisat_get_minisatClauseSize(self) - 4 <= clause_size) {
      sat_minisat_enlarge_minisatClause(self, clause_size + 5);
      minisatClause = sat_minisat_get_minisatClause(self);
    }
    i = 0;
    while (clause[i] != 0) {
      literal = clause[i];
      minisatClause[literalNumber]
        = sat_minisat_cnfLiteral2minisatLiteral(self, literal);
      ++literalNumber;
      i++;
    }

    if (groupIsNotPermanent) { /* add group id to the clause */
      minisatClause[literalNumber] = group;
      ++literalNumber;
    }
#ifdef MINISAT_WITH_PROOF_LOGGING
    /* add to real minisat */
    MiniSat_Add_Clause(self->minisatSolver, minisatClause,
                       literalNumber, SatSolver_curr_itp_group(solver));
#else
    MiniSat_Add_Clause(self->minisatSolver, minisatClause,
                       literalNumber);
#endif
    /* with the new interface of minisat there is not reason to remember
       that an unsatisfiable clause has been added to the solver */

  } /* while() */
Example #2
0
void Be_Cnf_PrintStat(const Be_Cnf_ptr self, FILE* outFile, char* prefix)
{
  /* compute values */
  int max_clause_size = 0;
  float sum_clause_size = 0;
  Siter cnf;

  nusmv_assert(self != (Be_Cnf_ptr)NULL);

  SLIST_FOREACH(Be_Cnf_GetClausesList(self), cnf) {
    int* clause = (int*)Siter_element(cnf);
    int clause_size;

    SLIST_CHECK_INSTANCE(Be_Cnf_GetClausesList(self));

    for (clause_size = 0; clause[clause_size] != 0; ++clause_size) { }

    sum_clause_size += clause_size;
    if (clause_size > max_clause_size) max_clause_size = clause_size;
  }
Example #3
0
void Be_Cnf_RemoveDuplicateLiterals(Be_Cnf_ptr self)
{
  int i, j;
  Siter iter;
  int * clause = (int *)NULL;
  hash_ptr lits = (hash_ptr)NULL;

  nusmv_assert(self != NULL);

  lits = new_assoc();

  for (iter = Slist_first(Be_Cnf_GetClausesList(self));
       !Siter_is_end(iter);
       iter = Siter_next(iter)) {

    clause = (int*) Siter_element(iter);

    i = 0;
    while (clause[i] != 0) {
      if (Nil != find_assoc(lits, NODE_FROM_INT(clause[i]))) {
        j = i+1;
        while (clause[j] != 0) {
          clause[j-1] = clause[j];
          j++;
        }
      }
      else {
        insert_assoc(lits, NODE_FROM_INT(clause[i]), NODE_FROM_INT(1));
      }
      i++;
    }

    /* this clear the hash */
    clear_assoc(lits);
  }

  free_assoc(lits);
}
Example #4
0
size_t Be_Cnf_GetClausesNumber(const Be_Cnf_ptr self)
{
  return Slist_get_size(Be_Cnf_GetClausesList(self));
}
Example #5
0
  /* print out values */
    fprintf(outFile,
            "%s Clause number: %i\n"
            "%s Var number: %i\n"
            "%s Max var index: %i\n"
            "%s Average clause size: %.2f\n"
            "%s Max clause size: %i\n",
            prefix,
            (int)Be_Cnf_GetClausesNumber(self),
            prefix,
            (int)Be_Cnf_GetVarsNumber(self),
            prefix,
            Be_Cnf_GetMaxVarIndex(self),
            prefix,
            /* the average clause size */
            (double)(sum_clause_size / Slist_get_size(Be_Cnf_GetClausesList(self))),
            prefix,
            max_clause_size);
}

/*!
  \brief Frees the array used to store the clause.

  
*/
static void _be_cnf_destroy_clause(void* data) {
  int * _data = (int *)data;

  FREE(_data);
}
/**AutomaticEnd***************************************************************/