ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
cadicalSolver.c File Reference
#include "ccadical.h"
#include "cadicalSolver.h"
Include dependency graph for cadicalSolver.c:

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START cadical_solvercadical_solver_new (void)
 DECLARATIONS ///.
 
void cadical_solver_delete (cadical_solver *s)
 
int cadical_solver_addclause (cadical_solver *s, int *begin, int *end)
 
int cadical_solver_solve (cadical_solver *s, int *begin, int *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
 
int cadical_solver_final (cadical_solver *s, int **ppArray)
 
int cadical_solver_nvars (cadical_solver *s)
 
int cadical_solver_addvar (cadical_solver *s)
 
void cadical_solver_setnvars (cadical_solver *s, int n)
 
int cadical_solver_get_var_value (cadical_solver *s, int v)
 
Vec_Int_tcadical_solve_cnf (Cnf_Dat_t *pCnf, char *pArgs, int nConfs, int nTimeLimit, int fSat, int fUnsat, int fPrintCex, int fVerbose)
 

Function Documentation

◆ cadical_solve_cnf()

Vec_Int_t * cadical_solve_cnf ( Cnf_Dat_t * pCnf,
char * pArgs,
int nConfs,
int nTimeLimit,
int fSat,
int fUnsat,
int fPrintCex,
int fVerbose )

Function*************************************************************

Synopsis [Solves the given CNF using cadical.]

Description []

SideEffects []

SeeAlso []

Definition at line 266 of file cadicalSolver.c.

267{
268 abctime clk = Abc_Clock();
269 Vec_Int_t * vRes = NULL;
270 int i, * pBeg, * pEnd, RetValue;
271 if ( fVerbose )
272 printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
274 cadical_solver_setnvars(pSat, pCnf->nVars);
275 assert(cadical_solver_nvars(pSat) == pCnf->nVars);
276 Cnf_CnfForClause( pCnf, pBeg, pEnd, i ) {
277 if ( !cadical_solver_addclause(pSat, pBeg, pEnd) )
278 {
279 assert( 0 ); // if it happens, can return 1 (unsatisfiable)
280 return NULL;
281 }
282 }
283 RetValue = cadical_solver_solve(pSat, NULL, NULL, 0, 0, 0, 0);
284 if ( RetValue == 1 )
285 printf( "Result: Satisfiable. " );
286 else if ( RetValue == -1 )
287 printf( "Result: Unsatisfiable. " );
288 else
289 printf( "Result: Undecided. " );
290 if ( RetValue == 1 ) {
291 vRes = Vec_IntAlloc( pCnf->nVars );
292 for ( i = 0; i < pCnf->nVars; i++ )
293 Vec_IntPush( vRes, cadical_solver_get_var_value(pSat, i) );
294 }
296 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
297 return vRes;
298}
ABC_INT64_T abctime
Definition abc_global.h:332
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
int cadical_solver_addclause(cadical_solver *s, int *begin, int *end)
int cadical_solver_get_var_value(cadical_solver *s, int v)
int cadical_solver_nvars(cadical_solver *s)
void cadical_solver_setnvars(cadical_solver *s, int n)
int cadical_solver_solve(cadical_solver *s, int *begin, int *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
ABC_NAMESPACE_IMPL_START cadical_solver * cadical_solver_new(void)
DECLARATIONS ///.
void cadical_solver_delete(cadical_solver *s)
typedefABC_NAMESPACE_HEADER_START struct cadical_solver_ cadical_solver
INCLUDES ///.
#define Cnf_CnfForClause(p, pBeg, pEnd, i)
MACRO DEFINITIONS ///.
Definition cnf.h:117
int nVars
Definition cnf.h:59
int nLiterals
Definition cnf.h:60
int nClauses
Definition cnf.h:61
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:

◆ cadical_solver_addclause()

int cadical_solver_addclause ( cadical_solver * s,
int * begin,
int * end )

Function*************************************************************

Synopsis [add clause]

Description [cadical takes x and -x as a literal for a variable x > 0, where 0 is an indicator of the end of a clause. since variables start from 0 in abc, a variable v is translated into v + 1 in cadical.]

SideEffects []

SeeAlso []

Definition at line 90 of file cadicalSolver.c.

90 {
91 for(;begin != end; begin++) {
92 if(*begin & 1) {
93 ccadical_add((CCaDiCaL*)s->p, -(1 + ((*begin) >> 1)));
94 } else {
95 ccadical_add((CCaDiCaL*)s->p, 1 + ((*begin) >> 1) );
96 }
97 }
98 ccadical_add((CCaDiCaL*)s->p, 0);
99 return !ccadical_is_inconsistent((CCaDiCaL*)s->p);
100}
int ccadical_is_inconsistent(CCaDiCaL *ptr)
void ccadical_add(CCaDiCaL *wrapper, int lit)
typedefABC_NAMESPACE_HEADER_START struct CCaDiCaL CCaDiCaL
Definition ccadical.h:15
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadical_solver_addvar()

int cadical_solver_addvar ( cadical_solver * s)

Function*************************************************************

Synopsis [add new variable]

Description [emulated using "nVars".]

SideEffects []

SeeAlso []

Definition at line 218 of file cadicalSolver.c.

218 {
219 return s->nVars++;
220}
Here is the caller graph for this function:

◆ cadical_solver_delete()

void cadical_solver_delete ( cadical_solver * s)

Function*************************************************************

Synopsis [delete solver]

Description []

SideEffects []

SeeAlso []

Definition at line 65 of file cadicalSolver.c.

65 {
67 if(s->vAssumptions) {
68 Vec_IntFree(s->vAssumptions);
69 }
70 if(s->vCore) {
71 Vec_IntFree(s->vCore);
72 }
73 free(s);
74}
void ccadical_release(CCaDiCaL *wrapper)
VOID_HACK free()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadical_solver_final()

int cadical_solver_final ( cadical_solver * s,
int ** ppArray )

Function*************************************************************

Synopsis [get unsat core]

Description [following minisat, return number of literals in core, which consists of responsible assumptions, negated. array will be freed by solver.]

SideEffects []

SeeAlso []

Definition at line 170 of file cadicalSolver.c.

170 {
171 int v, i;
172 if(s->vCore == NULL) {
173 s->vCore = Vec_IntAlloc(Vec_IntSize(s->vAssumptions));
174 } else {
175 Vec_IntClear(s->vCore);
176 }
177 Vec_IntForEachEntry(s->vAssumptions, v, i) {
178 int failed;
179 if(v & 1) {
180 failed = ccadical_failed((CCaDiCaL*)s->p, -(1 + (v >> 1)));
181 } else {
182 failed = ccadical_failed((CCaDiCaL*)s->p, 1 + (v >> 1) );
183 }
184 if(failed) {
185 Vec_IntPush(s->vCore, Abc_LitNot(v));
186 }
187 }
188 *ppArray = Vec_IntArray(s->vCore);
189 return Vec_IntSize(s->vCore);
190}
int ccadical_failed(CCaDiCaL *wrapper, int lit)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadical_solver_get_var_value()

int cadical_solver_get_var_value ( cadical_solver * s,
int v )

Function*************************************************************

Synopsis [get value of variable]

Description [cadical returns x (true) or -x (false) for a variable x. note a variable v was translated into v + 1 in cadical.]

SideEffects []

SeeAlso []

Definition at line 250 of file cadicalSolver.c.

250 {
251 return ccadical_val((CCaDiCaL*)s->p, v + 1) > 0;
252}
int ccadical_val(CCaDiCaL *wrapper, int lit)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadical_solver_new()

ABC_NAMESPACE_IMPL_START cadical_solver * cadical_solver_new ( void )

DECLARATIONS ///.

MACRO DEFINITIONS ///.

CFile****************************************************************

FileName [cadicalSolver.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [SAT solver CaDiCaL by Armin Biere, University of Freiburg]

Synopsis [https://github.com/arminbiere/cadical]

Author [Integrated into ABC by Yukio Miyasaka]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id
cadicalSolver.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

] FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [allocate solver]

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file cadicalSolver.c.

45 {
47 s->p = (void*)ccadical_init();
48 s->nVars = 0;
49 s->vAssumptions = NULL;
50 s->vCore = NULL;
51 return s;
52}
CCaDiCaL * ccadical_init(void)
char * malloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadical_solver_nvars()

int cadical_solver_nvars ( cadical_solver * s)

Function*************************************************************

Synopsis [get number of variables]

Description [emulated using "nVars".]

SideEffects []

SeeAlso []

Definition at line 203 of file cadicalSolver.c.

203 {
204 return s->nVars;
205}
Here is the caller graph for this function:

◆ cadical_solver_setnvars()

void cadical_solver_setnvars ( cadical_solver * s,
int n )

Function*************************************************************

Synopsis [set number of variables]

Description [not only emulate with "nVars" but also reserve memory.]

SideEffects []

SeeAlso []

Definition at line 233 of file cadicalSolver.c.

233 {
234 s->nVars = n;
235 ccadical_reserve((CCaDiCaL*)s->p, n);
236}
void ccadical_reserve(CCaDiCaL *ptr, int min_max_var)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ cadical_solver_solve()

int cadical_solver_solve ( cadical_solver * s,
int * begin,
int * end,
ABC_INT64_T nConfLimit,
ABC_INT64_T nInsLimit,
ABC_INT64_T nConfLimitGlobal,
ABC_INT64_T nInsLimitGlobal )

Function*************************************************************

Synopsis [solve with resource limits]

Description [assumptions and inspection limits are not supported.]

SideEffects []

SeeAlso []

Definition at line 113 of file cadicalSolver.c.

113 {
114 // inspection limits are not supported
115 assert(nInsLimit == 0);
116 assert(nInsLimitGlobal == 0);
117 // set conflict limits
118 if(nConfLimit)
119 ccadical_limit((CCaDiCaL*)s->p, "conflicts", nConfLimit);
120 if(nConfLimitGlobal && (nConfLimit == 0 || nConfLimit > nConfLimitGlobal))
121 ccadical_limit((CCaDiCaL*)s->p, "conflicts", nConfLimitGlobal);
122 // assumptions
123 if(begin != end) {
124 // save
125 if(s->vAssumptions == NULL) {
126 s->vAssumptions = Vec_IntAllocArrayCopy(begin, end - begin);
127 } else {
128 Vec_IntClear(s->vAssumptions);
129 Vec_IntGrow(s->vAssumptions, end - begin);
130 Vec_IntPushArray(s->vAssumptions, begin, end - begin);
131 }
132 // assume
133 for(;begin != end; begin++) {
134 if(*begin & 1) {
135 ccadical_assume((CCaDiCaL*)s->p, -(1 + ((*begin) >> 1)));
136 } else {
137 ccadical_assume((CCaDiCaL*)s->p, 1 + ((*begin) >> 1) );
138 }
139 }
140 }
141 // solve
142 int res = ccadical_solve((CCaDiCaL*)s->p);
143 // translate this cadical return value into a corresponding ABC status value
144 switch(res) {
145 case 0: // UNDETERMINED
146 return 0;
147 case 10: // SATISFIABLE
148 return 1;
149 case 20: // UNSATISFIABLE
150 return -1;
151 default:
152 assert(0);
153 }
154 return 0;
155}
void ccadical_assume(CCaDiCaL *wrapper, int lit)
int ccadical_solve(CCaDiCaL *wrapper)
void ccadical_limit(CCaDiCaL *wrapper, const char *name, int val)
Here is the call graph for this function:
Here is the caller graph for this function: