pdrCore.c 23.8 KB
Newer Older
1 2 3 4 5 6
/**CFile****************************************************************

  FileName    [pdrCore.c]

  SystemName  [ABC: Logic synthesis and verification system.]

7
  PackageName [Property driven reachability.]
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

  Synopsis    [Core procedures.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - November 20, 2010.]

  Revision    [$Id: pdrCore.c,v 1.00 2010/11/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "pdrInt.h"

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    [Returns 1 if the state could be blocked.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Pdr_ManSetDefaultParams( Pdr_Par_t * pPars )
{
    memset( pPars, 0, sizeof(Pdr_Par_t) );
    pPars->iOutput       =      -1;  // zero-based output number
    pPars->nRecycle      =     300;  // limit on vars for recycling
50
    pPars->nFrameMax     =   10000;  // limit on number of timeframes
51
    pPars->nTimeOut      =       0;  // timeout in seconds
52
    pPars->nConfLimit    =       0;  // limit on SAT solver conflicts
Alan Mishchenko committed
53
    pPars->nRestLimit    =       0;  // limit on the number of proof-obligations
54 55 56 57 58 59
    pPars->fTwoRounds    =       0;  // use two rounds for generalization
    pPars->fMonoCnf      =       0;  // monolythic CNF
    pPars->fDumpInv      =       0;  // dump inductive invariant
    pPars->fShortest     =       0;  // forces bug traces to be shortest
    pPars->fVerbose      =       0;  // verbose output
    pPars->fVeryVerbose  =       0;  // very verbose output
60
    pPars->iFrame        =      -1;  // explored up to this frame
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
}

/**Function*************************************************************

  Synopsis    [Reduces clause using analyzeFinal.]

  Description [Assumes that the SAT solver just terminated an UNSAT call.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Pdr_Set_t * Pdr_ManReduceClause( Pdr_Man_t * p, int k, Pdr_Set_t * pCube )
{
    Pdr_Set_t * pCubeMin;
    Vec_Int_t * vLits;
    int i, Entry, nCoreLits, * pCoreLits;
    // get relevant SAT literals
    nCoreLits = sat_solver_final(Pdr_ManSolver(p, k), &pCoreLits);
    // translate them into register literals and remove auxiliary
    vLits = Pdr_ManLitsToCube( p, k, pCoreLits, nCoreLits );
    // skip if there is no improvement
    if ( Vec_IntSize(vLits) == pCube->nLits )
        return NULL;
    assert( Vec_IntSize(vLits) < pCube->nLits );
    // if the cube overlaps with init, add any literal
    Vec_IntForEachEntry( vLits, Entry, i )
        if ( lit_sign(Entry) == 0 ) // positive literal
            break;
    if ( i == Vec_IntSize(vLits) ) // only negative literals
    {
        // add the first positive literal
        for ( i = 0; i < pCube->nLits; i++ )
            if ( lit_sign(pCube->Lits[i]) == 0 ) // positive literal
            {
                Vec_IntPush( vLits, pCube->Lits[i] );
                break;
            }
        assert( i < pCube->nLits );
    }
    // generate a starting cube
    pCubeMin  = Pdr_SetCreateSubset( pCube, Vec_IntArray(vLits), Vec_IntSize(vLits) );
    assert( !Pdr_SetIsInit(pCubeMin, -1) );
/*
    // make sure the cube works
    {
    int RetValue;
    RetValue = Pdr_ManCheckCube( p, k, pCubeMin, NULL, 0 );
    assert( RetValue );
    }
*/
    return pCubeMin;
}

