Commit f1dba69c by Alan Mishchenko

Improved memory management of proof-logging and propagated changes.

parent ce945006
......@@ -1261,6 +1261,10 @@ SOURCE=.\src\sat\bsat\satVec.h
SOURCE=.\src\sat\bsat\vecRec.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\vecSet.h
# End Source File
# End Group
# Begin Group "proof"
......
......@@ -147,7 +147,7 @@ int Fra_FraigSat( Aig_Man_t * pMan, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimi
pMan->pData = Sat_Solver2GetModel( pSat, vCiIds->pArray, vCiIds->nSize );
}
// free the sat_solver2
if ( fVerbose )
// if ( fVerbose )
Sat_Solver2PrintStats( stdout, pSat );
//sat_solver2_store_write( pSat, "trace.cnf" );
//sat_solver2_store_free( pSat );
......@@ -253,7 +253,7 @@ int Fra_FraigSat( Aig_Man_t * pMan, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimi
pMan->pData = Sat_SolverGetModel( pSat, vCiIds->pArray, vCiIds->nSize );
}
// free the sat_solver
if ( fVerbose )
// if ( fVerbose )
Sat_SolverPrintStats( stdout, pSat );
//sat_solver_store_write( pSat, "trace.cnf" );
//sat_solver_store_free( pSat );
......
......@@ -71,11 +71,6 @@ static inline int irand(double* seed, int size) {
//=================================================================================================
// Predeclarations:
static void sat_solver_sort(void** array, int size, int(*comp)(const void *, const void *));
//=================================================================================================
// Variable datatype + minor functions:
static const int var0 = 1;
......@@ -90,12 +85,12 @@ struct varinfo_t
unsigned lev : 28; // variable level
};
static inline int var_level (sat_solver* s, int v) { return s->levels[v]; }
static inline int var_value (sat_solver* s, int v) { return s->assigns[v]; }
static inline int var_level (sat_solver* s, int v) { return s->levels[v]; }
static inline int var_value (sat_solver* s, int v) { return s->assigns[v]; }
static inline int var_polar (sat_solver* s, int v) { return s->polarity[v]; }
static inline void var_set_level (sat_solver* s, int v, int lev) { s->levels[v] = lev; }
static inline void var_set_value (sat_solver* s, int v, int val) { s->assigns[v] = val; }
static inline void var_set_level (sat_solver* s, int v, int lev) { s->levels[v] = lev; }
static inline void var_set_value (sat_solver* s, int v, int val) { s->assigns[v] = val; }
static inline void var_set_polar (sat_solver* s, int v, int pol) { s->polarity[v] = pol; }
// variable tags
......@@ -130,7 +125,7 @@ int sat_solver_get_var_value(sat_solver* s, int v)
assert( 0 );
return 0;
}
//=================================================================================================
// Clause datatype + minor functions:
......@@ -140,6 +135,8 @@ struct clause_t
lit lits[0];
};
static inline clause* clause_read (sat_solver* s, int h) { return (clause *)Vec_SetEntry(&s->Mem, h>>1); }
static inline int clause_nlits (clause* c) { return c->size_learnt >> 1; }
static inline lit* clause_begin (clause* c) { return c->lits; }
static inline int clause_learnt (clause* c) { return c->size_learnt & 1; }
......@@ -155,21 +152,18 @@ static inline void clause_print (clause* c) {
printf( "}\n" );
}
static inline clause* clause_read( sat_solver* s, int h ) { return (clause *)Vec_RecEntryP(&s->Mem, h); }
static inline int clause_size( int nLits, int fLearnt ) { int a = nLits + fLearnt + 1; return a + (a & 1); }
//=================================================================================================
// Encode literals in clause pointers:
static inline int clause_from_lit (lit l) { return l + l + 1; }
static inline int clause_is_lit (int h) { return (h & 1); }
static inline lit clause_read_lit (int h) { return (lit)(h >> 1); }
static inline int clause_from_lit (lit l) { return l + l + 1; }
static inline int clause_is_lit (int h) { return (h & 1); }
static inline lit clause_read_lit (int h) { return (lit)(h >> 1); }
//=================================================================================================
// Simple helpers:
static inline int sat_solver_dl(sat_solver* s) { return veci_size(&s->trail_lim); }
static inline veci* sat_solver_read_wlist(sat_solver* s, lit l) { return &s->wlists[l]; }
static inline int sat_solver_dl(sat_solver* s) { return veci_size(&s->trail_lim); }
static inline veci* sat_solver_read_wlist(sat_solver* s, lit l) { return &s->wlists[l]; }
//=================================================================================================
// Variable order functions:
......@@ -418,15 +412,6 @@ static void sortrnd(void** array, int size, int(*comp)(const void *, const void
}
}
void sat_solver_sort(void** array, int size, int(*comp)(const void *, const void *))
{
// int i;
double seed = 91648253;
sortrnd(array,size,comp,&seed);
// for ( i = 1; i < size; i++ )
// assert(comp(array[i-1], array[i])<0);
}
//=================================================================================================
// Clause functions:
......@@ -451,9 +436,9 @@ static int clause_create_new(sat_solver* s, lit* begin, lit* end, int learnt)
}
// create new clause
h = Vec_RecAppend( &s->Mem, clause_size(size, learnt) );
c = clause_read( s, h );
h = Vec_SetAppend( &s->Mem, NULL, size + learnt + 1 ) << 1;
assert( !(h & 1) );
c = clause_read( s, h );
if ( s->hLearnts == -1 && learnt )
s->hLearnts = h;
c->size_learnt = (size << 1) | learnt;
......@@ -927,9 +912,9 @@ sat_solver* sat_solver_new(void)
{
sat_solver* s = (sat_solver*)ABC_CALLOC( char, sizeof(sat_solver));
Vec_RecAlloc_(&s->Mem);
Vec_SetAlloc_(&s->Mem);
s->hLearnts = -1;
s->hBinary = Vec_RecAppend( &s->Mem, clause_size(2, 0) );
s->hBinary = Vec_SetAppend( &s->Mem, NULL, 3 ) << 1;
s->binary = clause_read( s, s->hBinary );
s->binary->size_learnt = (2 << 1);
......@@ -1049,7 +1034,7 @@ void sat_solver_setnvars(sat_solver* s,int n)
void sat_solver_delete(sat_solver* s)
{
Vec_RecFree_( &s->Mem );
Vec_SetFree_( &s->Mem );
// delete vectors
veci_delete(&s->order);
......@@ -1087,10 +1072,10 @@ void sat_solver_delete(sat_solver* s)
void sat_solver_rollback( sat_solver* s )
{
int i;
Vec_RecRestart( &s->Mem );
Vec_SetRestart( &s->Mem );
s->hLearnts = -1;
s->hBinary = Vec_RecAppend( &s->Mem, clause_size(2, 0) );
s->hBinary = Vec_SetAppend( &s->Mem, NULL, 3 ) << 1;
s->binary = clause_read( s, s->hBinary );
s->binary->size_learnt = (2 << 1);
......
......@@ -29,7 +29,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
#include <assert.h>
#include "satVec.h"
#include "vecRec.h"
#include "vecSet.h"
ABC_NAMESPACE_HEADER_START
......@@ -92,7 +92,7 @@ struct sat_solver_t
int qtail; // Tail index of queue.
// clauses
Vec_Rec_t Mem;
Vec_Set_t Mem;
int hLearnts; // the first learnt clause
int hBinary; // the special binary clause
clause * binary;
......
......@@ -172,10 +172,12 @@ static inline void proof_chain_start( sat_solver2* s, satset* c )
{
if ( s->fProofLogging )
{
s->iStartChain = veci_size(&s->proofs);
veci_push(&s->proofs, 0);
veci_push(&s->proofs, 0);
veci_push(&s->proofs, clause_proofid(s, c, 0) );
int ProofId = clause_proofid(s, c, 0);
assert( ProofId > 0 );
veci_resize( &s->temp_proof, 0 );
veci_push( &s->temp_proof, 0 );
veci_push( &s->temp_proof, 0 );
veci_push( &s->temp_proof, ProofId );
}
}
......@@ -183,12 +185,10 @@ static inline void proof_chain_resolve( sat_solver2* s, satset* cls, int Var )
{
if ( s->fProofLogging )
{
// int CapOld = (&s->proofs)->cap;
satset* c = cls ? cls : var_unit_clause( s, Var );
veci_push(&s->proofs, clause_proofid(s, c, var_is_partA(s,Var)) );
// printf( "%d %d ", clause_proofid(s, c), Var );
// if ( (&s->proofs)->cap > CapOld )
// printf( "Resized proof from %d to %d.\n", CapOld, (&s->proofs)->cap );
int ProofId = clause_proofid(s, c, var_is_partA(s,Var));
assert( ProofId > 0 );
veci_push( &s->temp_proof, ProofId );
}
}
......@@ -196,12 +196,10 @@ static inline int proof_chain_stop( sat_solver2* s )
{
if ( s->fProofLogging )
{
int RetValue = s->iStartChain;
satset* c = (satset*)(veci_begin(&s->proofs) + s->iStartChain);
assert( s->iStartChain > 0 && s->iStartChain < veci_size(&s->proofs) );
c->nEnts = veci_size(&s->proofs) - s->iStartChain - 2;
s->iStartChain = 0;
return RetValue;
int h = Vec_SetAppend( &s->Proofs, veci_begin(&s->temp_proof), veci_size(&s->temp_proof) );
satset * c = (satset *)Vec_SetEntry( &s->Proofs, h );
c->nEnts = veci_size(&s->temp_proof) - 2;
return h;
}
return 0;
}
......@@ -1119,20 +1117,6 @@ sat_solver2* sat_solver2_new(void)
{
sat_solver2* s = (sat_solver2 *)ABC_CALLOC( char, sizeof(sat_solver2) );
// initialize vectors
veci_new(&s->order);
veci_new(&s->trail_lim);
veci_new(&s->tagged);
veci_new(&s->stack);
veci_new(&s->temp_clause);
veci_new(&s->conf_final);
veci_new(&s->mark_levels);
veci_new(&s->min_lit_order);
veci_new(&s->min_step_order);
veci_new(&s->learnt_live);
veci_new(&s->claActs); veci_push(&s->claActs, -1);
veci_new(&s->claProofs); veci_push(&s->claProofs, -1);
#ifdef USE_FLOAT_ACTIVITY2
s->var_inc = 1;
s->cla_inc = 1;
......@@ -1156,6 +1140,23 @@ sat_solver2* sat_solver2_new(void)
s->nLearntMax = 0;
s->fVerbose = 0;
// initialize vectors
veci_new(&s->order);
veci_new(&s->trail_lim);
veci_new(&s->tagged);
veci_new(&s->stack);
veci_new(&s->temp_clause);
veci_new(&s->temp_proof);
veci_new(&s->conf_final);
veci_new(&s->mark_levels);
veci_new(&s->min_lit_order);
veci_new(&s->min_step_order);
veci_new(&s->learnt_live);
veci_new(&s->claActs); veci_push(&s->claActs, -1);
veci_new(&s->claProofs); veci_push(&s->claProofs, -1);
if ( s->fProofLogging )
Vec_SetAlloc_( &s->Proofs );
// prealloc clause
assert( !s->clauses.ptr );
s->clauses.cap = (1 << 20);
......@@ -1166,21 +1167,17 @@ sat_solver2* sat_solver2_new(void)
s->learnts.cap = (1 << 20);
s->learnts.ptr = ABC_ALLOC( int, s->learnts.cap );
veci_push(&s->learnts, -1);
// prealloc proofs
if ( s->fProofLogging )
{
assert( !s->proofs.ptr );
s->proofs.cap = (1 << 20);
s->proofs.ptr = ABC_ALLOC( int, s->proofs.cap );
veci_push(&s->proofs, -1);
}
// initialize clause pointers
s->hLearntLast = -1; // the last learnt clause
s->hProofLast = -1; // the last proof ID
s->hClausePivot = 1; // the pivot among clauses
s->hLearntPivot = 1; // the pivot moang learned clauses
s->iVarPivot = 0; // the pivot among the variables
s->iSimpPivot = 0; // marker of unit-clauses
s->hLearntLast = -1; // the last learnt clause
s->hProofLast = -1; // the last proof ID
// initialize rollback
s->iVarPivot = 0; // the pivot for variables
s->iTrailPivot = 0; // the pivot for trail
s->iProofPivot = 0; // the pivot for proof records
s->hClausePivot = 1; // the pivot for problem clause
s->hLearntPivot = 1; // the pivot for learned clause
s->hProofPivot = 1; // the pivot for proof records
return s;
}
......@@ -1241,35 +1238,38 @@ void sat_solver2_setnvars(sat_solver2* s,int n)
void sat_solver2_delete(sat_solver2* s)
{
// veci * pCore;
int fVerify = 0;
if ( fVerify )
{
veci * pCore = Sat_ProofCore( s );
printf( "UNSAT core contains %d clauses (%6.2f %%).\n", veci_size(pCore), 100.0*veci_size(pCore)/veci_size(&s->clauses) );
veci_delete( pCore );
ABC_FREE( pCore );
if ( s->fProofLogging )
Sat_ProofCheck( s );
}
// report statistics
printf( "Used %6.2f Mb for proof-logging. Unit clauses = %d.\n", 2.0 * veci_size(&s->proofs) / (1<<20), s->nUnits );
/*
pCore = Sat_ProofCore( s );
printf( "UNSAT core contains %d clauses (%6.2f %%).\n", veci_size(pCore), 100.0*veci_size(pCore)/veci_size(&s->clauses) );
veci_delete( pCore );
ABC_FREE( pCore );
printf( "Used %6.2f Mb for proof-logging. Unit clauses = %d.\n", 1.0 * Vec_SetMemory(&s->Proofs) / (1<<20), s->nUnits );
if ( s->fProofLogging )
Sat_ProofCheck( s );
*/
// delete vectors
veci_delete(&s->order);
veci_delete(&s->trail_lim);
veci_delete(&s->tagged);
veci_delete(&s->stack);
veci_delete(&s->temp_clause);
veci_delete(&s->temp_proof);
veci_delete(&s->conf_final);
veci_delete(&s->mark_levels);
veci_delete(&s->min_lit_order);
veci_delete(&s->min_step_order);
veci_delete(&s->learnt_live);
veci_delete(&s->proofs);
veci_delete(&s->claActs);
veci_delete(&s->claProofs);
veci_delete(&s->clauses);
veci_delete(&s->learnts);
// veci_delete(&s->proofs);
Vec_SetFree_( &s->Proofs );
// delete arrays
if (s->vi != 0){
......@@ -1514,11 +1514,13 @@ void sat_solver2_rollback( sat_solver2* s )
{
int i, k, j;
assert( s->iVarPivot >= 0 && s->iVarPivot <= s->size );
assert( s->iSimpPivot >= 0 && s->iSimpPivot <= s->qtail );
assert( s->iTrailPivot >= 0 && s->iTrailPivot <= s->qtail );
assert( s->iProofPivot >= 0 && s->iProofPivot <= Vec_SetEntryNum(&s->Proofs) );
assert( s->hClausePivot >= 1 && s->hClausePivot <= veci_size(&s->clauses) );
assert( s->hLearntPivot >= 1 && s->hLearntPivot <= veci_size(&s->learnts) );
assert( s->hProofPivot >= 1 && s->hProofPivot <= Vec_SetHandCurrent(&s->Proofs) );
// reset implication queue
solver2_canceluntil_rollback( s, s->iSimpPivot );
solver2_canceluntil_rollback( s, s->iTrailPivot );
// update order
if ( s->iVarPivot < s->size )
{
......@@ -1558,7 +1560,9 @@ void sat_solver2_rollback( sat_solver2* s )
veci_resize(&s->claActs, first->Id);
if ( s->fProofLogging ) {
veci_resize(&s->claProofs, first->Id);
Sat_ProofReduce( s );
Vec_SetWriteEntryNum(&s->Proofs, s->iProofPivot);
Vec_SetShrink(&s->Proofs, s->hProofPivot);
// Sat_ProofReduce( s );
}
s->stats.learnts = first->Id-1;
veci_resize(&s->learnts, s->hLearntPivot);
......@@ -1600,12 +1604,16 @@ void sat_solver2_rollback( sat_solver2* s )
s->stats.learnts_literals = 0;
s->stats.tot_literals = 0;
// initialize clause pointers
s->hLearntLast = -1; // the last learnt clause
s->hProofLast = -1; // the last proof ID
s->hClausePivot = 1; // the pivot among clauses
s->hLearntPivot = 1; // the pivot among learned clauses
s->iVarPivot = 0; // the pivot among the variables
s->iSimpPivot = 0; // marker of unit-clauses
s->hLearntLast = -1; // the last learnt clause
s->hProofLast = -1; // the last proof ID
// initialize rollback
s->iVarPivot = 0; // the pivot for variables
s->iTrailPivot = 0; // the pivot for trail
s->iProofPivot = 0; // the pivot for proof records
s->hClausePivot = 1; // the pivot for problem clause
s->hLearntPivot = 1; // the pivot for learned clause
s->hProofPivot = 1; // the pivot for proof records
}
}
......@@ -1803,7 +1811,7 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
printf("==============================================================================\n");
solver2_canceluntil(s,0);
assert( s->qhead == s->qtail );
// assert( s->qhead == s->qtail );
// if ( status == l_True )
// sat_solver2_verify( s );
return status;
......
......@@ -29,6 +29,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
#include <assert.h>
#include "satVec.h"
#include "vecSet.h"
ABC_NAMESPACE_HEADER_START
......@@ -112,16 +113,19 @@ struct sat_solver2_t
veci clauses; // clause memory
veci learnts; // learnt memory
veci* wlists; // watcher lists (for each literal)
veci claActs; // clause activities
veci claProofs; // clause proofs
int hLearntLast; // in proof-logging mode, the ID of the final conflict clause (conf_final)
int hProofLast; // in proof-logging mode, the ID of the final conflict clause (conf_final)
int hClausePivot; // the pivot among problem clause
int hLearntPivot; // the pivot among learned clause
int iVarPivot; // the pivot among the variables
int iSimpPivot; // marker of unit-clauses
int nof_learnts; // the number of clauses to trigger reduceDB
veci claActs; // clause activities
veci claProofs; // clause proofs
// rollback
int iVarPivot; // the pivot for variables
int iTrailPivot; // the pivot for trail
int iProofPivot; // the pivot for proof records
int hClausePivot; // the pivot for problem clause
int hLearntPivot; // the pivot for learned clause
int hProofPivot; // the pivot for proof records
// internal state
varinfo2 * vi; // variable information
......@@ -146,8 +150,8 @@ struct sat_solver2_t
veci learnt_live; // remaining clauses after reduce DB
// proof logging
veci proofs; // sequence of proof records
int iStartChain; // temporary variable to remember beginning of the current chain in proof logging
Vec_Set_t Proofs; // sequence of proof records
veci temp_proof; // temporary place to store proofs
int nUnits; // the total number of unit clauses
// statistics
......@@ -251,10 +255,12 @@ static inline int sat_solver2_set_learntmax(sat_solver2* s, int nLearntMax)
static inline void sat_solver2_bookmark(sat_solver2* s)
{
assert( s->qhead == s->qtail );
s->hLearntPivot = veci_size(&s->learnts);
s->hClausePivot = veci_size(&s->clauses);
s->iVarPivot = s->size;
s->iSimpPivot = s->qhead;
s->iTrailPivot = s->qhead;
s->iProofPivot = Vec_SetEntryNum(&s->Proofs);
s->hClausePivot = veci_size(&s->clauses);
s->hLearntPivot = veci_size(&s->learnts);
s->hProofPivot = Vec_SetHandCurrent(&s->Proofs);
}
static inline int sat_solver2_add_const( sat_solver2 * pSat, int iVar, int fCompl, int fMark )
......
/**************************************************************************************************
MiniSat -- Copyright (c) 2005, Niklas Sorensson
http://www.cs.chalmers.se/Cs/Research/FormalMethods/MiniSat/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
**************************************************************************************************/
// Modified to compile with MS Visual Studio 6.0 by Alan Mishchenko
#ifndef ABC__sat__bsat__satSolver_old_h
#define ABC__sat__bsat__satSolver_old_h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "satVec.h"
#include "satMem.h"
ABC_NAMESPACE_HEADER_START
//#define USE_FLOAT_ACTIVITY
//=================================================================================================
// Public interface:
struct sat_solver_t;
typedef struct sat_solver_t sat_solver;
extern sat_solver* sat_solver_new(void);
extern void sat_solver_delete(sat_solver* s);
extern int sat_solver_addclause(sat_solver* s, lit* begin, lit* end);
extern int sat_solver_simplify(sat_solver* s);
extern int sat_solver_solve(sat_solver* s, lit* begin, lit* end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal);
extern void sat_solver_rollback( sat_solver* s );
extern int sat_solver_nvars(sat_solver* s);
extern int sat_solver_nclauses(sat_solver* s);
extern int sat_solver_nconflicts(sat_solver* s);
extern void sat_solver_setnvars(sat_solver* s,int n);
extern void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBegin, lit* assumptionsEnd, int incrementVars );
extern void Sat_SolverPrintStats( FILE * pFile, sat_solver * p );
extern int * Sat_SolverGetModel( sat_solver * p, int * pVars, int nVars );
extern void Sat_SolverDoubleClauses( sat_solver * p, int iVar );
// trace recording
extern void Sat_SolverTraceStart( sat_solver * pSat, char * pName );
extern void Sat_SolverTraceStop( sat_solver * pSat );
extern void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot );
// clause storage
extern void sat_solver_store_alloc( sat_solver * s );
extern void sat_solver_store_write( sat_solver * s, char * pFileName );
extern void sat_solver_store_free( sat_solver * s );
extern void sat_solver_store_mark_roots( sat_solver * s );
extern void sat_solver_store_mark_clauses_a( sat_solver * s );
extern void * sat_solver_store_release( sat_solver * s );
//=================================================================================================
// Solver representation:
struct clause_t;
typedef struct clause_t clause;
struct sat_solver_t
{
int size; // nof variables
int cap; // size of varmaps
int qhead; // Head index of queue.
int qtail; // Tail index of queue.
// clauses
vecp clauses; // List of problem constraints. (contains: clause*)
vecp learnts; // List of learnt clauses. (contains: clause*)
// activities
#ifdef USE_FLOAT_ACTIVITY
double var_inc; // Amount to bump next variable with.
double var_decay; // INVERSE decay factor for variable activity: stores 1/decay.
float cla_inc; // Amount to bump next clause with.
float cla_decay; // INVERSE decay factor for clause activity: stores 1/decay.
double* activity; // A heuristic measurement of the activity of a variable.
#else
int var_inc; // Amount to bump next variable with.
int cla_inc; // Amount to bump next clause with.
unsigned*activity; // A heuristic measurement of the activity of a variable.
#endif
vecp* wlists; //
lbool* assigns; // Current values of variables.
int* orderpos; // Index in variable order.
clause** reasons; //
int* levels; //
lit* trail;
char* polarity;
clause* binary; // A temporary binary clause
lbool* tags; //
veci tagged; // (contains: var)
veci stack; // (contains: var)
veci order; // Variable order. (heap) (contains: var)
veci trail_lim; // Separator indices for different decision levels in 'trail'. (contains: int)
veci model; // If problem is solved, this vector contains the model (contains: lbool).
veci conf_final; // If problem is unsatisfiable (possibly under assumptions),
// this vector represent the final conflict clause expressed in the assumptions.
int root_level; // Level of first proper decision.
int simpdb_assigns;// Number of top-level assignments at last 'simplifyDB()'.
int simpdb_props; // Number of propagations before next 'simplifyDB()'.
double random_seed;
double progress_estimate;
int verbosity; // Verbosity level. 0=silent, 1=some progress report, 2=everything
stats_t stats;
ABC_INT64_T nConfLimit; // external limit on the number of conflicts
ABC_INT64_T nInsLimit; // external limit on the number of implications
int nRuntimeLimit; // external limit on runtime
veci act_vars; // variables whose activity has changed
double* factors; // the activity factors
int nRestarts; // the number of local restarts
int nCalls; // the number of local restarts
int nCalls2; // the number of local restarts
Sat_MmStep_t * pMem;
int fSkipSimplify; // set to one to skip simplification of the clause database
int fNotUseRandom; // do not allow random decisions with a fixed probability
int * pGlobalVars; // for experiments with global vars during interpolation
// clause store
void * pStore;
int fSolved;
// trace recording
FILE * pFile;
int nClauses;
int nRoots;
veci temp_clause; // temporary storage for a CNF clause
};
static int sat_solver_var_value( sat_solver* s, int v )
{
assert( s->model.ptr != NULL && v < s->size );
return (int)(s->model.ptr[v] == l_True);
}
static int sat_solver_var_literal( sat_solver* s, int v )
{
assert( s->model.ptr != NULL && v < s->size );
return toLitCond( v, s->model.ptr[v] != l_True );
}
static void sat_solver_act_var_clear(sat_solver* s)
{
int i;
for (i = 0; i < s->size; i++)
s->activity[i] = 0.0;
s->var_inc = 1.0;
}
static void sat_solver_compress(sat_solver* s)
{
if ( s->qtail != s->qhead )
{
int RetValue = sat_solver_simplify(s);
assert( RetValue != 0 );
}
}
static int sat_solver_final(sat_solver* s, int ** ppArray)
{
*ppArray = s->conf_final.ptr;
return s->conf_final.size;
}
static int sat_solver_set_runtime_limit(sat_solver* s, int Limit)
{
int nRuntimeLimit = s->nRuntimeLimit;
s->nRuntimeLimit = Limit;
return nRuntimeLimit;
}
static int sat_solver_set_random(sat_solver* s, int fNotUseRandom)
{
int fNotUseRandomOld = s->fNotUseRandom;
s->fNotUseRandom = fNotUseRandom;
return fNotUseRandomOld;
}
ABC_NAMESPACE_HEADER_END
#endif
......@@ -19,7 +19,7 @@
***********************************************************************/
#include "satTruth.h"
#include "vecRec.h"
#include "vecSet.h"
ABC_NAMESPACE_IMPL_START
......@@ -39,7 +39,7 @@ struct Tru_Man_t_
int nEntrySize; // the size of one entry in 'int'
int nTableSize; // hash table size
int * pTable; // hash table
Vec_Rec_t * pMem; // memory for truth tables
Vec_Set_t * pMem; // memory for truth tables
word * pZero; // temporary truth table
int hIthVars[16]; // variable handles
int nTableLookups;
......@@ -53,7 +53,7 @@ struct Tru_One_t_
word pTruth[0]; // truth table
};
static inline Tru_One_t * Tru_ManReadOne( Tru_Man_t * p, int h ) { return h ? (Tru_One_t *)Vec_RecEntryP(p->pMem, h) : NULL; }
static inline Tru_One_t * Tru_ManReadOne( Tru_Man_t * p, int h ) { return h ? (Tru_One_t *)Vec_SetEntry(p->pMem, h) : NULL; }
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
......@@ -140,7 +140,7 @@ void Tru_ManResize( Tru_Man_t * p )
*pSpot = pThis->Handle;
Counter++;
}
assert( Counter == Vec_RecEntryNum(p->pMem) );
assert( Counter == Vec_SetEntryNum(p->pMem) );
ABC_FREE( pTableOld );
}
......@@ -163,7 +163,7 @@ int Tru_ManInsert( Tru_Man_t * p, word * pTruth )
if ( Tru_ManEqual1(pTruth, p->nWords) )
return 1;
p->nTableLookups++;
if ( Vec_RecEntryNum(p->pMem) > 2 * p->nTableSize )
if ( Vec_SetEntryNum(p->pMem) > 2 * p->nTableSize )
Tru_ManResize( p );
fCompl = pTruth[0] & 1;
if ( fCompl )
......@@ -172,7 +172,7 @@ int Tru_ManInsert( Tru_Man_t * p, word * pTruth )
if ( *pSpot == 0 )
{
Tru_One_t * pEntry;
*pSpot = Vec_RecAppend( p->pMem, p->nEntrySize );
*pSpot = Vec_SetAppend( p->pMem, NULL, p->nEntrySize );
assert( (*pSpot & 1) == 0 );
pEntry = Tru_ManReadOne( p, *pSpot );
Tru_ManCopy( pEntry->pTruth, pTruth, p->nWords );
......@@ -215,7 +215,7 @@ Tru_Man_t * Tru_ManAlloc( int nVars )
p->nEntrySize = (sizeof(Tru_One_t) + p->nWords * sizeof(word))/sizeof(int);
p->nTableSize = 8147;
p->pTable = ABC_CALLOC( int, p->nTableSize );
p->pMem = Vec_RecAlloc();
p->pMem = Vec_SetAlloc();
// initialize truth tables
p->pZero = ABC_ALLOC( word, p->nWords );
for ( i = 0; i < nVars; i++ )
......@@ -247,8 +247,8 @@ Tru_Man_t * Tru_ManAlloc( int nVars )
***********************************************************************/
void Tru_ManFree( Tru_Man_t * p )
{
printf( "Lookups = %d. Entries = %d.\n", p->nTableLookups, Vec_RecEntryNum(p->pMem) );
Vec_RecFree( p->pMem );
printf( "Lookups = %d. Entries = %d.\n", p->nTableLookups, Vec_SetEntryNum(p->pMem) );
Vec_SetFree( p->pMem );
ABC_FREE( p->pZero );
ABC_FREE( p->pTable );
ABC_FREE( p );
......@@ -287,25 +287,9 @@ word * Tru_ManFunc( Tru_Man_t * p, int h )
assert( (h & 1) == 0 );
if ( h == 0 )
return p->pZero;
assert( Vec_RecChunk(h) );
return Tru_ManReadOne( p, h )->pTruth;
}
/**Function*************************************************************
Synopsis [Returns stored truth table]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Tru_ManHandleMax( Tru_Man_t * p )
{
return p->pMem->hCurrent;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
......
......@@ -77,7 +77,7 @@ extern void Tru_ManFree( Tru_Man_t * p );
extern word * Tru_ManVar( Tru_Man_t * p, int v );
extern word * Tru_ManFunc( Tru_Man_t * p, int h );
extern int Tru_ManInsert( Tru_Man_t * p, word * pTruth );
extern int Tru_ManHandleMax( Tru_Man_t * p );
//extern int Tru_ManHandleMax( Tru_Man_t * p );
ABC_NAMESPACE_HEADER_END
......
/**CFile****************************************************************
FileName [vecSet.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [SAT solvers.]
Synopsis [Multi-page dynamic array.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: vecSet.h,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC__sat__bsat__vecSet_h
#define ABC__sat__bsat__vecSet_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include <stdio.h>
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// BASIC TYPES ///
////////////////////////////////////////////////////////////////////////
// data-structure for logging entries
// memory is allocated in 2^16 word-sized pages
// the first 'word' of each page is used storing additional data
// the first 'int' of additional data stores the word limit
// the second 'int' of the additional data stores the shadow word limit
typedef struct Vec_Set_t_ Vec_Set_t;
struct Vec_Set_t_
{
int nEntries; // entry count
int iPage; // current page
int iPageS; // shadow page
int nPagesAlloc; // page count allocated
word ** pPages; // page pointers
};
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
static inline int Vec_SetHandPage( int h ) { return h >> 16; }
static inline int Vec_SetHandShift( int h ) { return h & 0xFFFF; }
static inline word * Vec_SetEntry( Vec_Set_t * p, int h ) { return p->pPages[Vec_SetHandPage(h)] + Vec_SetHandShift(h); }
static inline int Vec_SetEntryNum( Vec_Set_t * p ) { return p->nEntries; }
static inline void Vec_SetWriteEntryNum( Vec_Set_t * p, int i){ p->nEntries = i; }
static inline int Vec_SetLimit( word * p ) { return ((int*)p)[0]; }
static inline int Vec_SetLimitS( word * p ) { return ((int*)p)[1]; }
static inline int Vec_SetIncLimit( word * p, int nWords ) { return ((int*)p)[0] += nWords; }
static inline int Vec_SetIncLimitS( word * p, int nWords ) { return ((int*)p)[1] += nWords; }
static inline void Vec_SetWriteLimit( word * p, int nWords ) { ((int*)p)[0] = nWords; }
static inline void Vec_SetWriteLimitS( word * p, int nWords ) { ((int*)p)[1] = nWords; }
static inline int Vec_SetHandCurrent( Vec_Set_t * p ) { return (p->iPage << 16) + Vec_SetLimit(p->pPages[p->iPage]); }
static inline int Vec_SetHandCurrentS( Vec_Set_t * p ) { return (p->iPageS << 16) + Vec_SetLimitS(p->pPages[p->iPageS]); }
static inline int Vec_SetHandMemory( Vec_Set_t * p, int h ) { return Vec_SetHandPage(h) * 0x8FFFF + Vec_SetHandShift(h) * 8; }
static inline int Vec_SetMemory( Vec_Set_t * p ) { return Vec_SetHandMemory(p, Vec_SetHandCurrent(p)); }
static inline int Vec_SetMemoryS( Vec_Set_t * p ) { return Vec_SetHandMemory(p, Vec_SetHandCurrentS(p)); }
static inline int Vec_SetMemoryAll( Vec_Set_t * p ) { return (p->iPage+1) * 0x8FFFF; }
// Type is the Set type
// pVec is vector of set
// nSize should be given by the user
// pSet is the pointer to the set
// p (page) and s (shift) are variables used here
#define Vec_SetForEachEntry( Type, pVec, nSize, pSet, p, s ) \
for ( p = 0; p <= pVec->iPage; p++ ) \
for ( s = 1; s < Vec_SetLimit(pVec->pPages[p]) && ((pSet) = (Type)(pVec->pPages[p] + (s))); s += nSize )
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Allocating vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Vec_SetAlloc_( Vec_Set_t * p )
{
memset( p, 0, sizeof(Vec_Set_t) );
p->nPagesAlloc = 256;
p->pPages = ABC_CALLOC( word *, p->nPagesAlloc );
p->pPages[0] = ABC_ALLOC( word, 0x10000 );
p->pPages[0][0] = ~0;
Vec_SetWriteLimit( p->pPages[0], 1 );
}
static inline Vec_Set_t * Vec_SetAlloc()
{
Vec_Set_t * p;
p = ABC_CALLOC( Vec_Set_t, 1 );
Vec_SetAlloc_( p );
return p;
}
/**Function*************************************************************
Synopsis [Resetting vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Vec_SetRestart( Vec_Set_t * p )
{
p->nEntries = 0;
p->iPage = 0;
p->iPageS = 0;
p->pPages[0][0] = ~0;
Vec_SetWriteLimit( p->pPages[0], 1 );
}
/**Function*************************************************************
Synopsis [Freeing vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Vec_SetFree_( Vec_Set_t * p )
{
int i;
for ( i = 0; i < p->nPagesAlloc; i++ )
ABC_FREE( p->pPages[i] );
ABC_FREE( p->pPages );
}
static inline void Vec_SetFree( Vec_Set_t * p )
{
Vec_SetFree_( p );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Appending entries to vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Vec_SetAppend( Vec_Set_t * p, int * pArray, int nSize )
{
int nWords = (nSize + 1) >> 1;
assert( nWords < 0x10000 );
p->nEntries++;
if ( Vec_SetLimit( p->pPages[p->iPage] ) + nWords > 0x10000 )
{
if ( ++p->iPage == p->nPagesAlloc )
{
p->pPages = ABC_REALLOC( word *, p->pPages, p->nPagesAlloc * 2 );
memset( p->pPages + p->nPagesAlloc, 0, sizeof(word *) * p->nPagesAlloc );
p->nPagesAlloc *= 2;
}
if ( p->pPages[p->iPage] == NULL )
p->pPages[p->iPage] = ABC_ALLOC( word, 0x10000 );
p->pPages[p->iPage][0] = ~0;
Vec_SetWriteLimit( p->pPages[p->iPage], 1 );
}
if ( pArray )
memmove( p->pPages[p->iPage] + Vec_SetLimit(p->pPages[p->iPage]), pArray, sizeof(int) * nSize );
Vec_SetIncLimit( p->pPages[p->iPage], nWords );
return Vec_SetHandCurrent(p) - nWords;
}
static inline int Vec_SetAppendS( Vec_Set_t * p, int nSize )
{
int nWords = (nSize + 1) >> 1;
assert( nWords < 0x10000 );
if ( Vec_SetLimitS( p->pPages[p->iPageS] ) + nWords > 0x10000 )
Vec_SetWriteLimitS( p->pPages[++p->iPageS], 1 );
Vec_SetIncLimitS( p->pPages[p->iPageS], nWords );
return Vec_SetHandCurrentS(p) - nWords;
}
/**Function*************************************************************
Synopsis [Shrinking vector size.]
Description []
SideEffects [This procedure does not update the number of entries.]
SeeAlso []
***********************************************************************/
static inline void Vec_SetShrink( Vec_Set_t * p, int h )
{
assert( h <= Vec_SetHandCurrent(p) );
p->iPage = Vec_SetHandPage(h);
Vec_SetWriteLimit( p->pPages[p->iPage], Vec_SetHandShift(h) );
}
static inline void Vec_SetShrinkS( Vec_Set_t * p, int h )
{
assert( h <= Vec_SetHandCurrent(p) );
p->iPageS = Vec_SetHandPage(h);
Vec_SetWriteLimitS( p->pPages[p->iPageS], Vec_SetHandShift(h) );
}
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment