Example #1
0
// Creates a new SAT variable in the solver. If 'decision_var' is cleared, variable will not be
// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result).
//
Var Solver::newVar(bool sign, bool dvar)
{
    int v = nVars();
    watches   .push();          // (list for positive literal)
    watches   .push();          // (list for negative literal)
    watchesBin   .push();          // (list for negative literal)
    watchesBin   .push();          // (list for negative literal)

    watchBackup.ws.push();
    watchBackup.ws.push();
    watchBackup.flags.push(false);
    watchBackup.flags.push(false);

    reason    .push(NULL);
    assigns   .push(toInt(l_Undef));
    level     .push(-1);
    activity  .push(0);
    seen      .push(0);
    permDiff  .push(0);

    polarity    .push((char)sign);
    decision_var.push((char)dvar);

    insertVarOrder(v);
    return v;
}
Example #2
0
int SAT::newVar(int n, ChannelInfo ci) {
	int s = assigns.size();

	watches  .growBy(n);
	watches  .growBy(n);
	assigns  .growBy(n, toInt(l_Undef));
	reason   .growBy(n, NULL);
	trailpos .growBy(n, -1);
	seen     .growBy(n, 0);
        if(so.rnd_init){
          for(int i = 0 ; i < n ; i++)
            activity.growBy(1, ((double)(rand()%0xFFFFFF))/0xFFFFFF);
        }
        else
          activity .growBy(n, 0);
	polarity .growBy(n, 1);
	flags    .growBy(n, 7);

	for (int i = 0; i < n; i++) {
		c_info.push(ci);
		ci.val++;
		insertVarOrder(s+i);
	}

	return s;
}
Example #3
0
// Revert to the state at given level (keeping all assignment at 'level' but not beyond).
//
void Solver::cancelUntil(int level) {
    if (decisionLevel() > level){
        for (int c = trail.size()-1; c >= trail_lim[level]; c--){
            Var     x  = var(trail[c]);
            assigns[x] = toInt(l_Undef);
            insertVarOrder(x); }
        qhead = trail_lim[level];
        trail.shrink(trail.size() - trail_lim[level]);
        trail_lim.shrink(trail_lim.size() - level);
    } }
Example #4
0
File: sat.c Project: cmears/chuffed
inline void SAT::untrailToPos(vec<Lit>& t, int p) {
	int dl = decisionLevel();

	for (int i = t.size(); i-- > p; ) {
		int x = var(t[i]);
		assigns[x] = toInt(l_Undef);
#if PHASE_SAVING
		if (so.phase_saving >= 1 || (so.phase_saving == 1 && dl >= l0))
			polarity[x] = sign(t[i]);
#endif
		insertVarOrder(x);
	}
	t.resize(p);
}
Example #5
0
// Revert to the state at given level (keeping all assignment at 'level' but not beyond).
//
void Solver::cancelUntil(int level) {
    #ifdef RESTORE
    printf("------------    Canceling until level %d\n", level);
    #endif
  if (decisionLevel() > level){
    for (int c = trail.size()-1; c >= trail_lim[level]; c--){
      Var     x  = var(trail[c]);
      assigns[x] = toInt(l_Undef);
      insertVarOrder(x);
      #ifdef RESTORE
      printf("Canceling lit ");printLit(trail[c]); printf("\n");
      #endif
    }
    qhead = trail_lim[level];
    trail.shrink(trail.size() - trail_lim[level]);
    trail_lim.shrink(trail_lim.size() - level);
  }
}
Example #6
0
// Creates a new SAT variable in the solver. If 'decision_var' is cleared, variable will not be
// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result).
//
Var Solver::newVar(bool sign, double act, bool dvar)
{
    int v = nVars();
    watches   .push();          // (list for positive literal)
    watches   .push();          // (list for negative literal)
    reason    .push(NULL);
    assigns   .push(toInt(l_Undef));
    level     .push(-1);
    activity  .push(act);
    original_activity  .push(act);
    seen      .push(0);

    polarity    .push((char)sign);
    decision_var.push((char)dvar);

    insertVarOrder(v);
    return v;
}
Example #7
0
File: sat.c Project: cmears/chuffed
int SAT::newVar(int n, ChannelInfo ci) {
	int s = assigns.size();

	watches  .growBy(n);
	watches  .growBy(n);
	assigns  .growBy(n, toInt(l_Undef));
	reason   .growBy(n, NULL);
	trailpos .growBy(n, -1);
	seen     .growBy(n, 0);
	activity .growBy(n, 0);
	polarity .growBy(n, 1);
	flags    .growBy(n, 7);

	for (int i = 0; i < n; i++) {
		c_info.push(ci);
		ci.val++;
		insertVarOrder(s+i);
	}

	return s;
}
Example #8
0
// Creates a new SAT variable in the solver. If 'decision_var' is cleared, variable will not be
// used as a decision variable (NOTE! This has effects on the meaning of a SATISFIABLE result).
//
Var MiniSATP::newVar(bool sign, bool dvar)
{
    int v = nVars();
    watches   .push();          // (list for positive literal)
    watches   .push();          // (list for negative literal)
    reason    .push(NULL);
    assigns   .push(toInt(l_Undef));
    level     .push(-1);
    activity  .push(0);
    seen      .push(0);

    polarity    .push((char)sign);
    decision_var.push((char)dvar);

    insertVarOrder(v);

    // Added Lines
    undo_stack_oper.push_back( NEWVAR );
    // undo_stack_elem.push_back( (void *)&v );
    undo_stack_elem.push_back( reinterpret_cast< void * >( v ) );

    return v;
}
Example #9
0
void
MiniSATP::popBacktrackPoint ( ) 
{ 
  //
  // Force restart, but retain assumptions
  //
  cancelUntil(0);
  //
  // Shrink back trail
  //
  int new_trail_size = undo_trail_size.back( );
  undo_trail_size.pop_back( );
  for ( int i = trail.size( ) - 1 ; i >= new_trail_size ; i -- )
  {
    Var     x  = var(trail[i]);
    assigns[x] = toInt(l_Undef);
    reason [x] = NULL;
    insertVarOrder(x);
  }  
  trail.shrink(trail.size( ) - new_trail_size);
  assert( trail_lim.size( ) == 0 );
  qhead = trail.size( );
  //
  // Undo operations
  //
  size_t new_stack_size = undo_stack_size.back( );
  undo_stack_size.pop_back( );
  while ( undo_stack_oper.size( ) > new_stack_size )
  {
    const oper_t op = undo_stack_oper.back( );

    if ( op == NEWVAR )
    {
#ifdef BUILD_64
      long xl = reinterpret_cast< long >( undo_stack_elem.back( ) );
      const Var x = static_cast< Var >( xl );
#else
      const Var x = reinterpret_cast< int >( undo_stack_elem.back( ) );
#endif

      // Undoes insertVarOrder( )
      assert( order_heap.inHeap(x) );
      order_heap  .remove(x);
      // Undoes decision_var ... watches
      decision_var.pop();
      polarity    .pop();
      seen        .pop();
      activity    .pop();
      level       .pop();
      assigns     .pop();
      reason      .pop();
      watches     .pop();
      watches     .pop();
    }
    else if ( op == NEWUNIT )
    {
    }
    else if ( op == NEWCLAUSE )
    {
      Clause * c = (Clause *)undo_stack_elem.back( );
      assert( clauses.last( ) == c );
      // assert( c->id + 1 == (int)clause_id_to_enode.size( ) );
      clauses.pop( );
      removeClause( *c );
      // clause_id_to_enode.pop_back( );
    }
    else
    {
      opensmt_error2( "unknown undo operation in BitBlaster", op );
    }

    undo_stack_oper.pop_back( );
    undo_stack_elem.pop_back( );
  }

  while( learnts.size( ) > 0 )
  {
    Clause * c = learnts.last( );
    learnts.pop( );
    removeClause( *c );
  }

  while( removed.size( ) > 0 )
  {
    Clause * c = removed.last( );
    removed.pop( );
    free( c ); 
  }
    
  assert( undo_stack_elem.size( ) == undo_stack_oper.size( ) );
  assert( learnts.size( ) == 0 );
  assert( removed.size( ) == 0 );
}