ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcSat.c File Reference
#include "base/abc/abc.h"
#include "base/main/main.h"
#include "base/cmd/cmd.h"
#include "sat/bsat/satSolver.h"
#include "aig/gia/gia.h"
#include "aig/gia/giaAig.h"
Include dependency graph for abcSat.c:

Go to the source code of this file.

Functions

Vec_Int_tAbc_NtkGetCiSatVarNums (Abc_Ntk_t *pNtk)
 
int Abc_NtkMiterSat (Abc_Ntk_t *pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T *pNumConfs, ABC_INT64_T *pNumInspects)
 FUNCTION DEFINITIONS ///.
 
int * Abc_NtkSolveGiaMiter (Gia_Man_t *p)
 
int Abc_NtkClauseTriv (sat_solver *pSat, Abc_Obj_t *pNode, Vec_Int_t *vVars)
 
int Abc_NtkClauseTop (sat_solver *pSat, Vec_Ptr_t *vNodes, Vec_Int_t *vVars)
 
int Abc_NtkClauseAnd (sat_solver *pSat, Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, Vec_Int_t *vVars)
 
int Abc_NtkClauseMux (sat_solver *pSat, Abc_Obj_t *pNode, Abc_Obj_t *pNodeC, Abc_Obj_t *pNodeT, Abc_Obj_t *pNodeE, Vec_Int_t *vVars)
 
int Abc_NtkCollectSupergate_rec (Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fStopAtMux)
 
void Abc_NtkCollectSupergate (Abc_Obj_t *pNode, int fStopAtMux, Vec_Ptr_t *vNodes)
 
int Abc_NtkNodeFactor (Abc_Obj_t *pObj, int nLevelMax)
 
int Abc_NtkMiterSatCreateInt (sat_solver *pSat, Abc_Ntk_t *pNtk)
 
void * Abc_NtkMiterSatCreate (Abc_Ntk_t *pNtk, int fAllPrimes)
 
void Abc_NtkWriteSorterCnf (char *pFileName, int nVars, int nQueens)
 

Function Documentation

◆ Abc_NtkClauseAnd()

int Abc_NtkClauseAnd ( sat_solver * pSat,
Abc_Obj_t * pNode,
Vec_Ptr_t * vSuper,
Vec_Int_t * vVars )

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

Synopsis [Adds trivial clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 256 of file abcSat.c.

257{
258 int fComp1, Var, Var1, i;
259//printf( "Adding AND %d. (%d) %d\n", pNode->Id, vSuper->nSize+1, (int)pSat->sat_solver_stats.clauses );
260
261 assert( !Abc_ObjIsComplement( pNode ) );
262 assert( Abc_ObjIsNode( pNode ) );
263
264// nVars = sat_solver_nvars(pSat);
265 Var = (int)(ABC_PTRINT_T)pNode->pCopy;
266// Var = pNode->Id;
267
268// assert( Var < nVars );
269 for ( i = 0; i < vSuper->nSize; i++ )
270 {
271 // get the predecessor nodes
272 // get the complemented attributes of the nodes
273 fComp1 = Abc_ObjIsComplement((Abc_Obj_t *)vSuper->pArray[i]);
274 // determine the variable numbers
275 Var1 = (int)(ABC_PTRINT_T)Abc_ObjRegular((Abc_Obj_t *)vSuper->pArray[i])->pCopy;
276// Var1 = (int)Abc_ObjRegular(vSuper->pArray[i])->Id;
277
278 // check that the variables are in the SAT manager
279// assert( Var1 < nVars );
280
281 // suppose the AND-gate is A * B = C
282 // add !A => !C or A + !C
283 // fprintf( pFile, "%d %d 0%c", Var1, -Var, 10 );
284 vVars->nSize = 0;
285 Vec_IntPush( vVars, toLitCond(Var1, fComp1) );
286 Vec_IntPush( vVars, toLitCond(Var, 1 ) );
287 if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
288 return 0;
289 }
290
291 // add A & B => C or !A + !B + C
292// fprintf( pFile, "%d %d %d 0%c", -Var1, -Var2, Var, 10 );
293 vVars->nSize = 0;
294 for ( i = 0; i < vSuper->nSize; i++ )
295 {
296 // get the predecessor nodes
297 // get the complemented attributes of the nodes
298 fComp1 = Abc_ObjIsComplement((Abc_Obj_t *)vSuper->pArray[i]);
299 // determine the variable numbers
300 Var1 = (int)(ABC_PTRINT_T)Abc_ObjRegular((Abc_Obj_t *)vSuper->pArray[i])->pCopy;
301// Var1 = (int)Abc_ObjRegular(vSuper->pArray[i])->Id;
302 // add this variable to the array
303 Vec_IntPush( vVars, toLitCond(Var1, !fComp1) );
304 }
305 Vec_IntPush( vVars, toLitCond(Var, 0) );
306 return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
307}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define sat_solver_addclause
Definition cecSatG2.c:37
int Var
Definition exorList.c:228
Abc_Obj_t * pCopy
Definition abc.h:148
#define assert(ex)
Definition util_old.h:213
@ Var1
Definition xsatSolver.h:56
Here is the caller graph for this function:

◆ Abc_NtkClauseMux()

int Abc_NtkClauseMux ( sat_solver * pSat,
Abc_Obj_t * pNode,
Abc_Obj_t * pNodeC,
Abc_Obj_t * pNodeT,
Abc_Obj_t * pNodeE,
Vec_Int_t * vVars )

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

Synopsis [Adds trivial clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 320 of file abcSat.c.

321{
322 int VarF, VarI, VarT, VarE, fCompT, fCompE;
323//printf( "Adding mux %d. %d\n", pNode->Id, (int)pSat->sat_solver_stats.clauses );
324
325 assert( !Abc_ObjIsComplement( pNode ) );
326 assert( Abc_NodeIsMuxType( pNode ) );
327 // get the variable numbers
328 VarF = (int)(ABC_PTRINT_T)pNode->pCopy;
329 VarI = (int)(ABC_PTRINT_T)pNodeC->pCopy;
330 VarT = (int)(ABC_PTRINT_T)Abc_ObjRegular(pNodeT)->pCopy;
331 VarE = (int)(ABC_PTRINT_T)Abc_ObjRegular(pNodeE)->pCopy;
332// VarF = (int)pNode->Id;
333// VarI = (int)pNodeC->Id;
334// VarT = (int)Abc_ObjRegular(pNodeT)->Id;
335// VarE = (int)Abc_ObjRegular(pNodeE)->Id;
336
337 // get the complementation flags
338 fCompT = Abc_ObjIsComplement(pNodeT);
339 fCompE = Abc_ObjIsComplement(pNodeE);
340
341 // f = ITE(i, t, e)
342 // i' + t' + f
343 // i' + t + f'
344 // i + e' + f
345 // i + e + f'
346 // create four clauses
347 vVars->nSize = 0;
348 Vec_IntPush( vVars, toLitCond(VarI, 1) );
349 Vec_IntPush( vVars, toLitCond(VarT, 1^fCompT) );
350 Vec_IntPush( vVars, toLitCond(VarF, 0) );
351 if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
352 return 0;
353 vVars->nSize = 0;
354 Vec_IntPush( vVars, toLitCond(VarI, 1) );
355 Vec_IntPush( vVars, toLitCond(VarT, 0^fCompT) );
356 Vec_IntPush( vVars, toLitCond(VarF, 1) );
357 if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
358 return 0;
359 vVars->nSize = 0;
360 Vec_IntPush( vVars, toLitCond(VarI, 0) );
361 Vec_IntPush( vVars, toLitCond(VarE, 1^fCompE) );
362 Vec_IntPush( vVars, toLitCond(VarF, 0) );
363 if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
364 return 0;
365 vVars->nSize = 0;
366 Vec_IntPush( vVars, toLitCond(VarI, 0) );
367 Vec_IntPush( vVars, toLitCond(VarE, 0^fCompE) );
368 Vec_IntPush( vVars, toLitCond(VarF, 1) );
369 if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
370 return 0;
371
372 if ( VarT == VarE )
373 {
374// assert( fCompT == !fCompE );
375 return 1;
376 }
377
378 // two additional clauses
379 // t' & e' -> f' t + e + f'
380 // t & e -> f t' + e' + f
381 vVars->nSize = 0;
382 Vec_IntPush( vVars, toLitCond(VarT, 0^fCompT) );
383 Vec_IntPush( vVars, toLitCond(VarE, 0^fCompE) );
384 Vec_IntPush( vVars, toLitCond(VarF, 1) );
385 if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
386 return 0;
387 vVars->nSize = 0;
388 Vec_IntPush( vVars, toLitCond(VarT, 1^fCompT) );
389 Vec_IntPush( vVars, toLitCond(VarE, 1^fCompE) );
390 Vec_IntPush( vVars, toLitCond(VarF, 0) );
391 return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
392}
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
Definition abcUtil.c:1342
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkClauseTop()

int Abc_NtkClauseTop ( sat_solver * pSat,
Vec_Ptr_t * vNodes,
Vec_Int_t * vVars )

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

Synopsis [Adds trivial clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 233 of file abcSat.c.

234{
235 Abc_Obj_t * pNode;
236 int i;
237//printf( "Adding triv %d. %d\n", Abc_ObjRegular(pNode)->Id, (int)pSat->sat_solver_stats.clauses );
238 vVars->nSize = 0;
239 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
240 Vec_IntPush( vVars, toLitCond( (int)(ABC_PTRINT_T)Abc_ObjRegular(pNode)->pCopy, Abc_ObjIsComplement(pNode) ) );
241// Vec_IntPush( vVars, toLitCond( (int)Abc_ObjRegular(pNode)->Id, Abc_ObjIsComplement(pNode) ) );
242 return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
243}
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the caller graph for this function:

◆ Abc_NtkClauseTriv()

int Abc_NtkClauseTriv ( sat_solver * pSat,
Abc_Obj_t * pNode,
Vec_Int_t * vVars )

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

Synopsis [Adds trivial clause.]

Description []

SideEffects []

SeeAlso []

Definition at line 213 of file abcSat.c.

214{
215//printf( "Adding triv %d. %d\n", Abc_ObjRegular(pNode)->Id, (int)pSat->sat_solver_stats.clauses );
216 vVars->nSize = 0;
217 Vec_IntPush( vVars, toLitCond( (int)(ABC_PTRINT_T)Abc_ObjRegular(pNode)->pCopy, Abc_ObjIsComplement(pNode) ) );
218// Vec_IntPush( vVars, toLitCond( (int)Abc_ObjRegular(pNode)->Id, Abc_ObjIsComplement(pNode) ) );
219 return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
220}
Here is the caller graph for this function:

◆ Abc_NtkCollectSupergate()

void Abc_NtkCollectSupergate ( Abc_Obj_t * pNode,
int fStopAtMux,
Vec_Ptr_t * vNodes )

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

Synopsis [Returns the array of nodes to be combined into one multi-input AND-gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 452 of file abcSat.c.

453{
454 int RetValue, i;
455 assert( !Abc_ObjIsComplement(pNode) );
456 // collect the nodes in the implication supergate
457 Vec_PtrClear( vNodes );
458 RetValue = Abc_NtkCollectSupergate_rec( pNode, vNodes, 1, fStopAtMux );
459 assert( vNodes->nSize > 1 );
460 // unmark the visited nodes
461 for ( i = 0; i < vNodes->nSize; i++ )
462 Abc_ObjRegular((Abc_Obj_t *)vNodes->pArray[i])->fMarkB = 0;
463 // if we found the node and its complement in the same implication supergate,
464 // return empty set of nodes (meaning that we should use constant-0 node)
465 if ( RetValue == -1 )
466 vNodes->nSize = 0;
467}
int Abc_NtkCollectSupergate_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst, int fStopAtMux)
Definition abcSat.c:405
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkCollectSupergate_rec()

int Abc_NtkCollectSupergate_rec ( Abc_Obj_t * pNode,
Vec_Ptr_t * vSuper,
int fFirst,
int fStopAtMux )

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

Synopsis [Returns the array of nodes to be combined into one multi-input AND-gate.]

Description []

SideEffects []

SeeAlso []

Definition at line 405 of file abcSat.c.

406{
407 int RetValue1, RetValue2, i;
408 // check if the node is visited
409 if ( Abc_ObjRegular(pNode)->fMarkB )
410 {
411 // check if the node occurs in the same polarity
412 for ( i = 0; i < vSuper->nSize; i++ )
413 if ( vSuper->pArray[i] == pNode )
414 return 1;
415 // check if the node is present in the opposite polarity
416 for ( i = 0; i < vSuper->nSize; i++ )
417 if ( vSuper->pArray[i] == Abc_ObjNot(pNode) )
418 return -1;
419 assert( 0 );
420 return 0;
421 }
422 // if the new node is complemented or a PI, another gate begins
423 if ( !fFirst )
424 if ( Abc_ObjIsComplement(pNode) || !Abc_ObjIsNode(pNode) || Abc_ObjFanoutNum(pNode) > 1 || (fStopAtMux && Abc_NodeIsMuxType(pNode)) )
425 {
426 Vec_PtrPush( vSuper, pNode );
427 Abc_ObjRegular(pNode)->fMarkB = 1;
428 return 0;
429 }
430 assert( !Abc_ObjIsComplement(pNode) );
431 assert( Abc_ObjIsNode(pNode) );
432 // go through the branches
433 RetValue1 = Abc_NtkCollectSupergate_rec( Abc_ObjChild0(pNode), vSuper, 0, fStopAtMux );
434 RetValue2 = Abc_NtkCollectSupergate_rec( Abc_ObjChild1(pNode), vSuper, 0, fStopAtMux );
435 if ( RetValue1 == -1 || RetValue2 == -1 )
436 return -1;
437 // return 1 if at least one branch has a duplicate
438 return RetValue1 || RetValue2;
439}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkGetCiSatVarNums()

Vec_Int_t * Abc_NtkGetCiSatVarNums ( Abc_Ntk_t * pNtk)
extern

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

Synopsis [Returns the array of CI IDs.]

Description []

SideEffects []

SeeAlso []

Definition at line 189 of file abcSat.c.

190{
191 Vec_Int_t * vCiIds;
192 Abc_Obj_t * pObj;
193 int i;
194 vCiIds = Vec_IntAlloc( Abc_NtkCiNum(pNtk) );
195 Abc_NtkForEachCi( pNtk, pObj, i )
196 Vec_IntPush( vCiIds, (int)(ABC_PTRINT_T)pObj->pCopy );
197 return vCiIds;
198}
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Here is the caller graph for this function:

◆ Abc_NtkMiterSat()

int Abc_NtkMiterSat ( Abc_Ntk_t * pNtk,
ABC_INT64_T nConfLimit,
ABC_INT64_T nInsLimit,
int fVerbose,
ABC_INT64_T * pNumConfs,
ABC_INT64_T * pNumInspects )

FUNCTION DEFINITIONS ///.

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

Synopsis [Attempts to solve the miter using an internal SAT sat_solver.]

Description [Returns -1 if timed out; 0 if SAT; 1 if UNSAT.]

SideEffects []

SeeAlso []

Definition at line 58 of file abcSat.c.

59{
60 sat_solver * pSat;
61 lbool status;
62 int RetValue = 0;
63 abctime clk;
64
65 if ( pNumConfs )
66 *pNumConfs = 0;
67 if ( pNumInspects )
68 *pNumInspects = 0;
69
70 assert( Abc_NtkLatchNum(pNtk) == 0 );
71
72// if ( Abc_NtkPoNum(pNtk) > 1 )
73// fprintf( stdout, "Warning: The miter has %d outputs. SAT will try to prove all of them.\n", Abc_NtkPoNum(pNtk) );
74
75 // load clauses into the sat_solver
76 clk = Abc_Clock();
77 pSat = (sat_solver *)Abc_NtkMiterSatCreate( pNtk, 0 );
78 if ( pSat == NULL )
79 return 1;
80//printf( "%d \n", pSat->clauses.size );
81//sat_solver_delete( pSat );
82//return 1;
83
84// printf( "Created SAT problem with %d variable and %d clauses. ", sat_solver_nvars(pSat), sat_solver_nclauses(pSat) );
85// ABC_PRT( "Time", Abc_Clock() - clk );
86
87 // simplify the problem
88 clk = Abc_Clock();
89 status = sat_solver_simplify(pSat);
90// printf( "Simplified the problem to %d variables and %d clauses. ", sat_solver_nvars(pSat), sat_solver_nclauses(pSat) );
91// ABC_PRT( "Time", Abc_Clock() - clk );
92 if ( status == 0 )
93 {
94 sat_solver_delete( pSat );
95// printf( "The problem is UNSATISFIABLE after simplification.\n" );
96 return 1;
97 }
98
99 // solve the miter
100 clk = Abc_Clock();
101 if ( fVerbose )
102 pSat->verbosity = 1;
103 status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, (ABC_INT64_T)0, (ABC_INT64_T)0 );
104 if ( status == l_Undef )
105 {
106// printf( "The problem timed out.\n" );
107 RetValue = -1;
108 }
109 else if ( status == l_True )
110 {
111// printf( "The problem is SATISFIABLE.\n" );
112 RetValue = 0;
113 }
114 else if ( status == l_False )
115 {
116// printf( "The problem is UNSATISFIABLE.\n" );
117 RetValue = 1;
118 }
119 else
120 assert( 0 );
121// ABC_PRT( "SAT sat_solver time", Abc_Clock() - clk );
122// printf( "The number of conflicts = %d.\n", (int)pSat->sat_solver_stats.conflicts );
123
124 // if the problem is SAT, get the counterexample
125 if ( status == l_True )
126 {
127// Vec_Int_t * vCiIds = Abc_NtkGetCiIds( pNtk );
128 Vec_Int_t * vCiIds = Abc_NtkGetCiSatVarNums( pNtk );
129 pNtk->pModel = Sat_SolverGetModel( pSat, vCiIds->pArray, vCiIds->nSize );
130 Vec_IntFree( vCiIds );
131 }
132 // free the sat_solver
133 if ( fVerbose )
134 Sat_SolverPrintStats( stdout, pSat );
135
136 if ( pNumConfs )
137 *pNumConfs = (int)pSat->stats.conflicts;
138 if ( pNumInspects )
139 *pNumInspects = (int)pSat->stats.inspects;
140
141sat_solver_store_write( pSat, "trace.cnf" );
143
144 sat_solver_delete( pSat );
145 return RetValue;
146}
void * Abc_NtkMiterSatCreate(Abc_Ntk_t *pNtk, int fAllPrimes)
Definition abcSat.c:664
Vec_Int_t * Abc_NtkGetCiSatVarNums(Abc_Ntk_t *pNtk)
Definition abcSat.c:189
ABC_INT64_T abctime
Definition abc_global.h:332
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_store_free(sat_solver *s)
Definition satSolver.c:2400
void sat_solver_store_write(sat_solver *s, char *pFileName)
Definition satSolver.c:2395
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int * Sat_SolverGetModel(sat_solver *p, int *pVars, int nVars)
Definition satUtil.c:270
void Sat_SolverPrintStats(FILE *pFile, sat_solver *p)
Definition satUtil.c:193
signed char lbool
Definition satVec.h:135
int * pModel
Definition abc.h:198
stats_t stats
Definition satSolver.h:163
ABC_INT64_T conflicts
Definition satVec.h:156
ABC_INT64_T inspects
Definition satVec.h:156
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMiterSatCreate()

void * Abc_NtkMiterSatCreate ( Abc_Ntk_t * pNtk,
int fAllPrimes )

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

Synopsis [Sets up the SAT sat_solver.]

Description []

SideEffects []

SeeAlso []

Definition at line 664 of file abcSat.c.

665{
666 sat_solver * pSat;
667 Abc_Obj_t * pNode;
668 int RetValue, i; //, clk = Abc_Clock();
669
670 assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsBddLogic(pNtk) );
671 if ( Abc_NtkIsBddLogic(pNtk) )
672 return Abc_NtkMiterSatCreateLogic(pNtk, fAllPrimes);
673
674 nMuxes = 0;
675 pSat = sat_solver_new();
676//sat_solver_store_alloc( pSat );
677 RetValue = Abc_NtkMiterSatCreateInt( pSat, pNtk );
679
680 Abc_NtkForEachObj( pNtk, pNode, i )
681 pNode->fMarkA = 0;
682// ASat_SolverWriteDimacs( pSat, "temp_sat.cnf", NULL, NULL, 1 );
683 if ( RetValue == 0 )
684 {
685 sat_solver_delete(pSat);
686 return NULL;
687 }
688// printf( "Ands = %6d. Muxes = %6d (%5.2f %%). ", Abc_NtkNodeNum(pNtk), nMuxes, 300.0*nMuxes/Abc_NtkNodeNum(pNtk) );
689// ABC_PRT( "Creating sat_solver", Abc_Clock() - clk );
690 return pSat;
691}
int Abc_NtkMiterSatCreateInt(sat_solver *pSat, Abc_Ntk_t *pNtk)
Definition abcSat.c:501
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
void sat_solver_store_mark_roots(sat_solver *s)
Definition satSolver.c:2412
unsigned fMarkA
Definition abc.h:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkMiterSatCreateInt()

int Abc_NtkMiterSatCreateInt ( sat_solver * pSat,
Abc_Ntk_t * pNtk )

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

Synopsis [Sets up the SAT sat_solver.]

Description []

SideEffects []

SeeAlso []

Definition at line 501 of file abcSat.c.

502{
503 Abc_Obj_t * pNode, * pFanin, * pNodeC, * pNodeT, * pNodeE;
504 Vec_Ptr_t * vNodes, * vSuper;
505 Vec_Int_t * vVars;
506 int i, k, fUseMuxes = 1;
507// int fOrderCiVarsFirst = 0;
508 int RetValue = 0;
509
510 assert( Abc_NtkIsStrash(pNtk) );
511
512 // clean the CI node pointers
513 Abc_NtkForEachCi( pNtk, pNode, i )
514 pNode->pCopy = NULL;
515
516 // start the data structures
517 vNodes = Vec_PtrAlloc( 1000 ); // the nodes corresponding to vars in the sat_solver
518 vSuper = Vec_PtrAlloc( 100 ); // the nodes belonging to the given implication supergate
519 vVars = Vec_IntAlloc( 100 ); // the temporary array for variables in the clause
520
521 // add the clause for the constant node
522 pNode = Abc_AigConst1(pNtk);
523 pNode->fMarkA = 1;
524 pNode->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
525 Vec_PtrPush( vNodes, pNode );
526 Abc_NtkClauseTriv( pSat, pNode, vVars );
527/*
528 // add the PI variables first
529 Abc_NtkForEachCi( pNtk, pNode, i )
530 {
531 pNode->fMarkA = 1;
532 pNode->pCopy = (Abc_Obj_t *)vNodes->nSize;
533 Vec_PtrPush( vNodes, pNode );
534 }
535*/
536 // collect the nodes that need clauses and top-level assignments
537 Vec_PtrClear( vSuper );
538 Abc_NtkForEachCo( pNtk, pNode, i )
539 {
540 // get the fanin
541 pFanin = Abc_ObjFanin0(pNode);
542 // create the node's variable
543 if ( pFanin->fMarkA == 0 )
544 {
545 pFanin->fMarkA = 1;
546 pFanin->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
547 Vec_PtrPush( vNodes, pFanin );
548 }
549 // add the trivial clause
550 Vec_PtrPush( vSuper, Abc_ObjChild0(pNode) );
551 }
552 if ( !Abc_NtkClauseTop( pSat, vSuper, vVars ) )
553 goto Quits;
554
555
556 // add the clauses
557 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
558 {
559 assert( !Abc_ObjIsComplement(pNode) );
560 if ( !Abc_AigNodeIsAnd(pNode) )
561 continue;
562//printf( "%d ", pNode->Id );
563
564 // add the clauses
565 if ( fUseMuxes && Abc_NodeIsMuxType(pNode) )
566 {
567 nMuxes++;
568
569 pNodeC = Abc_NodeRecognizeMux( pNode, &pNodeT, &pNodeE );
570 Vec_PtrClear( vSuper );
571 Vec_PtrPush( vSuper, pNodeC );
572 Vec_PtrPush( vSuper, pNodeT );
573 Vec_PtrPush( vSuper, pNodeE );
574 // add the fanin nodes to explore
575 Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pFanin, k )
576 {
577 pFanin = Abc_ObjRegular(pFanin);
578 if ( pFanin->fMarkA == 0 )
579 {
580 pFanin->fMarkA = 1;
581 pFanin->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
582 Vec_PtrPush( vNodes, pFanin );
583 }
584 }
585 // add the clauses
586 if ( !Abc_NtkClauseMux( pSat, pNode, pNodeC, pNodeT, pNodeE, vVars ) )
587 goto Quits;
588 }
589 else
590 {
591 // get the supergate
592 Abc_NtkCollectSupergate( pNode, fUseMuxes, vSuper );
593 // add the fanin nodes to explore
594 Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pFanin, k )
595 {
596 pFanin = Abc_ObjRegular(pFanin);
597 if ( pFanin->fMarkA == 0 )
598 {
599 pFanin->fMarkA = 1;
600 pFanin->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
601 Vec_PtrPush( vNodes, pFanin );
602 }
603 }
604 // add the clauses
605 if ( vSuper->nSize == 0 )
606 {
607 if ( !Abc_NtkClauseTriv( pSat, Abc_ObjNot(pNode), vVars ) )
608// if ( !Abc_NtkClauseTriv( pSat, pNode, vVars ) )
609 goto Quits;
610 }
611 else
612 {
613 if ( !Abc_NtkClauseAnd( pSat, pNode, vSuper, vVars ) )
614 goto Quits;
615 }
616 }
617 }
618/*
619 // set preferred variables
620 if ( fOrderCiVarsFirst )
621 {
622 int * pPrefVars = ABC_ALLOC( int, Abc_NtkCiNum(pNtk) );
623 int nVars = 0;
624 Abc_NtkForEachCi( pNtk, pNode, i )
625 {
626 if ( pNode->fMarkA == 0 )
627 continue;
628 pPrefVars[nVars++] = (int)pNode->pCopy;
629 }
630 nVars = Abc_MinInt( nVars, 10 );
631 ASat_SolverSetPrefVars( pSat, pPrefVars, nVars );
632 }
633*/
634/*
635 Abc_NtkForEachObj( pNtk, pNode, i )
636 {
637 if ( !pNode->fMarkA )
638 continue;
639 printf( "%10s : ", Abc_ObjName(pNode) );
640 printf( "%3d\n", (int)pNode->pCopy );
641 }
642 printf( "\n" );
643*/
644 RetValue = 1;
645Quits :
646 // delete
647 Vec_IntFree( vVars );
648 Vec_PtrFree( vNodes );
649 Vec_PtrFree( vSuper );
650 return RetValue;
651}
int Abc_NtkClauseTop(sat_solver *pSat, Vec_Ptr_t *vNodes, Vec_Int_t *vVars)
Definition abcSat.c:233
int Abc_NtkClauseAnd(sat_solver *pSat, Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, Vec_Int_t *vVars)
Definition abcSat.c:256
void Abc_NtkCollectSupergate(Abc_Obj_t *pNode, int fStopAtMux, Vec_Ptr_t *vNodes)
Definition abcSat.c:452
int Abc_NtkClauseMux(sat_solver *pSat, Abc_Obj_t *pNode, Abc_Obj_t *pNodeC, Abc_Obj_t *pNodeT, Abc_Obj_t *pNodeE, Vec_Int_t *vVars)
Definition abcSat.c:320
int Abc_NtkClauseTriv(sat_solver *pSat, Abc_Obj_t *pNode, Vec_Int_t *vVars)
Definition abcSat.c:213
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
Definition abcUtil.c:1430
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
Definition abcAig.c:683
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkNodeFactor()

int Abc_NtkNodeFactor ( Abc_Obj_t * pObj,
int nLevelMax )

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

Synopsis [Computes the factor of the node.]

Description []

SideEffects []

SeeAlso []

Definition at line 481 of file abcSat.c.

482{
483// nLevelMax = ((nLevelMax)/2)*3;
484 assert( (int)pObj->Level <= nLevelMax );
485// return (int)(100000000.0 * pow(0.999, nLevelMax - pObj->Level));
486 return (int)(100000000.0 * (1 + 0.01 * pObj->Level));
487// return (int)(100000000.0 / ((nLevelMax)/2)*3 - pObj->Level);
488}
unsigned Level
Definition abc.h:142

◆ Abc_NtkSolveGiaMiter()

int * Abc_NtkSolveGiaMiter ( Gia_Man_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 159 of file abcSat.c.

160{
161 extern Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan );
162 int RetValue = 0;
163 int * pResult = NULL;
164 Abc_Ntk_t * pNtk;
165 Aig_Man_t * pMan;
166 pMan = Gia_ManToAig( p, 0 );
167 pNtk = Abc_NtkFromAigPhase( pMan );
168 pNtk->pName = Extra_UtilStrsav(p->pName);
169 Aig_ManStop( pMan );
170 RetValue = Abc_NtkMiterSat( pNtk, 1000000, 0, 0, NULL, NULL );
171 if ( RetValue == 0 ) // sat
172 pResult = pNtk->pModel, pNtk->pModel = NULL;
173 Abc_NtkDelete( pNtk );
174 return pResult;
175}
int Abc_NtkMiterSat(Abc_Ntk_t *pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T *pNumConfs, ABC_INT64_T *pNumInspects)
FUNCTION DEFINITIONS ///.
Definition abcSat.c:58
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
Cube * p
Definition exorList.c:222
char * Extra_UtilStrsav(const char *s)
Aig_Man_t * Gia_ManToAig(Gia_Man_t *p, int fChoices)
Definition giaAig.c:318
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkFromAigPhase(Aig_Man_t *pMan)
DECLARATIONS ///.
Definition abcDar.c:595
char * pName
Definition abc.h:158
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkWriteSorterCnf()

void Abc_NtkWriteSorterCnf ( char * pFileName,
int nVars,
int nQueens )

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

Synopsis [Writes CNF for the sorter with N inputs asserting Q ones.]

Description []

SideEffects []

SeeAlso []

Definition at line 945 of file abcSat.c.

946{
947 char Command[100];
948 void * pAbc;
949 Abc_Ntk_t * pNtk;
950 Abc_Obj_t * pObj, * ppNodes[2], * ppRoots[2];
951 Vec_Ptr_t * vNodes;
952 FILE * pFile;
953 int i, Counter;
954
955 if ( nQueens <= 0 && nQueens >= nVars )
956 {
957 printf( "The number of queens (Q = %d) should belong to the interval: 0 < Q < %d.\n", nQueens, nQueens);
958 return;
959 }
960 assert( nQueens > 0 && nQueens < nVars );
962 // generate sorter
963 sprintf( Command, "gen -s -N %d sorter%d.blif", nVars, nVars );
964 if ( Cmd_CommandExecute( (Abc_Frame_t *)pAbc, Command ) )
965 {
966 fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
967 return;
968 }
969 // read the file
970 sprintf( Command, "read sorter%d.blif; strash", nVars );
971 if ( Cmd_CommandExecute( (Abc_Frame_t *)pAbc, Command ) )
972 {
973 fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
974 return;
975 }
976
977 // get the current network
978 pNtk = Abc_FrameReadNtk((Abc_Frame_t *)pAbc);
979 // collect the nodes for the given two primary outputs
980 ppNodes[0] = Abc_NtkPo( pNtk, nVars - nQueens - 1 );
981 ppNodes[1] = Abc_NtkPo( pNtk, nVars - nQueens );
982 ppRoots[0] = Abc_ObjFanin0( ppNodes[0] );
983 ppRoots[1] = Abc_ObjFanin0( ppNodes[1] );
984 vNodes = Abc_NtkDfsNodes( pNtk, ppRoots, 2 );
985
986 // assign CNF variables
987 Counter = 0;
988 Abc_NtkForEachObj( pNtk, pObj, i )
989 pObj->pCopy = (Abc_Obj_t *)~0;
990 Abc_NtkForEachPi( pNtk, pObj, i )
991 pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)Counter++;
992 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
993 pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)Counter++;
994
995/*
996 OutVar = pCnf->pVarNums[ pObj->Id ];
997 pVars[0] = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
998 pVars[1] = pCnf->pVarNums[ Aig_ObjFanin1(pObj)->Id ];
999
1000 // positive phase
1001 *pClas++ = pLits;
1002 *pLits++ = 2 * OutVar;
1003 *pLits++ = 2 * pVars[0] + !Aig_ObjFaninC0(pObj);
1004 *pLits++ = 2 * pVars[1] + !Aig_ObjFaninC1(pObj);
1005 // negative phase
1006 *pClas++ = pLits;
1007 *pLits++ = 2 * OutVar + 1;
1008 *pLits++ = 2 * pVars[0] + Aig_ObjFaninC0(pObj);
1009 *pClas++ = pLits;
1010 *pLits++ = 2 * OutVar + 1;
1011 *pLits++ = 2 * pVars[1] + Aig_ObjFaninC1(pObj);
1012*/
1013
1014 // add clauses for these nodes
1015 pFile = fopen( pFileName, "w" );
1016 fprintf( pFile, "c CNF for %d-bit sorter with %d bits set to 1 generated by ABC.\n", nVars, nQueens );
1017 fprintf( pFile, "p cnf %d %d\n", Counter, 3 * Vec_PtrSize(vNodes) + 2 );
1018 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
1019 {
1020 // positive phase
1021 fprintf( pFile, "%d %s%d %s%d 0\n", 1+(int)(ABC_PTRINT_T)pObj->pCopy,
1022 Abc_ObjFaninC0(pObj)? "" : "-", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy,
1023 Abc_ObjFaninC1(pObj)? "" : "-", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy );
1024 // negative phase
1025 fprintf( pFile, "-%d %s%d 0\n", 1+(int)(ABC_PTRINT_T)pObj->pCopy,
1026 Abc_ObjFaninC0(pObj)? "-" : "", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy );
1027 fprintf( pFile, "-%d %s%d 0\n", 1+(int)(ABC_PTRINT_T)pObj->pCopy,
1028 Abc_ObjFaninC1(pObj)? "-" : "", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy );
1029 }
1030 Vec_PtrFree( vNodes );
1031
1032/*
1033 *pClas++ = pLits;
1034 *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj);
1035*/
1036 // assert the first literal to zero
1037 fprintf( pFile, "%s%d 0\n",
1038 Abc_ObjFaninC0(ppNodes[0])? "" : "-", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(ppNodes[0])->pCopy );
1039 // assert the second literal to one
1040 fprintf( pFile, "%s%d 0\n",
1041 Abc_ObjFaninC0(ppNodes[1])? "-" : "", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(ppNodes[1])->pCopy );
1042 fclose( pFile );
1043}
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition abc.h:516
ABC_DLL Vec_Ptr_t * Abc_NtkDfsNodes(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
Definition abcDfs.c:151
typedefABC_NAMESPACE_HEADER_START struct Abc_Frame_t_ Abc_Frame_t
INCLUDES ///.
Definition abcapis.h:38
ABC_DLL Abc_Frame_t * Abc_FrameGetGlobalFrame()
Definition mainFrame.c:643
ABC_DLL Abc_Ntk_t * Abc_FrameReadNtk(Abc_Frame_t *p)
Definition mainFrame.c:327
ABC_DLL int Cmd_CommandExecute(Abc_Frame_t *pAbc, const char *sCommand)
Definition cmdApi.c:193
char * sprintf()
Here is the call graph for this function: