Ejemplo n.º 1
0
Archivo: sat.c Proyecto: cmears/chuffed
void SAT::addClause(Clause& c, bool one_watch) {
	assert(c.size() > 0);
	if (c.size() == 1) {
		assert(decisionLevel() == 0);
		if (DEBUG) fprintf(stderr, "warning: adding length 1 clause!\n");
		if (value(c[0]) == l_False) TL_FAIL();
		if (value(c[0]) == l_Undef) enqueue(c[0]);
		free(&c);
		return;
	}
	if (!c.learnt) {
		if (c.size() == 2) bin_clauses++;
		else if (c.size() == 3) tern_clauses++;
		else long_clauses++;
	}

	// Mark lazy lits which are used
	if (c.learnt) for (int i = 0; i < c.size(); i++) incVarUse(var(c[i]));

	if (c.size() == 2 && ((!c.learnt) || (so.bin_clause_opt))) {
		if (!one_watch) watches[toInt(~c[0])].push(c[1]);
		watches[toInt(~c[1])].push(c[0]);
		if (!c.learnt) free(&c);
		return;
	}
	if (!one_watch) watches[toInt(~c[0])].push(&c);
	watches[toInt(~c[1])].push(&c);
	if (c.learnt) learnts_literals += c.size();
	else            clauses_literals += c.size();
	if (c.learnt) {
          learnts.push(&c);
          if (so.learnt_stats) {
            std::set<int> levels;
            for (int i = 0 ; i < c.size() ; i++) {
              levels.insert(out_learnt_level[i]);
            }
            std::stringstream s;
            //            s << "learntclause,";
            s << c.clauseID() << "," << c.size() << "," << levels.size();
            if (so.learnt_stats_nogood) {
                s << ",";
                for (int i = 0 ; i < c.size() ; i++) {
                    s << (i == 0 ? "" : " ") << getLitString(toInt(c[i]));
              //              s << " (" << out_learnt_level[i] << ")";
                }
            }
            //std::cerr << "\n";
            learntClauseString[c.clauseID()] = s.str();
          }
        } else {
          clauses.push(&c);
        }
}
Ejemplo n.º 2
0
Archivo: sat.c Proyecto: cmears/chuffed
void SAT::removeClause(Clause& c) {
	assert(c.size() > 1);
	watches[toInt(~c[0])].remove(&c);
	watches[toInt(~c[1])].remove(&c);
	if (c.learnt) learnts_literals -= c.size();
	else          clauses_literals -= c.size();

	if (c.learnt) for (int i = 0; i < c.size(); i++) decVarUse(var(c[i]));

        if (c.learnt) {
            //            learntClauseScore[c.clauseID()] = c.rawActivity();
            /* if (so.debug) { */
            if (so.learnt_stats) {
                int id = c.clauseID();
                learntStatsStream << learntClauseString[id];
                learntStatsStream << ",";
                learntStatsStream << c.rawActivity();
                learntStatsStream << "\n";
                /* std::cerr << "clausescore," <<  << "," << c.rawActivity() << "\n"; */
            }
            /* } */
        }

	free(&c);
}