Advertisement
froleyks

temp.cpp

Aug 11th, 2020
1,297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.44 KB | None | 0 0
  1. /**Function*************************************************************
  2.  
  3.   Synopsis    [Checks if the cube holds (UNSAT) in the given timeframe.]
  4.  
  5.   Description [Return 1/0 if cube or property are proved to hold/fail
  6.   in k-th timeframe.  Returns the predecessor bad state in ppPred.]
  7.                
  8.   SideEffects []
  9.  
  10.   SeeAlso     []
  11.  
  12. ***********************************************************************/
  13. int Pdr_ManCheckCube( Pdr_Man_t * p, int k, Pdr_Set_t * pCube, Pdr_Set_t ** ppPred, int nConfLimit, int fTryConf, int fUseLit )
  14. {
  15.     //int fUseLit = 0;
  16.     int fLitUsed = 0;
  17.     sat_solver * pSat;
  18.     Vec_Int_t * vLits;
  19.     int Lit, RetValue;
  20.     abctime clk, Limit;
  21.     p->nCalls++;
  22.     pSat = Pdr_ManFetchSolver( p, k );
  23.     if ( pCube == NULL ) // solve the property
  24.     {
  25.         clk = Abc_Clock();
  26.         Lit = Abc_Var2Lit( Pdr_ObjSatVar(p, k, 2, Aig_ManCo(p->pAig, p->iOutCur)), 0 ); // pos literal (property fails)
  27.         Limit = sat_solver_set_runtime_limit( pSat, Pdr_ManTimeLimit(p) );
  28.         RetValue = CADICAL_sat_solver_solve( pSat, &Lit, &Lit + 1, nConfLimit, 0, 0, 0 );
  29.         sat_solver_set_runtime_limit( pSat, Limit );
  30.         if ( RetValue == l_Undef )
  31.             return -1;
  32.     }
  33.     else // check relative containment in terms of next states
  34.     {
  35.         if ( fUseLit )
  36.         {
  37.             fLitUsed = 1;
  38.             Vec_IntAddToEntry( p->vActVars, k, 1 );
  39.             // add the cube in terms of current state variables
  40.             vLits = Pdr_ManCubeToLits( p, k, pCube, 1, 0 );
  41.             // add activation literal
  42.             Lit = Abc_Var2Lit( Pdr_ManFreeVar(p, k), 0 );
  43.             // add activation literal
  44.             Vec_IntPush( vLits, Lit );
  45.             RetValue = sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits) );
  46.             assert( RetValue == 1 );
  47.             sat_solver_compress( pSat );
  48.             // create assumptions
  49.             vLits = Pdr_ManCubeToLits( p, k, pCube, 0, 1 );
  50.             // add activation literal
  51.             Vec_IntPush( vLits, Abc_LitNot(Lit) );
  52.         }
  53.         else
  54.             vLits = Pdr_ManCubeToLits( p, k, pCube, 0, 1 );
  55.  
  56.         // solve
  57.         clk = Abc_Clock();
  58.         Limit = sat_solver_set_runtime_limit( pSat, Pdr_ManTimeLimit(p) );
  59.         RetValue = CADICAL_sat_solver_solve( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + Vec_IntSize(vLits), fTryConf ? p->pPars->nConfGenLimit : nConfLimit, 0, 0, 0 );
  60.         sat_solver_set_runtime_limit( pSat, Limit );
  61.         if ( RetValue == l_Undef )
  62.         {
  63.             if ( fTryConf && p->pPars->nConfGenLimit )
  64.                 RetValue = l_True;
  65.             else
  66.                 return -1;
  67.         }
  68.     }
  69.     clk = Abc_Clock() - clk;
  70.     p->tSat += clk;
  71.     assert( RetValue != l_Undef );
  72.     if ( RetValue == l_False )
  73.     {
  74.         p->tSatUnsat += clk;
  75.         p->nCallsU++;
  76.         if ( ppPred )
  77.             *ppPred = NULL;
  78.         RetValue = 1;
  79.     }
  80.     else // if ( RetValue == l_True )
  81.     {
  82.         p->tSatSat += clk;
  83.         p->nCallsS++;
  84.         if ( ppPred )
  85.         {
  86.             abctime clk = Abc_Clock();
  87.             if ( p->pPars->fNewXSim )
  88.                 *ppPred = Txs3_ManTernarySim( p->pTxs3, k, pCube );
  89.             else
  90.                 *ppPred = Pdr_ManTernarySim( p, k, pCube );
  91.             p->tTsim += Abc_Clock() - clk;
  92.             p->nXsimLits += (*ppPred)->nLits;
  93.             p->nXsimRuns++;
  94.         }
  95.         RetValue = 0;
  96.     }
  97.  
  98. /* // for some reason, it does not work...
  99.     if ( fLitUsed )
  100.     {
  101.         int RetValue;
  102.         Lit = Abc_LitNot(Lit);
  103.         RetValue = sat_solver_addclause( pSat, &Lit, &Lit + 1 );
  104.         assert( RetValue == 1 );
  105.         sat_solver_compress( pSat );
  106.     }
  107. */
  108.     return RetValue;
  109. }
  110.  
  111.  
  112. /**Function*************************************************************
  113.  
  114.   Synopsis    [Converts the cube in terms of RO numbers into array of CNF literals.]
  115.  
  116.   Description []
  117.                
  118.   SideEffects []
  119.  
  120.   SeeAlso     []
  121.  
  122. ***********************************************************************/
  123. Vec_Int_t * Pdr_ManCubeToLits( Pdr_Man_t * p, int k, Pdr_Set_t * pCube, int fCompl, int fNext )
  124. {
  125.     Aig_Obj_t * pObj;
  126.     int i, iVar, iVarMax = 0;
  127.     abctime clk = Abc_Clock();
  128.     Vec_IntClear( p->vLits );
  129. //    assert( !(fNext && fCompl) );
  130.     for ( i = 0; i < pCube->nLits; i++ )
  131.     {
  132.         if ( pCube->Lits[i] == -1 )
  133.             continue;
  134.         if ( fNext )
  135.             pObj = Saig_ManLi( p->pAig, Abc_Lit2Var(pCube->Lits[i]) );
  136.         else
  137.             pObj = Saig_ManLo( p->pAig, Abc_Lit2Var(pCube->Lits[i]) );
  138.         iVar = Pdr_ObjSatVar( p, k, fNext ? 2 - Abc_LitIsCompl(pCube->Lits[i]) : 3, pObj ); assert( iVar >= 0 );
  139.         iVarMax = Abc_MaxInt( iVarMax, iVar );
  140.         Vec_IntPush( p->vLits, Abc_Var2Lit( iVar, fCompl ^ Abc_LitIsCompl(pCube->Lits[i]) ) );
  141.     }
  142. //    sat_solver_setnvars( Pdr_ManSolver(p, k), iVarMax + 1 );
  143.     p->tCnf += Abc_Clock() - clk;
  144.     return p->vLits;
  145. }
  146.  
  147. int CADICAL_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)
  148. {
  149.   /* printf("\nsolve %d\n", s); */
  150.   lit *i, l;
  151.   assert(begin < end);
  152.   for (i = begin; i < end; i++) {
  153.     l = ((*i) >> 1) * ((*i) & 1 ? -1 : 1);
  154.     /* printf("Assume %d %d\n", l, s); */
  155.     ccadical_assume(s, l);
  156.   }
  157.   int result = ccadical_solve(s);
  158.   if (result == 10) {
  159.     /* printf("SAT %d \n", s); */
  160.     return l_True;
  161.   } else if (result == 20) {
  162.     /* printf("UNSAT %d \n", s); */
  163.     return l_False;
  164.   }
  165.   return l_Undef;
  166. }
  167.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement