Example #1
0
void Solver::detachClause(Clause& c) {
    assert(c.size() > 1);
    assert(find(watches[toInt(~c[0])], &c));
    assert(find(watches[toInt(~c[1])], &c));
    remove(watches[toInt(~c[0])], &c);
    remove(watches[toInt(~c[1])], &c);
    if (c.learnt()) learnts_literals -= c.size();
    else            clauses_literals -= c.size(); }
Example #2
0
void MiniSATP::attachClause(Clause& c) 
{
    assert(c.size() > 1);
    watches[toInt(~c[0])].push(&c);
    watches[toInt(~c[1])].push(&c);
    if (c.learnt()) learnts_literals += c.size();
    else            clauses_literals += c.size(); 
}
void SimpSolver::removeClause(Clause& c)
{
    assert(!c.learnt());

    if (use_simplification)
        for (int i = 0; i < c.size(); i++){
            n_occ[toInt(c[i])]--;
            updateElimHeap(var(c[i]));
        }

    detachClause(c);
    c.mark(1);
}
Example #4
0
void Solver::detachClause(Clause& c) {
    assert(c.size() > 1);
    //    assert(find(watches[toInt(~c[0])], &c));
    //assert(find(watches[toInt(~c[1])], &c));

    if(c.size()==2) {
      removeBin(watchesBin[toInt(~c[0])],&c);
      removeBin(watchesBin[toInt(~c[1])],&c);
    } else {
      removeW(watches[toInt(~c[0])], &c);
      removeW(watches[toInt(~c[1])], &c);
    }
    if (c.learnt()) learnts_literals -= c.size();
    else            clauses_literals -= c.size(); }
