ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
satSolver2.c File Reference
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <math.h>
#include "satSolver2.h"
Include dependency graph for satSolver2.c:

Go to the source code of this file.

Classes

struct  varinfo2_t
 

Macros

#define SAT_USE_PROOF_LOGGING
 
#define L_IND   "%-*d"
 
#define L_ind   solver2_dlevel(s)*2+2,solver2_dlevel(s)
 
#define L_LIT   "%sx%d"
 
#define L_lit(p)
 
#define clause_foreach_var(p, var, i, start)
 

Functions

int var_is_assigned (sat_solver2 *s, int v)
 
int var_is_partA (sat_solver2 *s, int v)
 
void var_set_partA (sat_solver2 *s, int v, int partA)
 
clausesolver2_propagate (sat_solver2 *s)
 
int sat_solver2_simplify (sat_solver2 *s)
 
sat_solver2sat_solver2_new (void)
 
void sat_solver2_setnvars (sat_solver2 *s, int n)
 
void sat_solver2_delete (sat_solver2 *s)
 
int sat_solver2_addclause (sat_solver2 *s, lit *begin, lit *end, int Id)
 
double luby2 (double y, int x)
 
void luby2_test ()
 
void sat_solver2_reducedb (sat_solver2 *s)
 
void sat_solver2_rollback (sat_solver2 *s)
 
double sat_solver2_memory (sat_solver2 *s, int fAll)
 
double sat_solver2_memory_proof (sat_solver2 *s)
 
int sat_solver2_check_watched (sat_solver2 *s)
 
int sat_solver2_solve (sat_solver2 *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
 
void * Sat_ProofCore (sat_solver2 *s)
 

Macro Definition Documentation

◆ clause_foreach_var

#define clause_foreach_var ( p,
var,
i,
start )
Value:
for ( i = start; (i < (int)(p)->size) && ((var) = lit_var((p)->lits[i])); i++ )
Cube * p
Definition exorList.c:222

Definition at line 156 of file satSolver2.c.

156#define clause_foreach_var( p, var, i, start ) \
157 for ( i = start; (i < (int)(p)->size) && ((var) = lit_var((p)->lits[i])); i++ )

◆ L_IND

#define L_IND   "%-*d"

Definition at line 39 of file satSolver2.c.

◆ L_ind

#define L_ind   solver2_dlevel(s)*2+2,solver2_dlevel(s)

Definition at line 40 of file satSolver2.c.

◆ L_LIT

#define L_LIT   "%sx%d"

Definition at line 41 of file satSolver2.c.

◆ L_lit

#define L_lit ( p)
Value:
lit_sign(p)?"~":"", (lit_var(p))

Definition at line 42 of file satSolver2.c.

◆ SAT_USE_PROOF_LOGGING

#define SAT_USE_PROOF_LOGGING

Definition at line 31 of file satSolver2.c.

Function Documentation

◆ luby2()

double luby2 ( double y,
int x )

Definition at line 1384 of file satSolver2.c.

1385{
1386 int size, seq;
1387 for (size = 1, seq = 0; size < x+1; seq++, size = 2*size + 1);
1388 while (size-1 != x){
1389 size = (size-1) >> 1;
1390 seq--;
1391 x = x % size;
1392 }
1393 return pow(y, (double)seq);
1394}
unsigned long long size
Definition giaNewBdd.h:39
Here is the caller graph for this function:

◆ luby2_test()

void luby2_test ( )

Definition at line 1396 of file satSolver2.c.

1397{
1398 int i;
1399 for ( i = 0; i < 20; i++ )
1400 Abc_Print(1, "%d ", (int)luby2(2,i) );
1401 Abc_Print(1, "\n" );
1402}
double luby2(double y, int x)
Here is the call graph for this function:

◆ Sat_ProofCore()

void * Sat_ProofCore ( sat_solver2 * s)

Definition at line 1985 of file satSolver2.c.

1986{
1987 extern void * Proof_DeriveCore( Vec_Set_t * vProof, int hRoot );
1988 if ( s->pPrf1 )
1989 return Proof_DeriveCore( s->pPrf1, s->hProofLast );
1990 if ( s->pPrf2 )
1991 {
1992 s->dPrfMemory = Abc_MaxDouble( s->dPrfMemory, Prf_ManMemory(s->pPrf2) );
1993 return Prf_ManUnsatCore( s->pPrf2 );
1994 }
1995 return NULL;
1996}
void * Proof_DeriveCore(Vec_Set_t *vProof, int hRoot)
Definition satProof.c:913
Vec_Set_t * pPrf1
Definition satSolver2.h:162
Prf_Man_t * pPrf2
Definition satSolver2.h:166
double dPrfMemory
Definition satSolver2.h:167
typedefABC_NAMESPACE_HEADER_START struct Vec_Set_t_ Vec_Set_t
INCLUDES ///.
Definition vecSet.h:49
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_addclause()

int sat_solver2_addclause ( sat_solver2 * s,
lit * begin,
lit * end,
int Id )

Definition at line 1287 of file satSolver2.c.

1288{
1289 cla Cid;
1290 lit *i,*j,*iFree = NULL;
1291 int maxvar, count, temp;
1292 assert( solver2_dlevel(s) == 0 );
1293 assert( begin < end );
1294 assert( Id != 0 );
1295
1296 // copy clause into storage
1297 veci_resize( &s->temp_clause, 0 );
1298 for ( i = begin; i < end; i++ )
1299 veci_push( &s->temp_clause, *i );
1300 begin = veci_begin( &s->temp_clause );
1301 end = begin + veci_size( &s->temp_clause );
1302
1303 // insertion sort
1304 maxvar = lit_var(*begin);
1305 for (i = begin + 1; i < end; i++){
1306 lit l = *i;
1307 maxvar = lit_var(l) > maxvar ? lit_var(l) : maxvar;
1308 for (j = i; j > begin && *(j-1) > l; j--)
1309 *j = *(j-1);
1310 *j = l;
1311 }
1312 sat_solver2_setnvars(s,maxvar+1);
1313
1314
1315 // delete duplicates
1316 for (i = j = begin + 1; i < end; i++)
1317 {
1318 if ( *(i-1) == lit_neg(*i) ) // tautology
1319 return clause2_create_new( s, begin, end, 0, 0 ); // add it anyway, to preserve proper clause count
1320 if ( *(i-1) != *i )
1321 *j++ = *i;
1322 }
1323 end = j;
1324 assert( begin < end );
1325
1326 // coount the number of 0-literals
1327 count = 0;
1328 for ( i = begin; i < end; i++ )
1329 {
1330 // make sure all literals are unique
1331 assert( i == begin || lit_var(*(i-1)) != lit_var(*i) );
1332 // consider the value of this literal
1333 if ( var_value(s, lit_var(*i)) == lit_sign(*i) ) // this clause is always true
1334 return clause2_create_new( s, begin, end, 0, 0 ); // add it anyway, to preserve proper clause count
1335 if ( var_value(s, lit_var(*i)) == varX ) // unassigned literal
1336 iFree = i;
1337 else
1338 count++; // literal is 0
1339 }
1340 assert( count < end-begin ); // the clause cannot be UNSAT
1341
1342 // swap variables to make sure the clause is watched using unassigned variable
1343 temp = *iFree;
1344 *iFree = *begin;
1345 *begin = temp;
1346
1347 // create a new clause
1348 Cid = clause2_create_new( s, begin, end, 0, 0 );
1349 if ( Id )
1350 clause2_set_id( s, Cid, Id );
1351
1352 // handle unit clause
1353 if ( count+1 == end-begin )
1354 {
1355 if ( s->fProofLogging )
1356 {
1357 if ( count == 0 ) // original learned clause
1358 {
1359 var_set_unit_clause( s, lit_var(begin[0]), Cid );
1360 if ( !solver2_enqueue(s,begin[0],0) )
1361 assert( 0 );
1362 }
1363 else
1364 {
1365 // Log production of top-level unit clause:
1366 int x, k, proof_id, CidNew;
1367 clause* c = clause2_read(s, Cid);
1368 proof_chain_start( s, c );
1369 clause_foreach_var( c, x, k, 1 )
1370 proof_chain_resolve( s, NULL, x );
1371 proof_id = proof_chain_stop( s );
1372 // generate a new clause
1373 CidNew = clause2_create_new( s, begin, begin+1, 1, proof_id );
1374 var_set_unit_clause( s, lit_var(begin[0]), CidNew );
1375 if ( !solver2_enqueue(s,begin[0],Cid) )
1376 assert( 0 );
1377 }
1378 }
1379 }
1380 return Cid;
1381}
#define clause_foreach_var(p, var, i, start)
Definition satSolver2.c:156
void sat_solver2_setnvars(sat_solver2 *s, int n)
int lit
Definition satVec.h:130
int cla
Definition satVec.h:131
if(last==0)
Definition sparse_int.h:34
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_check_watched()

int sat_solver2_check_watched ( sat_solver2 * s)

Definition at line 1800 of file satSolver2.c.

1801{
1802 clause * c;
1803 int i, k, j, m;
1804 int claSat[2] = {0};
1805 // update watches
1806 for ( i = 0; i < s->size*2; i++ )
1807 {
1808 int * pArray = veci_begin(&s->wlists[i]);
1809 for ( m = k = 0; k < veci_size(&s->wlists[i]); k++ )
1810 {
1811 c = clause2_read(s, pArray[k]);
1812 for ( j = 0; j < (int)c->size; j++ )
1813 if ( var_value(s, lit_var(c->lits[j])) == lit_sign(c->lits[j]) ) // true lit
1814 break;
1815 if ( j == (int)c->size )
1816 {
1817 pArray[m++] = pArray[k];
1818 continue;
1819 }
1820 claSat[c->lrn]++;
1821 }
1822 veci_resize(&s->wlists[i],m);
1823 if ( m == 0 )
1824 {
1825// s->wlists[i].cap = 0;
1826// s->wlists[i].size = 0;
1827// ABC_FREE( s->wlists[i].ptr );
1828 }
1829 }
1830// printf( "\nClauses = %d (Sat = %d). Learned = %d (Sat = %d).\n",
1831// s->stats.clauses, claSat[0], s->stats.learnts, claSat[1] );
1832 return 0;
1833}
unsigned lits[3]
Definition clause.h:39
unsigned size
Definition clause.h:37

◆ sat_solver2_delete()

void sat_solver2_delete ( sat_solver2 * s)

Definition at line 1225 of file satSolver2.c.

