Пример #1
0
static int
btor_lingeling_sat (BtorSATMgr * smgr, int limit)
{
  BtorLGL * blgl = smgr->solver;
  LGL * lgl = blgl->lgl, * bforked;
  const int clone = 1; // TODO?
  const char * str;
  int res, bfres;
  char name[80];

  if (!smgr->inc_required)
    {
      lglsetopt (lgl, "clim", -1);
      res = lglsat (lgl);
      return res;
    }

  lglsetopt (lgl, "flipping", 0);
  
  if (smgr->nofork || (0 <= limit && limit < blgl->blimit))
    {
      if (limit < INT_MAX) lglsetopt (lgl, "clim", limit);
      res = lglsat (lgl);
    }
  else
    {
      btor_msg_sat (smgr, 1, "blimit = %d", blgl->blimit);
      lglsetopt (lgl, "clim", blgl->blimit);
      // if (smgr->inc_required) lglsetopt (lgl, "plain", 1);
      if (!(res = lglsat (lgl)))
	{
	  lglsetopt (lgl, "plain", 0);
	  blgl->blimit *= 2;
	  if (blgl->blimit > BTOR_LGL_MAX_BLIMIT)
	    blgl->blimit = BTOR_LGL_MAX_BLIMIT;
	  blgl->nforked++;
	  if (clone) {
	    bforked = lglclone (lgl);
	    lglfixate (bforked);
	    lglmeltall (bforked);
	    str = "clone";
	  } else bforked = lglbrutefork (lgl, 0), str = "fork";
	  lglsetopt (bforked, "seed", blgl->nforked);
	  lglsetopt (bforked, "flipping", 1);
	  sprintf (name, "[lgl%s%d] ", str, blgl->nforked);
	  lglsetprefix (bforked, name);
	  lglsetout (bforked, smgr->output);
	  if (lglgetopt (lgl, "verbose")) lglsetopt (bforked, "verbose", 1);
	  lglsetopt (bforked, "clim", limit);
	  res = lglsat (bforked);
	  if (smgr->verbosity > 0) lglstats (bforked);
	  if (clone) {
	    bfres = lglunclone (lgl, bforked);
	    lglrelease (bforked);
	  } else bfres = lgljoin (lgl, bforked);
	  assert (!res || bfres == res);
	  res = bfres;
	}
      else
	{
	  blgl->blimit = 9*(blgl->blimit/10);
	  if (blgl->blimit < BTOR_LGL_MIN_BLIMIT)
	    blgl->blimit = BTOR_LGL_MIN_BLIMIT;
	}
    }
  return res;
}
Пример #2
0
static void
btor_lingeling_set_prefix (BtorSATMgr * smgr, const char * prefix)
{
  BtorLGL * blgl = smgr->solver;
  lglsetprefix (blgl->lgl, prefix);
}
Пример #3
0
void
btor_process_skeleton (Btor * btor)
{
  BtorPtrHashTable * ids;
  BtorNodePtrStack unmark_stack;
  int count, fixed;
  BtorNodePtrStack work_stack;
  BtorMemMgr * mm = btor->mm;
  BtorHashTableIterator it;
  double start, delta;
  int res, lit, val;
  BtorNode * exp;
  LGL * lgl;

  start = btor_time_stamp ();

  ids = btor_new_ptr_hash_table (mm,
          (BtorHashPtr) btor_hash_exp_by_id,
          (BtorCmpPtr) btor_compare_exp_by_id);

  lgl = lglinit ();
  lglsetprefix (lgl, "[lglskel] ");

  if (btor->options.verbosity.val >= 2)
    {
      lglsetopt (lgl, "verbose", btor->options.verbosity.val - 1);
      lglbnr ("Lingeling", "[lglskel] ", stdout);
      fflush (stdout);
    }
  else
    lglsetopt (lgl, "verbose", -1);        

  count = 0;

  BTOR_INIT_STACK (work_stack);
  BTOR_INIT_STACK (unmark_stack);

  btor_init_node_hash_table_iterator (&it, btor->synthesized_constraints);
  btor_queue_node_hash_table_iterator (&it, btor->unsynthesized_constraints);
  while (btor_has_next_node_hash_table_iterator (&it))
    {
      count++;
      exp = btor_next_node_hash_table_iterator (&it);
      assert (btor_get_exp_width (btor, exp) == 1);
      process_skeleton_tseitin (btor, lgl,
        &work_stack, &unmark_stack, ids, exp);
      lgladd (lgl, process_skeleton_tseitin_lit (ids, exp));
      lgladd (lgl, 0);
    }

  BTOR_RELEASE_STACK (mm, work_stack);

  while (!BTOR_EMPTY_STACK (unmark_stack))
    {
      exp = BTOR_POP_STACK (unmark_stack);
      assert (!BTOR_IS_INVERTED_NODE (exp));
      assert (exp->mark);
      exp->mark = 0;
    }

  BTOR_RELEASE_STACK (mm, unmark_stack);

  BTOR_MSG (btor->msg, 1, "found %u skeleton literals in %d constraints",
                ids->count, count);

  res = lglsimp (lgl, 0);

  if (btor->options.verbosity.val)
    {
      BTOR_MSG (btor->msg, 1, "skeleton preprocessing result %d", res);
      lglstats (lgl);
    }

  fixed = 0;

  if (res == 20)
    {
      BTOR_MSG (btor->msg, 1, "skeleton inconsistent");
      btor->inconsistent = 1;
    }
  else
    {
      assert (res == 0 || res == 10);
      btor_init_node_hash_table_iterator (&it, ids);
      while (btor_has_next_node_hash_table_iterator (&it))
        {
          exp = btor_next_node_hash_table_iterator (&it);
          assert (!BTOR_IS_INVERTED_NODE (exp));
          lit = process_skeleton_tseitin_lit (ids, exp);
          val = lglfixed (lgl, lit);
          if (val)
            {
              if (!btor_find_in_ptr_hash_table (
                    btor->synthesized_constraints, exp) &&
                  !btor_find_in_ptr_hash_table (
                    btor->unsynthesized_constraints, exp))
                {
                  if (val < 0)
                    exp = BTOR_INVERT_NODE (exp);
                  btor_assert_exp (btor, exp);
                  btor->stats.skeleton_constraints++;
                  fixed++;
                }
            }
          else
            {
              assert (!btor_find_in_ptr_hash_table (
                         btor->synthesized_constraints, exp));
              assert (!btor_find_in_ptr_hash_table (
                         btor->unsynthesized_constraints, exp));
            }
        }
    }

  btor_delete_ptr_hash_table (ids);
  lglrelease (lgl);

  delta = btor_time_stamp () - start;
  btor->time.skel += delta;
  BTOR_MSG (btor->msg, 1,
      "skeleton preprocessing produced %d new constraints in %.1f seconds",
      fixed, delta);
  assert (btor_check_id_table_mark_unset_dbg (btor));
}