/**Function************************************************************* Synopsis [] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Abc_NtkMfsNode( Mfs_Man_t * p, Abc_Obj_t * pNode ) { Hop_Obj_t * pObj; int RetValue; float dProb; extern Hop_Obj_t * Abc_NodeIfNodeResyn( Bdc_Man_t * p, Hop_Man_t * pHop, Hop_Obj_t * pRoot, int nVars, Vec_Int_t * vTruth, unsigned * puCare, float dProb ); int nGain; abctime clk; p->nNodesTried++; // prepare data structure for this node Mfs_ManClean( p ); // compute window roots, window support, and window nodes clk = Abc_Clock(); p->vRoots = Abc_MfsComputeRoots( pNode, p->pPars->nWinTfoLevs, p->pPars->nFanoutsMax ); p->vSupp = Abc_NtkNodeSupport( p->pNtk, (Abc_Obj_t **)Vec_PtrArray(p->vRoots), Vec_PtrSize(p->vRoots) ); p->vNodes = Abc_NtkDfsNodes( p->pNtk, (Abc_Obj_t **)Vec_PtrArray(p->vRoots), Vec_PtrSize(p->vRoots) ); p->timeWin += Abc_Clock() - clk; // count the number of patterns // p->dTotalRatios += Abc_NtkConstraintRatio( p, pNode ); // construct AIG for the window clk = Abc_Clock(); p->pAigWin = Abc_NtkConstructAig( p, pNode ); p->timeAig += Abc_Clock() - clk; // translate it into CNF clk = Abc_Clock(); p->pCnf = Cnf_DeriveSimple( p->pAigWin, Abc_ObjFaninNum(pNode) ); p->timeCnf += Abc_Clock() - clk; // create the SAT problem clk = Abc_Clock(); p->pSat = (sat_solver *)Cnf_DataWriteIntoSolver( p->pCnf, 1, 0 ); if ( p->pSat && p->pPars->fOneHotness ) Abc_NtkAddOneHotness( p ); if ( p->pSat == NULL ) return 0; // solve the SAT problem RetValue = Abc_NtkMfsSolveSat( p, pNode ); p->nTotConfLevel += p->pSat->stats.conflicts; p->timeSat += Abc_Clock() - clk; if ( RetValue == 0 ) { p->nTimeOutsLevel++; p->nTimeOuts++; return 0; } // minimize the local function of the node using bi-decomposition assert( p->nFanins == Abc_ObjFaninNum(pNode) ); dProb = p->pPars->fPower? ((float *)p->vProbs->pArray)[pNode->Id] : -1.0; pObj = Abc_NodeIfNodeResyn( p->pManDec, (Hop_Man_t *)pNode->pNtk->pManFunc, (Hop_Obj_t *)pNode->pData, p->nFanins, p->vTruth, p->uCare, dProb ); nGain = Hop_DagSize((Hop_Obj_t *)pNode->pData) - Hop_DagSize(pObj); if ( nGain >= 0 ) { p->nNodesDec++; p->nNodesGained += nGain; p->nNodesGainedLevel += nGain; pNode->pData = pObj; } return 1; }
/**Function************************************************************* Synopsis [Finds one satisfiable assignment of the timeframes.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Ssw_ManSetConstrPhases( Aig_Man_t * p, int nFrames, Vec_Int_t ** pvInits ) { Aig_Man_t * pFrames; sat_solver * pSat; Cnf_Dat_t * pCnf; Aig_Obj_t * pObj; int i, RetValue; if ( pvInits ) *pvInits = NULL; // assert( p->nConstrs > 0 ); // derive the timeframes pFrames = Ssw_FramesWithConstraints( p, nFrames ); // create CNF pCnf = Cnf_Derive( pFrames, 0 ); // create SAT solver pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 ); if ( pSat == NULL ) { Cnf_DataFree( pCnf ); Aig_ManStop( pFrames ); return 1; } // solve RetValue = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)1000000, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 ); if ( RetValue == l_True && pvInits ) { *pvInits = Vec_IntAlloc( 1000 ); Aig_ManForEachCi( pFrames, pObj, i ) Vec_IntPush( *pvInits, sat_solver_var_value(pSat, pCnf->pVarNums[Aig_ObjId(pObj)]) ); // Aig_ManForEachCi( pFrames, pObj, i ) // Abc_Print( 1, "%d", Vec_IntEntry(*pvInits, i) ); // Abc_Print( 1, "\n" ); } sat_solver_delete( pSat ); Cnf_DataFree( pCnf ); Aig_ManStop( pFrames ); if ( RetValue == l_False ) return 1; if ( RetValue == l_True ) return 0; return -1; }
/**Function************************************************************* Synopsis [Returns 1 if AIG has transition into init state.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ int Int2_ManCheckInit( Gia_Man_t * p ) { sat_solver * pSat; Cnf_Dat_t * pCnf; Gia_Man_t * pNew; Gia_Obj_t * pObj; Vec_Int_t * vLits; int i, Lit, RetValue = 0; assert( Gia_ManRegNum(p) > 0 ); pNew = Jf_ManDeriveCnf( p, 0 ); pCnf = (Cnf_Dat_t *)pNew->pData; pNew->pData = NULL; pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 ); if ( pSat != NULL ) { vLits = Vec_IntAlloc( Gia_ManRegNum(p) ); Gia_ManForEachRi( pNew, pObj, i ) { Lit = pCnf->pVarNums[ Gia_ObjId(pNew, Gia_ObjFanin0(pObj)) ]; Lit = Abc_Var2Lit( Lit, Gia_ObjFaninC0(pObj) ); Vec_IntPush( vLits, Abc_LitNot(Lit) ); }
/**Function************************************************************* Synopsis [Performs fraiging for one node.] Description [Returns the fraiged node.] SideEffects [] SeeAlso [] ***********************************************************************/ int Ssw_ManSetConstrPhases_( Aig_Man_t * p, int nFrames, Vec_Int_t ** pvInits ) { Vec_Int_t * vLits; sat_solver * pSat; Cnf_Dat_t * pCnf; Aig_Obj_t * pObj; int i, f, iVar, RetValue, nRegs; if ( pvInits ) *pvInits = NULL; assert( p->nConstrs > 0 ); // create CNF nRegs = p->nRegs; p->nRegs = 0; pCnf = Cnf_Derive( p, Aig_ManCoNum(p) ); p->nRegs = nRegs; // create SAT solver pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, nFrames, 0 ); assert( pSat->size == nFrames * pCnf->nVars ); // collect constraint literals vLits = Vec_IntAlloc( 100 ); Saig_ManForEachLo( p, pObj, i ) { assert( pCnf->pVarNums[Aig_ObjId(pObj)] >= 0 ); Vec_IntPush( vLits, toLitCond(pCnf->pVarNums[Aig_ObjId(pObj)], 1) ); }
/**Function************************************************************* Synopsis [Run the SAT solver on the unrolled instance.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ void * Inter_ManGetCounterExample( Aig_Man_t * pAig, int nFrames, int fVerbose ) { int nConfLimit = 1000000; Abc_Cex_t * pCtrex = NULL; Aig_Man_t * pFrames; sat_solver * pSat; Cnf_Dat_t * pCnf; int status; clock_t clk = clock(); Vec_Int_t * vCiIds; // create timeframes assert( Saig_ManPoNum(pAig) == 1 ); pFrames = Inter_ManFramesBmc( pAig, nFrames ); // derive CNF pCnf = Cnf_Derive( pFrames, 0 ); Cnf_DataTranformPolarity( pCnf, 0 ); vCiIds = Cnf_DataCollectPiSatNums( pCnf, pFrames ); Aig_ManStop( pFrames ); // convert into SAT solver pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 ); Cnf_DataFree( pCnf ); if ( pSat == NULL ) { printf( "Counter-example generation in command \"int\" has failed.\n" ); printf( "Use command \"bmc2\" to produce a valid counter-example.\n" ); Vec_IntFree( vCiIds ); return NULL; } // simplify the problem status = sat_solver_simplify(pSat); if ( status == 0 ) { Vec_IntFree( vCiIds ); sat_solver_delete( pSat ); return NULL; } // solve the miter status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 ); // if the problem is SAT, get the counterexample if ( status == l_True ) { int i, * pModel = Sat_SolverGetModel( pSat, vCiIds->pArray, vCiIds->nSize ); pCtrex = Abc_CexAlloc( Saig_ManRegNum(pAig), Saig_ManPiNum(pAig), nFrames ); pCtrex->iFrame = nFrames - 1; pCtrex->iPo = 0; for ( i = 0; i < Vec_IntSize(vCiIds); i++ ) if ( pModel[i] ) Abc_InfoSetBit( pCtrex->pData, Saig_ManRegNum(pAig) + i ); ABC_FREE( pModel ); } // free the sat_solver sat_solver_delete( pSat ); Vec_IntFree( vCiIds ); // verify counter-example status = Saig_ManVerifyCex( pAig, pCtrex ); if ( status == 0 ) printf( "Inter_ManGetCounterExample(): Counter-example verification has FAILED.\n" ); // report the results if ( fVerbose ) { ABC_PRT( "Total ctrex generation time", clock() - clk ); } return pCtrex; }
/**Function************************************************************* Synopsis [Takes the AIG with the single output to be checked.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Cla_Man_t * Fra_ClauStart( Aig_Man_t * pMan ) { Cla_Man_t * p; Cnf_Dat_t * pCnfMain; Cnf_Dat_t * pCnfTest; Cnf_Dat_t * pCnfBmc; Aig_Man_t * pFramesMain; Aig_Man_t * pFramesTest; Aig_Man_t * pFramesBmc; assert( Aig_ManCoNum(pMan) - Aig_ManRegNum(pMan) == 1 ); // start the manager p = ABC_ALLOC( Cla_Man_t, 1 ); memset( p, 0, sizeof(Cla_Man_t) ); p->vCexMain0 = Vec_IntAlloc( Aig_ManRegNum(pMan) ); p->vCexMain = Vec_IntAlloc( Aig_ManRegNum(pMan) ); p->vCexTest = Vec_IntAlloc( Aig_ManRegNum(pMan) ); p->vCexBase = Vec_IntAlloc( Aig_ManRegNum(pMan) ); p->vCexAssm = Vec_IntAlloc( Aig_ManRegNum(pMan) ); p->vCexBmc = Vec_IntAlloc( Aig_ManRegNum(pMan) ); // derive two timeframes to be checked pFramesMain = Aig_ManFrames( pMan, 2, 0, 1, 0, 0, NULL ); // nFrames, fInit, fOuts, fRegs //Aig_ManShow( pFramesMain, 0, NULL ); assert( Aig_ManCoNum(pFramesMain) == 2 ); Aig_ObjChild0Flip( Aig_ManCo(pFramesMain, 0) ); // complement the first output pCnfMain = Cnf_DeriveSimple( pFramesMain, 0 ); //Cnf_DataWriteIntoFile( pCnfMain, "temp.cnf", 1 ); p->pSatMain = (sat_solver *)Cnf_DataWriteIntoSolver( pCnfMain, 1, 0 ); /* { int i; Aig_Obj_t * pObj; Aig_ManForEachObj( pFramesMain, pObj, i ) printf( "%d -> %d \n", pObj->Id, pCnfMain->pVarNums[pObj->Id] ); printf( "\n" ); } */ // derive one timeframe to be checked pFramesTest = Aig_ManFrames( pMan, 1, 0, 0, 1, 0, NULL ); assert( Aig_ManCoNum(pFramesTest) == Aig_ManRegNum(pMan) ); pCnfTest = Cnf_DeriveSimple( pFramesTest, Aig_ManRegNum(pMan) ); p->pSatTest = (sat_solver *)Cnf_DataWriteIntoSolver( pCnfTest, 1, 0 ); p->nSatVarsTestBeg = p->nSatVarsTestCur = sat_solver_nvars( p->pSatTest ); // derive one timeframe to be checked for BMC pFramesBmc = Aig_ManFrames( pMan, 1, 1, 0, 1, 0, NULL ); //Aig_ManShow( pFramesBmc, 0, NULL ); assert( Aig_ManCoNum(pFramesBmc) == Aig_ManRegNum(pMan) ); pCnfBmc = Cnf_DeriveSimple( pFramesBmc, Aig_ManRegNum(pMan) ); p->pSatBmc = (sat_solver *)Cnf_DataWriteIntoSolver( pCnfBmc, 1, 0 ); // create variable sets p->vSatVarsMainCs = Fra_ClauSaveInputVars( pFramesMain, pCnfMain, 2 * (Aig_ManCiNum(pMan)-Aig_ManRegNum(pMan)) ); p->vSatVarsTestCs = Fra_ClauSaveLatchVars( pFramesTest, pCnfTest, 1 ); p->vSatVarsTestNs = Fra_ClauSaveLatchVars( pFramesTest, pCnfTest, 0 ); p->vSatVarsBmcNs = Fra_ClauSaveOutputVars( pFramesBmc, pCnfBmc ); assert( Vec_IntSize(p->vSatVarsTestCs) == Vec_IntSize(p->vSatVarsMainCs) ); assert( Vec_IntSize(p->vSatVarsTestCs) == Vec_IntSize(p->vSatVarsBmcNs) ); // create mapping of CS into NS vars p->pMapCsMainToCsTest = Fra_ClauCreateMapping( p->vSatVarsMainCs, p->vSatVarsTestCs, Aig_ManObjNumMax(pFramesMain) ); p->pMapCsTestToCsMain = Fra_ClauCreateMapping( p->vSatVarsTestCs, p->vSatVarsMainCs, Aig_ManObjNumMax(pFramesTest) ); p->pMapCsTestToNsTest = Fra_ClauCreateMapping( p->vSatVarsTestCs, p->vSatVarsTestNs, Aig_ManObjNumMax(pFramesTest) ); p->pMapCsTestToNsBmc = Fra_ClauCreateMapping( p->vSatVarsTestCs, p->vSatVarsBmcNs, Aig_ManObjNumMax(pFramesTest) ); // cleanup Cnf_DataFree( pCnfMain ); Cnf_DataFree( pCnfTest ); Cnf_DataFree( pCnfBmc ); Aig_ManStop( pFramesMain ); Aig_ManStop( pFramesTest ); Aig_ManStop( pFramesBmc ); if ( p->pSatMain == NULL || p->pSatTest == NULL || p->pSatBmc == NULL ) { Fra_ClauStop( p ); return NULL; } return p; }