/**Function*************************************************************

  Synopsis    [Returns 1 if the state could be blocked.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManPushClauses( Pdr_Man_t * p )
{
    Pdr_Set_t * pTemp, * pCubeK, * pCubeK1;
    Vec_Ptr_t * vArrayK, * vArrayK1;
131
    int i, j, k, m, RetValue = 0, RetValue2, kMax = Vec_PtrSize(p->vSolvers)-1;
132
    int Counter = 0;
133
    clock_t clk = clock();
134
    Vec_VecForEachLevelStartStop( p->vClauses, vArrayK, k, 1, kMax )
135 136
    {
        Vec_PtrSort( vArrayK, (int (*)(void))Pdr_SetCompare );
137
        vArrayK1 = Vec_VecEntry( p->vClauses, k+1 );
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
        Vec_PtrForEachEntry( Pdr_Set_t *, vArrayK, pCubeK, j )
        {
            Counter++;

            // remove cubes in the same frame that are contained by pCubeK
            Vec_PtrForEachEntryStart( Pdr_Set_t *, vArrayK, pTemp, m, j+1 )
            {
                if ( !Pdr_SetContains( pTemp, pCubeK ) ) // pCubeK contains pTemp
                    continue;
                Pdr_SetDeref( pTemp );
                Vec_PtrWriteEntry( vArrayK, m, Vec_PtrEntryLast(vArrayK) );
                Vec_PtrPop(vArrayK);
                m--;
            }

            // check if the clause can be moved to the next frame
154 155 156 157
            RetValue2 = Pdr_ManCheckCube( p, k, pCubeK, NULL, 0 );
            if ( RetValue2 == -1 )
                return -1;
            if ( !RetValue2 )
158 159 160 161 162 163 164
                continue;

            {
                Pdr_Set_t * pCubeMin;
                pCubeMin = Pdr_ManReduceClause( p, k, pCubeK );
                if ( pCubeMin != NULL )
                {
165
//                Abc_Print( 1, "%d ", pCubeK->nLits - pCubeMin->nLits );
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
                    Pdr_SetDeref( pCubeK );
                    pCubeK = pCubeMin;
                }
            }

            // if it can be moved, add it to the next frame
            Pdr_ManSolverAddClause( p, k+1, pCubeK );
            // check if the clause subsumes others
            Vec_PtrForEachEntry( Pdr_Set_t *, vArrayK1, pCubeK1, i )
            {
                if ( !Pdr_SetContains( pCubeK1, pCubeK ) ) // pCubeK contains pCubeK1
                    continue;
                Pdr_SetDeref( pCubeK1 );
                Vec_PtrWriteEntry( vArrayK1, i, Vec_PtrEntryLast(vArrayK1) );
                Vec_PtrPop(vArrayK1);
                i--;
            }
            // add the last clause
            Vec_PtrPush( vArrayK1, pCubeK );
            Vec_PtrWriteEntry( vArrayK, j, Vec_PtrEntryLast(vArrayK) );
            Vec_PtrPop(vArrayK);
            j--;
        }
        if ( Vec_PtrSize(vArrayK) == 0 )
            RetValue = 1;
    }

    // clean up the last one
194
    vArrayK = Vec_VecEntry( p->vClauses, kMax );
195 196 197 198 199 200 201 202 203
    Vec_PtrSort( vArrayK, (int (*)(void))Pdr_SetCompare );
    Vec_PtrForEachEntry( Pdr_Set_t *, vArrayK, pCubeK, j )
    {
        // remove cubes in the same frame that are contained by pCubeK
        Vec_PtrForEachEntryStart( Pdr_Set_t *, vArrayK, pTemp, m, j+1 )
        {
            if ( !Pdr_SetContains( pTemp, pCubeK ) ) // pCubeK contains pTemp
                continue;
/*
204
            Abc_Print( 1, "===\n" );
205
            Pdr_SetPrint( stdout, pCubeK, Aig_ManRegNum(p->pAig), NULL );
206
            Abc_Print( 1, "\n" );
207
            Pdr_SetPrint( stdout, pTemp, Aig_ManRegNum(p->pAig), NULL );
208
            Abc_Print( 1, "\n" );
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
*/
            Pdr_SetDeref( pTemp );
            Vec_PtrWriteEntry( vArrayK, m, Vec_PtrEntryLast(vArrayK) );
            Vec_PtrPop(vArrayK);
            m--;
        }
    }
    p->tPush += clock() - clk;
    return RetValue;
}

/**Function*************************************************************

  Synopsis    [Returns 1 if the clause is contained in higher clauses.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManCheckContainment( Pdr_Man_t * p, int k, Pdr_Set_t * pSet )
{
    Pdr_Set_t * pThis;
    Vec_Ptr_t * vArrayK;
    int i, j, kMax = Vec_PtrSize(p->vSolvers)-1;
236
    Vec_VecForEachLevelStartStop( p->vClauses, vArrayK, i, k, kMax+1 )
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
        Vec_PtrForEachEntry( Pdr_Set_t *, vArrayK, pThis, j )
            if ( Pdr_SetContains( pSet, pThis ) )
                return 1;
    return 0;
}


/**Function*************************************************************

  Synopsis    [Sorts literals by priority.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int * Pdr_ManSortByPriority( Pdr_Man_t * p, Pdr_Set_t * pCube )
{
    int * pPrios = Vec_IntArray(p->vPrio);
    int * pArray = p->pOrder;
    int temp, i, j, best_i, nSize = pCube->nLits;
    // initialize variable order
    for ( i = 0; i < nSize; i++ )
        pArray[i] = i;
    for ( i = 0; i < nSize-1; i++ )
    {
        best_i = i;
        for ( j = i+1; j < nSize; j++ )
//            if ( pArray[j] < pArray[best_i] )
            if ( pPrios[pCube->Lits[pArray[j]]>>1] < pPrios[pCube->Lits[pArray[best_i]]>>1] )
                best_i = j;
        temp = pArray[i]; 
        pArray[i] = pArray[best_i]; 
        pArray[best_i] = temp;
    }
/*
    for ( i = 0; i < pCube->nLits; i++ )
276 277
        Abc_Print( 1, "%2d : %5d    %5d  %5d\n", i, pArray[i], pCube->Lits[pArray[i]]>>1, pPrios[pCube->Lits[pArray[i]]>>1] );
    Abc_Print( 1, "\n" );
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
*/
    return pArray;
}


