Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
abc
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
abc
Commits
c265d244
Commit
c265d244
authored
Jul 09, 2012
by
Alan Mishchenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added learned clause recycling to the SAT solver (may impact bmc2, bmc3, dsat, etc).
parent
685faae8
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
731 additions
and
280 deletions
+731
-280
abclib.dsp
+4
-0
src/aig/aig/aigRepar.c
+11
-11
src/misc/vec/vecSet.h
+10
-7
src/sat/bsat/satClause.h
+401
-0
src/sat/bsat/satSolver.c
+217
-190
src/sat/bsat/satSolver.h
+14
-3
src/sat/bsat/satSolver2.c
+49
-49
src/sat/bsat/satSolver2.h
+16
-15
src/sat/bsat/satUtil.c
+9
-3
src/sat/bsat/satVec.h
+0
-2
No files found.
abclib.dsp
View file @
c265d244
...
@@ -1199,6 +1199,10 @@ SOURCE=.\src\sat\csat\csat_apis.h
...
@@ -1199,6 +1199,10 @@ SOURCE=.\src\sat\csat\csat_apis.h
# PROP Default_Filter ""
# PROP Default_Filter ""
# Begin Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satClause.h
# End Source File
# Begin Source File
SOURCE=.\src\sat\bsat\satInter.c
SOURCE=.\src\sat\bsat\satInter.c
# End Source File
# End Source File
# Begin Source File
# Begin Source File
...
...
src/aig/aig/aigRepar.c
View file @
c265d244
...
@@ -54,13 +54,13 @@ static inline void Aig_ManInterAddBuffer( sat_solver2 * pSat, int iVarA, int iVa
...
@@ -54,13 +54,13 @@ static inline void Aig_ManInterAddBuffer( sat_solver2 * pSat, int iVarA, int iVa
Lits
[
1
]
=
toLitCond
(
iVarB
,
!
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
!
fCompl
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
1
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
fCompl
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
}
}
/**Function*************************************************************
/**Function*************************************************************
...
@@ -85,28 +85,28 @@ static inline void Aig_ManInterAddXor( sat_solver2 * pSat, int iVarA, int iVarB,
...
@@ -85,28 +85,28 @@ static inline void Aig_ManInterAddXor( sat_solver2 * pSat, int iVarA, int iVarB,
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
!
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
!
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
1
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
1
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
}
}
/**Function*************************************************************
/**Function*************************************************************
...
@@ -152,7 +152,7 @@ void Aig_ManInterTest( Aig_Man_t * pMan, int fVerbose )
...
@@ -152,7 +152,7 @@ void Aig_ManInterTest( Aig_Man_t * pMan, int fVerbose )
for
(
i
=
0
;
i
<
pCnf
->
nClauses
;
i
++
)
for
(
i
=
0
;
i
<
pCnf
->
nClauses
;
i
++
)
{
{
Cid
=
sat_solver2_addclause
(
pSat
,
pCnf
->
pClauses
[
i
],
pCnf
->
pClauses
[
i
+
1
]
);
Cid
=
sat_solver2_addclause
(
pSat
,
pCnf
->
pClauses
[
i
],
pCnf
->
pClauses
[
i
+
1
]
);
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
}
}
// add clauses of B
// add clauses of B
...
@@ -283,7 +283,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
...
@@ -283,7 +283,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
for
(
i
=
0
;
i
<
pCnf
->
nClauses
;
i
++
)
for
(
i
=
0
;
i
<
pCnf
->
nClauses
;
i
++
)
{
{
Cid
=
sat_solver2_addclause
(
pSat
,
pCnf
->
pClauses
[
i
],
pCnf
->
pClauses
[
i
+
1
]
);
Cid
=
sat_solver2_addclause
(
pSat
,
pCnf
->
pClauses
[
i
],
pCnf
->
pClauses
[
i
+
1
]
);
clause_set_partA
(
pSat
,
Cid
,
k
==
0
);
clause
2
_set_partA
(
pSat
,
Cid
,
k
==
0
);
}
}
// add equality p[k] == A1/B1
// add equality p[k] == A1/B1
Aig_ManForEachCo
(
pMan
,
pObj
,
i
)
Aig_ManForEachCo
(
pMan
,
pObj
,
i
)
...
@@ -293,7 +293,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
...
@@ -293,7 +293,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
for
(
i
=
0
;
i
<
pCnf
->
nClauses
;
i
++
)
for
(
i
=
0
;
i
<
pCnf
->
nClauses
;
i
++
)
{
{
Cid
=
sat_solver2_addclause
(
pSat
,
pCnf
->
pClauses
[
i
],
pCnf
->
pClauses
[
i
+
1
]
);
Cid
=
sat_solver2_addclause
(
pSat
,
pCnf
->
pClauses
[
i
],
pCnf
->
pClauses
[
i
+
1
]
);
clause_set_partA
(
pSat
,
Cid
,
k
==
0
);
clause
2
_set_partA
(
pSat
,
Cid
,
k
==
0
);
}
}
// add comparator (!p[k] ^ A2/B2) == or[k]
// add comparator (!p[k] ^ A2/B2) == or[k]
Vec_IntClear
(
vVars
);
Vec_IntClear
(
vVars
);
...
@@ -303,7 +303,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
...
@@ -303,7 +303,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
Vec_IntPush
(
vVars
,
toLitCond
(
ShiftOr
[
k
]
+
i
,
1
)
);
Vec_IntPush
(
vVars
,
toLitCond
(
ShiftOr
[
k
]
+
i
,
1
)
);
}
}
Cid
=
sat_solver2_addclause
(
pSat
,
Vec_IntArray
(
vVars
),
Vec_IntArray
(
vVars
)
+
Vec_IntSize
(
vVars
)
);
Cid
=
sat_solver2_addclause
(
pSat
,
Vec_IntArray
(
vVars
),
Vec_IntArray
(
vVars
)
+
Vec_IntSize
(
vVars
)
);
clause_set_partA
(
pSat
,
Cid
,
k
==
0
);
clause
2
_set_partA
(
pSat
,
Cid
,
k
==
0
);
// return to normal
// return to normal
Cnf_DataLift
(
pCnf
,
-
ShiftCnf
[
k
]
-
pCnf
->
nVars
);
Cnf_DataLift
(
pCnf
,
-
ShiftCnf
[
k
]
-
pCnf
->
nVars
);
}
}
...
@@ -362,7 +362,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
...
@@ -362,7 +362,7 @@ Aig_Man_t * Aig_ManInterRepar( Aig_Man_t * pMan, int fVerbose )
for
(
i
=
0
;
i
<
pCnfInter
->
nClauses
;
i
++
)
for
(
i
=
0
;
i
<
pCnfInter
->
nClauses
;
i
++
)
{
{
Cid
=
sat_solver2_addclause
(
pSat
,
pCnfInter
->
pClauses
[
i
],
pCnfInter
->
pClauses
[
i
+
1
]
);
Cid
=
sat_solver2_addclause
(
pSat
,
pCnfInter
->
pClauses
[
i
],
pCnfInter
->
pClauses
[
i
+
1
]
);
clause_set_partA
(
pSat
,
Cid
,
c
==
0
);
clause
2
_set_partA
(
pSat
,
Cid
,
c
==
0
);
}
}
// connect to the inputs
// connect to the inputs
Aig_ManForEachCi
(
pInter
,
pObj
,
i
)
Aig_ManForEachCi
(
pInter
,
pObj
,
i
)
...
...
src/misc/vec/vecSet.h
View file @
c265d244
...
@@ -210,10 +210,11 @@ static inline double Vec_ReportMemory( Vec_Set_t * p )
...
@@ -210,10 +210,11 @@ static inline double Vec_ReportMemory( Vec_Set_t * p )
***********************************************************************/
***********************************************************************/
static
inline
int
Vec_SetAppend
(
Vec_Set_t
*
p
,
int
*
pArray
,
int
nSize
)
static
inline
int
Vec_SetAppend
(
Vec_Set_t
*
p
,
int
*
pArray
,
int
nSize
)
{
{
word
*
pPage
=
p
->
pPages
[
p
->
iPage
];
int
nWords
=
Vec_SetWordNum
(
nSize
);
int
nWords
=
Vec_SetWordNum
(
nSize
);
assert
(
nWords
<
(
1
<<
p
->
nPageSize
)
);
assert
(
nWords
+
3
<
(
1
<<
p
->
nPageSize
)
);
p
->
nEntries
++
;
// need two extra at the begining of the page and one extra in the end
if
(
Vec_SetLimit
(
p
->
pPages
[
p
->
iPage
]
)
+
nWords
>
(
1
<<
p
->
nPageSize
)
)
if
(
Vec_SetLimit
(
pPage
)
+
nWords
>=
(
1
<<
p
->
nPageSize
)
)
{
{
if
(
++
p
->
iPage
==
p
->
nPagesAlloc
)
if
(
++
p
->
iPage
==
p
->
nPagesAlloc
)
{
{
...
@@ -223,12 +224,14 @@ static inline int Vec_SetAppend( Vec_Set_t * p, int * pArray, int nSize )
...
@@ -223,12 +224,14 @@ static inline int Vec_SetAppend( Vec_Set_t * p, int * pArray, int nSize )
}
}
if
(
p
->
pPages
[
p
->
iPage
]
==
NULL
)
if
(
p
->
pPages
[
p
->
iPage
]
==
NULL
)
p
->
pPages
[
p
->
iPage
]
=
ABC_ALLOC
(
word
,
(
1
<<
p
->
nPageSize
)
);
p
->
pPages
[
p
->
iPage
]
=
ABC_ALLOC
(
word
,
(
1
<<
p
->
nPageSize
)
);
Vec_SetWriteLimit
(
p
->
pPages
[
p
->
iPage
],
2
);
pPage
=
p
->
pPages
[
p
->
iPage
];
p
->
pPages
[
p
->
iPage
][
1
]
=
~
0
;
Vec_SetWriteLimit
(
pPage
,
2
);
pPage
[
1
]
=
~
0
;
}
}
if
(
pArray
)
if
(
pArray
)
memcpy
(
p
->
pPages
[
p
->
iPage
]
+
Vec_SetLimit
(
p
->
pPages
[
p
->
iPage
]),
pArray
,
sizeof
(
int
)
*
nSize
);
memcpy
(
pPage
+
Vec_SetLimit
(
pPage
),
pArray
,
sizeof
(
int
)
*
nSize
);
Vec_SetIncLimit
(
p
->
pPages
[
p
->
iPage
],
nWords
);
p
->
nEntries
++
;
Vec_SetIncLimit
(
pPage
,
nWords
);
return
Vec_SetHandCurrent
(
p
)
-
nWords
;
return
Vec_SetHandCurrent
(
p
)
-
nWords
;
}
}
static
inline
int
Vec_SetAppendS
(
Vec_Set_t
*
p
,
int
nSize
)
static
inline
int
Vec_SetAppendS
(
Vec_Set_t
*
p
,
int
nSize
)
...
...
src/sat/bsat/satClause.h
0 → 100644
View file @
c265d244
/**CFile****************************************************************
FileName [satMem.h]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [SAT solver.]
Synopsis [Memory management.]
Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - January 1, 2004.]
Revision [$Id: satMem.h,v 1.0 2004/01/01 1:00:00 alanmi Exp $]
***********************************************************************/
#ifndef ABC__sat__bsat__satMem_h
#define ABC__sat__bsat__satMem_h
////////////////////////////////////////////////////////////////////////
/// INCLUDES ///
////////////////////////////////////////////////////////////////////////
#include "misc/util/abc_global.h"
ABC_NAMESPACE_HEADER_START
////////////////////////////////////////////////////////////////////////
/// PARAMETERS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// STRUCTURE DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
//=================================================================================================
// Clause datatype + minor functions:
typedef
int
lit
;
typedef
int
cla
;
typedef
struct
clause_t
clause
;
struct
clause_t
{
unsigned
lrn
:
1
;
unsigned
mark
:
1
;
unsigned
partA
:
1
;
unsigned
lbd
:
8
;
unsigned
size
:
21
;
lit
lits
[
0
];
};
// learned clauses have "hidden" literal (c->lits[c->size]) to store clause ID
// data-structure for logging entries
// memory is allocated in 2^nPageSize word-sized pages
// the first 'word' of each page are stores the word limit
// although clause memory pieces are aligned to 64-bit words
// the integer clause handles are in terms of 32-bit unsigneds
// allowing for the first bit to be used for labeling 2-lit clauses
typedef
struct
Sat_Mem_t_
Sat_Mem_t
;
struct
Sat_Mem_t_
{
int
nEntries
[
2
];
// entry count
int
BookMarkH
[
2
];
// bookmarks for handles
int
BookMarkE
[
2
];
// bookmarks for entries
int
iPage
[
2
];
// current memory page
int
nPageSize
;
// page log size in terms of ints
unsigned
uPageMask
;
// page mask
unsigned
uLearnedMask
;
// learned mask
int
nPagesAlloc
;
// page count allocated
int
**
pPages
;
// page pointers
};
static
inline
int
Sat_MemLimit
(
int
*
p
)
{
return
p
[
0
];
}
static
inline
int
Sat_MemIncLimit
(
int
*
p
,
int
nInts
)
{
return
p
[
0
]
+=
nInts
;
}
static
inline
void
Sat_MemWriteLimit
(
int
*
p
,
int
nInts
)
{
p
[
0
]
=
nInts
;
}
static
inline
int
Sat_MemHandPage
(
Sat_Mem_t
*
p
,
cla
h
)
{
return
h
>>
p
->
nPageSize
;
}
static
inline
int
Sat_MemHandShift
(
Sat_Mem_t
*
p
,
cla
h
)
{
return
h
&
p
->
uPageMask
;
}
static
inline
int
Sat_MemIntSize
(
int
size
,
int
lrn
)
{
return
(
size
+
2
+
lrn
)
&
~
01
;
}
static
inline
int
Sat_MemClauseSize
(
clause
*
p
)
{
return
Sat_MemIntSize
(
p
->
size
,
p
->
lrn
);
}
//static inline clause * Sat_MemClause( Sat_Mem_t * p, int i, int k ) { assert(i <= p->iPage[i&1] && k <= Sat_MemLimit(p->pPages[i])); return (clause *)(p->pPages[i] + k ); }
static
inline
clause
*
Sat_MemClause
(
Sat_Mem_t
*
p
,
int
i
,
int
k
)
{
return
(
clause
*
)(
p
->
pPages
[
i
]
+
k
);
}
//static inline clause * Sat_MemClauseHand( Sat_Mem_t * p, cla h ) { assert(Sat_MemHandPage(p, h) <= p->iPage[(h & p->uLearnedMask) > 0]); assert(Sat_MemHandShift(p, h) >= 2 && Sat_MemHandShift(p, h) < (int)p->uLearnedMask); return Sat_MemClause( p, Sat_MemHandPage(p, h), Sat_MemHandShift(p, h) ); }
static
inline
clause
*
Sat_MemClauseHand
(
Sat_Mem_t
*
p
,
cla
h
)
{
return
Sat_MemClause
(
p
,
Sat_MemHandPage
(
p
,
h
),
Sat_MemHandShift
(
p
,
h
)
);
}
static
inline
int
Sat_MemEntryNum
(
Sat_Mem_t
*
p
,
int
lrn
)
{
return
p
->
nEntries
[
lrn
];
}
static
inline
cla
Sat_MemHand
(
Sat_Mem_t
*
p
,
int
i
,
int
k
)
{
return
(
i
<<
p
->
nPageSize
)
|
k
;
}
static
inline
cla
Sat_MemHandCurrent
(
Sat_Mem_t
*
p
,
int
lrn
)
{
return
(
p
->
iPage
[
lrn
]
<<
p
->
nPageSize
)
|
Sat_MemLimit
(
p
->
pPages
[
p
->
iPage
[
lrn
]]
);
}
static
inline
double
Sat_MemMemoryHand
(
Sat_Mem_t
*
p
,
cla
h
)
{
return
1
.
0
*
((
Sat_MemHandPage
(
p
,
h
)
+
2
)
/
2
*
(
1
<<
(
p
->
nPageSize
+
2
))
+
Sat_MemHandShift
(
p
,
h
)
*
4
);
}
static
inline
double
Sat_MemMemoryUsed
(
Sat_Mem_t
*
p
,
int
lrn
)
{
return
Sat_MemMemoryHand
(
p
,
Sat_MemHandCurrent
(
p
,
lrn
)
);
}
static
inline
double
Sat_MemMemoryAllUsed
(
Sat_Mem_t
*
p
)
{
return
Sat_MemMemoryUsed
(
p
,
0
)
+
Sat_MemMemoryUsed
(
p
,
1
);
}
static
inline
double
Sat_MemMemoryAll
(
Sat_Mem_t
*
p
)
{
return
1
.
0
*
(
p
->
iPage
[
0
]
+
p
->
iPage
[
1
]
+
2
)
*
(
1
<<
(
p
->
nPageSize
+
2
));
}
// p is memory storage
// c is clause pointer
// i is page number
// k is page offset
#define Sat_MemForEachClause( p, c, i, k ) \
for ( i = 0; i <= p->iPage[0]; i += 2 ) \
for ( k = 2; k < Sat_MemLimit(p->pPages[i]) && ((c) = Sat_MemClause( p, i, k )); k += Sat_MemClauseSize(c) )
#define Sat_MemForEachLearned( p, c, i, k ) \
for ( i = 1; i <= p->iPage[1]; i += 2 ) \
for ( k = 2; k < Sat_MemLimit(p->pPages[i]) && ((c) = Sat_MemClause( p, i, k )); k += Sat_MemClauseSize(c) )
////////////////////////////////////////////////////////////////////////
/// GLOBAL VARIABLES ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// MACRO DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
static
inline
int
clause_from_lit
(
lit
l
)
{
return
l
+
l
+
1
;
}
static
inline
int
clause_is_lit
(
cla
h
)
{
return
(
h
&
1
);
}
static
inline
lit
clause_read_lit
(
cla
h
)
{
return
(
lit
)(
h
>>
1
);
}
static
inline
int
clause_learnt_h
(
Sat_Mem_t
*
p
,
cla
h
)
{
return
(
h
&
p
->
uLearnedMask
)
>
0
;
}
static
inline
int
clause_learnt
(
clause
*
c
)
{
return
c
->
lrn
;
}
static
inline
int
clause_id
(
clause
*
c
)
{
assert
(
c
->
lrn
);
return
c
->
lits
[
c
->
size
];
}
static
inline
int
clause_size
(
clause
*
c
)
{
return
c
->
size
;
}
static
inline
lit
*
clause_begin
(
clause
*
c
)
{
return
c
->
lits
;
}
static
inline
lit
*
clause_end
(
clause
*
c
)
{
return
c
->
lits
+
c
->
size
;
}
static
inline
void
clause_print
(
clause
*
c
)
{
int
i
;
printf
(
"{ "
);
for
(
i
=
0
;
i
<
clause_size
(
c
);
i
++
)
printf
(
"%d "
,
(
clause_begin
(
c
)[
i
]
&
1
)?
-
(
clause_begin
(
c
)[
i
]
>>
1
)
:
clause_begin
(
c
)[
i
]
>>
1
);
printf
(
"}
\n
"
);
}
////////////////////////////////////////////////////////////////////////
/// FUNCTION DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Allocating vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Sat_MemAlloc_
(
Sat_Mem_t
*
p
,
int
nPageSize
)
{
assert
(
nPageSize
>
8
&&
nPageSize
<
32
);
memset
(
p
,
0
,
sizeof
(
Sat_Mem_t
)
);
p
->
nPageSize
=
nPageSize
;
p
->
uLearnedMask
=
(
unsigned
)(
1
<<
nPageSize
);
p
->
uPageMask
=
(
unsigned
)((
1
<<
nPageSize
)
-
1
);
p
->
nPagesAlloc
=
256
;
p
->
pPages
=
ABC_CALLOC
(
int
*
,
p
->
nPagesAlloc
);
p
->
pPages
[
0
]
=
ABC_ALLOC
(
int
,
(
1
<<
p
->
nPageSize
)
);
p
->
pPages
[
1
]
=
ABC_ALLOC
(
int
,
(
1
<<
p
->
nPageSize
)
);
p
->
iPage
[
0
]
=
0
;
p
->
iPage
[
1
]
=
1
;
Sat_MemWriteLimit
(
p
->
pPages
[
0
],
2
);
Sat_MemWriteLimit
(
p
->
pPages
[
1
],
2
);
}
static
inline
Sat_Mem_t
*
Sat_MemAlloc
(
int
nPageSize
)
{
Sat_Mem_t
*
p
;
p
=
ABC_CALLOC
(
Sat_Mem_t
,
1
);
Sat_MemAlloc_
(
p
,
nPageSize
);
return
p
;
}
/**Function*************************************************************
Synopsis [Resetting vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Sat_MemRestart
(
Sat_Mem_t
*
p
)
{
p
->
nEntries
[
0
]
=
0
;
p
->
nEntries
[
1
]
=
0
;
p
->
iPage
[
0
]
=
0
;
p
->
iPage
[
1
]
=
1
;
Sat_MemWriteLimit
(
p
->
pPages
[
0
],
2
);
Sat_MemWriteLimit
(
p
->
pPages
[
1
],
2
);
}
/**Function*************************************************************
Synopsis [Sets the bookmark.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Sat_MemBookMark
(
Sat_Mem_t
*
p
)
{
p
->
BookMarkH
[
0
]
=
Sat_MemHandCurrent
(
p
,
0
);
p
->
BookMarkH
[
1
]
=
Sat_MemHandCurrent
(
p
,
1
);
p
->
BookMarkE
[
0
]
=
p
->
nEntries
[
0
];
p
->
BookMarkE
[
1
]
=
p
->
nEntries
[
1
];
}
static
inline
void
Sat_MemRollBack
(
Sat_Mem_t
*
p
)
{
p
->
nEntries
[
0
]
=
p
->
BookMarkE
[
0
];
p
->
nEntries
[
1
]
=
p
->
BookMarkE
[
1
];
p
->
iPage
[
0
]
=
Sat_MemHandPage
(
p
,
p
->
BookMarkH
[
0
]
);
p
->
iPage
[
1
]
=
Sat_MemHandPage
(
p
,
p
->
BookMarkH
[
1
]
);
Sat_MemWriteLimit
(
p
->
pPages
[
0
],
Sat_MemHandShift
(
p
,
p
->
BookMarkH
[
0
]
)
);
Sat_MemWriteLimit
(
p
->
pPages
[
1
],
Sat_MemHandShift
(
p
,
p
->
BookMarkH
[
1
]
)
);
}
/**Function*************************************************************
Synopsis [Freeing vector.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
void
Sat_MemFree_
(
Sat_Mem_t
*
p
)
{
int
i
;
for
(
i
=
0
;
i
<
p
->
nPagesAlloc
;
i
++
)
ABC_FREE
(
p
->
pPages
[
i
]
);
ABC_FREE
(
p
->
pPages
);
}
static
inline
void
Sat_MemFree
(
Sat_Mem_t
*
p
)
{
Sat_MemFree_
(
p
);
ABC_FREE
(
p
);
}
/**Function*************************************************************
Synopsis [Creates new clause.]
Description [The resulting clause is fully initialized.]
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
int
Sat_MemAppend
(
Sat_Mem_t
*
p
,
int
*
pArray
,
int
nSize
,
int
lrn
)
{
clause
*
c
;
int
*
pPage
=
p
->
pPages
[
p
->
iPage
[
lrn
]];
int
nInts
=
Sat_MemIntSize
(
nSize
,
lrn
);
assert
(
nInts
+
3
<
(
1
<<
p
->
nPageSize
)
);
// need two extra at the begining of the page and one extra in the end
if
(
Sat_MemLimit
(
pPage
)
+
nInts
>=
(
1
<<
p
->
nPageSize
)
)
{
p
->
iPage
[
lrn
]
+=
2
;
if
(
p
->
iPage
[
lrn
]
>=
p
->
nPagesAlloc
)
{
p
->
pPages
=
ABC_REALLOC
(
int
*
,
p
->
pPages
,
p
->
nPagesAlloc
*
2
);
memset
(
p
->
pPages
+
p
->
nPagesAlloc
,
0
,
sizeof
(
int
*
)
*
p
->
nPagesAlloc
);
p
->
nPagesAlloc
*=
2
;
}
if
(
p
->
pPages
[
p
->
iPage
[
lrn
]]
==
NULL
)
p
->
pPages
[
p
->
iPage
[
lrn
]]
=
ABC_ALLOC
(
int
,
(
1
<<
p
->
nPageSize
)
);
pPage
=
p
->
pPages
[
p
->
iPage
[
lrn
]];
Sat_MemWriteLimit
(
pPage
,
2
);
}
pPage
[
Sat_MemLimit
(
pPage
)]
=
0
;
c
=
(
clause
*
)(
pPage
+
Sat_MemLimit
(
pPage
));
c
->
size
=
nSize
;
c
->
lrn
=
lrn
;
if
(
pArray
)
memcpy
(
c
->
lits
,
pArray
,
sizeof
(
int
)
*
nSize
);
if
(
lrn
)
c
->
lits
[
c
->
size
]
=
p
->
nEntries
[
1
];
p
->
nEntries
[
lrn
]
++
;
Sat_MemIncLimit
(
pPage
,
nInts
);
return
Sat_MemHandCurrent
(
p
,
lrn
)
-
nInts
;
}
/**Function*************************************************************
Synopsis [Shrinking vector size.]
Description []
SideEffects [This procedure does not update the number of entries.]
SeeAlso []
***********************************************************************/
static
inline
void
Sat_MemShrink
(
Sat_Mem_t
*
p
,
int
h
,
int
lrn
)
{
assert
(
clause_learnt_h
(
p
,
h
)
==
lrn
);
assert
(
h
&&
h
<=
Sat_MemHandCurrent
(
p
,
lrn
)
);
p
->
iPage
[
lrn
]
=
Sat_MemHandPage
(
p
,
h
);
Sat_MemWriteLimit
(
p
->
pPages
[
p
->
iPage
[
lrn
]],
Sat_MemHandShift
(
p
,
h
)
);
}
/**Function*************************************************************
Synopsis [Compacts learned clauses by removing marked entries.]
Description [Returns the number of remaining entries.]
SideEffects []
SeeAlso []
***********************************************************************/
static
inline
int
Sat_MemCompactLearned
(
Sat_Mem_t
*
p
,
int
fDoMove
)
{
clause
*
c
;
int
i
,
k
,
iNew
=
1
,
kNew
=
2
,
nInts
,
Counter
=
0
;
// iterate through the learned clauses
Sat_MemForEachLearned
(
p
,
c
,
i
,
k
)
{
assert
(
c
->
lrn
);
// skip marked entry
if
(
c
->
mark
)
continue
;
// compute entry size
nInts
=
Sat_MemClauseSize
(
c
);
assert
(
!
(
nInts
&
1
)
);
// check if we need to scroll to the next page
if
(
kNew
+
nInts
>=
(
1
<<
p
->
nPageSize
)
)
{
// set the limit of the current page
if
(
fDoMove
)
Sat_MemWriteLimit
(
p
->
pPages
[
iNew
],
kNew
);
// move writing position to the new page
iNew
+=
2
;
kNew
=
2
;
}
if
(
fDoMove
)
{
// make sure the result is the same as previous dry run
assert
(
c
->
lits
[
c
->
size
]
==
Sat_MemHand
(
p
,
iNew
,
kNew
)
);
// only copy the clause if it has changed
if
(
i
!=
iNew
||
k
!=
kNew
)
{
memmove
(
p
->
pPages
[
iNew
]
+
kNew
,
c
,
sizeof
(
int
)
*
nInts
);
// c = Sat_MemClause( p, iNew, kNew ); // assersions do not hold during dry run
c
=
(
clause
*
)(
p
->
pPages
[
iNew
]
+
kNew
);
assert
(
nInts
==
Sat_MemClauseSize
(
c
)
);
}
// set the new ID value
c
->
lits
[
c
->
size
]
=
Counter
;
}
else
// remember the address of the clause in the new location
c
->
lits
[
c
->
size
]
=
Sat_MemHand
(
p
,
iNew
,
kNew
);
// update writing position
kNew
+=
nInts
;
assert
(
iNew
<=
i
&&
kNew
<
(
1
<<
p
->
nPageSize
)
);
// update counter
Counter
++
;
}
if
(
fDoMove
)
{
// update the page count
p
->
iPage
[
1
]
=
iNew
;
// set the limit of the last page
Sat_MemWriteLimit
(
p
->
pPages
[
iNew
],
kNew
);
// update the counter
p
->
nEntries
[
1
]
=
Counter
;
}
return
Counter
;
}
ABC_NAMESPACE_HEADER_END
#endif
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
src/sat/bsat/satSolver.c
View file @
c265d244
...
@@ -29,6 +29,10 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
...
@@ -29,6 +29,10 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
ABC_NAMESPACE_IMPL_START
ABC_NAMESPACE_IMPL_START
//#define LEARNT_MAX_START 0
#define LEARNT_MAX_START 20000
#define LEARNT_MAX_INCRE 1000
#define SAT_USE_ANALYZE_FINAL
#define SAT_USE_ANALYZE_FINAL
//=================================================================================================
//=================================================================================================
...
@@ -125,39 +129,6 @@ int sat_solver_get_var_value(sat_solver* s, int v)
...
@@ -125,39 +129,6 @@ int sat_solver_get_var_value(sat_solver* s, int v)
assert
(
0
);
assert
(
0
);
return
0
;
return
0
;
}
}
//=================================================================================================
// Clause datatype + minor functions:
struct
clause_t
{
int
size_learnt
;
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
;
}
static
inline
float
clause_activity
(
clause
*
c
)
{
return
*
((
float
*
)
&
c
->
lits
[
c
->
size_learnt
>>
1
]);
}
static
inline
unsigned
clause_activity2
(
clause
*
c
)
{
return
*
((
unsigned
*
)
&
c
->
lits
[
c
->
size_learnt
>>
1
]);
}
static
inline
void
clause_setactivity
(
clause
*
c
,
float
a
)
{
*
((
float
*
)
&
c
->
lits
[
c
->
size_learnt
>>
1
])
=
a
;
}
static
inline
void
clause_setactivity2
(
clause
*
c
,
unsigned
a
)
{
*
((
unsigned
*
)
&
c
->
lits
[
c
->
size_learnt
>>
1
])
=
a
;
}
static
inline
void
clause_print
(
clause
*
c
)
{
int
i
;
printf
(
"{ "
);
for
(
i
=
0
;
i
<
clause_nlits
(
c
);
i
++
)
printf
(
"%d "
,
(
clause_begin
(
c
)[
i
]
&
1
)
?
-
(
clause_begin
(
c
)[
i
]
>>
1
)
:
clause_begin
(
c
)[
i
]
>>
1
);
printf
(
"}
\n
"
);
}
//=================================================================================================
// 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
);
}
//=================================================================================================
//=================================================================================================
// Simple helpers:
// Simple helpers:
...
@@ -257,7 +228,7 @@ static inline void act_var_rescale(sat_solver* s) {
...
@@ -257,7 +228,7 @@ static inline void act_var_rescale(sat_solver* s) {
s
->
var_inc
*=
1e-100
;
s
->
var_inc
*=
1e-100
;
}
}
static
inline
void
act_clause_rescale
(
sat_solver
*
s
)
{
static
inline
void
act_clause_rescale
(
sat_solver
*
s
)
{
// static
in
t Total = 0;
// static
clock_
t Total = 0;
clause
**
cs
=
(
clause
**
)
veci_begin
(
&
s
->
learnts
);
clause
**
cs
=
(
clause
**
)
veci_begin
(
&
s
->
learnts
);
int
i
;
//, clk = clock();
int
i
;
//, clk = clock();
for
(
i
=
0
;
i
<
veci_size
(
&
s
->
learnts
);
i
++
){
for
(
i
=
0
;
i
<
veci_size
(
&
s
->
learnts
);
i
++
){
...
@@ -267,8 +238,8 @@ static inline void act_clause_rescale(sat_solver* s) {
...
@@ -267,8 +238,8 @@ static inline void act_clause_rescale(sat_solver* s) {
s
->
cla_inc
*=
(
float
)
1e-20
;
s
->
cla_inc
*=
(
float
)
1e-20
;
Total
+=
clock
()
-
clk
;
Total
+=
clock
()
-
clk
;
printf
(
"Rescaling... Cla inc = %10.3f Conf = %10d "
,
s
->
cla_inc
,
s
->
stats
.
conflicts
);
//
printf( "Rescaling... Cla inc = %10.3f Conf = %10d ", s->cla_inc, s->stats.conflicts );
Abc_PrintTime
(
1
,
"Time"
,
Total
);
//
Abc_PrintTime( 1, "Time", Total );
}
}
static
inline
void
act_var_bump
(
sat_solver
*
s
,
int
v
)
{
static
inline
void
act_var_bump
(
sat_solver
*
s
,
int
v
)
{
s
->
activity
[
v
]
+=
s
->
var_inc
;
s
->
activity
[
v
]
+=
s
->
var_inc
;
...
@@ -313,24 +284,21 @@ static inline void act_var_rescale(sat_solver* s) {
...
@@ -313,24 +284,21 @@ static inline void act_var_rescale(sat_solver* s) {
s
->
var_inc
>>=
19
;
s
->
var_inc
>>=
19
;
s
->
var_inc
=
Abc_MaxInt
(
s
->
var_inc
,
(
1
<<
4
)
);
s
->
var_inc
=
Abc_MaxInt
(
s
->
var_inc
,
(
1
<<
4
)
);
}
}
/*
static
inline
void
act_clause_rescale
(
sat_solver
*
s
)
{
static
inline
void
act_clause_rescale
(
sat_solver
*
s
)
{
static int Total = 0;
static
clock_t
Total
=
0
;
clause** cs = (clause**)vecp_begin(&s->learnts);
int i;
clock_t
clk
=
clock
();
clock_t
clk
=
clock
();
for (i = 0; i < vecp_size(&s->learnts); i++){
unsigned
*
activity
=
(
unsigned
*
)
veci_begin
(
&
s
->
act_clas
);
unsigned a = clause_activity2(cs[i])
;
int
i
;
clause_setactivity2(cs[i], a >> 14);
for
(
i
=
0
;
i
<
veci_size
(
&
s
->
act_clas
);
i
++
)
}
activity
[
i
]
>>=
14
;
s
->
cla_inc
>>=
14
;
s
->
cla_inc
>>=
14
;
s
->
cla_inc
=
Abc_MaxInt
(
s
->
cla_inc
,
(
1
<<
10
)
);
s
->
cla_inc
=
Abc_MaxInt
(
s
->
cla_inc
,
(
1
<<
10
)
);
Total
+=
clock
()
-
clk
;
// Total += clock() - clk;
// printf( "Rescaling... Cla inc = %5d Conf = %10d ", s->cla_inc, s->stats.conflicts );
// printf( "Rescaling... Cla inc = %5d Conf = %10d ", s->cla_inc, s->stats.conflicts );
// Abc_PrintTime( 1, "Time", Total );
// Abc_PrintTime( 1, "Time", Total );
}
}
*/
static
inline
void
act_var_bump
(
sat_solver
*
s
,
int
v
)
{
static
inline
void
act_var_bump
(
sat_solver
*
s
,
int
v
)
{
s
->
activity
[
v
]
+=
s
->
var_inc
;
s
->
activity
[
v
]
+=
s
->
var_inc
;
if
(
s
->
activity
[
v
]
&
0x80000000
)
if
(
s
->
activity
[
v
]
&
0x80000000
)
...
@@ -356,16 +324,16 @@ static inline void act_var_bump_factor(sat_solver* s, int v) {
...
@@ -356,16 +324,16 @@ static inline void act_var_bump_factor(sat_solver* s, int v) {
if
(
s
->
orderpos
[
v
]
!=
-
1
)
if
(
s
->
orderpos
[
v
]
!=
-
1
)
order_update
(
s
,
v
);
order_update
(
s
,
v
);
}
}
/*
static
inline
void
act_clause_bump
(
sat_solver
*
s
,
clause
*
c
)
{
static
inline
void
act_clause_bump
(
sat_solver
*
s
,
clause
*
c
)
{
unsigned
a = clause_activity2(c) + s->cla_inc
;
unsigned
*
act
=
(
unsigned
*
)
veci_begin
(
&
s
->
act_clas
)
+
c
->
lits
[
c
->
size
]
;
clause_setactivity2(c,a)
;
*
act
+=
s
->
cla_inc
;
if (
a & 0x80000000)
if
(
*
act
&
0x80000000
)
act_clause_rescale
(
s
);
act_clause_rescale
(
s
);
}
}
*/
static
inline
void
act_var_decay
(
sat_solver
*
s
)
{
s
->
var_inc
+=
(
s
->
var_inc
>>
4
);
}
static
inline
void
act_var_decay
(
sat_solver
*
s
)
{
s
->
var_inc
+=
(
s
->
var_inc
>>
4
);
}
//
static inline void act_clause_decay(sat_solver* s) { s->cla_inc += (s->cla_inc >> 10); }
static
inline
void
act_clause_decay
(
sat_solver
*
s
)
{
s
->
cla_inc
+=
(
s
->
cla_inc
>>
10
);
}
#endif
#endif
...
@@ -416,13 +384,30 @@ static void sortrnd(void** array, int size, int(*comp)(const void *, const void
...
@@ -416,13 +384,30 @@ static void sortrnd(void** array, int size, int(*comp)(const void *, const void
//=================================================================================================
//=================================================================================================
// Clause functions:
// Clause functions:
static
inline
int
sat_clause_compute_lbd
(
sat_solver
*
s
,
clause
*
c
)
{
int
i
,
lev
,
minl
=
0
,
lbd
=
0
;
for
(
i
=
0
;
i
<
(
int
)
c
->
size
;
i
++
)
{
lev
=
var_level
(
s
,
lit_var
(
c
->
lits
[
i
]));
if
(
!
(
minl
&
(
1
<<
(
lev
&
31
)))
)
{
minl
|=
1
<<
(
lev
&
31
);
lbd
++
;
// printf( "%d ", lev );
}
}
// printf( " -> %d\n", lbd );
return
lbd
;
}
/* pre: size > 1 && no variable occurs twice
/* pre: size > 1 && no variable occurs twice
*/
*/
static
int
clause_create_new
(
sat_solver
*
s
,
lit
*
begin
,
lit
*
end
,
int
learnt
)
static
int
clause_create_new
(
sat_solver
*
s
,
lit
*
begin
,
lit
*
end
,
int
learnt
)
{
{
int
size
;
int
size
;
clause
*
c
;
clause
*
c
;
int
h
,
i
;
int
h
;
assert
(
end
-
begin
>
1
);
assert
(
end
-
begin
>
1
);
assert
(
learnt
>=
0
&&
learnt
<
2
);
assert
(
learnt
>=
0
&&
learnt
<
2
);
...
@@ -433,20 +418,33 @@ static int clause_create_new(sat_solver* s, lit* begin, lit* end, int learnt)
...
@@ -433,20 +418,33 @@ static int clause_create_new(sat_solver* s, lit* begin, lit* end, int learnt)
{
{
veci_push
(
sat_solver_read_wlist
(
s
,
lit_neg
(
begin
[
0
])),(
clause_from_lit
(
begin
[
1
])));
veci_push
(
sat_solver_read_wlist
(
s
,
lit_neg
(
begin
[
0
])),(
clause_from_lit
(
begin
[
1
])));
veci_push
(
sat_solver_read_wlist
(
s
,
lit_neg
(
begin
[
1
])),(
clause_from_lit
(
begin
[
0
])));
veci_push
(
sat_solver_read_wlist
(
s
,
lit_neg
(
begin
[
1
])),(
clause_from_lit
(
begin
[
0
])));
s
->
stats
.
clauses
++
;
s
->
stats
.
clauses_literals
+=
size
;
return
0
;
return
0
;
}
}
// create new clause
// create new clause
h
=
Vec_SetAppend
(
&
s
->
Mem
,
NULL
,
size
+
learnt
+
1
)
<<
1
;
// h = Vec_SetAppend( &s->Mem, NULL, size + learnt + 1 + 1 ) << 1;
h
=
Sat_MemAppend
(
&
s
->
Mem
,
begin
,
size
,
learnt
);
assert
(
!
(
h
&
1
)
);
assert
(
!
(
h
&
1
)
);
c
=
clause_read
(
s
,
h
);
if
(
s
->
hLearnts
==
-
1
&&
learnt
)
if
(
s
->
hLearnts
==
-
1
&&
learnt
)
s
->
hLearnts
=
h
;
s
->
hLearnts
=
h
;
c
->
size_learnt
=
(
size
<<
1
)
|
learnt
;
for
(
i
=
0
;
i
<
size
;
i
++
)
c
->
lits
[
i
]
=
begin
[
i
];
if
(
learnt
)
if
(
learnt
)
*
((
float
*
)
&
c
->
lits
[
size
])
=
0
.
0
;
{
c
=
clause_read
(
s
,
h
);
c
->
lbd
=
sat_clause_compute_lbd
(
s
,
c
);
assert
(
clause_id
(
c
)
==
veci_size
(
&
s
->
act_clas
)
);
// veci_push(&s->learned, h);
// act_clause_bump(s,clause_read(s, h));
veci_push
(
&
s
->
act_clas
,
(
1
<<
10
));
s
->
stats
.
learnts
++
;
s
->
stats
.
learnts_literals
+=
size
;
}
else
{
s
->
stats
.
clauses
++
;
s
->
stats
.
clauses_literals
+=
size
;
}
assert
(
begin
[
0
]
>=
0
);
assert
(
begin
[
0
]
>=
0
);
assert
(
begin
[
0
]
<
s
->
size
*
2
);
assert
(
begin
[
0
]
<
s
->
size
*
2
);
...
@@ -541,6 +539,7 @@ static void sat_solver_record(sat_solver* s, veci* cls)
...
@@ -541,6 +539,7 @@ static void sat_solver_record(sat_solver* s, veci* cls)
lit
*
end
=
begin
+
veci_size
(
cls
);
lit
*
end
=
begin
+
veci_size
(
cls
);
int
h
=
(
veci_size
(
cls
)
>
1
)
?
clause_create_new
(
s
,
begin
,
end
,
1
)
:
0
;
int
h
=
(
veci_size
(
cls
)
>
1
)
?
clause_create_new
(
s
,
begin
,
end
,
1
)
:
0
;
sat_solver_enqueue
(
s
,
*
begin
,
h
);
sat_solver_enqueue
(
s
,
*
begin
,
h
);
assert
(
veci_size
(
cls
)
>
0
);
///////////////////////////////////
///////////////////////////////////
// add clause to internal storage
// add clause to internal storage
...
@@ -550,15 +549,13 @@ static void sat_solver_record(sat_solver* s, veci* cls)
...
@@ -550,15 +549,13 @@ static void sat_solver_record(sat_solver* s, veci* cls)
assert
(
RetValue
);
assert
(
RetValue
);
}
}
///////////////////////////////////
///////////////////////////////////
/*
assert
(
veci_size
(
cls
)
>
0
);
if (h != 0) {
if (h != 0) {
// veci_push(&s->learnts,c);
act_clause_bump(s,clause_read(s, h));
// act_clause_bump(s,c);
s->stats.learnts++;
s->stats.learnts++;
s->stats.learnts_literals += veci_size(cls);
s->stats.learnts_literals += veci_size(cls);
}
}
*/
}
}
...
@@ -602,7 +599,7 @@ static int sat_solver_lit_removable(sat_solver* s, int x, int minl)
...
@@ -602,7 +599,7 @@ static int sat_solver_lit_removable(sat_solver* s, int x, int minl)
clause
*
c
=
clause_read
(
s
,
s
->
reasons
[
v
]);
clause
*
c
=
clause_read
(
s
,
s
->
reasons
[
v
]);
lit
*
lits
=
clause_begin
(
c
);
lit
*
lits
=
clause_begin
(
c
);
int
i
;
int
i
;
for
(
i
=
1
;
i
<
clause_
nlits
(
c
);
i
++
){
for
(
i
=
1
;
i
<
clause_
size
(
c
);
i
++
){
int
v
=
lit_var
(
lits
[
i
]);
int
v
=
lit_var
(
lits
[
i
]);
if
(
!
var_tag
(
s
,
v
)
&&
var_level
(
s
,
v
)){
if
(
!
var_tag
(
s
,
v
)
&&
var_level
(
s
,
v
)){
if
(
s
->
reasons
[
v
]
!=
0
&&
((
1
<<
(
var_level
(
s
,
v
)
&
31
))
&
minl
)){
if
(
s
->
reasons
[
v
]
!=
0
&&
((
1
<<
(
var_level
(
s
,
v
)
&
31
))
&
minl
)){
...
@@ -681,7 +678,7 @@ static void sat_solver_analyze_final(sat_solver* s, int hConf, int skip_first)
...
@@ -681,7 +678,7 @@ static void sat_solver_analyze_final(sat_solver* s, int hConf, int skip_first)
assert
(
veci_size
(
&
s
->
tagged
)
==
0
);
assert
(
veci_size
(
&
s
->
tagged
)
==
0
);
// assert( s->tags[lit_var(p)] == l_Undef );
// assert( s->tags[lit_var(p)] == l_Undef );
// s->tags[lit_var(p)] = l_True;
// s->tags[lit_var(p)] = l_True;
for
(
i
=
skip_first
?
1
:
0
;
i
<
clause_
nlits
(
conf
);
i
++
)
for
(
i
=
skip_first
?
1
:
0
;
i
<
clause_
size
(
conf
);
i
++
)
{
{
int
x
=
lit_var
(
clause_begin
(
conf
)[
i
]);
int
x
=
lit_var
(
clause_begin
(
conf
)[
i
]);
if
(
var_level
(
s
,
x
)
>
0
)
if
(
var_level
(
s
,
x
)
>
0
)
...
@@ -705,7 +702,7 @@ static void sat_solver_analyze_final(sat_solver* s, int hConf, int skip_first)
...
@@ -705,7 +702,7 @@ static void sat_solver_analyze_final(sat_solver* s, int hConf, int skip_first)
else
{
else
{
clause
*
c
=
clause_read
(
s
,
s
->
reasons
[
x
]);
clause
*
c
=
clause_read
(
s
,
s
->
reasons
[
x
]);
int
*
lits
=
clause_begin
(
c
);
int
*
lits
=
clause_begin
(
c
);
for
(
j
=
1
;
j
<
clause_
nlits
(
c
);
j
++
)
for
(
j
=
1
;
j
<
clause_
size
(
c
);
j
++
)
if
(
var_level
(
s
,
lit_var
(
lits
[
j
]))
>
0
)
if
(
var_level
(
s
,
lit_var
(
lits
[
j
]))
>
0
)
var_set_tag
(
s
,
lit_var
(
lits
[
j
]),
1
);
var_set_tag
(
s
,
lit_var
(
lits
[
j
]),
1
);
}
}
...
@@ -717,7 +714,6 @@ static void sat_solver_analyze_final(sat_solver* s, int hConf, int skip_first)
...
@@ -717,7 +714,6 @@ static void sat_solver_analyze_final(sat_solver* s, int hConf, int skip_first)
#endif
#endif
static
void
sat_solver_analyze
(
sat_solver
*
s
,
int
h
,
veci
*
learnt
)
static
void
sat_solver_analyze
(
sat_solver
*
s
,
int
h
,
veci
*
learnt
)
{
{
lit
*
trail
=
s
->
trail
;
lit
*
trail
=
s
->
trail
;
...
@@ -741,15 +737,18 @@ static void sat_solver_analyze(sat_solver* s, int h, veci* learnt)
...
@@ -741,15 +737,18 @@ static void sat_solver_analyze(sat_solver* s, int h, veci* learnt)
}
}
}
else
{
}
else
{
clause
*
c
=
clause_read
(
s
,
h
);
clause
*
c
=
clause_read
(
s
,
h
);
//
if (clause_learnt(c))
if
(
clause_learnt
(
c
))
//
act_clause_bump(s,c);
act_clause_bump
(
s
,
c
);
lits
=
clause_begin
(
c
);
lits
=
clause_begin
(
c
);
//printlits(lits,lits+clause_
nlits
(c)); printf("\n");
//printlits(lits,lits+clause_
size
(c)); printf("\n");
for
(
j
=
(
p
==
lit_Undef
?
0
:
1
);
j
<
clause_
nlits
(
c
);
j
++
){
for
(
j
=
(
p
==
lit_Undef
?
0
:
1
);
j
<
clause_
size
(
c
);
j
++
){
int
x
=
lit_var
(
lits
[
j
]);
int
x
=
lit_var
(
lits
[
j
]);
if
(
var_tag
(
s
,
x
)
==
0
&&
var_level
(
s
,
x
)
>
0
){
if
(
var_tag
(
s
,
x
)
==
0
&&
var_level
(
s
,
x
)
>
0
){
var_set_tag
(
s
,
x
,
1
);
var_set_tag
(
s
,
x
,
1
);
act_var_bump
(
s
,
x
);
act_var_bump
(
s
,
x
);
// bump variables propaged by the LBD=2 clause
// if ( s->reasons[x] && clause_read(s, s->reasons[x])->lbd <= 2 )
// act_var_bump(s,x);
if
(
var_level
(
s
,
x
)
==
sat_solver_dl
(
s
))
if
(
var_level
(
s
,
x
)
==
sat_solver_dl
(
s
))
cnt
++
;
cnt
++
;
else
else
...
@@ -785,6 +784,7 @@ static void sat_solver_analyze(sat_solver* s, int h, veci* learnt)
...
@@ -785,6 +784,7 @@ static void sat_solver_analyze(sat_solver* s, int h, veci* learnt)
veci_resize
(
learnt
,
j
);
veci_resize
(
learnt
,
j
);
s
->
stats
.
tot_literals
+=
j
;
s
->
stats
.
tot_literals
+=
j
;
// clear tags
// clear tags
solver2_clear_tags
(
s
,
0
);
solver2_clear_tags
(
s
,
0
);
...
@@ -836,7 +836,7 @@ int sat_solver_propagate(sat_solver* s)
...
@@ -836,7 +836,7 @@ int sat_solver_propagate(sat_solver* s)
int
*
i
,
*
j
;
int
*
i
,
*
j
;
s
->
stats
.
propagations
++
;
s
->
stats
.
propagations
++
;
s
->
simpdb_props
--
;
//
s->simpdb_props--;
//printf("checking lit %d: "L_LIT"\n", veci_size(ws), L_lit(p));
//printf("checking lit %d: "L_LIT"\n", veci_size(ws), L_lit(p));
for
(
i
=
j
=
begin
;
i
<
end
;
){
for
(
i
=
j
=
begin
;
i
<
end
;
){
...
@@ -875,7 +875,7 @@ int sat_solver_propagate(sat_solver* s)
...
@@ -875,7 +875,7 @@ int sat_solver_propagate(sat_solver* s)
*
j
++
=
*
i
;
*
j
++
=
*
i
;
else
{
else
{
// Look for new watch:
// Look for new watch:
lit
*
stop
=
lits
+
clause_
nlits
(
c
);
lit
*
stop
=
lits
+
clause_
size
(
c
);
lit
*
k
;
lit
*
k
;
for
(
k
=
lits
+
2
;
k
<
stop
;
k
++
){
for
(
k
=
lits
+
2
;
k
<
stop
;
k
++
){
if
(
var_value
(
s
,
lit_var
(
*
k
))
!=
!
lit_sign
(
*
k
)){
if
(
var_value
(
s
,
lit_var
(
*
k
))
!=
!
lit_sign
(
*
k
)){
...
@@ -887,6 +887,8 @@ int sat_solver_propagate(sat_solver* s)
...
@@ -887,6 +887,8 @@ int sat_solver_propagate(sat_solver* s)
*
j
++
=
*
i
;
*
j
++
=
*
i
;
// Clause is unit under assignment:
// Clause is unit under assignment:
if
(
c
->
lrn
)
c
->
lbd
=
sat_clause_compute_lbd
(
s
,
c
);
if
(
!
sat_solver_enqueue
(
s
,
lits
[
0
],
*
i
)){
if
(
!
sat_solver_enqueue
(
s
,
lits
[
0
],
*
i
)){
hConfl
=
*
i
++
;
hConfl
=
*
i
++
;
// Copy the remaining watches:
// Copy the remaining watches:
...
@@ -913,16 +915,20 @@ sat_solver* sat_solver_new(void)
...
@@ -913,16 +915,20 @@ sat_solver* sat_solver_new(void)
{
{
sat_solver
*
s
=
(
sat_solver
*
)
ABC_CALLOC
(
char
,
sizeof
(
sat_solver
));
sat_solver
*
s
=
(
sat_solver
*
)
ABC_CALLOC
(
char
,
sizeof
(
sat_solver
));
Vec_SetAlloc_
(
&
s
->
Mem
,
15
);
// Vec_SetAlloc_(&s->Mem, 15);
Sat_MemAlloc_
(
&
s
->
Mem
,
14
);
s
->
hLearnts
=
-
1
;
s
->
hLearnts
=
-
1
;
s
->
hBinary
=
Vec_SetAppend
(
&
s
->
Mem
,
NULL
,
3
)
<<
1
;
s
->
hBinary
=
Sat_MemAppend
(
&
s
->
Mem
,
NULL
,
2
,
0
)
;
s
->
binary
=
clause_read
(
s
,
s
->
hBinary
);
s
->
binary
=
clause_read
(
s
,
s
->
hBinary
);
s
->
binary
->
size_learnt
=
(
2
<<
1
);
s
->
nLearntMax
=
LEARNT_MAX_START
;
// initialize vectors
// initialize vectors
veci_new
(
&
s
->
order
);
veci_new
(
&
s
->
order
);
veci_new
(
&
s
->
trail_lim
);
veci_new
(
&
s
->
trail_lim
);
veci_new
(
&
s
->
tagged
);
veci_new
(
&
s
->
tagged
);
// veci_new(&s->learned);
veci_new
(
&
s
->
act_clas
);
veci_new
(
&
s
->
stack
);
veci_new
(
&
s
->
stack
);
// veci_new(&s->model);
// veci_new(&s->model);
veci_new
(
&
s
->
act_vars
);
veci_new
(
&
s
->
act_vars
);
...
@@ -944,15 +950,15 @@ sat_solver* sat_solver_new(void)
...
@@ -944,15 +950,15 @@ sat_solver* sat_solver_new(void)
#ifdef USE_FLOAT_ACTIVITY
#ifdef USE_FLOAT_ACTIVITY
s
->
var_inc
=
1
;
s
->
var_inc
=
1
;
s
->
cla_inc
=
1
;
s
->
cla_inc
=
1
;
s
->
var_decay
=
(
float
)(
1
/
0
.
95
);
s
->
var_decay
=
(
float
)(
1
/
0
.
95
);
s
->
cla_decay
=
(
float
)(
1
/
0
.
999
);
s
->
cla_decay
=
(
float
)(
1
/
0
.
999
);
#else
#else
s
->
var_inc
=
(
1
<<
5
);
s
->
var_inc
=
(
1
<<
5
);
s
->
cla_inc
=
(
1
<<
11
);
s
->
cla_inc
=
(
1
<<
11
);
#endif
#endif
s
->
root_level
=
0
;
s
->
root_level
=
0
;
s
->
simpdb_assigns
=
0
;
//
s->simpdb_assigns = 0;
s
->
simpdb_props
=
0
;
//
s->simpdb_props = 0;
s
->
random_seed
=
91648253
;
s
->
random_seed
=
91648253
;
s
->
progress_estimate
=
0
;
s
->
progress_estimate
=
0
;
// s->binary = (clause*)ABC_ALLOC( char, sizeof(clause) + sizeof(lit)*2);
// s->binary = (clause*)ABC_ALLOC( char, sizeof(clause) + sizeof(lit)*2);
...
@@ -1035,12 +1041,15 @@ void sat_solver_setnvars(sat_solver* s,int n)
...
@@ -1035,12 +1041,15 @@ void sat_solver_setnvars(sat_solver* s,int n)
void
sat_solver_delete
(
sat_solver
*
s
)
void
sat_solver_delete
(
sat_solver
*
s
)
{
{
Vec_SetFree_
(
&
s
->
Mem
);
// Vec_SetFree_( &s->Mem );
Sat_MemFree_
(
&
s
->
Mem
);
// delete vectors
// delete vectors
veci_delete
(
&
s
->
order
);
veci_delete
(
&
s
->
order
);
veci_delete
(
&
s
->
trail_lim
);
veci_delete
(
&
s
->
trail_lim
);
veci_delete
(
&
s
->
tagged
);
veci_delete
(
&
s
->
tagged
);
// veci_delete(&s->learned);
veci_delete
(
&
s
->
act_clas
);
veci_delete
(
&
s
->
stack
);
veci_delete
(
&
s
->
stack
);
// veci_delete(&s->model);
// veci_delete(&s->model);
veci_delete
(
&
s
->
act_vars
);
veci_delete
(
&
s
->
act_vars
);
...
@@ -1073,12 +1082,10 @@ void sat_solver_delete(sat_solver* s)
...
@@ -1073,12 +1082,10 @@ void sat_solver_delete(sat_solver* s)
void
sat_solver_rollback
(
sat_solver
*
s
)
void
sat_solver_rollback
(
sat_solver
*
s
)
{
{
int
i
;
int
i
;
Vec_SetRestart
(
&
s
->
Mem
);
Sat_MemRestart
(
&
s
->
Mem
);
s
->
hLearnts
=
-
1
;
s
->
hLearnts
=
-
1
;
s
->
hBinary
=
Vec_SetAppend
(
&
s
->
Mem
,
NULL
,
3
)
<<
1
;
s
->
hBinary
=
Sat_MemAppend
(
&
s
->
Mem
,
NULL
,
2
,
0
)
;
s
->
binary
=
clause_read
(
s
,
s
->
hBinary
);
s
->
binary
=
clause_read
(
s
,
s
->
hBinary
);
s
->
binary
->
size_learnt
=
(
2
<<
1
);
veci_resize
(
&
s
->
trail_lim
,
0
);
veci_resize
(
&
s
->
trail_lim
,
0
);
veci_resize
(
&
s
->
order
,
0
);
veci_resize
(
&
s
->
order
,
0
);
...
@@ -1100,8 +1107,8 @@ void sat_solver_rollback( sat_solver* s )
...
@@ -1100,8 +1107,8 @@ void sat_solver_rollback( sat_solver* s )
s
->
cla_inc
=
(
1
<<
11
);
s
->
cla_inc
=
(
1
<<
11
);
#endif
#endif
s
->
root_level
=
0
;
s
->
root_level
=
0
;
s
->
simpdb_assigns
=
0
;
//
s->simpdb_assigns = 0;
s
->
simpdb_props
=
0
;
//
s->simpdb_props = 0;
s
->
random_seed
=
91648253
;
s
->
random_seed
=
91648253
;
s
->
progress_estimate
=
0
;
s
->
progress_estimate
=
0
;
s
->
verbosity
=
0
;
s
->
verbosity
=
0
;
...
@@ -1145,116 +1152,138 @@ double sat_solver_memory( sat_solver* s )
...
@@ -1145,116 +1152,138 @@ double sat_solver_memory( sat_solver* s )
Mem
+=
s
->
order
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
order
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
trail_lim
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
trail_lim
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
tagged
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
tagged
.
cap
*
sizeof
(
int
);
// Mem += s->learned.cap * sizeof(int);
Mem
+=
s
->
stack
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
stack
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
act_vars
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
act_vars
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
act_clas
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
temp_clause
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
temp_clause
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
conf_final
.
cap
*
sizeof
(
int
);
Mem
+=
s
->
conf_final
.
cap
*
sizeof
(
int
);
Mem
+=
Vec_ReportMemory
(
&
s
->
Mem
);
Mem
+=
Sat_MemMemoryAll
(
&
s
->
Mem
);
return
Mem
;
return
Mem
;
}
}
int
sat_solver_simplify
(
sat_solver
*
s
)
/*
static void clause_remove(sat_solver* s, clause* c)
{
{
lit* lits = clause_begin(c);
assert
(
sat_solver_dl
(
s
)
==
0
);
assert(lit_neg(lits[0]) < s->size*2);
if
(
sat_solver_propagate
(
s
)
!=
0
)
assert(lit_neg(lits[1]) < s->size*2);
return
false
;
return
true
;
//veci_remove(sat_solver_read_wlist(s,lit_neg(lits[0])),(void*)c);
//veci_remove(sat_solver_read_wlist(s,lit_neg(lits[1])),(void*)c);
assert(lits[0] < s->size*2);
veci_remove(sat_solver_read_wlist(s,lit_neg(lits[0])),(clause_nlits(c) > 2 ? c : clause_from_lit(lits[1])));
veci_remove(sat_solver_read_wlist(s,lit_neg(lits[1])),(clause_nlits(c) > 2 ? c : clause_from_lit(lits[0])));
if (clause_learnt(c)){
s->stats.learnts--;
s->stats.learnts_literals -= clause_nlits(c);
}else{
s->stats.clauses--;
s->stats.clauses_literals -= clause_nlits(c);
}
}
}
static lbool clause_simplify(sat_solver* s, clause* c
)
void
sat_solver_reducedb
(
sat_solver
*
s
)
{
{
lit* lits = clause_begin(c);
static
clock_t
TimeTotal
=
0
;
int i;
clock_t
clk
=
clock
();
Sat_Mem_t
*
pMem
=
&
s
->
Mem
;
assert(sat_solver_dl(s) == 0);
int
nLearnedOld
=
veci_size
(
&
s
->
act_clas
);
int
*
act_clas
=
veci_begin
(
&
s
->
act_clas
);
for (i = 0; i < clause_nlits(c); i++){
int
*
pPerm
,
*
pArray
,
*
pSortValues
,
nCutoffValue
;
lbool sig = !lit_sign(lits[i]); sig += sig - 1;
int
i
,
k
,
j
,
Id
,
Counter
,
CounterStart
,
nSelected
;
if (s->assignss[lit_var(lits[i])] == sig)
clause
*
c
;
return l_True;
assert
(
s
->
nLearntMax
>
0
);
assert
(
nLearnedOld
==
Sat_MemEntryNum
(
pMem
,
1
)
);
assert
(
nLearnedOld
==
(
int
)
s
->
stats
.
learnts
);
s
->
nDBreduces
++
;
// printf( "Calling reduceDB with %d learned clause limit.\n", s->nLearntMax );
s
->
nLearntMax
=
LEARNT_MAX_START
+
LEARNT_MAX_INCRE
*
s
->
nDBreduces
;
// return;
// create sorting values
pSortValues
=
ABC_ALLOC
(
int
,
nLearnedOld
);
Sat_MemForEachLearned
(
pMem
,
c
,
i
,
k
)
{
Id
=
clause_id
(
c
);
pSortValues
[
Id
]
=
(((
7
-
Abc_MinInt
(
c
->
lbd
,
7
))
<<
28
)
|
(
act_clas
[
Id
]
>>
4
));
// pSortValues[Id] = act[Id];
assert
(
pSortValues
[
Id
]
>=
0
);
}
}
return l_False;
}
*/
int
sat_solver_simplify
(
sat_solver
*
s
)
// preserve 1/20 of last clauses
{
CounterStart
=
nLearnedOld
-
(
s
->
nLearntMax
/
20
);
// clause** reasons;
// int type;
assert
(
sat_solver_dl
(
s
)
==
0
);
if
(
sat_solver_propagate
(
s
)
!=
0
)
// preserve 3/4 of most active clauses
return
false
;
nSelected
=
nLearnedOld
*
5
/
10
;
if
(
s
->
qhead
==
s
->
simpdb_assigns
||
s
->
simpdb_props
>
0
)
// find non-decreasing permutation
return
true
;
pPerm
=
Abc_MergeSortCost
(
pSortValues
,
nLearnedOld
);
/*
assert
(
pSortValues
[
pPerm
[
0
]]
<=
pSortValues
[
pPerm
[
nLearnedOld
-
1
]]
);
reasons = s->reasons;
nCutoffValue
=
pSortValues
[
pPerm
[
nLearnedOld
-
nSelected
]];
for (type = 0; type < 2; type++){
ABC_FREE
(
pPerm
);
vecp* cs = type ? &s->learnts : &s->clauses;
// ActCutOff = ABC_INFINITY;
clause** cls = (clause**)vecp_begin(cs);
// mark learned clauses to remove
int i, j;
Counter
=
j
=
0
;
for (j = i = 0; i < vecp_size(cs); i++){
Sat_MemForEachLearned
(
pMem
,
c
,
i
,
k
)
if (reasons[lit_var(*clause_begin(cls[i]))] != cls[i] &&
{
clause_simplify(s,cls[i]) == l_True)
assert
(
c
->
mark
==
0
);
clause_remove(s,cls[i]);
if
(
Counter
++
>
CounterStart
||
clause_size
(
c
)
<
3
||
pSortValues
[
clause_id
(
c
)]
>
nCutoffValue
||
s
->
reasons
[
lit_var
(
c
->
lits
[
0
])]
==
Sat_MemHand
(
pMem
,
i
,
k
)
)
else
act_clas
[
j
++
]
=
act_clas
[
clause_id
(
c
)];
cls[j++] = cls[i];
else
// delete
{
c
->
mark
=
1
;
s
->
stats
.
learnts_literals
-=
clause_size
(
c
);
s
->
stats
.
learnts
--
;
}
}
vecp_resize(cs,j);
}
}
*/
assert
(
s
->
stats
.
learnts
==
(
unsigned
)
j
);
s
->
simpdb_assigns
=
s
->
qhead
;
assert
(
Counter
==
nLearnedOld
);
// (shouldn't depend on 'stats' really, but it will do for now)
veci_resize
(
&
s
->
act_clas
,
j
);
s
->
simpdb_props
=
(
int
)(
s
->
stats
.
clauses_literals
+
s
->
stats
.
learnts_literals
);
ABC_FREE
(
pSortValues
);
return
true
;
}
// update ID of each clause to be its new handle
Counter
=
Sat_MemCompactLearned
(
pMem
,
0
);
assert
(
Counter
==
(
int
)
s
->
stats
.
learnts
);
/*
// update reasons
static int clause_cmp (const void* x, const void* y) {
for
(
i
=
0
;
i
<
s
->
size
;
i
++
)
return clause_nlits((clause*)x) > 2 && (clause_nlits((clause*)y) == 2 || clause_activity((clause*)x) < clause_activity((clause*)y)) ? -1 : 1; }
{
void sat_solver_reducedb(sat_solver* s)
if
(
!
s
->
reasons
[
i
]
)
// no reason
{
continue
;
int i, j;
if
(
clause_is_lit
(
s
->
reasons
[
i
])
)
// 2-lit clause
double extra_lim = s->cla_inc / veci_size(&s->learnts); // Remove any clause below this activity
continue
;
clause** learnts = (clause**)veci_begin(&s->learnts);
if
(
!
clause_learnt_h
(
pMem
,
s
->
reasons
[
i
])
)
// problem clause
clause** reasons = s->reasons;
continue
;
c
=
clause_read
(
s
,
s
->
reasons
[
i
]
);
sat_solver_sort(veci_begin(&s->learnts), veci_size(&s->learnts), &clause_cmp);
assert
(
c
->
mark
==
0
);
s
->
reasons
[
i
]
=
clause_id
(
c
);
// updating handle here!!!
}
for (i = j = 0; i < veci_size(&s->learnts) / 2; i++){
// update watches
if (clause_nlits(learnts[i]) > 2 && reasons[lit_var(*clause_begin(learnts[i]))] != learnts[i])
for
(
i
=
0
;
i
<
s
->
size
*
2
;
i
++
)
clause_remove(s,learnts[i]);
{
else
pArray
=
veci_begin
(
&
s
->
wlists
[
i
]);
learnts[j++] = learnts[i];
for
(
j
=
k
=
0
;
k
<
veci_size
(
&
s
->
wlists
[
i
]);
k
++
)
{
if
(
clause_is_lit
(
pArray
[
k
])
)
// 2-lit clause
pArray
[
j
++
]
=
pArray
[
k
];
else
if
(
!
clause_learnt_h
(
pMem
,
pArray
[
k
])
)
// problem clause
pArray
[
j
++
]
=
pArray
[
k
];
else
{
c
=
clause_read
(
s
,
pArray
[
k
]);
if
(
!
c
->
mark
)
// useful learned clause
pArray
[
j
++
]
=
clause_id
(
c
);
// updating handle here!!!
}
}
veci_resize
(
&
s
->
wlists
[
i
],
j
);
}
}
for (; i < veci_size(&s->learnts); i++){
if (clause_nlits(learnts[i]) > 2 && reasons[lit_var(*clause_begin(learnts[i]))] != learnts[i] && clause_activity(learnts[i]) < extra_lim)
// perform final move of the clauses
clause_remove(s,learnts[i]);
Counter
=
Sat_MemCompactLearned
(
pMem
,
1
);
else
assert
(
Counter
==
(
int
)
s
->
stats
.
learnts
);
learnts[j++] = learnts[i];
// report the results
TimeTotal
+=
clock
()
-
clk
;
if
(
s
->
fVerbose
)
{
Abc_Print
(
1
,
"reduceDB: Keeping %7d out of %7d clauses (%5.2f %%) "
,
s
->
stats
.
learnts
,
nLearnedOld
,
100
.
0
*
s
->
stats
.
learnts
/
nLearnedOld
);
Abc_PrintTime
(
1
,
"Time"
,
TimeTotal
);
}
}
veci_resize(&s->learnts,j);
}
}
*/
int
sat_solver_addclause
(
sat_solver
*
s
,
lit
*
begin
,
lit
*
end
)
int
sat_solver_addclause
(
sat_solver
*
s
,
lit
*
begin
,
lit
*
end
)
{
{
...
@@ -1308,9 +1337,6 @@ int sat_solver_addclause(sat_solver* s, lit* begin, lit* end)
...
@@ -1308,9 +1337,6 @@ int sat_solver_addclause(sat_solver* s, lit* begin, lit* end)
// create new clause
// create new clause
clause_create_new
(
s
,
begin
,
j
,
0
);
clause_create_new
(
s
,
begin
,
j
,
0
);
s
->
stats
.
clauses
++
;
s
->
stats
.
clauses_literals
+=
j
-
begin
;
return
true
;
return
true
;
}
}
...
@@ -1335,7 +1361,7 @@ void luby_test()
...
@@ -1335,7 +1361,7 @@ void luby_test()
printf
(
"
\n
"
);
printf
(
"
\n
"
);
}
}
static
lbool
sat_solver_search
(
sat_solver
*
s
,
ABC_INT64_T
nof_conflicts
,
ABC_INT64_T
nof_learnts
)
static
lbool
sat_solver_search
(
sat_solver
*
s
,
ABC_INT64_T
nof_conflicts
)
{
{
// double var_decay = 0.95;
// double var_decay = 0.95;
// double clause_decay = 0.999;
// double clause_decay = 0.999;
...
@@ -1395,36 +1421,37 @@ static lbool sat_solver_search(sat_solver* s, ABC_INT64_T nof_conflicts, ABC_INT
...
@@ -1395,36 +1421,37 @@ static lbool sat_solver_search(sat_solver* s, ABC_INT64_T nof_conflicts, ABC_INT
var_set_level
(
s
,
lit_var
(
learnt_clause
.
ptr
[
0
]),
0
);
var_set_level
(
s
,
lit_var
(
learnt_clause
.
ptr
[
0
]),
0
);
#endif
#endif
act_var_decay
(
s
);
act_var_decay
(
s
);
//
act_clause_decay(s);
act_clause_decay
(
s
);
}
else
{
}
else
{
// NO CONFLICT
// NO CONFLICT
int
next
;
int
next
;
// Reached bound on number of conflicts:
if
(
nof_conflicts
>=
0
&&
conflictC
>=
nof_conflicts
){
if
(
nof_conflicts
>=
0
&&
conflictC
>=
nof_conflicts
){
// Reached bound on number of conflicts:
s
->
progress_estimate
=
sat_solver_progress
(
s
);
s
->
progress_estimate
=
sat_solver_progress
(
s
);
sat_solver_canceluntil
(
s
,
s
->
root_level
);
sat_solver_canceluntil
(
s
,
s
->
root_level
);
veci_delete
(
&
learnt_clause
);
veci_delete
(
&
learnt_clause
);
return
l_Undef
;
}
return
l_Undef
;
}
// Reached bound on number of conflicts:
if
(
(
s
->
nConfLimit
&&
s
->
stats
.
conflicts
>
s
->
nConfLimit
)
||
if
(
(
s
->
nConfLimit
&&
s
->
stats
.
conflicts
>
s
->
nConfLimit
)
||
(
s
->
nInsLimit
&&
s
->
stats
.
propagations
>
s
->
nInsLimit
)
)
(
s
->
nInsLimit
&&
s
->
stats
.
propagations
>
s
->
nInsLimit
)
)
{
{
// Reached bound on number of conflicts:
s
->
progress_estimate
=
sat_solver_progress
(
s
);
s
->
progress_estimate
=
sat_solver_progress
(
s
);
sat_solver_canceluntil
(
s
,
s
->
root_level
);
sat_solver_canceluntil
(
s
,
s
->
root_level
);
veci_delete
(
&
learnt_clause
);
veci_delete
(
&
learnt_clause
);
return
l_Undef
;
return
l_Undef
;
}
}
// Simplify the set of problem clauses:
if
(
sat_solver_dl
(
s
)
==
0
&&
!
s
->
fSkipSimplify
)
if
(
sat_solver_dl
(
s
)
==
0
&&
!
s
->
fSkipSimplify
)
// Simplify the set of problem clauses:
sat_solver_simplify
(
s
);
sat_solver_simplify
(
s
);
// if (nof_learnts >= 0 && veci_size(&s->learnts) - s->qtail >= nof_learnts)
// Reduce the set of learnt clauses:
// Reduce the set of learnt clauses:
// if (s->nLearntMax && veci_size(&s->learned) - s->qtail >= s->nLearntMax)
// sat_solver_reducedb(s);
if
(
s
->
nLearntMax
&&
veci_size
(
&
s
->
act_clas
)
>=
s
->
nLearntMax
)
sat_solver_reducedb
(
s
);
// New variable decision:
// New variable decision:
s
->
stats
.
decisions
++
;
s
->
stats
.
decisions
++
;
...
@@ -1463,7 +1490,7 @@ int sat_solver_solve(sat_solver* s, lit* begin, lit* end, ABC_INT64_T nConfLimit
...
@@ -1463,7 +1490,7 @@ int sat_solver_solve(sat_solver* s, lit* begin, lit* end, ABC_INT64_T nConfLimit
{
{
int
restart_iter
=
0
;
int
restart_iter
=
0
;
ABC_INT64_T
nof_conflicts
;
ABC_INT64_T
nof_conflicts
;
ABC_INT64_T
nof_learnts
=
sat_solver_nclauses
(
s
)
/
3
;
//
ABC_INT64_T nof_learnts = sat_solver_nclauses(s) / 3;
lbool
status
=
l_Undef
;
lbool
status
=
l_Undef
;
lit
*
i
;
lit
*
i
;
...
@@ -1623,8 +1650,8 @@ int sat_solver_solve(sat_solver* s, lit* begin, lit* end, ABC_INT64_T nConfLimit
...
@@ -1623,8 +1650,8 @@ int sat_solver_solve(sat_solver* s, lit* begin, lit* end, ABC_INT64_T nConfLimit
fflush
(
stdout
);
fflush
(
stdout
);
}
}
nof_conflicts
=
(
ABC_INT64_T
)(
100
*
luby
(
2
,
restart_iter
++
)
);
nof_conflicts
=
(
ABC_INT64_T
)(
100
*
luby
(
2
,
restart_iter
++
)
);
status
=
sat_solver_search
(
s
,
nof_conflicts
,
nof_learnts
);
status
=
sat_solver_search
(
s
,
nof_conflicts
);
nof_learnts
=
nof_learnts
*
11
/
10
;
//*= 1.1;
//
nof_learnts = nof_learnts * 11 / 10; //*= 1.1;
// quit the loop if reached an external limit
// quit the loop if reached an external limit
if
(
s
->
nConfLimit
&&
s
->
stats
.
conflicts
>
s
->
nConfLimit
)
if
(
s
->
nConfLimit
&&
s
->
stats
.
conflicts
>
s
->
nConfLimit
)
break
;
break
;
...
...
src/sat/bsat/satSolver.h
View file @
c265d244
...
@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
...
@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
#include <string.h>
#include <string.h>
#include <assert.h>
#include <assert.h>
#include "satClause.h"
#include "satVec.h"
#include "satVec.h"
#include "misc/vec/vecSet.h"
#include "misc/vec/vecSet.h"
...
@@ -79,8 +80,8 @@ extern void * sat_solver_store_release( sat_solver * s );
...
@@ -79,8 +80,8 @@ extern void * sat_solver_store_release( sat_solver * s );
//=================================================================================================
//=================================================================================================
// Solver representation:
// Solver representation:
struct
clause_t
;
//
struct clause_t;
typedef
struct
clause_t
clause
;
//
typedef struct clause_t clause;
struct
varinfo_t
;
struct
varinfo_t
;
typedef
struct
varinfo_t
varinfo
;
typedef
struct
varinfo_t
varinfo
;
...
@@ -93,7 +94,7 @@ struct sat_solver_t
...
@@ -93,7 +94,7 @@ struct sat_solver_t
int
qtail
;
// Tail index of queue.
int
qtail
;
// Tail index of queue.
// clauses
// clauses
Vec_Set
_t
Mem
;
Sat_Mem
_t
Mem
;
int
hLearnts
;
// the first learnt clause
int
hLearnts
;
// the first learnt clause
int
hBinary
;
// the special binary clause
int
hBinary
;
// the special binary clause
clause
*
binary
;
clause
*
binary
;
...
@@ -137,8 +138,13 @@ struct sat_solver_t
...
@@ -137,8 +138,13 @@ struct sat_solver_t
double
random_seed
;
double
random_seed
;
double
progress_estimate
;
double
progress_estimate
;
int
verbosity
;
// Verbosity level. 0=silent, 1=some progress report, 2=everything
int
verbosity
;
// Verbosity level. 0=silent, 1=some progress report, 2=everything
int
fVerbose
;
stats_t
stats
;
stats_t
stats
;
int
nLearntMax
;
// max number of learned clauses
int
nDBreduces
;
// number of DB reductions
// veci learned; // contain learnt clause handles
veci
act_clas
;
// contain clause activities
ABC_INT64_T
nConfLimit
;
// external limit on the number of conflicts
ABC_INT64_T
nConfLimit
;
// external limit on the number of conflicts
ABC_INT64_T
nInsLimit
;
// external limit on the number of implications
ABC_INT64_T
nInsLimit
;
// external limit on the number of implications
...
@@ -166,6 +172,11 @@ struct sat_solver_t
...
@@ -166,6 +172,11 @@ struct sat_solver_t
veci
temp_clause
;
// temporary storage for a CNF clause
veci
temp_clause
;
// temporary storage for a CNF clause
};
};
static
inline
clause
*
clause_read
(
sat_solver
*
s
,
cla
h
)
{
return
Sat_MemClauseHand
(
&
s
->
Mem
,
h
);
}
static
int
sat_solver_var_value
(
sat_solver
*
s
,
int
v
)
static
int
sat_solver_var_value
(
sat_solver
*
s
,
int
v
)
{
{
assert
(
v
>=
0
&&
v
<
s
->
size
);
assert
(
v
>=
0
&&
v
<
s
->
size
);
...
...
src/sat/bsat/satSolver2.c
View file @
c265d244
...
@@ -136,28 +136,28 @@ static inline void solver2_clear_marks(sat_solver2* s) {
...
@@ -136,28 +136,28 @@ static inline void solver2_clear_marks(sat_solver2* s) {
//=================================================================================================
//=================================================================================================
// Clause datatype + minor functions:
// Clause datatype + minor functions:
static
inline
satset
*
clause_read
(
sat_solver2
*
s
,
cla
h
)
{
return
(
h
&
1
)
?
satset_read
(
&
s
->
learnts
,
h
>>
1
)
:
satset_read
(
&
s
->
clauses
,
h
>>
1
);
}
static
inline
satset
*
clause
2
_read
(
sat_solver2
*
s
,
cla
h
)
{
return
(
h
&
1
)
?
satset_read
(
&
s
->
learnts
,
h
>>
1
)
:
satset_read
(
&
s
->
clauses
,
h
>>
1
);
}
static
inline
cla
clause_handle
(
sat_solver2
*
s
,
satset
*
c
)
{
return
c
->
learnt
?
(
satset_handle
(
&
s
->
learnts
,
c
)
<<
1
)
|
1
:
satset_handle
(
&
s
->
clauses
,
c
)
<<
1
;
}
static
inline
cla
clause
2
_handle
(
sat_solver2
*
s
,
satset
*
c
)
{
return
c
->
learnt
?
(
satset_handle
(
&
s
->
learnts
,
c
)
<<
1
)
|
1
:
satset_handle
(
&
s
->
clauses
,
c
)
<<
1
;
}
static
inline
int
clause_check
(
sat_solver2
*
s
,
satset
*
c
)
{
return
c
->
learnt
?
satset_check
(
&
s
->
learnts
,
c
)
:
satset_check
(
&
s
->
clauses
,
c
);
}
static
inline
int
clause
2
_check
(
sat_solver2
*
s
,
satset
*
c
)
{
return
c
->
learnt
?
satset_check
(
&
s
->
learnts
,
c
)
:
satset_check
(
&
s
->
clauses
,
c
);
}
static
inline
int
clause_proofid
(
sat_solver2
*
s
,
satset
*
c
,
int
partA
)
{
return
c
->
learnt
?
(
veci_begin
(
&
s
->
claProofs
)[
c
->
Id
]
<<
2
)
|
(
partA
<<
1
)
:
(
satset_handle
(
&
s
->
clauses
,
c
)
<<
2
)
|
(
partA
<<
1
)
|
1
;
}
static
inline
int
clause
2
_proofid
(
sat_solver2
*
s
,
satset
*
c
,
int
partA
)
{
return
c
->
learnt
?
(
veci_begin
(
&
s
->
claProofs
)[
c
->
Id
]
<<
2
)
|
(
partA
<<
1
)
:
(
satset_handle
(
&
s
->
clauses
,
c
)
<<
2
)
|
(
partA
<<
1
)
|
1
;
}
static
inline
int
clause_is_used
(
sat_solver2
*
s
,
cla
h
)
{
return
(
h
&
1
)
?
((
h
>>
1
)
<
s
->
hLearntPivot
)
:
((
h
>>
1
)
<
s
->
hClausePivot
);
}
static
inline
int
clause
2
_is_used
(
sat_solver2
*
s
,
cla
h
)
{
return
(
h
&
1
)
?
((
h
>>
1
)
<
s
->
hLearntPivot
)
:
((
h
>>
1
)
<
s
->
hClausePivot
);
}
//static inline int var_reason (sat_solver2* s, int v) { return (s->reasons[v]&1) ? 0 : s->reasons[v] >> 1; }
//static inline int var_reason (sat_solver2* s, int v) { return (s->reasons[v]&1) ? 0 : s->reasons[v] >> 1; }
//static inline int lit_reason (sat_solver2* s, int l) { return (s->reasons[lit_var(l)&1]) ? 0 : s->reasons[lit_var(l)] >> 1; }
//static inline int lit_reason (sat_solver2* s, int l) { return (s->reasons[lit_var(l)&1]) ? 0 : s->reasons[lit_var(l)] >> 1; }
//static inline satset* var_unit_clause(sat_solver2* s, int v) { return (s->reasons[v]&1) ? clause_read(s, s->reasons[v] >> 1) : NULL; }
//static inline satset* var_unit_clause(sat_solver2* s, int v) { return (s->reasons[v]&1) ? clause
2
_read(s, s->reasons[v] >> 1) : NULL; }
//static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(i && !s->reasons[v]); s->reasons[v] = (i << 1) | 1; }
//static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(i && !s->reasons[v]); s->reasons[v] = (i << 1) | 1; }
static
inline
int
var_reason
(
sat_solver2
*
s
,
int
v
)
{
return
s
->
reasons
[
v
];
}
static
inline
int
var_reason
(
sat_solver2
*
s
,
int
v
)
{
return
s
->
reasons
[
v
];
}
static
inline
int
lit_reason
(
sat_solver2
*
s
,
int
l
)
{
return
s
->
reasons
[
lit_var
(
l
)];
}
static
inline
int
lit_reason
(
sat_solver2
*
s
,
int
l
)
{
return
s
->
reasons
[
lit_var
(
l
)];
}
static
inline
satset
*
var_unit_clause
(
sat_solver2
*
s
,
int
v
)
{
return
clause_read
(
s
,
s
->
units
[
v
]);
}
static
inline
satset
*
var_unit_clause
(
sat_solver2
*
s
,
int
v
)
{
return
clause
2
_read
(
s
,
s
->
units
[
v
]);
}
static
inline
void
var_set_unit_clause
(
sat_solver2
*
s
,
int
v
,
cla
i
){
static
inline
void
var_set_unit_clause
(
sat_solver2
*
s
,
int
v
,
cla
i
){
assert
(
v
>=
0
&&
v
<
s
->
size
&&
!
s
->
units
[
v
]);
s
->
units
[
v
]
=
i
;
s
->
nUnits
++
;
assert
(
v
>=
0
&&
v
<
s
->
size
&&
!
s
->
units
[
v
]);
s
->
units
[
v
]
=
i
;
s
->
nUnits
++
;
}
}
//static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(v >= 0 && v < s->size); s->units[v] = i; s->nUnits++; }
//static inline void var_set_unit_clause(sat_solver2* s, int v, cla i){ assert(v >= 0 && v < s->size); s->units[v] = i; s->nUnits++; }
// these two only work after creating a clause before the solver is called
// these two only work after creating a clause before the solver is called
int
clause
_is_partA
(
sat_solver2
*
s
,
int
h
)
{
return
clause
_read
(
s
,
h
)
->
partA
;
}
int
clause
2_is_partA
(
sat_solver2
*
s
,
int
h
)
{
return
clause2
_read
(
s
,
h
)
->
partA
;
}
void
clause
_set_partA
(
sat_solver2
*
s
,
int
h
,
int
partA
)
{
clause
_read
(
s
,
h
)
->
partA
=
partA
;
}
void
clause
2_set_partA
(
sat_solver2
*
s
,
int
h
,
int
partA
)
{
clause2
_read
(
s
,
h
)
->
partA
=
partA
;
}
int
clause
_id
(
sat_solver2
*
s
,
int
h
)
{
return
clause
_read
(
s
,
h
)
->
Id
;
}
int
clause
2_id
(
sat_solver2
*
s
,
int
h
)
{
return
clause2
_read
(
s
,
h
)
->
Id
;
}
//=================================================================================================
//=================================================================================================
// Simple helpers:
// Simple helpers:
...
@@ -172,7 +172,7 @@ static inline void proof_chain_start( sat_solver2* s, satset* c )
...
@@ -172,7 +172,7 @@ static inline void proof_chain_start( sat_solver2* s, satset* c )
{
{
if
(
s
->
fProofLogging
)
if
(
s
->
fProofLogging
)
{
{
int
ProofId
=
clause_proofid
(
s
,
c
,
0
);
int
ProofId
=
clause
2
_proofid
(
s
,
c
,
0
);
assert
(
ProofId
>
0
);
assert
(
ProofId
>
0
);
veci_resize
(
&
s
->
temp_proof
,
0
);
veci_resize
(
&
s
->
temp_proof
,
0
);
veci_push
(
&
s
->
temp_proof
,
0
);
veci_push
(
&
s
->
temp_proof
,
0
);
...
@@ -186,7 +186,7 @@ static inline void proof_chain_resolve( sat_solver2* s, satset* cls, int Var )
...
@@ -186,7 +186,7 @@ static inline void proof_chain_resolve( sat_solver2* s, satset* cls, int Var )
if
(
s
->
fProofLogging
)
if
(
s
->
fProofLogging
)
{
{
satset
*
c
=
cls
?
cls
:
var_unit_clause
(
s
,
Var
);
satset
*
c
=
cls
?
cls
:
var_unit_clause
(
s
,
Var
);
int
ProofId
=
clause_proofid
(
s
,
c
,
var_is_partA
(
s
,
Var
));
int
ProofId
=
clause
2
_proofid
(
s
,
c
,
var_is_partA
(
s
,
Var
));
assert
(
ProofId
>
0
);
assert
(
ProofId
>
0
);
veci_push
(
&
s
->
temp_proof
,
ProofId
);
veci_push
(
&
s
->
temp_proof
,
ProofId
);
}
}
...
@@ -291,7 +291,7 @@ static inline void act_var_rescale(sat_solver2* s) {
...
@@ -291,7 +291,7 @@ static inline void act_var_rescale(sat_solver2* s) {
activity
[
i
]
*=
1e-100
;
activity
[
i
]
*=
1e-100
;
s
->
var_inc
*=
1e-100
;
s
->
var_inc
*=
1e-100
;
}
}
static
inline
void
act_clause_rescale
(
sat_solver2
*
s
)
{
static
inline
void
act_clause
2
_rescale
(
sat_solver2
*
s
)
{
static
int
Total
=
0
;
static
int
Total
=
0
;
float
*
claActs
=
(
float
*
)
veci_begin
(
&
s
->
claActs
);
float
*
claActs
=
(
float
*
)
veci_begin
(
&
s
->
claActs
);
int
i
;
int
i
;
...
@@ -311,15 +311,15 @@ static inline void act_var_bump(sat_solver2* s, int v) {
...
@@ -311,15 +311,15 @@ static inline void act_var_bump(sat_solver2* s, int v) {
if
(
s
->
orderpos
[
v
]
!=
-
1
)
if
(
s
->
orderpos
[
v
]
!=
-
1
)
order_update
(
s
,
v
);
order_update
(
s
,
v
);
}
}
static
inline
void
act_clause_bump
(
sat_solver2
*
s
,
satset
*
c
)
{
static
inline
void
act_clause
2
_bump
(
sat_solver2
*
s
,
satset
*
c
)
{
float
*
claActs
=
(
float
*
)
veci_begin
(
&
s
->
claActs
);
float
*
claActs
=
(
float
*
)
veci_begin
(
&
s
->
claActs
);
assert
(
c
->
Id
<
veci_size
(
&
s
->
claActs
)
);
assert
(
c
->
Id
<
veci_size
(
&
s
->
claActs
)
);
claActs
[
c
->
Id
]
+=
s
->
cla_inc
;
claActs
[
c
->
Id
]
+=
s
->
cla_inc
;
if
(
claActs
[
c
->
Id
]
>
(
float
)
1e20
)
if
(
claActs
[
c
->
Id
]
>
(
float
)
1e20
)
act_clause_rescale
(
s
);
act_clause
2
_rescale
(
s
);
}
}
static
inline
void
act_var_decay
(
sat_solver2
*
s
)
{
s
->
var_inc
*=
s
->
var_decay
;
}
static
inline
void
act_var_decay
(
sat_solver2
*
s
)
{
s
->
var_inc
*=
s
->
var_decay
;
}
static
inline
void
act_clause_decay
(
sat_solver2
*
s
)
{
s
->
cla_inc
*=
s
->
cla_decay
;
}
static
inline
void
act_clause
2
_decay
(
sat_solver2
*
s
)
{
s
->
cla_inc
*=
s
->
cla_decay
;
}
#else
#else
...
@@ -331,7 +331,7 @@ static inline void act_var_rescale(sat_solver2* s) {
...
@@ -331,7 +331,7 @@ static inline void act_var_rescale(sat_solver2* s) {
s
->
var_inc
>>=
19
;
s
->
var_inc
>>=
19
;
s
->
var_inc
=
Abc_MaxInt
(
s
->
var_inc
,
(
1
<<
4
)
);
s
->
var_inc
=
Abc_MaxInt
(
s
->
var_inc
,
(
1
<<
4
)
);
}
}
static
inline
void
act_clause_rescale
(
sat_solver2
*
s
)
{
static
inline
void
act_clause
2
_rescale
(
sat_solver2
*
s
)
{
// static int Total = 0;
// static int Total = 0;
int
i
;
//, clk = clock();
int
i
;
//, clk = clock();
unsigned
*
claActs
=
(
unsigned
*
)
veci_begin
(
&
s
->
claActs
);
unsigned
*
claActs
=
(
unsigned
*
)
veci_begin
(
&
s
->
claActs
);
...
@@ -351,22 +351,22 @@ static inline void act_var_bump(sat_solver2* s, int v) {
...
@@ -351,22 +351,22 @@ static inline void act_var_bump(sat_solver2* s, int v) {
if
(
s
->
orderpos
[
v
]
!=
-
1
)
if
(
s
->
orderpos
[
v
]
!=
-
1
)
order_update
(
s
,
v
);
order_update
(
s
,
v
);
}
}
static
inline
void
act_clause_bump
(
sat_solver2
*
s
,
satset
*
c
)
{
static
inline
void
act_clause
2
_bump
(
sat_solver2
*
s
,
satset
*
c
)
{
unsigned
*
claActs
=
(
unsigned
*
)
veci_begin
(
&
s
->
claActs
);
unsigned
*
claActs
=
(
unsigned
*
)
veci_begin
(
&
s
->
claActs
);
assert
(
c
->
Id
>
0
&&
c
->
Id
<
veci_size
(
&
s
->
claActs
)
);
assert
(
c
->
Id
>
0
&&
c
->
Id
<
veci_size
(
&
s
->
claActs
)
);
claActs
[
c
->
Id
]
+=
s
->
cla_inc
;
claActs
[
c
->
Id
]
+=
s
->
cla_inc
;
if
(
claActs
[
c
->
Id
]
&
0x80000000
)
if
(
claActs
[
c
->
Id
]
&
0x80000000
)
act_clause_rescale
(
s
);
act_clause
2
_rescale
(
s
);
}
}
static
inline
void
act_var_decay
(
sat_solver2
*
s
)
{
s
->
var_inc
+=
(
s
->
var_inc
>>
4
);
}
static
inline
void
act_var_decay
(
sat_solver2
*
s
)
{
s
->
var_inc
+=
(
s
->
var_inc
>>
4
);
}
static
inline
void
act_clause_decay
(
sat_solver2
*
s
)
{
s
->
cla_inc
+=
(
s
->
cla_inc
>>
10
);
}
static
inline
void
act_clause
2
_decay
(
sat_solver2
*
s
)
{
s
->
cla_inc
+=
(
s
->
cla_inc
>>
10
);
}
#endif
#endif
//=================================================================================================
//=================================================================================================
// Clause functions:
// Clause functions:
static
int
clause_create_new
(
sat_solver2
*
s
,
lit
*
begin
,
lit
*
end
,
int
learnt
,
int
proof_id
)
static
int
clause
2
_create_new
(
sat_solver2
*
s
,
lit
*
begin
,
lit
*
end
,
int
learnt
,
int
proof_id
)
{
{
satset
*
c
;
satset
*
c
;
int
i
,
Cid
,
nLits
=
end
-
begin
;
int
i
,
Cid
,
nLits
=
end
-
begin
;
...
@@ -404,7 +404,7 @@ static int clause_create_new(sat_solver2* s, lit* begin, lit* end, int learnt, i
...
@@ -404,7 +404,7 @@ static int clause_create_new(sat_solver2* s, lit* begin, lit* end, int learnt, i
if
(
proof_id
)
if
(
proof_id
)
veci_push
(
&
s
->
claProofs
,
proof_id
);
veci_push
(
&
s
->
claProofs
,
proof_id
);
if
(
nLits
>
2
)
if
(
nLits
>
2
)
act_clause_bump
(
s
,
c
);
act_clause
2
_bump
(
s
,
c
);
// extend storage
// extend storage
Cid
=
(
veci_size
(
&
s
->
learnts
)
<<
1
)
|
1
;
Cid
=
(
veci_size
(
&
s
->
learnts
)
<<
1
)
|
1
;
s
->
learnts
.
size
+=
satset_size
(
nLits
);
s
->
learnts
.
size
+=
satset_size
(
nLits
);
...
@@ -475,7 +475,7 @@ static inline int solver2_enqueue(sat_solver2* s, lit l, cla from)
...
@@ -475,7 +475,7 @@ static inline int solver2_enqueue(sat_solver2* s, lit l, cla from)
/*
/*
if ( solver2_dlevel(s) == 0 )
if ( solver2_dlevel(s) == 0 )
{
{
satset * c = from ? clause_read( s, from ) : NULL;
satset * c = from ? clause
2
_read( s, from ) : NULL;
Abc_Print(1, "Enqueing var %d on level %d with reason clause ", v, solver2_dlevel(s) );
Abc_Print(1, "Enqueing var %d on level %d with reason clause ", v, solver2_dlevel(s) );
if ( c )
if ( c )
satset_print( c );
satset_print( c );
...
@@ -554,7 +554,7 @@ static void solver2_record(sat_solver2* s, veci* cls, int proof_id)
...
@@ -554,7 +554,7 @@ static void solver2_record(sat_solver2* s, veci* cls, int proof_id)
{
{
lit
*
begin
=
veci_begin
(
cls
);
lit
*
begin
=
veci_begin
(
cls
);
lit
*
end
=
begin
+
veci_size
(
cls
);
lit
*
end
=
begin
+
veci_size
(
cls
);
cla
Cid
=
clause_create_new
(
s
,
begin
,
end
,
1
,
proof_id
);
cla
Cid
=
clause
2
_create_new
(
s
,
begin
,
end
,
1
,
proof_id
);
assert
(
veci_size
(
cls
)
>
0
);
assert
(
veci_size
(
cls
)
>
0
);
if
(
veci_size
(
cls
)
==
1
)
if
(
veci_size
(
cls
)
==
1
)
{
{
...
@@ -607,7 +607,7 @@ void Solver::analyzeFinal(satset* confl, bool skip_first)
...
@@ -607,7 +607,7 @@ void Solver::analyzeFinal(satset* confl, bool skip_first)
Var x = var(trail[i]);
Var x = var(trail[i]);
if (seen[x]){
if (seen[x]){
GClause r = reason[x];
GClause r = reason[x];
if (r == G
Clause
_NULL){
if (r == G
clause2
_NULL){
assert(level[x] > 0);
assert(level[x] > 0);
conflict.push(~trail[i]);
conflict.push(~trail[i]);
}else{
}else{
...
@@ -647,7 +647,7 @@ static int solver2_analyze_final(sat_solver2* s, satset* conf, int skip_first)
...
@@ -647,7 +647,7 @@ static int solver2_analyze_final(sat_solver2* s, satset* conf, int skip_first)
for
(
i
=
s
->
qtail
-
1
;
i
>=
(
veci_begin
(
&
s
->
trail_lim
))[
0
];
i
--
){
for
(
i
=
s
->
qtail
-
1
;
i
>=
(
veci_begin
(
&
s
->
trail_lim
))[
0
];
i
--
){
x
=
lit_var
(
s
->
trail
[
i
]);
x
=
lit_var
(
s
->
trail
[
i
]);
if
(
var_tag
(
s
,
x
)){
if
(
var_tag
(
s
,
x
)){
satset
*
c
=
clause_read
(
s
,
var_reason
(
s
,
x
));
satset
*
c
=
clause
2
_read
(
s
,
var_reason
(
s
,
x
));
if
(
c
){
if
(
c
){
proof_chain_resolve
(
s
,
c
,
x
);
proof_chain_resolve
(
s
,
c
,
x
);
satset_foreach_var
(
c
,
x
,
j
,
1
){
satset_foreach_var
(
c
,
x
,
j
,
1
){
...
@@ -680,7 +680,7 @@ static int solver2_lit_removable_rec(sat_solver2* s, int v)
...
@@ -680,7 +680,7 @@ static int solver2_lit_removable_rec(sat_solver2* s, int v)
return
(
var_tag
(
s
,
v
)
&
4
)
>
0
;
return
(
var_tag
(
s
,
v
)
&
4
)
>
0
;
// skip decisions on a wrong level
// skip decisions on a wrong level
c
=
clause_read
(
s
,
var_reason
(
s
,
v
));
c
=
clause
2
_read
(
s
,
var_reason
(
s
,
v
));
if
(
c
==
NULL
){
if
(
c
==
NULL
){
var_add_tag
(
s
,
v
,
2
);
var_add_tag
(
s
,
v
,
2
);
return
0
;
return
0
;
...
@@ -730,7 +730,7 @@ static int solver2_lit_removable(sat_solver2* s, int x)
...
@@ -730,7 +730,7 @@ static int solver2_lit_removable(sat_solver2* s, int x)
veci_push
(
&
s
->
stack
,
x
^
1
);
veci_push
(
&
s
->
stack
,
x
^
1
);
}
}
x
>>=
1
;
x
>>=
1
;
c
=
clause_read
(
s
,
var_reason
(
s
,
x
));
c
=
clause
2
_read
(
s
,
var_reason
(
s
,
x
));
satset_foreach_var
(
c
,
x
,
i
,
1
){
satset_foreach_var
(
c
,
x
,
i
,
1
){
if
(
var_tag
(
s
,
x
)
||
!
var_level
(
s
,
x
))
if
(
var_tag
(
s
,
x
)
||
!
var_level
(
s
,
x
))
continue
;
continue
;
...
@@ -763,7 +763,7 @@ static void solver2_logging_order(sat_solver2* s, int x)
...
@@ -763,7 +763,7 @@ static void solver2_logging_order(sat_solver2* s, int x)
}
}
veci_push
(
&
s
->
stack
,
x
^
1
);
veci_push
(
&
s
->
stack
,
x
^
1
);
x
>>=
1
;
x
>>=
1
;
c
=
clause_read
(
s
,
var_reason
(
s
,
x
));
c
=
clause
2
_read
(
s
,
var_reason
(
s
,
x
));
// if ( !c )
// if ( !c )
// Abc_Print(1, "solver2_logging_order(): Error in conflict analysis!!!\n" );
// Abc_Print(1, "solver2_logging_order(): Error in conflict analysis!!!\n" );
satset_foreach_var
(
c
,
x
,
i
,
1
){
satset_foreach_var
(
c
,
x
,
i
,
1
){
...
@@ -781,7 +781,7 @@ static void solver2_logging_order_rec(sat_solver2* s, int x)
...
@@ -781,7 +781,7 @@ static void solver2_logging_order_rec(sat_solver2* s, int x)
int
i
,
y
;
int
i
,
y
;
if
(
(
var_tag
(
s
,
x
)
&
8
)
)
if
(
(
var_tag
(
s
,
x
)
&
8
)
)
return
;
return
;
c
=
clause_read
(
s
,
var_reason
(
s
,
x
));
c
=
clause
2
_read
(
s
,
var_reason
(
s
,
x
));
satset_foreach_var
(
c
,
y
,
i
,
1
)
satset_foreach_var
(
c
,
y
,
i
,
1
)
if
(
var_level
(
s
,
y
)
&&
(
var_tag
(
s
,
y
)
&
1
)
==
0
)
if
(
var_level
(
s
,
y
)
&&
(
var_tag
(
s
,
y
)
&
1
)
==
0
)
solver2_logging_order_rec
(
s
,
y
);
solver2_logging_order_rec
(
s
,
y
);
...
@@ -806,7 +806,7 @@ static int solver2_analyze(sat_solver2* s, satset* c, veci* learnt)
...
@@ -806,7 +806,7 @@ static int solver2_analyze(sat_solver2* s, satset* c, veci* learnt)
while
(
1
){
while
(
1
){
assert
(
c
!=
0
);
assert
(
c
!=
0
);
if
(
c
->
learnt
)
if
(
c
->
learnt
)
act_clause_bump
(
s
,
c
);
act_clause
2
_bump
(
s
,
c
);
satset_foreach_var
(
c
,
x
,
j
,
(
int
)(
p
>
0
)
){
satset_foreach_var
(
c
,
x
,
j
,
(
int
)(
p
>
0
)
){
assert
(
x
>=
0
&&
x
<
s
->
size
);
assert
(
x
>=
0
&&
x
<
s
->
size
);
if
(
var_tag
(
s
,
x
)
)
if
(
var_tag
(
s
,
x
)
)
...
@@ -827,7 +827,7 @@ static int solver2_analyze(sat_solver2* s, satset* c, veci* learnt)
...
@@ -827,7 +827,7 @@ static int solver2_analyze(sat_solver2* s, satset* c, veci* learnt)
while
(
!
var_tag
(
s
,
lit_var
(
s
->
trail
[
ind
--
])));
while
(
!
var_tag
(
s
,
lit_var
(
s
->
trail
[
ind
--
])));
p
=
s
->
trail
[
ind
+
1
];
p
=
s
->
trail
[
ind
+
1
];
c
=
clause_read
(
s
,
lit_reason
(
s
,
p
));
c
=
clause
2
_read
(
s
,
lit_reason
(
s
,
p
));
cnt
--
;
cnt
--
;
if
(
cnt
==
0
)
if
(
cnt
==
0
)
break
;
break
;
...
@@ -862,7 +862,7 @@ static int solver2_analyze(sat_solver2* s, satset* c, veci* learnt)
...
@@ -862,7 +862,7 @@ static int solver2_analyze(sat_solver2* s, satset* c, veci* learnt)
// add them in the reverse order
// add them in the reverse order
vars
=
veci_begin
(
&
s
->
min_step_order
);
vars
=
veci_begin
(
&
s
->
min_step_order
);
for
(
i
=
veci_size
(
&
s
->
min_step_order
);
i
>
0
;
)
{
i
--
;
for
(
i
=
veci_size
(
&
s
->
min_step_order
);
i
>
0
;
)
{
i
--
;
c
=
clause_read
(
s
,
var_reason
(
s
,
vars
[
i
]));
c
=
clause
2
_read
(
s
,
var_reason
(
s
,
vars
[
i
]));
proof_chain_resolve
(
s
,
c
,
vars
[
i
]
);
proof_chain_resolve
(
s
,
c
,
vars
[
i
]
);
satset_foreach_var
(
c
,
x
,
k
,
1
)
satset_foreach_var
(
c
,
x
,
k
,
1
)
if
(
var_level
(
s
,
x
)
==
0
)
if
(
var_level
(
s
,
x
)
==
0
)
...
@@ -930,7 +930,7 @@ satset* solver2_propagate(sat_solver2* s)
...
@@ -930,7 +930,7 @@ satset* solver2_propagate(sat_solver2* s)
s
->
stats
.
propagations
++
;
s
->
stats
.
propagations
++
;
for
(
i
=
j
=
begin
;
i
<
end
;
){
for
(
i
=
j
=
begin
;
i
<
end
;
){
c
=
clause_read
(
s
,
*
i
);
c
=
clause
2
_read
(
s
,
*
i
);
lits
=
c
->
pEnts
;
lits
=
c
->
pEnts
;
// Make sure the false literal is data[1]:
// Make sure the false literal is data[1]:
...
@@ -968,7 +968,7 @@ satset* solver2_propagate(sat_solver2* s)
...
@@ -968,7 +968,7 @@ satset* solver2_propagate(sat_solver2* s)
}
}
proof_id
=
proof_chain_stop
(
s
);
proof_id
=
proof_chain_stop
(
s
);
// get a new clause
// get a new clause
Cid
=
clause_create_new
(
s
,
&
Lit
,
&
Lit
+
1
,
1
,
proof_id
);
Cid
=
clause
2
_create_new
(
s
,
&
Lit
,
&
Lit
+
1
,
1
,
proof_id
);
assert
(
(
var_unit_clause
(
s
,
Var
)
==
NULL
)
!=
fLitIsFalse
);
assert
(
(
var_unit_clause
(
s
,
Var
)
==
NULL
)
!=
fLitIsFalse
);
// if variable already has unit clause, it must be with the other polarity
// if variable already has unit clause, it must be with the other polarity
// in this case, we should derive the empty clause here
// in this case, we should derive the empty clause here
...
@@ -976,18 +976,18 @@ satset* solver2_propagate(sat_solver2* s)
...
@@ -976,18 +976,18 @@ satset* solver2_propagate(sat_solver2* s)
var_set_unit_clause
(
s
,
Var
,
Cid
);
var_set_unit_clause
(
s
,
Var
,
Cid
);
else
{
else
{
// Empty clause derived:
// Empty clause derived:
proof_chain_start
(
s
,
clause_read
(
s
,
Cid
)
);
proof_chain_start
(
s
,
clause
2
_read
(
s
,
Cid
)
);
proof_chain_resolve
(
s
,
NULL
,
Var
);
proof_chain_resolve
(
s
,
NULL
,
Var
);
proof_id
=
proof_chain_stop
(
s
);
proof_id
=
proof_chain_stop
(
s
);
s
->
hProofLast
=
proof_id
;
s
->
hProofLast
=
proof_id
;
// clause_create_new( s, &Lit, &Lit, 1, proof_id );
// clause
2
_create_new( s, &Lit, &Lit, 1, proof_id );
}
}
}
}
*
j
++
=
*
i
;
*
j
++
=
*
i
;
// Clause is unit under assignment:
// Clause is unit under assignment:
if
(
!
solver2_enqueue
(
s
,
Lit
,
*
i
)){
if
(
!
solver2_enqueue
(
s
,
Lit
,
*
i
)){
confl
=
clause_read
(
s
,
*
i
++
);
confl
=
clause
2
_read
(
s
,
*
i
++
);
// Copy the remaining watches:
// Copy the remaining watches:
while
(
i
<
end
)
while
(
i
<
end
)
*
j
++
=
*
i
++
;
*
j
++
=
*
i
++
;
...
@@ -1052,7 +1052,7 @@ static lbool solver2_search(sat_solver2* s, ABC_INT64_T nof_conflicts)
...
@@ -1052,7 +1052,7 @@ static lbool solver2_search(sat_solver2* s, ABC_INT64_T nof_conflicts)
if
(
learnt_clause
.
size
==
1
)
if
(
learnt_clause
.
size
==
1
)
var_set_level
(
s
,
lit_var
(
learnt_clause
.
ptr
[
0
]),
0
);
var_set_level
(
s
,
lit_var
(
learnt_clause
.
ptr
[
0
]),
0
);
act_var_decay
(
s
);
act_var_decay
(
s
);
act_clause_decay
(
s
);
act_clause
2
_decay
(
s
);
}
else
{
}
else
{
// NO CONFLICT
// NO CONFLICT
...
@@ -1327,7 +1327,7 @@ int sat_solver2_addclause(sat_solver2* s, lit* begin, lit* end)
...
@@ -1327,7 +1327,7 @@ int sat_solver2_addclause(sat_solver2* s, lit* begin, lit* end)
assert
(
i
==
begin
||
lit_var
(
*
(
i
-
1
))
!=
lit_var
(
*
i
)
);
assert
(
i
==
begin
||
lit_var
(
*
(
i
-
1
))
!=
lit_var
(
*
i
)
);
// consider the value of this literal
// consider the value of this literal
if
(
var_value
(
s
,
lit_var
(
*
i
))
==
lit_sign
(
*
i
)
)
// this clause is always true
if
(
var_value
(
s
,
lit_var
(
*
i
))
==
lit_sign
(
*
i
)
)
// this clause is always true
return
clause_create_new
(
s
,
begin
,
end
,
0
,
0
);
// add it anyway, to preserve proper clause count
return
clause
2
_create_new
(
s
,
begin
,
end
,
0
,
0
);
// add it anyway, to preserve proper clause count
if
(
var_value
(
s
,
lit_var
(
*
i
))
==
varX
)
// unassigned literal
if
(
var_value
(
s
,
lit_var
(
*
i
))
==
varX
)
// unassigned literal
iFree
=
i
;
iFree
=
i
;
else
else
...
@@ -1341,7 +1341,7 @@ int sat_solver2_addclause(sat_solver2* s, lit* begin, lit* end)
...
@@ -1341,7 +1341,7 @@ int sat_solver2_addclause(sat_solver2* s, lit* begin, lit* end)
*
begin
=
temp
;
*
begin
=
temp
;
// create a new clause
// create a new clause
Cid
=
clause_create_new
(
s
,
begin
,
end
,
0
,
0
);
Cid
=
clause
2
_create_new
(
s
,
begin
,
end
,
0
,
0
);
// handle unit clause
// handle unit clause
if
(
count
+
1
==
end
-
begin
)
if
(
count
+
1
==
end
-
begin
)
...
@@ -1358,13 +1358,13 @@ int sat_solver2_addclause(sat_solver2* s, lit* begin, lit* end)
...
@@ -1358,13 +1358,13 @@ int sat_solver2_addclause(sat_solver2* s, lit* begin, lit* end)
{
{
// Log production of top-level unit clause:
// Log production of top-level unit clause:
int
x
,
k
,
proof_id
,
CidNew
;
int
x
,
k
,
proof_id
,
CidNew
;
satset
*
c
=
clause_read
(
s
,
Cid
);
satset
*
c
=
clause
2
_read
(
s
,
Cid
);
proof_chain_start
(
s
,
c
);
proof_chain_start
(
s
,
c
);
satset_foreach_var
(
c
,
x
,
k
,
1
)
satset_foreach_var
(
c
,
x
,
k
,
1
)
proof_chain_resolve
(
s
,
NULL
,
x
);
proof_chain_resolve
(
s
,
NULL
,
x
);
proof_id
=
proof_chain_stop
(
s
);
proof_id
=
proof_chain_stop
(
s
);
// generate a new clause
// generate a new clause
CidNew
=
clause_create_new
(
s
,
begin
,
begin
+
1
,
1
,
proof_id
);
CidNew
=
clause
2
_create_new
(
s
,
begin
,
begin
+
1
,
1
,
proof_id
);
var_set_unit_clause
(
s
,
lit_var
(
begin
[
0
]),
CidNew
);
var_set_unit_clause
(
s
,
lit_var
(
begin
[
0
]),
CidNew
);
if
(
!
solver2_enqueue
(
s
,
begin
[
0
],
Cid
)
)
if
(
!
solver2_enqueue
(
s
,
begin
[
0
],
Cid
)
)
assert
(
0
);
assert
(
0
);
...
@@ -1458,7 +1458,7 @@ void sat_solver2_reducedb(sat_solver2* s)
...
@@ -1458,7 +1458,7 @@ void sat_solver2_reducedb(sat_solver2* s)
for
(
i
=
0
;
i
<
s
->
size
;
i
++
)
for
(
i
=
0
;
i
<
s
->
size
;
i
++
)
if
(
s
->
reasons
[
i
]
&&
(
s
->
reasons
[
i
]
&
1
)
)
if
(
s
->
reasons
[
i
]
&&
(
s
->
reasons
[
i
]
&
1
)
)
{
{
c
=
clause_read
(
s
,
s
->
reasons
[
i
]
);
c
=
clause
2
_read
(
s
,
s
->
reasons
[
i
]
);
assert
(
c
->
mark
==
0
);
assert
(
c
->
mark
==
0
);
s
->
reasons
[
i
]
=
(
c
->
Id
<<
1
)
|
1
;
s
->
reasons
[
i
]
=
(
c
->
Id
<<
1
)
|
1
;
}
}
...
@@ -1470,7 +1470,7 @@ void sat_solver2_reducedb(sat_solver2* s)
...
@@ -1470,7 +1470,7 @@ void sat_solver2_reducedb(sat_solver2* s)
for
(
j
=
k
=
0
;
k
<
veci_size
(
&
s
->
wlists
[
i
]);
k
++
)
for
(
j
=
k
=
0
;
k
<
veci_size
(
&
s
->
wlists
[
i
]);
k
++
)
if
(
!
(
pArray
[
k
]
&
1
)
)
// problem clause
if
(
!
(
pArray
[
k
]
&
1
)
)
// problem clause
pArray
[
j
++
]
=
pArray
[
k
];
pArray
[
j
++
]
=
pArray
[
k
];
else
if
(
!
(
c
=
clause_read
(
s
,
pArray
[
k
]))
->
mark
)
// useful learned clause
else
if
(
!
(
c
=
clause
2
_read
(
s
,
pArray
[
k
]))
->
mark
)
// useful learned clause
pArray
[
j
++
]
=
(
c
->
Id
<<
1
)
|
1
;
pArray
[
j
++
]
=
(
c
->
Id
<<
1
)
|
1
;
veci_resize
(
&
s
->
wlists
[
i
],
j
);
veci_resize
(
&
s
->
wlists
[
i
],
j
);
}
}
...
@@ -1479,7 +1479,7 @@ void sat_solver2_reducedb(sat_solver2* s)
...
@@ -1479,7 +1479,7 @@ void sat_solver2_reducedb(sat_solver2* s)
for
(
i
=
0
;
i
<
s
->
size
;
i
++
)
for
(
i
=
0
;
i
<
s
->
size
;
i
++
)
if
(
s
->
units
[
i
]
&&
(
s
->
units
[
i
]
&
1
)
)
if
(
s
->
units
[
i
]
&&
(
s
->
units
[
i
]
&
1
)
)
{
{
c
=
clause_read
(
s
,
s
->
units
[
i
]
);
c
=
clause
2
_read
(
s
,
s
->
units
[
i
]
);
assert
(
c
->
mark
==
0
);
assert
(
c
->
mark
==
0
);
s
->
units
[
i
]
=
(
c
->
Id
<<
1
)
|
1
;
s
->
units
[
i
]
=
(
c
->
Id
<<
1
)
|
1
;
}
}
...
@@ -1544,7 +1544,7 @@ void sat_solver2_rollback( sat_solver2* s )
...
@@ -1544,7 +1544,7 @@ void sat_solver2_rollback( sat_solver2* s )
{
{
cla
*
pArray
=
veci_begin
(
&
s
->
wlists
[
i
]);
cla
*
pArray
=
veci_begin
(
&
s
->
wlists
[
i
]);
for
(
j
=
k
=
0
;
k
<
veci_size
(
&
s
->
wlists
[
i
]);
k
++
)
for
(
j
=
k
=
0
;
k
<
veci_size
(
&
s
->
wlists
[
i
]);
k
++
)
if
(
clause_is_used
(
s
,
pArray
[
k
])
)
if
(
clause
2
_is_used
(
s
,
pArray
[
k
])
)
pArray
[
j
++
]
=
pArray
[
k
];
pArray
[
j
++
]
=
pArray
[
k
];
veci_resize
(
&
s
->
wlists
[
i
],
j
);
veci_resize
(
&
s
->
wlists
[
i
],
j
);
}
}
...
@@ -1759,7 +1759,7 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
...
@@ -1759,7 +1759,7 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
assert(var(p) < nVars());
assert(var(p) < nVars());
if (!solver2_assume(p)){
if (!solver2_assume(p)){
GClause r = reason[var(p)];
GClause r = reason[var(p)];
if (r != G
Clause
_NULL){
if (r != G
clause2
_NULL){
satset* confl;
satset* confl;
if (r.isLit()){
if (r.isLit()){
confl = propagate_tmpbin;
confl = propagate_tmpbin;
...
@@ -1792,7 +1792,7 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
...
@@ -1792,7 +1792,7 @@ int sat_solver2_solve(sat_solver2* s, lit* begin, lit* end, ABC_INT64_T nConfLim
veci_push
(
&
s
->
trail_lim
,
s
->
qtail
);
veci_push
(
&
s
->
trail_lim
,
s
->
qtail
);
if
(
!
solver2_enqueue
(
s
,
p
,
0
))
if
(
!
solver2_enqueue
(
s
,
p
,
0
))
{
{
satset
*
r
=
clause_read
(
s
,
lit_reason
(
s
,
p
));
satset
*
r
=
clause
2
_read
(
s
,
lit_reason
(
s
,
p
));
if
(
r
!=
NULL
)
if
(
r
!=
NULL
)
{
{
satset
*
confl
=
r
;
satset
*
confl
=
r
;
...
...
src/sat/bsat/satSolver2.h
View file @
c265d244
...
@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
...
@@ -28,6 +28,7 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
#include <string.h>
#include <string.h>
#include <assert.h>
#include <assert.h>
#include "satClause.h"
#include "satVec.h"
#include "satVec.h"
#include "misc/vec/vecSet.h"
#include "misc/vec/vecSet.h"
...
@@ -63,10 +64,10 @@ extern void Sat_Solver2DoubleClauses( sat_solver2 * p, int iVar );
...
@@ -63,10 +64,10 @@ extern void Sat_Solver2DoubleClauses( sat_solver2 * p, int iVar );
extern
int
var_is_partA
(
sat_solver2
*
s
,
int
v
);
extern
int
var_is_partA
(
sat_solver2
*
s
,
int
v
);
extern
void
var_set_partA
(
sat_solver2
*
s
,
int
v
,
int
partA
);
extern
void
var_set_partA
(
sat_solver2
*
s
,
int
v
,
int
partA
);
// clause grouping (these two only work after creating a clause before the solver is called)
// clause grouping (these two only work after creating a clause before the solver is called)
extern
int
clause_is_partA
(
sat_solver2
*
s
,
int
handle
);
extern
int
clause
2
_is_partA
(
sat_solver2
*
s
,
int
handle
);
extern
void
clause_set_partA
(
sat_solver2
*
s
,
int
handle
,
int
partA
);
extern
void
clause
2
_set_partA
(
sat_solver2
*
s
,
int
handle
,
int
partA
);
// other clause functions
// other clause functions
extern
int
clause_id
(
sat_solver2
*
s
,
int
h
);
extern
int
clause
2
_id
(
sat_solver2
*
s
,
int
h
);
// proof-based APIs
// proof-based APIs
extern
void
*
Sat_ProofCore
(
sat_solver2
*
s
);
extern
void
*
Sat_ProofCore
(
sat_solver2
*
s
);
...
@@ -274,7 +275,7 @@ static inline int sat_solver2_add_const( sat_solver2 * pSat, int iVar, int fComp
...
@@ -274,7 +275,7 @@ static inline int sat_solver2_add_const( sat_solver2 * pSat, int iVar, int fComp
Lits
[
0
]
=
toLitCond
(
iVar
,
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVar
,
fCompl
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
1
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
return
1
;
return
1
;
}
}
static
inline
int
sat_solver2_add_buffer
(
sat_solver2
*
pSat
,
int
iVarA
,
int
iVarB
,
int
fCompl
,
int
fMark
)
static
inline
int
sat_solver2_add_buffer
(
sat_solver2
*
pSat
,
int
iVarA
,
int
iVarB
,
int
fCompl
,
int
fMark
)
...
@@ -287,13 +288,13 @@ static inline int sat_solver2_add_buffer( sat_solver2 * pSat, int iVarA, int iVa
...
@@ -287,13 +288,13 @@ static inline int sat_solver2_add_buffer( sat_solver2 * pSat, int iVarA, int iVa
Lits
[
1
]
=
toLitCond
(
iVarB
,
!
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
!
fCompl
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
1
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
fCompl
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
return
2
;
return
2
;
}
}
static
inline
int
sat_solver2_add_and
(
sat_solver2
*
pSat
,
int
iVar
,
int
iVar0
,
int
iVar1
,
int
fCompl0
,
int
fCompl1
,
int
fMark
)
static
inline
int
sat_solver2_add_and
(
sat_solver2
*
pSat
,
int
iVar
,
int
iVar0
,
int
iVar1
,
int
fCompl0
,
int
fCompl1
,
int
fMark
)
...
@@ -305,20 +306,20 @@ static inline int sat_solver2_add_and( sat_solver2 * pSat, int iVar, int iVar0,
...
@@ -305,20 +306,20 @@ static inline int sat_solver2_add_and( sat_solver2 * pSat, int iVar, int iVar0,
Lits
[
1
]
=
toLitCond
(
iVar0
,
fCompl0
);
Lits
[
1
]
=
toLitCond
(
iVar0
,
fCompl0
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVar
,
1
);
Lits
[
0
]
=
toLitCond
(
iVar
,
1
);
Lits
[
1
]
=
toLitCond
(
iVar1
,
fCompl1
);
Lits
[
1
]
=
toLitCond
(
iVar1
,
fCompl1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVar
,
0
);
Lits
[
0
]
=
toLitCond
(
iVar
,
0
);
Lits
[
1
]
=
toLitCond
(
iVar0
,
!
fCompl0
);
Lits
[
1
]
=
toLitCond
(
iVar0
,
!
fCompl0
);
Lits
[
2
]
=
toLitCond
(
iVar1
,
!
fCompl1
);
Lits
[
2
]
=
toLitCond
(
iVar1
,
!
fCompl1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
return
3
;
return
3
;
}
}
static
inline
int
sat_solver2_add_xor
(
sat_solver2
*
pSat
,
int
iVarA
,
int
iVarB
,
int
iVarC
,
int
fCompl
,
int
fMark
)
static
inline
int
sat_solver2_add_xor
(
sat_solver2
*
pSat
,
int
iVarA
,
int
iVarB
,
int
iVarC
,
int
fCompl
,
int
fMark
)
...
@@ -332,28 +333,28 @@ static inline int sat_solver2_add_xor( sat_solver2 * pSat, int iVarA, int iVarB,
...
@@ -332,28 +333,28 @@ static inline int sat_solver2_add_xor( sat_solver2 * pSat, int iVarA, int iVarB,
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
!
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
!
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
1
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
1
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
0
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVarA
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
1
]
=
toLitCond
(
iVarB
,
0
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Lits
[
2
]
=
toLitCond
(
iVarC
,
1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
3
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
return
4
;
return
4
;
}
}
static
inline
int
sat_solver2_add_constraint
(
sat_solver2
*
pSat
,
int
iVar
,
int
iVar2
,
int
fCompl
,
int
fMark
)
static
inline
int
sat_solver2_add_constraint
(
sat_solver2
*
pSat
,
int
iVar
,
int
iVar2
,
int
fCompl
,
int
fMark
)
...
@@ -366,13 +367,13 @@ static inline int sat_solver2_add_constraint( sat_solver2 * pSat, int iVar, int
...
@@ -366,13 +367,13 @@ static inline int sat_solver2_add_constraint( sat_solver2 * pSat, int iVar, int
Lits
[
1
]
=
toLitCond
(
iVar2
,
0
);
Lits
[
1
]
=
toLitCond
(
iVar2
,
0
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
Lits
[
0
]
=
toLitCond
(
iVar
,
fCompl
);
Lits
[
0
]
=
toLitCond
(
iVar
,
fCompl
);
Lits
[
1
]
=
toLitCond
(
iVar2
,
1
);
Lits
[
1
]
=
toLitCond
(
iVar2
,
1
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
Cid
=
sat_solver2_addclause
(
pSat
,
Lits
,
Lits
+
2
);
if
(
fMark
)
if
(
fMark
)
clause_set_partA
(
pSat
,
Cid
,
1
);
clause
2
_set_partA
(
pSat
,
Cid
,
1
);
return
2
;
return
2
;
}
}
...
...
src/sat/bsat/satUtil.c
View file @
c265d244
...
@@ -30,14 +30,18 @@ ABC_NAMESPACE_IMPL_START
...
@@ -30,14 +30,18 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS ///
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/*
struct clause_t
struct clause_t
{
{
int
size_learnt
;
unsigned size : 24;
unsigned lbd : 6;
unsigned leant : 1;
unsigned mark : 1;
lit lits[0];
lit lits[0];
};
};
static inline int clause_size( clause* c ) { return c->size; }
static
inline
int
clause_size
(
clause
*
c
)
{
return
c
->
size_learnt
>>
1
;
}
static inline lit* clause_begin( clause* c ) { return c->lits; }
static inline lit* clause_begin( clause* c ) { return c->lits; }
*/
static
void
Sat_SolverClauseWriteDimacs
(
FILE
*
pFile
,
clause
*
pC
,
int
fIncrement
);
static
void
Sat_SolverClauseWriteDimacs
(
FILE
*
pFile
,
clause
*
pC
,
int
fIncrement
);
...
@@ -127,6 +131,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe
...
@@ -127,6 +131,7 @@ void Sat_SolverWriteDimacs( sat_solver * p, char * pFileName, lit* assumptionsBe
***********************************************************************/
***********************************************************************/
void
Sat_SolverClauseWriteDimacs
(
FILE
*
pFile
,
clause
*
pC
,
int
fIncrement
)
void
Sat_SolverClauseWriteDimacs
(
FILE
*
pFile
,
clause
*
pC
,
int
fIncrement
)
{
{
/*
lit * pLits = clause_begin(pC);
lit * pLits = clause_begin(pC);
int nLits = clause_size(pC);
int nLits = clause_size(pC);
int i;
int i;
...
@@ -136,6 +141,7 @@ void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncrement )
...
@@ -136,6 +141,7 @@ void Sat_SolverClauseWriteDimacs( FILE * pFile, clause * pC, int fIncrement )
if ( fIncrement )
if ( fIncrement )
fprintf( pFile, "0" );
fprintf( pFile, "0" );
fprintf( pFile, "\n" );
fprintf( pFile, "\n" );
*/
}
}
/**Function*************************************************************
/**Function*************************************************************
...
...
src/sat/bsat/satVec.h
View file @
c265d244
...
@@ -127,8 +127,6 @@ static inline void vecp_remove(vecp* v, void* e)
...
@@ -127,8 +127,6 @@ static inline void vecp_remove(vecp* v, void* e)
#endif
#endif
#endif
#endif
typedef
int
lit
;
typedef
int
cla
;
typedef
char
lbool
;
typedef
char
lbool
;
static
const
int
var_Undef
=
-
1
;
static
const
int
var_Undef
=
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment