1.drup_file

声明的成员与函数

     FILE*     drup_file;

 

 

#ifdef BIN_DRUP


static int buf_len;
static unsigned char drup_buf[];
static unsigned char* buf_ptr;

static inline void byteDRUP(Lit l){

unsigned int u = 2 * (var(l) + 1) + sign(l);
do{
    *buf_ptr++ = u & 0x7f | 0x80; buf_len++;
    u = u >> 7;
}while (u);
*(buf_ptr - 1) &= 0x7f; // End marker of this unsigned number.

}

template<class V>
static inline void binDRUP(unsigned char op, const V& c, FILE* drup_file){

assert(op == 'a' || op == 'd');
*buf_ptr++ = op; buf_len++;
for (int i = 0; i < c.size(); i++) byteDRUP(c[i]);
*buf_ptr++ = 0; buf_len++;
if (buf_len > 1048576) binDRUP_flush(drup_file);

}

static inline void binDRUP_strengthen(const Clause& c, Lit l, FILE* drup_file){

*buf_ptr++ = 'a'; buf_len++;
for (int i = 0; i < c.size(); i++)
if (c[i] != l) byteDRUP(c[i]);
*buf_ptr++ = 0; buf_len++;
if (buf_len > 1048576) binDRUP_flush(drup_file);

}

static inline void binDRUP_flush(FILE* drup_file){

fwrite(drup_buf, sizeof(unsigned char), buf_len, drup_file);
//fwrite_unlocked(drup_buf, sizeof(unsigned char), buf_len, drup_file);
buf_ptr = drup_buf; buf_len = 0;

}


#endif

   

    被使用的情况

 

bool Solver::addClause_(vec<Lit>& ps)
{


assert(decisionLevel() == 0);
if (!ok) return false;

// Check if clause is satisfied and remove false/duplicate literals:
sort(ps);
Lit p; int i, j;

if (drup_file){


add_oc.clear();
for (int i = 0; i < ps.size(); i++) add_oc.push(ps[i]); }

for (i = j = 0, p = lit_Undef; i < ps.size(); i++)
if (value(ps[i]) == l_True || ps[i] == ~p)
return true;
else if (value(ps[i]) != l_False && ps[i] != p)
ps[j++] = p = ps[i];
ps.shrink(i - j);

if (drup_file && i != j){
#ifdef BIN_DRUP
binDRUP('a', ps, drup_file);
binDRUP('d', add_oc, drup_file);
#else
for (int i = 0; i < ps.size(); i++)
fprintf(drup_file, "%i ", (var(ps[i]) + 1) * (-2 * sign(ps[i]) + 1));
fprintf(drup_file, "0\n");

fprintf(drup_file, "d ");
for (int i = 0; i < add_oc.size(); i++)
fprintf(drup_file, "%i ", (var(add_oc[i]) + 1) * (-2 * sign(add_oc[i]) + 1));
fprintf(drup_file, "0\n");
#endif
}

if (ps.size() == 0)
return ok = false;
else if (ps.size() == 1){
uncheckedEnqueue(ps[0]);
return ok = (propagate() == CRef_Undef);
}else{
CRef cr = ca.alloc(ps, false);
clauses.push(cr);
attachClause(cr);
}

return true;


}

   
 

void Solver::removeClause(CRef cr) {
Clause& c = ca[cr];

if (drup_file){
if (c.mark() != 1){
#ifdef BIN_DRUP
binDRUP('d', c, drup_file);
#else
fprintf(drup_file, "d ");
for (int i = 0; i < c.size(); i++)
fprintf(drup_file, "%i ", (var(c[i]) + 1) * (-2 * sign(c[i]) + 1));
fprintf(drup_file, "0\n");
#endif
}else
printf("c Bug. I don't expect this to happen.\n");
}

detachClause(cr);
// Don't leave pointers to free'd memory!
if (locked(c)){
Lit implied = c.size() != 2 ? c[0] : (value(c[0]) == l_True ? c[0] : c[1]);
vardata[var(implied)].reason = CRef_Undef; }
c.mark(1);
ca.free(cr);
}

   
 

search函数传播遇到冲突代码段中有以下相关代码:

if (drup_file){
#ifdef BIN_DRUP
binDRUP('a', learnt_clause, drup_file);
#else
for (int i = 0; i < learnt_clause.size(); i++)
fprintf(drup_file, "%i ", (var(learnt_clause[i]) + 1) * (-2 * sign(learnt_clause[i]) + 1));
fprintf(drup_file, "0\n");
#endif
}

   
 

solve_最后也有相关代码段

#ifdef BIN_DRUP
if (drup_file && status == l_False) binDRUP_flush(drup_file);
#endif

   
  其余被使用均在化简的相关函数之中

 

2.

真正的化简函数

// simplify
//
public:
bool simplifyAll();
void simplifyLearnt(Clause& c);
bool simplifyLearnt_x(vec<CRef>& learnts_x);
bool simplifyLearnt_core();
bool simplifyLearnt_tier2();
int trailRecord;
void litsEnqueue(int cutP, Clause& c);
void cancelUntilTrailRecord();
void simpleUncheckEnqueue(Lit p, CRef from = CRef_Undef);
CRef simplePropagate();
uint64_t nbSimplifyAll;
uint64_t simplified_length_record, original_length_record;
uint64_t s_propagations;

vec<Lit> simp_learnt_clause;
vec<CRef> simp_reason_clause;
void simpleAnalyze(CRef confl, vec<Lit>& out_learnt, vec<CRef>& reason_clause, bool True_confl);


 

3. 删除的学习子句“捞回”操作

// duplicate learnts version
int is_duplicate (std::vector<uint32_t>&c); //returns TRUE if a clause is duplicate
// duplicate learnts version

-------

// duplicate learnts version
uint32_t min_number_of_learnts_copies;
uint32_t dupl_db_init_size;
uint32_t max_lbd_dup;
std::chrono::microseconds duptime;
// duplicate learnts version

------

// duplicate learnts version
uint64_t duplicates_added_conflicts;
uint64_t duplicates_added_tier2;
uint64_t duplicates_added_minimization;
uint64_t dupl_db_size;
// duplicate learnts version

------

// duplicate learnts version
std::map<int32_t,std::map<uint32_t,std::unordered_map<uint64_t,uint32_t>>> ht;
// duplicate learnts version

 


 

4.利用seen解决回溯中学习子句的构建——切割UIP、距离冲突点的距离

涉及以下函数:

void analyze (CRef confl, vec<Lit>& out_learnt, int& out_btlevel, int& out_lbd); // (bt = backtrack)
void analyzeFinal (Lit p, vec<Lit>& out_conflict); // COULD THIS BE IMPLEMENTED BY THE ORDINARIY "analyze" BY SOME REASONABLE GENE

bool collectFirstUIP(CRef confl);

void simpleAnalyze(CRef confl, vec<Lit>& out_learnt, vec<CRef>& reason_clause, bool True_confl);


 

5.冗余检查、归结操作等逻辑推理操作(含化简)

bool     litRedundant     (Lit p, uint32_t abstract_levels);  

//在SolverType.h中有两个函数需要重点注意subsumes 、strengthen

/*_________________________________________________________________________________________________
|
| subsumes : (other : const Clause&) -> Lit
|
| Description:
| Checks if clause subsumes 'other', and at the same time, if it can be used to simplify 'other'
| by subsumption resolution.
|
| Result:
| lit_Error - No subsumption or simplification
| lit_Undef - Clause subsumes 'other'
| p - The literal p can be deleted from 'other'
|________________________________________________________________________________________________@*/
inline Lit Clause::subsumes(const Clause& other) const
{
//if (other.size() < size() || (extra.abst & ~other.extra.abst) != 0)
//if (other.size() < size() || (!learnt() && !other.learnt() && (extra.abst & ~other.extra.abst) != 0))
assert(!header.learnt); assert(!other.header.learnt);
assert(header.has_extra); assert(other.header.has_extra);
if (other.header.size < header.size || (data[header.size].abs & ~other.data[other.header.size].abs) != 0)
return lit_Error;

Lit ret = lit_Undef;
const Lit* c = (const Lit*)(*this);
const Lit* d = (const Lit*)other;

for (unsigned i = 0; i < header.size; i++) {
// search for c[i] or ~c[i]
for (unsigned j = 0; j < other.header.size; j++)
if (c[i] == d[j])
goto ok;
else if (ret == lit_Undef && c[i] == ~d[j]){
ret = c[i];
goto ok;
}

// did not find it
return lit_Error;
ok:;
}

return ret;
}

inline void Clause::strengthen(Lit p)
{
remove(*this, p);
calcAbstraction();
}

 


 

6.有部分假定已知赋值(部分模型已知)开展求解

vec<Lit>            assumptions;      // Current set of assumptions provided to solve by the user.

double              progress_estimate;// Set by 'search()'.

inline void Solver::checkGarbage(void){ return checkGarbage(garbage_frac); }


 

7.内存控制与垃圾回收

// Resource contraints:
//
int64_t conflict_budget; // -1 means no budget.
int64_t propagation_budget; // -1 means no budget.
bool asynch_interrupt;

 

void Solver::relocAll(ClauseAllocator& to)

void Solver::garbageCollect()

 

posted on 2021-05-18 10:28  海阔凭鱼跃越  阅读(96)  评论(0编辑  收藏  举报