/**Function*************************************************************

  Synopsis    [Returns 1 if the state could be blocked.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManGeneralize( Pdr_Man_t * p, int k, Pdr_Set_t * pCube, Pdr_Set_t ** ppPred, Pdr_Set_t ** ppCubeMin )
{
    Pdr_Set_t * pCubeMin, * pCubeTmp = NULL;
297 298
    int i, j, n, Lit, RetValue;
    clock_t clk = clock();
299 300 301 302 303 304 305 306 307 308 309
    int * pOrder;
    // if there is no induction, return
    *ppCubeMin = NULL;
    RetValue = Pdr_ManCheckCube( p, k, pCube, ppPred, p->pPars->nConfLimit );
    if ( RetValue == -1 )
        return -1;
    if ( RetValue == 0 )
    {
        p->tGeneral += clock() - clk;
        return 0;
    }
310

311 312 313 314 315 316
    // reduce clause using assumptions
//    pCubeMin = Pdr_SetDup( pCube );
    pCubeMin = Pdr_ManReduceClause( p, k, pCube );
    if ( pCubeMin == NULL )
        pCubeMin = Pdr_SetDup( pCube );

317 318
    // perform generalization
    if ( !p->pPars->fSkipGeneral )
319
    {
320 321 322 323
        // sort literals by their occurences
        pOrder = Pdr_ManSortByPriority( p, pCubeMin );
        // try removing literals
        for ( j = 0; j < pCubeMin->nLits; j++ )
324
        {
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
            // use ordering
    //        i = j;
            i = pOrder[j];

            // check init state
            assert( pCubeMin->Lits[i] != -1 );
            if ( Pdr_SetIsInit(pCubeMin, i) )
                continue;
            // try removing this literal
            Lit = pCubeMin->Lits[i]; pCubeMin->Lits[i] = -1; 
            RetValue = Pdr_ManCheckCube( p, k, pCubeMin, NULL, p->pPars->nConfLimit );
            if ( RetValue == -1 )
            {
                Pdr_SetDeref( pCubeMin );
                return -1;
            }
            pCubeMin->Lits[i] = Lit;
            if ( RetValue == 0 )
                continue;

            // remove j-th entry
            for ( n = j; n < pCubeMin->nLits-1; n++ )
                pOrder[n] = pOrder[n+1];
            j--;

            // success - update the cube
            pCubeMin = Pdr_SetCreateFrom( pCubeTmp = pCubeMin, i );
            Pdr_SetDeref( pCubeTmp );
            assert( pCubeMin->nLits > 0 );
            i--;

            // get the ordering by decreasing priorit
            pOrder = Pdr_ManSortByPriority( p, pCubeMin );
358 359
        }

360 361
        if ( p->pPars->fTwoRounds )
        for ( j = 0; j < pCubeMin->nLits; j++ )
362
        {
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
            // use ordering
    //        i = j;
            i = pOrder[j];

            // check init state
            assert( pCubeMin->Lits[i] != -1 );
            if ( Pdr_SetIsInit(pCubeMin, i) )
                continue;
            // try removing this literal
            Lit = pCubeMin->Lits[i]; pCubeMin->Lits[i] = -1; 
            RetValue = Pdr_ManCheckCube( p, k, pCubeMin, NULL, p->pPars->nConfLimit );
            if ( RetValue == -1 )
            {
                Pdr_SetDeref( pCubeMin );
                return -1;
            }
            pCubeMin->Lits[i] = Lit;
            if ( RetValue == 0 )
                continue;

            // remove j-th entry
            for ( n = j; n < pCubeMin->nLits-1; n++ )
                pOrder[n] = pOrder[n+1];
            j--;

            // success - update the cube
            pCubeMin = Pdr_SetCreateFrom( pCubeTmp = pCubeMin, i );
            Pdr_SetDeref( pCubeTmp );
            assert( pCubeMin->nLits > 0 );
            i--;

            // get the ordering by decreasing priorit
            pOrder = Pdr_ManSortByPriority( p, pCubeMin );
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420
        }
    }

    assert( ppCubeMin != NULL );
    *ppCubeMin = pCubeMin;
    p->tGeneral += clock() - clk;
    return 1;
}

/**Function*************************************************************

  Synopsis    [Returns 1 if the state could be blocked.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManBlockCube( Pdr_Man_t * p, Pdr_Set_t * pCube )
{
    Pdr_Obl_t * pThis;
    Pdr_Set_t * pPred, * pCubeMin;
    int i, k, RetValue, Prio = ABC_INFINITY, Counter = 0;
421 422
    int kMax = Vec_PtrSize(p->vSolvers)-1;
    clock_t clk;
423 424 425 426 427 428 429 430 431 432 433 434
    p->nBlocks++;
    // create first proof obligation
    assert( p->pQueue == NULL );
    pThis = Pdr_OblStart( kMax, Prio--, pCube, NULL ); // consume ref
    Pdr_QueuePush( p, pThis );
    // try to solve it recursively
    while ( !Pdr_QueueIsEmpty(p) )
    {
        Counter++;
        pThis = Pdr_QueueHead( p );
        if ( pThis->iFrame == 0 )
            return 0; // SAT
Alan Mishchenko committed
435 436
        if ( p->nQueLim && p->nQueCur >= p->nQueLim )
        {
Alan Mishchenko committed
437
            p->nQueLim = p->nQueLim * 3 / 2;
Alan Mishchenko committed
438 439 440
            Pdr_QueueStop( p );
            return 1; // restart
        }
441 442 443 444 445 446 447 448 449 450 451 452 453 454
        pThis = Pdr_QueuePop( p );
        assert( pThis->iFrame > 0 );
        assert( !Pdr_SetIsInit(pThis->pState, -1) );

        clk = clock();
        if ( Pdr_ManCheckContainment( p, pThis->iFrame, pThis->pState ) )
        {
            p->tContain += clock() - clk;
            Pdr_OblDeref( pThis );
            continue;
        }
        p->tContain += clock() - clk;

        // check if the cube is already contained
455 456 457 458 459 460 461
        RetValue = Pdr_ManCheckCubeCs( p, pThis->iFrame, pThis->pState );
        if ( RetValue == -1 ) // cube is blocked by clauses in this frame
        {
            Pdr_OblDeref( pThis );
            return -1;
        }
        if ( RetValue ) // cube is blocked by clauses in this frame
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
        {
            Pdr_OblDeref( pThis );
            continue;
        }

        // check if the cube holds with relative induction
        pCubeMin = NULL;
        RetValue = Pdr_ManGeneralize( p, pThis->iFrame-1, pThis->pState, &pPred, &pCubeMin );
        if ( RetValue == -1 )
        {
            Pdr_OblDeref( pThis );
            return -1;
        }
        if ( RetValue ) // cube is blocked inductively in this frame
        {
            assert( pCubeMin != NULL );

            // k is the last frame where pCubeMin holds
            k = pThis->iFrame;

            // check other frames
            assert( pPred == NULL );
            for ( k = pThis->iFrame; k < kMax; k++ )
                if ( !Pdr_ManCheckCube( p, k, pCubeMin, NULL, 0 ) )
                    break;

            // add new clause
            if ( p->pPars->fVeryVerbose )
            {
491
            Abc_Print( 1, "Adding cube " );
492
            Pdr_SetPrint( stdout, pCubeMin, Aig_ManRegNum(p->pAig), NULL );
493
            Abc_Print( 1, " to frame %d.\n", k );
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
            }
            // set priority flops
            for ( i = 0; i < pCubeMin->nLits; i++ )
            {
                assert( pCubeMin->Lits[i] >= 0 );
                assert( (pCubeMin->Lits[i] / 2) < Aig_ManRegNum(p->pAig) );
                Vec_IntAddToEntry( p->vPrio, pCubeMin->Lits[i] / 2, 1 );
            }

            Vec_VecPush( p->vClauses, k, pCubeMin );   // consume ref
            p->nCubes++;
            // add clause
            for ( i = 1; i <= k; i++ )
                Pdr_ManSolverAddClause( p, i, pCubeMin );
            // schedule proof obligation
            if ( k < kMax && !p->pPars->fShortest )
            {
                pThis->iFrame = k+1;
                pThis->prio   = Prio--;
                Pdr_QueuePush( p, pThis );
            }
            else
            {
                Pdr_OblDeref( pThis );
            }
        }
        else
        {
            assert( pCubeMin == NULL );
            assert( pPred != NULL );
            pThis->prio = Prio--;
            Pdr_QueuePush( p, pThis );

            pThis = Pdr_OblStart( pThis->iFrame-1, Prio--, pPred, Pdr_OblRef(pThis) );
            Pdr_QueuePush( p, pThis );
        }

        // check the timeout
532
        if ( p->timeToStop && clock() > p->timeToStop )
533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
            return -1;
    }
    return 1;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManSolveInt( Pdr_Man_t * p )
{
    int fPrintClauses = 0;
    Pdr_Set_t * pCube;
    int k, RetValue = -1;
554
    clock_t clkStart = clock();
555
    p->timeToStop = p->pPars->nTimeOut ? p->pPars->nTimeOut * CLOCKS_PER_SEC + clock(): 0;
556 557 558 559 560 561 562 563 564 565 566 567
    assert( Vec_PtrSize(p->vSolvers) == 0 );
    // create the first timeframe
    Pdr_ManCreateSolver( p, (k = 0) );
    while ( 1 )
    {
        p->nFrames = k;
        assert( k == Vec_PtrSize(p->vSolvers)-1 );
        RetValue = Pdr_ManCheckCube( p, k, NULL, &pCube, p->pPars->nConfLimit );
        if ( RetValue == -1 )
        {
            if ( p->pPars->fVerbose ) 
                Pdr_ManPrintProgress( p, 1, clock() - clkStart );
568
            Abc_Print( 1, "Reached conflict limit (%d).\n",  p->pPars->nConfLimit );
569
            p->pPars->iFrame = k;
570 571 572 573 574 575 576 577 578
            return -1;
        }
        if ( RetValue == 0 )
        {
            RetValue = Pdr_ManBlockCube( p, pCube );
            if ( RetValue == -1 )
            {
                if ( p->pPars->fVerbose ) 
                    Pdr_ManPrintProgress( p, 1, clock() - clkStart );
579
                Abc_Print( 1, "Reached conflict limit (%d).\n",  p->pPars->nConfLimit );
580
                p->pPars->iFrame = k;
581 582 583 584 585 586
                return -1;
            }
            if ( RetValue == 0 )
            {
                if ( fPrintClauses )
                {
587
                    Abc_Print( 1, "*** Clauses after frame %d:\n", k );
588 589 590 591
                    Pdr_ManPrintClauses( p, 0 );
                }
                if ( p->pPars->fVerbose ) 
                    Pdr_ManPrintProgress( p, 1, clock() - clkStart );
592
                p->pPars->iFrame = k;
593 594
                return 0; // SAT
            }
Alan Mishchenko committed
595 596
            if ( p->pPars->fVerbose ) 
                Pdr_ManPrintProgress( p, 0, clock() - clkStart );
597 598 599
        }
        else
        {
600 601
            if ( p->pPars->fVerbose ) 
                Pdr_ManPrintProgress( p, 1, clock() - clkStart );
602
            // open a new timeframe
Alan Mishchenko committed
603
            p->nQueLim = p->pPars->nRestLimit;
604 605 606 607 608
            assert( pCube == NULL );
            Pdr_ManSetPropertyOutput( p, k );
            Pdr_ManCreateSolver( p, ++k );
            if ( fPrintClauses )
            {
609
                Abc_Print( 1, "*** Clauses after frame %d:\n", k );
610 611 612
                Pdr_ManPrintClauses( p, 0 );
            }
            // push clauses into this timeframe
613 614 615 616 617
            RetValue = Pdr_ManPushClauses( p );
            if ( RetValue == -1 )
            {
                if ( p->pPars->fVerbose ) 
                    Pdr_ManPrintProgress( p, 1, clock() - clkStart );
618
                Abc_Print( 1, "Reached conflict limit (%d).\n",  p->pPars->nConfLimit );
619 620 621 622
                p->pPars->iFrame = k;
                return -1;
            }
            if ( RetValue )
623 624 625 626 627
            {
                if ( p->pPars->fVerbose ) 
                    Pdr_ManPrintProgress( p, 1, clock() - clkStart );
                Pdr_ManReportInvariant( p );
                Pdr_ManVerifyInvariant( p );
628
                p->pPars->iFrame = k;
629 630 631
                return 1; // UNSAT
            }
            if ( p->pPars->fVerbose ) 
632
                Pdr_ManPrintProgress( p, 0, clock() - clkStart );
Alan Mishchenko committed
633
//            clkStart = clock();
634 635 636
        }

        // check the timeout
637
        if ( p->timeToStop && clock() > p->timeToStop )
638 639 640
        {
            if ( fPrintClauses )
            {
641
                Abc_Print( 1, "*** Clauses after frame %d:\n", k );
642 643 644 645
                Pdr_ManPrintClauses( p, 0 );
            }
            if ( p->pPars->fVerbose ) 
                Pdr_ManPrintProgress( p, 1, clock() - clkStart );
646
            Abc_Print( 1, "Reached timeout (%d seconds).\n",  p->pPars->nTimeOut );
647
            p->pPars->iFrame = k;
648 649 650 651 652 653
            return -1;
        }
        if ( p->pPars->nFrameMax && k >= p->pPars->nFrameMax )
        {
            if ( p->pPars->fVerbose ) 
                Pdr_ManPrintProgress( p, 1, clock() - clkStart );
654
            Abc_Print( 1, "Reached limit on the number of timeframes (%d).\n", p->pPars->nFrameMax );
655
            p->pPars->iFrame = k;
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676
            return -1;
        } 
    }
    return RetValue;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManSolve_( Aig_Man_t * pAig, Pdr_Par_t * pPars, Vec_Int_t ** pvPrioInit, Abc_Cex_t ** ppCex )
{
    Pdr_Man_t * p;
    int RetValue;
677
    clock_t clk = clock();
678 679 680
    p = Pdr_ManStart( pAig, pPars, pvPrioInit? *pvPrioInit : NULL );
    RetValue = Pdr_ManSolveInt( p );
    *ppCex = RetValue ? NULL : Pdr_ManDeriveCex( p );
681 682
    if ( p->pPars->fDumpInv )
        Pdr_ManDumpClauses( p, (char *)"inv.pla", RetValue==1 );
683
//    if ( *ppCex && pPars->fVerbose )
684
//        Abc_Print( 1, "Found counter-example in frame %d after exploring %d frames.\n", 
685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708
//            (*ppCex)->iFrame, p->nFrames );
    p->tTotal += clock() - clk;
    if ( pvPrioInit )
    {
        *pvPrioInit = p->vPrio;
        p->vPrio = NULL;
    }
    Pdr_ManStop( p );
    return RetValue;
}

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Pdr_ManSolve( Aig_Man_t * pAig, Pdr_Par_t * pPars, Abc_Cex_t ** ppCex )
{
709 710
    if ( pPars->fVerbose )
    {
711 712
//    Abc_Print( 1, "Running PDR by Niklas Een (aka IC3 by Aaron Bradley) with these parameters:\n" );
    Abc_Print( 1, "VarMax = %d. FrameMax = %d. QueueMax = %d. TimeMax = %d. ", 
Alan Mishchenko committed
713 714
        pPars->nRecycle, pPars->nFrameMax, pPars->nRestLimit, pPars->nTimeOut );
    if ( pPars->iOutput >= 0 )
715 716
        Abc_Print( 1, "Output = %d. ", pPars->iOutput );
    Abc_Print( 1, "MonoCNF = %s. SkipGen = %s.\n", 
Alan Mishchenko committed
717
        pPars->fMonoCnf ? "yes" : "no", pPars->fSkipGeneral ? "yes" : "no" );
718
    }
Alan Mishchenko committed
719

720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
/*
    Vec_Int_t * vPrioInit = NULL;
    int RetValue, nTimeOut;
    if ( pPars->nTimeOut > 0 )
        return Pdr_ManSolve_( pAig, pPars, NULL, ppCex );
    nTimeOut = pPars->nTimeOut;
    pPars->nTimeOut = 10;
    RetValue = Pdr_ManSolve_( pAig, pPars, &vPrioInit, ppCex );
    pPars->nTimeOut = nTimeOut;
    if ( RetValue == -1 )
        RetValue = Pdr_ManSolve_( pAig, pPars, &vPrioInit, ppCex );
    Vec_IntFree( vPrioInit );
    return RetValue;
*/
    return Pdr_ManSolve_( pAig, pPars, NULL, ppCex );
}

////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END