Example #5
0
/**
@brief Helper function for replace_set()
*/
bool VarReplacer::handleUpdatedClause(Clause& c, const Lit origLit1, const Lit origLit2, const Lit origLit3)
{
    bool satisfied = false;
    std::sort(c.getData(), c.getData() + c.size());
    Lit p;
    uint32_t i, j;
    const uint32_t origSize = c.size();
    for (i = j = 0, p = lit_Undef; i != origSize; i++) {
        if (solver.value(c[i]) == l_True || c[i] == ~p) {
            satisfied = true;
            break;
        }
        else if (solver.value(c[i]) != l_False && c[i] != p)
            c[j++] = p = c[i];
    }
    c.shrink(i - j);
    c.setChanged();

    solver.detachModifiedClause(origLit1, origLit2, origLit3, origSize, &c);

    #ifdef VERBOSE_DEBUG
    cout << "clause after replacing: ";
    c.plainPrint();
    #endif

    if (satisfied) return true;

    switch(c.size()) {
    case 0:
        solver.ok = false;
        return true;
    case 1 :
        solver.uncheckedEnqueue(c[0]);
        solver.ok = (solver.propagate<false>().isNULL());
        return true;
    case 2:
        solver.attachBinClause(c[0], c[1], c.learnt());
        solver.numNewBin++;
        solver.dataSync->signalNewBinClause(c);
        return true;
    default:
        solver.attachClause(c);
        return false;
    }

    assert(false);
    return false;
}
bool SimpSolver::strengthenClause(Clause& c, Lit l)
{
    assert(decisionLevel() == 0);
    assert(c.mark() == 0);
    assert(!c.learnt());
    assert(find(watches[toInt(~c[0])], &c));
    assert(find(watches[toInt(~c[1])], &c));

    // FIX: this is too inefficient but would be nice to have (properly implemented)
    // if (!find(subsumption_queue, &c))
    subsumption_queue.insert(&c);

    // If l is watched, delete it from watcher list and watch a new literal
    if (c[0] == l || c[1] == l){
        Lit other = c[0] == l ? c[1] : c[0];
        if (c.size() == 2){
            removeClause(c);
            c.strengthen(l);
        }else{
            c.strengthen(l);
            remove(watches[toInt(~l)], &c);

            // Add a watch for the correct literal
            watches[toInt(~(c[1] == other ? c[0] : c[1]))].push(&c);

            // !! this version assumes that remove does not change the order !!
            //watches[toInt(~c[1])].push(&c);
            clauses_literals -= 1;
        }
    }
    else{
        c.strengthen(l);
        clauses_literals -= 1;
    }

    // if subsumption-indexing is active perform the necessary updates
    if (use_simplification){
        remove(occurs[var(l)], &c);
        n_occ[toInt(l)]--;
        updateElimHeap(var(l));
    }

    return c.size() == 1 ? enqueue(c[0]) && propagate() == NULL : true;
}
Example #7
0
void Solver::attachClause(Clause& c) {
    assert(c.size() > 1);
    if(c.size()==2) {
      watchesBin[toInt(~c[0])].push();
      watchesBin[toInt(~c[1])].push();
      watchesBin[toInt(~c[0])].last().clause = &c;
      watchesBin[toInt(~c[0])].last().implied = c[1];
      watchesBin[toInt(~c[1])].last().clause = &c;
      watchesBin[toInt(~c[1])].last().implied = c[0];

    } else {
      watches[toInt(~c[0])].push();
      watches[toInt(~c[1])].push();
      watches[toInt(~c[0])].last().wcl = &c;
      watches[toInt(~c[0])].last().blocked = c[c.size()/2];
      watches[toInt(~c[1])].last().wcl = &c;
      watches[toInt(~c[1])].last().blocked = c[c.size()/2];
    }
    if (c.learnt()) learnts_literals += c.size();
    else            clauses_literals += c.size();
}
Example #8
0
bool Solver::handleConflict(Clause& c, int& num_props)
{
    if (backup.running
        && c.learnt()
        && backup.stage == 0
        && decisionLevel() > 0
    ) {
        #ifdef DEBUG_CONFLICTS
        printf("clause orig:");printClause(c);
        //printf("orig pointer: %p\n", &c);
        #endif //#ifdef DEBUG_CONFLICTS

        #ifdef RESTORE_FULL
        printf("Learnt clause %p wanted to make a conflict! declevel: %d trail: %d\n", &c, decisionLevel(), trail.size());
        //printClause(c);
        #endif
        backup.order_heap = order_heap;
        backup.detachedClause = &c;
        backup.stage = 1;

        //Save misc state
        backup.propagations = propagations;
        backup.bogoProps = bogoProps;
        backup.decisions = decisions;
        backup.simpDB_props = simpDB_props;
        backup.num_props = num_props;
        backup.random_seed = random_seed;
        backup.polarity = polarity;
        return false;
    }

    if (backup.running
        && c.learnt()
        && backup.stage == 1
        && decisionLevel() > 0
        && &c == backup.detachedClause
    ) {
        #ifdef RESTORE_FULL
        printf("Skipping over conflicting with clause %p\n", backup.detachedClause);
        #endif
        return false;
    }

    if (backup.running
        && c.learnt()
        && backup.stage == 2
        && decisionLevel() > 0
    ) {
        #ifdef DEBUG_CONFLICTS
        printf("clause final:");
        printClause(c);
        #endif //#ifdef DEBUG_CONFLICTS

        //printf("final pointer: %p\n", &c);
        assert(&c == backup.detachedClause);
        backup.stage = 0;
        #ifdef RESTORE_FULL
        printf("Now clause %p is making the conflict it wanted to make earlier. declevel: %d trail: %d \n", backup.detachedClause, decisionLevel(), trail.size());
        //printClause(*backup.detachedClause);
        #endif
        assert(backup.decisions <= decisions);
        assert(backup.propagations <= propagations);

        c.getGainedProps() += (propagations + num_props - backup.propagations - backup.num_props);
        c.getGainedBogoProps() += (bogoProps - backup.bogoProps);
        c.getGainedDecisions() += (decisions - backup.decisions);
        #ifdef DEBUG_DECLEVELGAIN
        if (backup.decisions < decisions) {
            fprintf(stderr, "gained declevel: %d\n", (int)(decisions - backup.decisions));
        }
        #endif //DEBUG_DECLEVELGAIN
        c.getNumConflicted()++;

        //Restore misc state
        propagations = backup.propagations;
        bogoProps = backup.bogoProps;
        decisions = backup.decisions;
        simpDB_props = backup.simpDB_props;
        random_seed = backup.random_seed;
        polarity = backup.polarity;
        num_props = backup.num_props;

        order_heap = backup.order_heap;
        backup.detachedClause = NULL;
    }

    if (backup.stage == 1) {
        #ifdef DEBUG_CONFLICTS
        printf("clause middle:");
        printClause(c);
        //printf("middle pointer: %p\n", &c);
        #endif //#ifdef DEBUG_CONFLICTS
    }

    return true;
}
Example #9
0
void Solver::attachClause(Clause& c) {
  watches[toInt(~c[0])].push(&c);
  watches[toInt(~c[1])].push(&c);
  if (c.learnt()) learnts_literals += c.size();
  else            clauses_literals += c.size(); }