29 #ifdef ABC_USE_PTHREADS
32 #include "../lib/pthread.h"
47 #ifndef ABC_USE_PTHREADS
49 int Cec_GiaSplitTest(
Gia_Man_t *
p,
int nProcs,
int nTimeOut,
int nIterMax,
int LookAhead,
int fVerbose,
int fVeryVerbose ) {
return -1; }
51 #else // pthreads are used
74 DdNode * bBdd, * bBdd0, * bBdd1;
106 printf(
"Equivalent!\n" );
108 printf(
"Not tquivalent!\n" );
126 void Gia_ManBuildBddTest(
Gia_Man_t * p )
129 DdManager * dd = Gia_ManBuildBdd( p, &vNodes, 50 );
130 Gia_ManDerefBdd( dd, vNodes );
146 void Cec_GiaSplitExplore(
Gia_Man_t * p )
160 printf(
"%5d : ", Counter++ );
177 int * Gia_PermuteSpecialOrder(
Gia_Man_t * p )
194 int * pOrder = Gia_PermuteSpecialOrder( p );
212 int Gia_SplitCofVar2(
Gia_Man_t * p,
int * pnFanouts,
int * pnCost )
215 int i, iBest = -1, CostBest = -1;
216 if ( p->
pRefs == NULL )
226 int Gia_SplitCofVar(
Gia_Man_t * p,
int LookAhead,
int * pnFanouts,
int * pnCost )
230 int * pOrder, i, iBest = -1;
231 if ( LookAhead == 1 )
232 return Gia_SplitCofVar2( p, pnFanouts, pnCost );
233 pOrder = Gia_PermuteSpecialOrder( p );
235 for ( i = 0; i < LookAhead; i++ )
245 if ( CostBest > Cost0 + Cost1 )
246 CostBest = Cost0 + Cost1, iBest = pOrder[i];
282 int i, iLit, * pModel;
320 for ( i = 0; i < pCnf->
nClauses; i++ )
330 static inline int Cnf_GiaSolveOne(
Gia_Man_t * p,
Cnf_Dat_t * pCnf,
int nTimeOut,
int * pnVars,
int * pnConfs )
333 sat_solver * pSat = Cec_GiaDeriveSolver( p, pCnf, nTimeOut );
340 status =
sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 );
344 p->
pCexComb = Cec_SplitDeriveModel( p, pCnf, pSat );
352 static inline void Cec_GiaSplitClean(
Vec_Ptr_t * vStack )
372 void Cec_GiaSplitPrint(
int nIter,
int Depth,
int nVars,
int nConfs,
int fStatus,
double Prog,
abctime clk )
374 printf(
"%4d : ", nIter );
375 printf(
"Depth =%3d ", Depth );
376 printf(
"SatVar =%7d ", nVars );
377 printf(
"SatConf =%7d ", nConfs );
378 printf(
"%s ", fStatus ? (fStatus == 1 ?
"UNSAT " :
"UNDECIDED") :
"SAT " );
379 printf(
"Solved %8.4f %% ", 100*Prog );
384 void Cec_GiaSplitPrintRefs(
Gia_Man_t * p )
388 if ( p->
pRefs == NULL )
406 int Cec_GiaSplitTest2(
Gia_Man_t * p,
int nProcs,
int nTimeOut,
int nIterMax,
int LookAhead,
int fVerbose,
int fVeryVerbose )
411 int nSatVars, nSatConfs;
412 int nIter, status, RetValue = -1;
415 pCnf = Cec_GiaDeriveGiaRemapped( p );
416 status = Cnf_GiaSolveOne( p, pCnf, nTimeOut, &nSatVars, &nSatConfs );
419 Cec_GiaSplitPrint( 0, 0, nSatVars, nSatConfs, status, Progress,
Abc_Clock() - clkTotal );
422 printf(
"The problem is SAT without cofactoring.\n" );
427 printf(
"The problem is UNSAT without cofactoring.\n" );
435 for ( nIter = 1;
Vec_PtrSize(vStack) > 0; nIter++ )
441 int nFanouts, Cost, iVar = Gia_SplitCofVar( pLast, LookAhead, &nFanouts, &Cost );
450 printf(
"Var = %5d. Fanouts = %5d. Cost = %8d. AndBefore = %6d. AndAfter = %6d.\n",
459 pCnf = Cec_GiaDeriveGiaRemapped( pPart );
460 status = Cnf_GiaSolveOne( pPart, pCnf, nTimeOut, &nSatVars, &nSatConfs );
463 Progress += 1.0 / pow(2, Depth);
465 Cec_GiaSplitPrint( nIter, Depth, nSatVars, nSatConfs, status, Progress,
Abc_Clock() - clkTotal );
486 pCnf = Cec_GiaDeriveGiaRemapped( pPart );
487 status = Cnf_GiaSolveOne( pPart, pCnf, nTimeOut, &nSatVars, &nSatConfs );
490 Progress += 1.0 / pow(2, Depth);
492 Cec_GiaSplitPrint( nIter, Depth, nSatVars, nSatConfs, status, Progress,
Abc_Clock() - clkTotal );
504 if ( nIterMax && nIter >= nIterMax )
510 Cec_GiaSplitClean( vStack );
512 printf(
"Problem is SAT " );
513 else if ( RetValue == 1 )
514 printf(
"Problem is UNSAT " );
515 else if ( RetValue == -1 )
516 printf(
"Problem is UNDECIDED " );
518 printf(
"after %d case-splits. ", nIter );
535 #define PAR_THR_MAX 100
536 typedef struct Par_ThData_t_
547 void * Cec_GiaSplitWorkerThread(
void * pArg )
549 Par_ThData_t * pThData = (Par_ThData_t *)pArg;
550 volatile int * pPlace = &pThData->fWorking;
553 while ( *pPlace == 0 );
554 assert( pThData->fWorking );
555 if ( pThData->p == NULL )
557 pthread_exit( NULL );
561 pThData->Result = Cnf_GiaSolveOne( pThData->p, pThData->pCnf, pThData->nTimeOut, &pThData->nVars, &pThData->nConfs );
562 pThData->fWorking = 0;
567 int Cec_GiaSplitTestInt(
Gia_Man_t * p,
int nProcs,
int nTimeOut,
int nIterMax,
int LookAhead,
int fVerbose,
int fVeryVerbose )
570 Par_ThData_t ThData[PAR_THR_MAX];
571 pthread_t WorkerThread[PAR_THR_MAX];
575 int i, status, nSatVars, nSatConfs;
576 int nIter = 0, RetValue = -1, fWorkToDo = 1;
579 printf(
"Solving CEC problem by cofactoring with the following parameters:\n" );
581 printf(
"Processes = %d TimeOut = %d sec MaxIter = %d LookAhead = %d Verbose = %d.\n", nProcs, nTimeOut, nIterMax, LookAhead, fVerbose );
584 return Cec_GiaSplitTest2( p, nProcs, nTimeOut, nIterMax, LookAhead, fVerbose, fVeryVerbose );
587 assert( nProcs >= 1 && nProcs <= PAR_THR_MAX );
589 pCnf = Cec_GiaDeriveGiaRemapped( p );
590 status = Cnf_GiaSolveOne( p, pCnf, nTimeOut, &nSatVars, &nSatConfs );
592 if ( fVerbose && status != -1 )
593 Cec_GiaSplitPrint( 0, 0, nSatVars, nSatConfs, status, Progress,
Abc_Clock() - clkTotal );
596 printf(
"The problem is SAT without cofactoring.\n" );
601 printf(
"The problem is UNSAT without cofactoring.\n" );
609 for ( i = 0; i < nProcs; i++ )
612 ThData[i].pCnf = NULL;
613 ThData[i].iThread = i;
614 ThData[i].nTimeOut = nTimeOut;
615 ThData[i].fWorking = 0;
616 ThData[i].Result = -1;
617 ThData[i].nVars = -1;
618 ThData[i].nConfs = -1;
619 status = pthread_create( WorkerThread + i, NULL,Cec_GiaSplitWorkerThread, (
void *)(ThData + i) );
assert( status == 0 );
625 for ( i = 0; i < nProcs; i++ )
628 if ( ThData[i].fWorking )
634 if ( ThData[i].p != NULL )
641 Cec_GiaSplitPrint( i+1, Depth, ThData[i].nVars, ThData[i].nConfs, ThData[i].Result, Progress,
Abc_Clock() - clkTotal );
642 if ( ThData[i].Result == 0 )
648 if ( ThData[i].Result == -1 )
651 int nFanouts, Cost, iVar = Gia_SplitCofVar( pLast, LookAhead, &nFanouts, &Cost );
662 printf(
"Var = %5d. Fanouts = %5d. Cost = %8d. AndBefore = %6d. AndAfter = %6d.\n",
677 Progress += 1.0 / pow(2, Depth);
679 if ( ThData[i].pCnf == NULL )
682 ThData[i].pCnf = NULL;
687 assert( ThData[i].p == NULL );
689 ThData[i].pCnf = Cec_GiaDeriveGiaRemapped( ThData[i].p );
690 ThData[i].fWorking = 1;
692 if ( nIterMax && nIter >= nIterMax )
699 for ( i = 0; i < nProcs; i++ )
700 if ( ThData[i].fWorking )
703 for ( i = 0; i < nProcs; i++ )
705 assert( !ThData[i].fWorking );
708 if ( ThData[i].pCnf == NULL )
711 ThData[i].pCnf = NULL;
714 ThData[i].fWorking = 1;
717 Cec_GiaSplitClean( vStack );
719 printf(
"Problem is SAT " );
720 else if ( RetValue == 1 )
721 printf(
"Problem is UNSAT " );
722 else if ( RetValue == -1 )
723 printf(
"Problem is UNDECIDED " );
725 printf(
"after %d case-splits. ", nIter );
730 int Cec_GiaSplitTest(
Gia_Man_t * p,
int nProcs,
int nTimeOut,
int nIterMax,
int LookAhead,
int fVerbose,
int fVeryVerbose )
735 int i, RetValue1, fOneUndef = 0, RetValue = -1;
741 printf(
"\nSolving output %d:\n", i );
742 RetValue1 = Cec_GiaSplitTestInt( pOne, nProcs, nTimeOut, nIterMax, LookAhead, fVerbose, fVeryVerbose );
745 if ( RetValue1 == 0 && RetValue == -1 )
751 if ( RetValue1 == -1 )
754 if ( RetValue == -1 )
755 RetValue = fOneUndef ? -1 : 1;
772 void Cec_GiaPrintCofStats(
Gia_Man_t * p )
775 Gia_Obj_t * pObj, * pFan0, * pFan1, * pCtrl;
789 printf(
"The AIG with %d candidate nodes (PI+AND) has %d unique MUX control drivers:\n",
798 printf(
"%6d : ", Count++ );
799 printf(
"Obj = %6d ", i );
810 void Cec_GiaPrintCofStats2(
Gia_Man_t * p )
821 printf(
"PI %5d : ", i );
831 #endif // pthreads are used
static int Vec_IntCountPositive(Vec_Int_t *p)
static abctime sat_solver_set_runtime_limit(sat_solver *s, abctime Limit)
static int Gia_ObjLevelId(Gia_Man_t *p, int Id)
static int * Vec_IntArray(Vec_Int_t *p)
void Gia_ManCreateRefs(Gia_Man_t *p)
static Vec_Ptr_t * Vec_PtrStart(int nSize)
int Gia_ObjRecognizeExor(Gia_Obj_t *pObj, Gia_Obj_t **ppFan0, Gia_Obj_t **ppFan1)
int * Abc_QuickSortCost(int *pCosts, int nSize, int fDecrease)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define CUDD_UNIQUE_SLOTS
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
void Gia_ManStop(Gia_Man_t *p)
Aig_Man_t * Gia_ManToAigSimple(Gia_Man_t *p)
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
int sat_solver_addclause(sat_solver *s, lit *begin, lit *end)
Gia_Man_t * Gia_ManDupPerm(Gia_Man_t *p, Vec_Int_t *vPiPerm)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
void Aig_ManStop(Aig_Man_t *p)
static Gia_Obj_t * Gia_Regular(Gia_Obj_t *p)
Gia_Man_t * Gia_ManDupCofactorObj(Gia_Man_t *p, int iObj, int Value)
static Vec_Int_t * Vec_IntAllocArray(int *pArray, int nSize)
int sat_solver_solve(sat_solver *s, lit *begin, lit *end, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, ABC_INT64_T nConfLimitGlobal, ABC_INT64_T nInsLimitGlobal)
DdNode * Cudd_ReadLogicZero(DdManager *dd)
void sat_solver_delete(sat_solver *s)
static int Abc_Var2Lit(int Var, int fCompl)
Gia_Man_t * Gia_ManDupOutputGroup(Gia_Man_t *p, int iOutStart, int iOutStop)
int sat_solver_nconflicts(sat_solver *s)
static int Gia_ObjRefNum(Gia_Man_t *p, Gia_Obj_t *pObj)
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
static abctime Abc_Clock()
static int Vec_PtrSize(Vec_Ptr_t *p)
static void * Vec_PtrPop(Vec_Ptr_t *p)
static int sat_solver_var_value(sat_solver *s, int v)
void Gia_ManStopP(Gia_Man_t **p)
static void Abc_PrintTime(int level, const char *pStr, abctime time)
static int Gia_ManAndNum(Gia_Man_t *p)
static int Abc_MinInt(int a, int b)
static Vec_Int_t * Vec_IntStart(int nSize)
static int Abc_LitIsCompl(int Lit)
static Gia_Obj_t * Gia_ManPi(Gia_Man_t *p, int v)
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
ABC_NAMESPACE_IMPL_START int Cec_GiaSplitTest(Gia_Man_t *p, int nProcs, int nTimeOut, int nIterMax, int LookAhead, int fVerbose, int fVeryVerbose)
DECLARATIONS ///.
int Cudd_PrintInfo(DdManager *dd, FILE *fp)
static void Vec_IntAddToEntry(Vec_Int_t *p, int i, int Addition)
void sat_solver_setnvars(sat_solver *s, int n)
static int Vec_IntEntry(Vec_Int_t *p, int i)
void Abc_CexFreeP(Abc_Cex_t **p)
int sat_solver_nvars(sat_solver *s)
#define ABC_NAMESPACE_IMPL_END
DdManager * Cudd_Init(unsigned int numVars, unsigned int numVarsZ, unsigned int numSlots, unsigned int cacheSize, unsigned long maxMemory)
#define Gia_ManForEachAnd(p, pObj, i)
static void Vec_IntPush(Vec_Int_t *p, int Entry)
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
static int Gia_ManCandNum(Gia_Man_t *p)
#define Gia_ManForEachPi(p, pObj, i)
static void Vec_PtrWriteEntry(Vec_Ptr_t *p, int i, void *Entry)
#define Gia_ManForEachCand(p, pObj, i)
#define ABC_NAMESPACE_IMPL_START
int Cudd_CheckZeroRef(DdManager *manager)
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
int Gia_ObjIsMuxType(Gia_Obj_t *pNode)
sat_solver * sat_solver_new(void)
Gia_Man_t * Gia_ManDupCofactorVar(Gia_Man_t *p, int iVar, int Value)
static int Vec_IntSize(Vec_Int_t *p)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
DdNode * Cudd_bddIthVar(DdManager *dd, int i)
static int Abc_Lit2Var(int Lit)
#define ABC_CALLOC(type, num)
void Cnf_DataFree(Cnf_Dat_t *p)
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
#define Cudd_NotCond(node, c)
DdNode * Cudd_bddAnd(DdManager *dd, DdNode *f, DdNode *g)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
int Gia_ManLevelNum(Gia_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Abc_Cex_t_ Abc_Cex_t
INCLUDES ///.
void Cudd_Quit(DdManager *unique)
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
static void Vec_IntFree(Vec_Int_t *p)
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
static int Gia_ManPiNum(Gia_Man_t *p)
Abc_Cex_t * Abc_CexCreate(int nRegs, int nPis, int *pArray, int iFrame, int iPo, int fSkipRegs)
#define Gia_ManForEachPo(p, pObj, i)
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
static int Gia_ObjFaninId1(Gia_Obj_t *pObj, int ObjId)
static int Gia_ManObjNum(Gia_Man_t *p)
static void Vec_PtrFree(Vec_Ptr_t *p)
static int Gia_ObjFaninId0(Gia_Obj_t *pObj, int ObjId)