1226{
1227 int fVerify = 0;
1228 if ( fVerify )
1229 {
1230 veci * pCore = (veci *)Sat_ProofCore( s );
1231// Abc_Print(1, "UNSAT core contains %d clauses (%6.2f %%).\n", veci_size(pCore), 100.0*veci_size(pCore)/veci_size(&s->clauses) );
1232 veci_delete( pCore );
1233 ABC_FREE( pCore );
1234// if ( s->fProofLogging )
1235// Sat_ProofCheck( s );
1236 }
1237
1238 // report statistics
1239// Abc_Print(1, "Used %6.2f MB for proof-logging. Unit clauses = %d.\n", 1.0 * Vec_ReportMemory(&s->Proofs) / (1<<20), s->nUnits );
1240
1241 // delete vectors
1242 veci_delete(&s->order);
1243 veci_delete(&s->trail_lim);
1244 veci_delete(&s->tagged);
1245 veci_delete(&s->stack);
1246 veci_delete(&s->temp_clause);
1247 veci_delete(&s->temp_proof);
1248 veci_delete(&s->conf_final);
1249 veci_delete(&s->mark_levels);
1250 veci_delete(&s->min_lit_order);
1251 veci_delete(&s->min_step_order);
1252// veci_delete(&s->learnt_live);
1253 veci_delete(&s->act_clas);
1254 veci_delete(&s->claProofs);
1255// veci_delete(&s->clauses);
1256// veci_delete(&s->lrns);
1257 Sat_MemFree_( &s->Mem );
1258// veci_delete(&s->proofs);
1259 Vec_SetFree( s->pPrf1 );
1260 Prf_ManStop( s->pPrf2 );
1261 Int2_ManStop( s->pInt2 );
1262
1263 // delete arrays
1264 if (s->vi != 0){
1265 int i;
1266 if ( s->wlists )
1267 for (i = 0; i < s->cap*2; i++)
1268 veci_delete(&s->wlists[i]);
1269 ABC_FREE(s->wlists );
1270 ABC_FREE(s->vi );
1271 ABC_FREE(s->levels );
1272 ABC_FREE(s->assigns );
1273 ABC_FREE(s->trail );
1274 ABC_FREE(s->orderpos );
1275 ABC_FREE(s->reasons );
1276 ABC_FREE(s->units );
1277 ABC_FREE(s->activity );
1278 ABC_FREE(s->activity2);
1279 ABC_FREE(s->model );
1280 }
1281 ABC_FREE(s);
1282
1283// Abc_PrintTime( 1, "Time", Time );
1284}
#define ABC_FREE(obj)
Definition abc_global.h:267
void * Sat_ProofCore(sat_solver2 *s)
struct veci_t veci
Definition satVec.h:36
veci min_step_order
Definition satSolver2.h:158
unsigned * activity
Definition satSolver2.h:112
unsigned * activity2
Definition satSolver2.h:113
varinfo2 * vi
Definition satSolver2.h:140
Sat_Mem_t Mem
Definition satSolver2.h:129
Int2_Man_t * pInt2
Definition satSolver2.h:168
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_memory()

double sat_solver2_memory ( sat_solver2 * s,
int fAll )

Definition at line 1692 of file satSolver2.c.

1693{
1694 int i;
1695 double Mem = sizeof(sat_solver2);
1696 if ( fAll )
1697 for (i = 0; i < s->cap*2; i++)
1698 Mem += s->wlists[i].cap * sizeof(int);
1699 Mem += s->cap * sizeof(veci); // ABC_FREE(s->wlists );
1700 Mem += s->act_clas.cap * sizeof(int);
1701 Mem += s->claProofs.cap * sizeof(int);
1702// Mem += s->cap * sizeof(char); // ABC_FREE(s->polarity );
1703// Mem += s->cap * sizeof(char); // ABC_FREE(s->tags );
1704 Mem += s->cap * sizeof(varinfo2); // ABC_FREE(s->vi );
1705 Mem += s->cap * sizeof(int); // ABC_FREE(s->levels );
1706 Mem += s->cap * sizeof(char); // ABC_FREE(s->assigns );
1707#ifdef USE_FLOAT_ACTIVITY2
1708 Mem += s->cap * sizeof(double); // ABC_FREE(s->activity );
1709#else
1710 Mem += s->cap * sizeof(unsigned); // ABC_FREE(s->activity );
1711 if ( s->activity2 )
1712 Mem += s->cap * sizeof(unsigned); // ABC_FREE(s->activity2);
1713#endif
1714 Mem += s->cap * sizeof(lit); // ABC_FREE(s->trail );
1715 Mem += s->cap * sizeof(int); // ABC_FREE(s->orderpos );
1716 Mem += s->cap * sizeof(int); // ABC_FREE(s->reasons );
1717 Mem += s->cap * sizeof(int); // ABC_FREE(s->units );
1718 Mem += s->cap * sizeof(int); // ABC_FREE(s->model );
1719 Mem += s->tagged.cap * sizeof(int);
1720 Mem += s->stack.cap * sizeof(int);
1721 Mem += s->order.cap * sizeof(int);
1722 Mem += s->trail_lim.cap * sizeof(int);
1723 Mem += s->temp_clause.cap * sizeof(int);
1724 Mem += s->conf_final.cap * sizeof(int);
1725 Mem += s->mark_levels.cap * sizeof(int);
1726 Mem += s->min_lit_order.cap * sizeof(int);
1727 Mem += s->min_step_order.cap * sizeof(int);
1728 Mem += s->temp_proof.cap * sizeof(int);
1729 Mem += Sat_MemMemoryAll( &s->Mem );
1730// Mem += Vec_ReportMemory( s->pPrf1 );
1731 return Mem;
1732}
struct sat_solver2_t sat_solver2
Definition satSolver2.h:44
struct varinfo2_t varinfo2
Definition satSolver2.h:88
int cap
Definition satVec.h:32
Here is the caller graph for this function:

◆ sat_solver2_memory_proof()

double sat_solver2_memory_proof ( sat_solver2 * s)

Definition at line 1733 of file satSolver2.c.

1734{
1735 double Mem = s->dPrfMemory;
1736 if ( s->pPrf1 )
1737 Mem += Vec_ReportMemory( s->pPrf1 );
1738 return Mem;
1739}
Here is the caller graph for this function:

◆ sat_solver2_new()

sat_solver2 * sat_solver2_new ( void )

Definition at line 1109 of file satSolver2.c.

1110{
1111 sat_solver2* s = (sat_solver2 *)ABC_CALLOC( char, sizeof(sat_solver2) );
1112
1113#ifdef USE_FLOAT_ACTIVITY2
1114 s->var_inc = 1;
1115 s->cla_inc = 1;
1116 s->var_decay = (float)(1 / 0.95 );
1117 s->cla_decay = (float)(1 / 0.999 );
1118// s->cla_decay = 1;
1119// s->var_decay = 1;
1120#else
1121 s->var_inc = (1 << 5);
1122 s->cla_inc = (1 << 11);
1123#endif
1124 s->random_seed = 91648253;
1125
1126#ifdef SAT_USE_PROOF_LOGGING
1127 s->fProofLogging = 1;
1128#else
1129 s->fProofLogging = 0;
1130#endif
1131 s->fSkipSimplify = 1;
1132 s->fNotUseRandom = 0;
1133 s->fVerbose = 0;
1134
1135 s->nLearntStart = LEARNT_MAX_START_DEFAULT; // starting learned clause limit
1136 s->nLearntDelta = LEARNT_MAX_INCRE_DEFAULT; // delta of learned clause limit
1137 s->nLearntRatio = LEARNT_MAX_RATIO_DEFAULT; // ratio of learned clause limit
1138 s->nLearntMax = s->nLearntStart;
1139
1140 // initialize vectors
1141 veci_new(&s->order);
1142 veci_new(&s->trail_lim);
1143 veci_new(&s->tagged);
1144 veci_new(&s->stack);
1145 veci_new(&s->temp_clause);
1146 veci_new(&s->temp_proof);
1147 veci_new(&s->conf_final);
1148 veci_new(&s->mark_levels);
1149 veci_new(&s->min_lit_order);
1150 veci_new(&s->min_step_order);
1151// veci_new(&s->learnt_live);
1152 Sat_MemAlloc_( &s->Mem, 14 );
1153 veci_new(&s->act_clas);
1154 // proof-logging
1155 veci_new(&s->claProofs);
1156// s->pPrf1 = Vec_SetAlloc( 20 );
1157 s->tempInter = -1;
1158
1159 // initialize clause pointers
1160 s->hLearntLast = -1; // the last learnt clause
1161 s->hProofLast = -1; // the last proof ID
1162 // initialize rollback
1163 s->iVarPivot = 0; // the pivot for variables
1164 s->iTrailPivot = 0; // the pivot for trail
1165 s->hProofPivot = 1; // the pivot for proof records
1166 return s;
1167}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define LEARNT_MAX_RATIO_DEFAULT
Definition satClause.h:39
#define LEARNT_MAX_START_DEFAULT
INCLUDES ///.
Definition satClause.h:37
#define LEARNT_MAX_INCRE_DEFAULT
Definition satClause.h:38
double random_seed
Definition satSolver2.h:98
Here is the caller graph for this function:

◆ sat_solver2_reducedb()

void sat_solver2_reducedb ( sat_solver2 * s)

Definition at line 1406 of file satSolver2.c.

