/**CFile**************************************************************** FileName [llb2Cex.c] SystemName [ABC: Logic synthesis and verification system.] PackageName [BDD based reachability.] Synopsis [Non-linear quantification scheduling.] Author [Alan Mishchenko] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - June 20, 2005.] Revision [$Id: llb2Cex.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] ***********************************************************************/ #include "llbInt.h" #include "cnf.h" #include "satSolver.h" ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Translates a sequence of states into a counter-example.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Abc_Cex_t * Llb4_Nonlin4TransformCex( Aig_Man_t * pAig, Vec_Ptr_t * vStates, int fVerbose ) { Abc_Cex_t * pCex; Cnf_Dat_t * pCnf; Vec_Int_t * vAssumps; sat_solver * pSat; Aig_Obj_t * pObj; unsigned * pNext, * pThis; int i, k, iBit, status, nRegs, clk = clock(); /* Vec_PtrForEachEntry( unsigned *, vStates, pNext, i ) { printf( "%4d : ", i ); Extra_PrintBinary( stdout, pNext, Aig_ManRegNum(pAig) ); printf( "\n" ); } */ // derive SAT solver nRegs = Aig_ManRegNum(pAig); pAig->nRegs = 0; pCnf = Cnf_Derive( pAig, Aig_ManPoNum(pAig) ); pAig->nRegs = nRegs; // Cnf_DataTranformPolarity( pCnf, 0 ); // convert into SAT solver pSat = (sat_solver *)Cnf_DataWriteIntoSolver( pCnf, 1, 0 ); if ( pSat == NULL ) { printf( "Llb4_Nonlin4TransformCex(): Counter-example generation has failed.\n" ); Cnf_DataFree( pCnf ); return NULL; } // simplify the problem status = sat_solver_simplify(pSat); if ( status == 0 ) { printf( "Llb4_Nonlin4TransformCex(): SAT solver is invalid.\n" ); sat_solver_delete( pSat ); Cnf_DataFree( pCnf ); return NULL; } // start the counter-example pCex = Abc_CexAlloc( Saig_ManRegNum(pAig), Saig_ManPiNum(pAig), Vec_PtrSize(vStates) ); pCex->iFrame = Vec_PtrSize(vStates)-1; pCex->iPo = -1; // solve each time frame iBit = Saig_ManRegNum(pAig); pThis = Vec_PtrEntry( vStates, 0 ); vAssumps = Vec_IntAlloc( 2 * Aig_ManRegNum(pAig) ); Vec_PtrForEachEntryStart( unsigned *, vStates, pNext, i, 1 ) { // create assumptions Vec_IntClear( vAssumps ); Saig_ManForEachLo( pAig, pObj, k ) Vec_IntPush( vAssumps, toLitCond( pCnf->pVarNums[Aig_ObjId(pObj)], !Aig_InfoHasBit(pThis,k) ) ); Saig_ManForEachLi( pAig, pObj, k ) Vec_IntPush( vAssumps, toLitCond( pCnf->pVarNums[Aig_ObjId(pObj)], !Aig_InfoHasBit(pNext,k) ) ); // solve SAT problem status = sat_solver_solve( pSat, Vec_IntArray(vAssumps), Vec_IntArray(vAssumps) + Vec_IntSize(vAssumps), (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 ); // if the problem is SAT, get the counterexample if ( status != l_True ) { printf( "Llb4_Nonlin4TransformCex(): There is no transition between state %d and %d.\n", i-1, i ); Vec_IntFree( vAssumps ); sat_solver_delete( pSat ); Cnf_DataFree( pCnf ); ABC_FREE( pCex ); return NULL; } // get the assignment of PIs Saig_ManForEachPi( pAig, pObj, k ) if ( sat_solver_var_value(pSat, pCnf->pVarNums[Aig_ObjId(pObj)]) ) Aig_InfoSetBit( pCex->pData, iBit + k ); // update the counter iBit += Saig_ManPiNum(pAig); pThis = pNext; } // add the last frame when the property fails Vec_IntClear( vAssumps ); Saig_ManForEachPo( pAig, pObj, k ) Vec_IntPush( vAssumps, toLitCond( pCnf->pVarNums[Aig_ObjId(pObj)], 0 ) ); // add clause status = sat_solver_addclause( pSat, Vec_IntArray(vAssumps), Vec_IntArray(vAssumps) + Vec_IntSize(vAssumps) ); if ( status == 0 ) { printf( "Llb4_Nonlin4TransformCex(): The SAT solver is unsat after adding last clause.\n" ); Vec_IntFree( vAssumps ); sat_solver_delete( pSat ); Cnf_DataFree( pCnf ); ABC_FREE( pCex ); return NULL; } // create assumptions Vec_IntClear( vAssumps ); Saig_ManForEachLo( pAig, pObj, k ) Vec_IntPush( vAssumps, toLitCond( pCnf->pVarNums[Aig_ObjId(pObj)], !Aig_InfoHasBit(pThis,k) ) ); // solve the last frame status = sat_solver_solve( pSat, Vec_IntArray(vAssumps), Vec_IntArray(vAssumps) + Vec_IntSize(vAssumps), (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0, (ABC_INT64_T)0 ); if ( status != l_True ) { printf( "Llb4_Nonlin4TransformCex(): There is no last transition that makes the property fail.\n" ); Vec_IntFree( vAssumps ); sat_solver_delete( pSat ); Cnf_DataFree( pCnf ); ABC_FREE( pCex ); return NULL; } // get the assignment of PIs Saig_ManForEachPi( pAig, pObj, k ) if ( sat_solver_var_value(pSat, pCnf->pVarNums[Aig_ObjId(pObj)]) ) Aig_InfoSetBit( pCex->pData, iBit + k ); iBit += Saig_ManPiNum(pAig); assert( iBit == pCex->nBits ); // free the sat_solver Vec_IntFree( vAssumps ); sat_solver_delete( pSat ); Cnf_DataFree( pCnf ); // verify counter-example status = Saig_ManFindFailedPoCex( pAig, pCex ); if ( status >= 0 && status < Saig_ManPoNum(pAig) ) pCex->iPo = status; else { printf( "Inter_ManGetCounterExample(): Counter-example verification has FAILED.\n" ); ABC_FREE( pCex ); return NULL; } // report the results // if ( fVerbose ) // Abc_PrintTime( 1, "SAT-based cex generation time", clock() - clk ); return pCex; } //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// ABC_NAMESPACE_IMPL_END