Example #1
0
static void
printa (PicoSAT * picosat, int partial)
{
  int max_idx = picosat_variables (picosat), i, lit, val;

  assert (bhead == buffer);

  for (i = 1; i <= max_idx; i++)
    {
      if (partial)
	{
	  val = picosat_deref_partial (picosat, i);
	  if (!val)
	    continue;
	}
      else
	val = picosat_deref (picosat, i);
      lit = (val > 0) ? i : -i;
      printi (lit);
    }

  printi (0);
  if (bhead > buffer)
    bflush ();
}
Example #2
0
CAMLprim value caml_model(value unit) {
    CAMLparam0 ();
    CAMLlocal1( tl );
    tl = Val_emptylist;
    int i, max_idx = picosat_variables ();
    for (i = 1; i <= max_idx; i++)
        /* discard all variables that are unknown */
        if (picosat_deref (i))
            tl = append (Val_int(i), tl);

    CAMLreturn(tl);
}
Example #3
0
CAMLprim value caml_unsatcore(value unit) {
    CAMLparam0 ();
    CAMLlocal1( tl );
    tl = Val_emptylist;
    int i, max_idx = picosat_variables ();
    for (i = 1; i <= max_idx; i++)
        /* discard all variables that are not in the unsat core */
        if (picosat_corelit (i))
            tl = append (Val_int(i), tl);

    CAMLreturn(tl);
}
Example #4
0
static void
write_core_variables (PicoSAT * picosat, FILE * file)
{
  int i, max_idx = picosat_variables (picosat), count = 0;
  for (i = 1; i <= max_idx; i++)
    if (picosat_corelit (picosat, i))
      {
	fprintf (file, "%d\n", i);
	count++;
      }

  if (verbose)
    fprintf (output, "c found and wrote %d core variables\n", count);
}
Example #5
0
static void
blocksol (PicoSAT * picosat)
{
  int max_idx = picosat_variables (picosat), i;

  if (!sol)
    {
      sol = malloc (max_idx + 1);
      memset (sol, 0, max_idx + 1);
    }

  for (i = 1; i <= max_idx; i++)
    sol[i] = (picosat_deref (picosat, i) > 0) ? 1 : -1;

  for (i = 1; i <= max_idx; i++)
    picosat_add (picosat, (sol[i] < 0) ? i : -i);

  picosat_add (picosat, 0);
}
Example #6
0
static void
write_failed_assumptions (PicoSAT * picosat, FILE * file)
{
  int i, lit, count = 0;
#ifndef NDEBUG
  int max_idx = picosat_variables (picosat);
#endif
  i = 0;
  while ((i = next_assumption (i))) {
    lit = atoi (sargv[i]);
    if (!picosat_failed_assumption (picosat, lit)) continue;
    fprintf (file, "%d\n", lit);
    count++;
  }
  if (verbose)
    fprintf (output, "c found and wrote %d failed assumptions\n", count);
#ifndef NDEBUG
  for (i = 1; i <= max_idx; i++)
    if (picosat_failed_assumption (picosat, i))
      count--;
#endif
  assert (!count);
}
Example #7
0
static int
btor_picosat_variables (BtorSATMgr * smgr)
{
  return picosat_variables (smgr->solver);
}
Example #8
0
int main(int argc, char **argv)
{
  int i,j,k,l,m;

  if (argc < 2) {
    fprintf(stderr, "usage: sudoku [puzzles]\n");
    exit(1);
  }

  picosat_init();
  /* picosat_enable_trace_generation(); */

  mapFile = fopen("var-map.txt", "w"), assert(mapFile);
  cnfFile = fopen("general.cnf", "w"), assert(cnfFile);
  if (0 == strcmp(argv[1], "-") || argc <= 1) {
    inputFile = stdin;
  } else {
    inputFile = fopen(argv[1], "r");
  }

  /* create vars */
  for (j = 0; j < N; j++) {
    for (k = 0; k < N; k++) {
      for (i = 0; i < N; i++) {
        p[i][j][k] = picosat_inc_max_var();
        fprintf(mapFile, "%d = p[%d][%d][%d]\n", p[i][j][k], i, j, k);
      }
    }
  }
  fprintf(stderr, "%d variables\n", picosat_variables());

  /* each cell set to at least one value */
  for (j = 0; j < N; j++) {
    for (k = 0; k < N; k++) {
      for (i = 0; i < N; i++) {
        picosat_add(p[i][j][k]);
      }
      picosat_add(0);
    }
  }

  /* each cell set to at most one value */
  for (j = 0; j < N; j++) {
    for (k = 0; k < N; k++) {
      for (i = 0; i < N; i++) {
        for (l = 0; l < N; l++) {
          if (i != l) {
            /* pijk -> !pljk (when l!=i) */
            picosat_add(-p[i][j][k]);
            picosat_add(-p[l][j][k]);
            picosat_add(0);
          }
        }
      }
    }
  }

  /* column: no cell has the same value */
  LINE(i,0,N, j,0,N, k,0,N, {
      for (l = 0; l < N; l++) {
        if (l != j) {
          picosat_add(-p[i][j][k]);
          picosat_add(-p[i][l][k]);
          picosat_add(0);
        }
      }
    });