1407{
1408 static abctime TimeTotal = 0;
1409 Sat_Mem_t * pMem = &s->Mem;
1410 clause * c = NULL;
1411 int nLearnedOld = veci_size(&s->act_clas);
1412 int * act_clas = veci_begin(&s->act_clas);
1413 int * pPerm, * pSortValues, nCutoffValue, * pClaProofs;
1414 int i, j, k, Id, nSelected;//, LastSize = 0;
1415 int Counter, CounterStart;
1416 abctime clk = Abc_Clock();
1417 static int Count = 0;
1418 Count++;
1419 assert( s->nLearntMax );
1420 s->nDBreduces++;
1421// printf( "Calling reduceDB with %d clause limit and parameters (%d %d %d).\n", s->nLearntMax, s->nLearntStart, s->nLearntDelta, s->nLearntRatio );
1422
1423/*
1424 // find the new limit
1425 s->nLearntMax = s->nLearntMax * 11 / 10;
1426 // preserve 1/10 of last clauses
1427 CounterStart = s->stats.learnts - (s->nLearntMax / 10);
1428 // preserve 1/10 of most active clauses
1429 pSortValues = veci_begin(&s->act_clas);
1430 pPerm = Abc_MergeSortCost( pSortValues, nLearnedOld );
1431 assert( pSortValues[pPerm[0]] <= pSortValues[pPerm[nLearnedOld-1]] );
1432 nCutoffValue = pSortValues[pPerm[nLearnedOld*9/10]];
1433 ABC_FREE( pPerm );
1434// nCutoffValue = ABC_INFINITY;
1435*/
1436
1437
1438 // find the new limit
1440 // preserve 1/20 of last clauses
1441 CounterStart = nLearnedOld - (s->nLearntMax / 20);
1442 // preserve 3/4 of most active clauses
1443 nSelected = nLearnedOld*s->nLearntRatio/100;
1444 // create sorting values
1445 pSortValues = ABC_ALLOC( int, nLearnedOld );
1446 Sat_MemForEachLearned( pMem, c, i, k )
1447 {
1448 Id = clause_id(c);
1449 pSortValues[Id] = (((7 - Abc_MinInt(c->lbd, 7)) << 28) | (act_clas[Id] >> 4));
1450// pSortValues[Id] = act_clas[Id];
1451 assert( pSortValues[Id] >= 0 );
1452 }
1453 // find non-decreasing permutation
1454 pPerm = Abc_MergeSortCost( pSortValues, nLearnedOld );
1455 assert( pSortValues[pPerm[0]] <= pSortValues[pPerm[nLearnedOld-1]] );
1456 nCutoffValue = pSortValues[pPerm[nLearnedOld-nSelected]];
1457 ABC_FREE( pPerm );
1458// nCutoffValue = ABC_INFINITY;
1459
1460 // count how many clauses satisfy the condition
1461 Counter = j = 0;
1462 Sat_MemForEachLearned( pMem, c, i, k )
1463 {
1464 assert( c->mark == 0 );
1465 if ( Counter++ > CounterStart || clause_size(c) < 2 || pSortValues[clause_id(c)] >= nCutoffValue || s->reasons[lit_var(c->lits[0])] == Sat_MemHand(pMem, i, k) )
1466 {
1467 }
1468 else
1469 j++;
1470 if ( j >= nLearnedOld / 6 )
1471 break;
1472 }
1473 if ( j < nLearnedOld / 6 )
1474 {
1475 ABC_FREE( pSortValues );
1476 return;
1477 }
1478
1479 // mark learned clauses to remove
1480 Counter = j = 0;
1481 pClaProofs = veci_size(&s->claProofs) ? veci_begin(&s->claProofs) : NULL;
1482 Sat_MemForEachLearned( pMem, c, i, k )
1483 {
1484 assert( c->mark == 0 );
1485 if ( Counter++ > CounterStart || clause_size(c) < 2 || pSortValues[clause_id(c)] >= nCutoffValue || s->reasons[lit_var(c->lits[0])] == Sat_MemHand(pMem, i, k) )
1486 {
1487 pSortValues[j] = pSortValues[clause_id(c)];
1488 if ( pClaProofs )
1489 pClaProofs[j] = pClaProofs[clause_id(c)];
1490 if ( s->pPrf2 )
1491 Prf_ManAddSaved( s->pPrf2, clause_id(c), j );
1492 j++;
1493 }
1494 else // delete
1495 {
1496 c->mark = 1;
1497 s->stats.learnts_literals -= clause_size(c);
1498 s->stats.learnts--;
1499 }
1500 }
1501 ABC_FREE( pSortValues );
1502 if ( s->pPrf2 )
1503 Prf_ManCompact( s->pPrf2, j );
1504// if ( j == nLearnedOld )
1505// return;
1506
1507 assert( s->stats.learnts == (unsigned)j );
1508 assert( Counter == nLearnedOld );
1509 veci_resize(&s->act_clas,j);
1510 if ( veci_size(&s->claProofs) )
1511 veci_resize(&s->claProofs,j);
1512
1513 // update ID of each clause to be its new handle
1514 Counter = Sat_MemCompactLearned( pMem, 0 );
1515 assert( Counter == (int)s->stats.learnts );
1516
1517 // update reasons
1518 for ( i = 0; i < s->size; i++ )
1519 {
1520 if ( !s->reasons[i] ) // no reason
1521 continue;
1522 if ( clause_is_lit(s->reasons[i]) ) // 2-lit clause
1523 continue;
1524 if ( !clause_learnt_h(pMem, s->reasons[i]) ) // problem clause
1525 continue;
1526 assert( c->lrn );
1527 c = clause2_read( s, s->reasons[i] );
1528 assert( c->mark == 0 );
1529 s->reasons[i] = clause_id(c); // updating handle here!!!
1530 }
1531
1532 // update watches
1533 for ( i = 0; i < s->size*2; i++ )
1534 {
1535 int * pArray = veci_begin(&s->wlists[i]);
1536 for ( j = k = 0; k < veci_size(&s->wlists[i]); k++ )
1537 {
1538 if ( clause_is_lit(pArray[k]) ) // 2-lit clause
1539 pArray[j++] = pArray[k];
1540 else if ( !clause_learnt_h(pMem, pArray[k]) ) // problem clause
1541 pArray[j++] = pArray[k];
1542 else
1543 {
1544 assert( c->lrn );
1545 c = clause2_read(s, pArray[k]);
1546 if ( !c->mark ) // useful learned clause
1547 pArray[j++] = clause_id(c); // updating handle here!!!
1548 }
1549 }
1550 veci_resize(&s->wlists[i],j);
1551 }
1552
1553 // compact units
1554 if ( s->fProofLogging )
1555 for ( i = 0; i < s->size; i++ )
1556 if ( s->units[i] && clause_learnt_h(pMem, s->units[i]) )
1557 {
1558 assert( c->lrn );
1559 c = clause2_read( s, s->units[i] );
1560 assert( c->mark == 0 );
1561 s->units[i] = clause_id(c);
1562 }
1563
1564 // perform final move of the clauses
1565 Counter = Sat_MemCompactLearned( pMem, 1 );
1566 assert( Counter == (int)s->stats.learnts );
1567
1568 // compact proof (compacts 'proofs' and update 'claProofs')
1569 if ( s->pPrf1 )
1570 {
1571 extern int Sat_ProofReduce( Vec_Set_t * vProof, void * pRoots, int hProofPivot );
1573 }
1574
1575 // report the results
1576 TimeTotal += Abc_Clock() - clk;
1577 if ( s->fVerbose )
1578 {
1579 Abc_Print(1, "reduceDB: Keeping %7d out of %7d clauses (%5.2f %%) ",
1580 s->stats.learnts, nLearnedOld, 100.0 * s->stats.learnts / nLearnedOld );
1581 Abc_PrintTime( 1, "Time", TimeTotal );
1582 }
1583}
ABC_INT64_T abctime
Definition abc_global.h:332
int * Abc_MergeSortCost(int *pCosts, int nSize)
Definition utilSort.c:442
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define Sat_MemForEachLearned(p, c, i, k)
Definition satClause.h:127
struct Sat_Mem_t_ Sat_Mem_t
Definition satClause.h:70
int Sat_ProofReduce(Vec_Set_t *vProof, void *pRoots, int hProofPivot)
Definition satProof.c:383
unsigned lbd
Definition clause.h:22
stats_t stats
Definition satSolver2.h:172
ABC_INT64_T learnts_literals
Definition satVec.h:157
unsigned learnts
Definition satVec.h:155
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_rollback()

void sat_solver2_rollback ( sat_solver2 * s)

Definition at line 1586 of file satSolver2.c.

1587{
1588 Sat_Mem_t * pMem = &s->Mem;
1589 int i, k, j;
1590 static int Count = 0;
1591 Count++;
1592 assert( s->iVarPivot >= 0 && s->iVarPivot <= s->size );
1593 assert( s->iTrailPivot >= 0 && s->iTrailPivot <= s->qtail );
1594 assert( s->pPrf1 == NULL || (s->hProofPivot >= 1 && s->hProofPivot <= Vec_SetHandCurrent(s->pPrf1)) );
1595 // reset implication queue
1596 solver2_canceluntil_rollback( s, s->iTrailPivot );
1597 // update order
1598 if ( s->iVarPivot < s->size )
1599 {
1600 if ( s->activity2 )
1601 {
1602 s->var_inc = s->var_inc2;
1603 memcpy( s->activity, s->activity2, sizeof(unsigned) * s->iVarPivot );
1604 }
1605 veci_resize(&s->order, 0);
1606 for ( i = 0; i < s->iVarPivot; i++ )
1607 {
1608 if ( var_value(s, i) != varX )
1609 continue;
1610 s->orderpos[i] = veci_size(&s->order);
1611 veci_push(&s->order,i);
1612 order_update(s, i);
1613 }
1614 }
1615 // compact watches
1616 for ( i = 0; i < s->iVarPivot*2; i++ )
1617 {
1618 cla* pArray = veci_begin(&s->wlists[i]);
1619 for ( j = k = 0; k < veci_size(&s->wlists[i]); k++ )
1620 if ( Sat_MemClauseUsed(pMem, pArray[k]) )
1621 pArray[j++] = pArray[k];
1622 veci_resize(&s->wlists[i],j);
1623 }
1624 // reset watcher lists
1625 for ( i = 2*s->iVarPivot; i < 2*s->size; i++ )
1626 s->wlists[i].size = 0;
1627
1628 // reset clause counts
1629 s->stats.clauses = pMem->BookMarkE[0];
1630 s->stats.learnts = pMem->BookMarkE[1];
1631 // rollback clauses
1632 Sat_MemRollBack( pMem );
1633
1634 // resize learned arrays
1635 veci_resize(&s->act_clas, s->stats.learnts);
1636 if ( s->pPrf1 )
1637 {
1638 veci_resize(&s->claProofs, s->stats.learnts);
1639 Vec_SetShrink(s->pPrf1, s->hProofPivot);
1640 // some weird bug here, which shows only on 64-bits!
1641 // temporarily, perform more general proof reduction
1642// Sat_ProofReduce( s->pPrf1, &s->claProofs, s->hProofPivot );
1643 }
1644 assert( s->pPrf2 == NULL );
1645// if ( s->pPrf2 )
1646// Prf_ManShrink( s->pPrf2, s->stats.learnts );
1647
1648 // initialize other vars
1649 s->size = s->iVarPivot;
1650 if ( s->size == 0 )
1651 {
1652 // s->size = 0;
1653 // s->cap = 0;
1654 s->qhead = 0;
1655 s->qtail = 0;
1656#ifdef USE_FLOAT_ACTIVITY2
1657 s->var_inc = 1;
1658 s->cla_inc = 1;
1659 s->var_decay = (float)(1 / 0.95 );
1660 s->cla_decay = (float)(1 / 0.999 );
1661#else
1662 s->var_inc = (1 << 5);
1663 s->cla_inc = (1 << 11);
1664#endif
1665 s->root_level = 0;
1666 s->random_seed = 91648253;
1667 s->progress_estimate = 0;
1668 s->verbosity = 0;
1669
1670 s->stats.starts = 0;
1671 s->stats.decisions = 0;
1672 s->stats.propagations = 0;
1673 s->stats.inspects = 0;
1674 s->stats.conflicts = 0;
1675 s->stats.clauses = 0;
1676 s->stats.clauses_literals = 0;
1677 s->stats.learnts = 0;
1678 s->stats.learnts_literals = 0;
1679 s->stats.tot_literals = 0;
1680 // initialize clause pointers
1681 s->hLearntLast = -1; // the last learnt clause
1682 s->hProofLast = -1; // the last proof ID
1683
1684 // initialize rollback
1685 s->iVarPivot = 0; // the pivot for variables
1686 s->iTrailPivot = 0; // the pivot for trail
1687 s->hProofPivot = 1; // the pivot for proof records
1688 }
1689}
int BookMarkE[2]
Definition satClause.h:75
double progress_estimate
Definition satSolver2.h:99
ABC_INT64_T decisions
Definition satVec.h:156
ABC_INT64_T conflicts
Definition satVec.h:156
ABC_INT64_T tot_literals
Definition satVec.h:157
unsigned clauses
Definition satVec.h:155
unsigned starts
Definition satVec.h:155
ABC_INT64_T inspects
Definition satVec.h:156
ABC_INT64_T clauses_literals
Definition satVec.h:157
ABC_INT64_T propagations
Definition satVec.h:156
int size
Definition satVec.h:33
char * memcpy()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_setnvars()

void sat_solver2_setnvars ( sat_solver2 * s,
int n )

Definition at line 1170 of file satSolver2.c.

1171{
1172 int var;
1173
1174 if (s->cap < n){
1175 int old_cap = s->cap;
1176 while (s->cap < n) s->cap = s->cap*2+1;
1177
1178 s->wlists = ABC_REALLOC(veci, s->wlists, s->cap*2);
1179 s->vi = ABC_REALLOC(varinfo2, s->vi, s->cap);
1180 s->levels = ABC_REALLOC(int, s->levels, s->cap);
1181 s->assigns = ABC_REALLOC(char, s->assigns, s->cap);
1182 s->trail = ABC_REALLOC(lit, s->trail, s->cap);
1183 s->orderpos = ABC_REALLOC(int, s->orderpos, s->cap);
1184 s->reasons = ABC_REALLOC(cla, s->reasons, s->cap);
1185 if ( s->fProofLogging )
1186 s->units = ABC_REALLOC(cla, s->units, s->cap);
1187#ifdef USE_FLOAT_ACTIVITY2
1188 s->activity = ABC_REALLOC(double, s->activity, s->cap);
1189#else
1190 s->activity = ABC_REALLOC(unsigned, s->activity, s->cap);
1191 s->activity2 = ABC_REALLOC(unsigned, s->activity2,s->cap);
1192#endif
1193 s->model = ABC_REALLOC(int, s->model, s->cap);
1194 memset( s->wlists + 2*old_cap, 0, 2*(s->cap-old_cap)*sizeof(vecp) );
1195 }
1196
1197 for (var = s->size; var < n; var++){
1198 assert(!s->wlists[2*var].size);
1199 assert(!s->wlists[2*var+1].size);
1200 if ( s->wlists[2*var].ptr == NULL )
1201 veci_new(&s->wlists[2*var]);
1202 if ( s->wlists[2*var+1].ptr == NULL )
1203 veci_new(&s->wlists[2*var+1]);
1204 *((int*)s->vi + var) = 0; //s->vi[var].val = varX;
1205 s->levels [var] = 0;
1206 s->assigns [var] = varX;
1207 s->reasons [var] = 0;
1208 if ( s->fProofLogging )
1209 s->units [var] = 0;
1210#ifdef USE_FLOAT_ACTIVITY2
1211 s->activity[var] = 0;
1212#else
1213 s->activity[var] = (1<<10);
1214#endif
1215 s->model [var] = 0;
1216 // does not hold because variables enqueued at top level will not be reinserted in the heap
1217 // assert(veci_size(&s->order) == var);
1218 s->orderpos[var] = veci_size(&s->order);
1219 veci_push(&s->order,var);
1220 order_update(s, var);
1221 }
1222 s->size = n > s->size ? n : s->size;
1223}
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
unsigned short var
Definition giaNewBdd.h:35
struct vecp_t vecp
Definition satVec.h:85
int * ptr
Definition satVec.h:34
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_simplify()

int sat_solver2_simplify ( sat_solver2 * s)

Definition at line 996 of file satSolver2.c.

997{
998 assert(solver2_dlevel(s) == 0);
999 return (solver2_propagate(s) == NULL);
1000}
clause * solver2_propagate(sat_solver2 *s)
Definition satSolver2.c:904
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sat_solver2_solve()

int sat_solver2_solve ( sat_solver2 * s,
lit * begin,
lit * end,
ABC_INT64_T nConfLimit,
ABC_INT64_T nInsLimit,
ABC_INT64_T nConfLimitGlobal,
ABC_INT64_T nInsLimitGlobal )

Definition at line 1835 of file satSolver2.c.

1836{
1837 int restart_iter = 0;
1838 ABC_INT64_T nof_conflicts;
1839 lbool status = l_Undef;
1840 int proof_id;
1841 lit * i;
1842
1843 s->hLearntLast = -1;
1844 s->hProofLast = -1;
1845
1846 // set the external limits
1847// s->nCalls++;
1848// s->nRestarts = 0;
1849 s->nConfLimit = 0;
1850 s->nInsLimit = 0;
1851 if ( nConfLimit )
1852 s->nConfLimit = s->stats.conflicts + nConfLimit;
1853 if ( nInsLimit )
1854// s->nInsLimit = s->stats.inspects + nInsLimit;
1855 s->nInsLimit = s->stats.propagations + nInsLimit;
1856 if ( nConfLimitGlobal && (s->nConfLimit == 0 || s->nConfLimit > nConfLimitGlobal) )
1857 s->nConfLimit = nConfLimitGlobal;
1858 if ( nInsLimitGlobal && (s->nInsLimit == 0 || s->nInsLimit > nInsLimitGlobal) )
1859 s->nInsLimit = nInsLimitGlobal;
1860
1861/*
1862 // Perform assumptions:
1863 root_level = assumps.size();
1864 for (int i = 0; i < assumps.size(); i++){
1865 Lit p = assumps[i];
1866 assert(var(p) < nVars());
1867 if (!solver2_assume(p)){
1868 GClause r = reason[var(p)];
1869 if (r != Gclause2_NULL){
1870 clause* confl;
1871 if (r.isLit()){
1872 confl = propagate_tmpbin;
1873 (*confl)[1] = ~p;
1874 (*confl)[0] = r.lit();
1875 }else
1876 confl = r.clause();
1877 analyzeFinal(confl, true);
1878 conflict.push(~p);
1879 }else
1880 conflict.clear(),
1881 conflict.push(~p);
1882 cancelUntil(0);
1883 return false; }
1884 clause* confl = propagate();
1885 if (confl != NULL){
1886 analyzeFinal(confl), assert(conflict.size() > 0);
1887 cancelUntil(0);
1888 return false; }
1889 }
1890 assert(root_level == decisionLevel());
1891*/
1892
1893 // Perform assumptions:
1894 s->root_level = end - begin;
1895 for ( i = begin; i < end; i++ )
1896 {
1897 lit p = *i;
1898 assert(lit_var(p) < s->size);
1899 veci_push(&s->trail_lim,s->qtail);
1900 if (!solver2_enqueue(s,p,0))
1901 {
1902 clause* r = clause2_read(s, lit_reason(s,p));
1903 if (r != NULL)
1904 {
1905 clause* confl = r;
1906 proof_id = solver2_analyze_final(s, confl, 1);
1907 veci_push(&s->conf_final, lit_neg(p));
1908 }
1909 else
1910 {
1911// assert( 0 );
1912// r = var_unit_clause( s, lit_var(p) );
1913// assert( r != NULL );
1914// proof_id = clause2_proofid(s, r, 0);
1915 proof_id = -1; // the only case when ProofId is not assigned (conflicting assumptions)
1916 veci_resize(&s->conf_final,0);
1917 veci_push(&s->conf_final, lit_neg(p));
1918 // the two lines below are a bug fix by Siert Wieringa
1919 if (var_level(s, lit_var(p)) > 0)
1920 veci_push(&s->conf_final, p);
1921 }
1922 s->hProofLast = proof_id;
1923 solver2_canceluntil(s, 0);
1924 return l_False;
1925 }
1926 else
1927 {
1928 clause* confl = solver2_propagate(s);
1929 if (confl != NULL){
1930 proof_id = solver2_analyze_final(s, confl, 0);
1931 assert(s->conf_final.size > 0);
1932 s->hProofLast = proof_id;
1933 solver2_canceluntil(s, 0);
1934 return l_False;
1935 }
1936 }
1937 }
1938 assert(s->root_level == solver2_dlevel(s));
1939
1940 if (s->verbosity >= 1){
1941 Abc_Print(1,"==================================[MINISAT]===================================\n");
1942 Abc_Print(1,"| Conflicts | ORIGINAL | LEARNT | Progress |\n");
1943 Abc_Print(1,"| | Clauses Literals | Limit Clauses Literals Lit/Cl | |\n");
1944 Abc_Print(1,"==============================================================================\n");
1945 }
1946
1947 while (status == l_Undef){
1948 if (s->verbosity >= 1)
1949 {
1950 Abc_Print(1,"| %9.0f | %7.0f %8.0f | %7.0f %7.0f %8.0f %7.1f | %6.3f %% |\n",
1951 (double)s->stats.conflicts,
1952 (double)s->stats.clauses,
1953 (double)s->stats.clauses_literals,
1954 (double)s->nLearntMax,
1955 (double)s->stats.learnts,
1956 (double)s->stats.learnts_literals,
1957 (s->stats.learnts == 0)? 0.0 : (double)s->stats.learnts_literals / s->stats.learnts,
1958 s->progress_estimate*100);
1959 fflush(stdout);
1960 }
1961 if ( s->nRuntimeLimit && Abc_Clock() > s->nRuntimeLimit )
1962 break;
1963 // reduce the set of learnt clauses
1964 if ( s->nLearntMax && veci_size(&s->act_clas) >= s->nLearntMax && s->pPrf2 == NULL )
1966 // perform next run
1967 nof_conflicts = (ABC_INT64_T)( 100 * luby2(2, restart_iter++) );
1968 status = solver2_search(s, nof_conflicts);
1969 // quit the loop if reached an external limit
1970 if ( s->nConfLimit && s->stats.conflicts > s->nConfLimit )
1971 break;
1972 if ( s->nInsLimit && s->stats.propagations > s->nInsLimit )
1973 break;
1974 }
1975 if (s->verbosity >= 1)
1976 Abc_Print(1,"==============================================================================\n");
1977
1978 solver2_canceluntil(s,0);
1979// assert( s->qhead == s->qtail );
1980// if ( status == l_True )
1981// sat_solver2_verify( s );
1982 return status;
1983}
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
void sat_solver2_reducedb(sat_solver2 *s)
signed char lbool
Definition satVec.h:135
ABC_INT64_T nInsLimit
Definition satSolver2.h:174
abctime nRuntimeLimit
Definition satSolver2.h:175
ABC_INT64_T nConfLimit
Definition satSolver2.h:173
Here is the call graph for this function:
Here is the caller graph for this function:

◆ solver2_propagate()

clause * solver2_propagate ( sat_solver2 * s)

Definition at line 904 of file satSolver2.c.

905{
906 clause* c, * confl = NULL;
907 veci* ws;
908 lit* lits, false_lit, p, * stop, * k;
909 cla* begin,* end, *i, *j;
910 int Lit;
911
912 while (confl == 0 && s->qtail - s->qhead > 0){
913
914 p = s->trail[s->qhead++];
915 ws = solver2_wlist(s,p);
916 begin = (cla*)veci_begin(ws);
917 end = begin + veci_size(ws);
918
919 s->stats.propagations++;
920 for (i = j = begin; i < end; ){
921 c = clause2_read(s,*i);
922 lits = c->lits;
923
924 // Make sure the false literal is data[1]:
925 false_lit = lit_neg(p);
926 if (lits[0] == false_lit){
927 lits[0] = lits[1];
928 lits[1] = false_lit;
929 }
930 assert(lits[1] == false_lit);
931
932 // If 0th watch is true, then clause is already satisfied.
933 if (var_value(s, lit_var(lits[0])) == lit_sign(lits[0]))
934 *j++ = *i;
935 else{
936 // Look for new watch:
937 stop = lits + c->size;
938 for (k = lits + 2; k < stop; k++){
939 if (var_value(s, lit_var(*k)) != !lit_sign(*k)){
940 lits[1] = *k;
941 *k = false_lit;
942 veci_push(solver2_wlist(s,lit_neg(lits[1])),*i);
943 goto WatchFound; }
944 }
945
946 // Did not find watch -- clause is unit under assignment:
947 Lit = lits[0];
948 if ( s->fProofLogging && solver2_dlevel(s) == 0 )
949 {
950 int k, x, proof_id, Cid, Var = lit_var(Lit);
951 int fLitIsFalse = (var_value(s, Var) == !lit_sign(Lit));
952 // Log production of top-level unit clause:
953 proof_chain_start( s, c );
954 clause_foreach_var( c, x, k, 1 ){
955 assert( var_level(s, x) == 0 );
956 proof_chain_resolve( s, NULL, x );
957 }
958 proof_id = proof_chain_stop( s );
959 // get a new clause
960 Cid = clause2_create_new( s, &Lit, &Lit + 1, 1, proof_id );
961 assert( (var_unit_clause(s, Var) == NULL) != fLitIsFalse );
962 // if variable already has unit clause, it must be with the other polarity
963 // in this case, we should derive the empty clause here
964 if ( var_unit_clause(s, Var) == NULL )
965 var_set_unit_clause(s, Var, Cid);
966 else{
967 // Empty clause derived:
968 proof_chain_start( s, clause2_read(s,Cid) );
969 proof_chain_resolve( s, NULL, Var );
970 proof_id = proof_chain_stop( s );
971 s->hProofLast = proof_id;
972// clause2_create_new( s, &Lit, &Lit, 1, proof_id );
973 }
974 }
975
976 *j++ = *i;
977 // Clause is unit under assignment:
978 if ( c->lrn )
979 c->lbd = sat_clause_compute_lbd(s, c);
980 if (!solver2_enqueue(s,Lit, *i)){
981 confl = clause2_read(s,*i++);
982 // Copy the remaining watches:
983 while (i < end)
984 *j++ = *i++;
985 }
986 }
987WatchFound: i++;
988 }
989 s->stats.inspects += j - (int*)veci_begin(ws);
990 veci_resize(ws,j - (int*)veci_begin(ws));
991 }
992
993 return confl;
994}
int Var
Definition exorList.c:228
Here is the caller graph for this function:

◆ var_is_assigned()

int var_is_assigned ( sat_solver2 * s,
int v )

Definition at line 83 of file satSolver2.c.

83{ return s->assigns[v] != varX; }
Here is the caller graph for this function:

◆ var_is_partA()

int var_is_partA ( sat_solver2 * s,
int v )

Definition at line 84 of file satSolver2.c.

84{ return s->vi[v].partA; }
unsigned partA
Definition satSolver2.c:78

◆ var_set_partA()

void var_set_partA ( sat_solver2 * s,
int v,
int partA )

Definition at line 85 of file satSolver2.c.

85{ s->vi[v].partA = partA; }
Here is the caller graph for this function: