cecCore.c 20.6 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6
/**CFile****************************************************************

  FileName    [cecCore.c]

  SystemName  [ABC: Logic synthesis and verification system.]

Alan Mishchenko committed
7
  PackageName [Combinational equivalence checking.]
Alan Mishchenko committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

  Synopsis    [Core procedures.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: cecCore.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

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

#include "cecInt.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []
Alan Mishchenko committed
43
 
Alan Mishchenko committed
44 45 46 47
***********************************************************************/
void Cec_ManSatSetDefaultParams( Cec_ParSat_t * p )
{
    memset( p, 0, sizeof(Cec_ParSat_t) );
48
    p->SolverType     =      -1;  // SAT solver type
Alan Mishchenko committed
49
    p->nBTLimit       =     100;  // conflict limit at a node
Alan Mishchenko committed
50
    p->nSatVarMax     =    2000;  // the max number of SAT variables
Alan Mishchenko committed
51
    p->nCallsRecycle  =     200;  // calls to perform before recycling SAT solver
52
    p->fNonChrono     =       1;  // use non-chronological backtracling (for circuit SAT only)
Alan Mishchenko committed
53
    p->fPolarFlip     =       1;  // flops polarity of variables
Alan Mishchenko committed
54
    p->fCheckMiter    =       0;  // the circuit is the miter
Alan Mishchenko committed
55
//    p->fFirstStop     =       0;  // stop on the first sat output
Alan Mishchenko committed
56
    p->fLearnCls      =       0;  // perform clause learning
Alan Mishchenko committed
57
    p->fVerbose       =       0;  // verbose stats
Alan Mishchenko committed
58
}  
Alan Mishchenko committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73

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

  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cec_ManSimSetDefaultParams( Cec_ParSim_t * p )
{
    memset( p, 0, sizeof(Cec_ParSim_t) );
Alan Mishchenko committed
74 75 76 77
    p->nWords         =      31;  // the number of simulation words
    p->nFrames        =     100;  // the number of simulation frames
    p->nRounds        =      20;  // the max number of simulation rounds
    p->nNonRefines    =       3;  // the max number of rounds without refinement
Alan Mishchenko committed
78 79
    p->TimeLimit      =       0;  // the runtime limit in seconds
    p->fCheckMiter    =       0;  // the circuit is the miter
Alan Mishchenko committed
80
//    p->fFirstStop     =       0;  // stop on the first sat output
Alan Mishchenko committed
81
    p->fDualOut       =       0;  // miter with separate outputs
82
    p->fConstCorr     =       0;  // consider only constants
Alan Mishchenko committed
83 84 85 86
    p->fSeqSimulate   =       0;  // performs sequential simulation
    p->fVeryVerbose   =       0;  // verbose stats
    p->fVerbose       =       0;  // verbose stats
} 
Alan Mishchenko committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

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

  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cec_ManSmfSetDefaultParams( Cec_ParSmf_t * p )
{
    memset( p, 0, sizeof(Cec_ParSmf_t) );
Alan Mishchenko committed
102
    p->nWords         =      31;  // the number of simulation words
Alan Mishchenko committed
103 104 105 106
    p->nRounds        =     200;  // the number of simulation rounds
    p->nFrames        =     200;  // the max number of time frames
    p->nNonRefines    =       3;  // the max number of rounds without refinement
    p->nMinOutputs    =       0;  // the min outputs to accumulate
Alan Mishchenko committed
107
    p->nBTLimit       =     100;  // conflict limit at a node
Alan Mishchenko committed
108 109 110
    p->TimeLimit      =       0;  // the runtime limit in seconds
    p->fDualOut       =       0;  // miter with separate outputs
    p->fCheckMiter    =       0;  // the circuit is the miter
Alan Mishchenko committed
111
//    p->fFirstStop     =       0;  // stop on the first sat output
Alan Mishchenko committed
112 113 114
    p->fVerbose       =       0;  // verbose stats
} 

Alan Mishchenko committed
115
/**Function************  *************************************************
Alan Mishchenko committed
116 117 118 119 120 121 122 123 124 125

  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
126
void Cec_ManFraSetDefaultParams( Cec_ParFra_t * p )
Alan Mishchenko committed
127
{
Alan Mishchenko committed
128 129 130 131
    memset( p, 0, sizeof(Cec_ParFra_t) );
    p->nWords         =      15;  // the number of simulation words
    p->nRounds        =      15;  // the number of simulation rounds
    p->TimeLimit      =       0;  // the runtime limit in seconds
Alan Mishchenko committed
132 133
    p->nItersMax      =      10;  // the maximum number of iterations of SAT sweeping
    p->nBTLimit       =     100;  // conflict limit at a node
Alan Mishchenko committed
134 135 136
    p->nLevelMax      =       0;  // restriction on the level of nodes to be swept
    p->nDepthMax      =       1;  // the depth in terms of steps of speculative reduction
    p->fRewriting     =       0;  // enables AIG rewriting
Alan Mishchenko committed
137
    p->fCheckMiter    =       0;  // the circuit is the miter
Alan Mishchenko committed
138
//    p->fFirstStop     =       0;  // stop on the first sat output
Alan Mishchenko committed
139
    p->fDualOut       =       0;  // miter with separate outputs
Alan Mishchenko committed
140
    p->fColorDiff     =       0;  // miter with separate outputs
141
    p->fSatSweeping   =       0;  // enable SAT sweeping
142
    p->fUseCones      =       0;  // use cones
Alan Mishchenko committed
143 144
    p->fVeryVerbose   =       0;  // verbose stats
    p->fVerbose       =       0;  // verbose stats
145
    p->iOutFail       =      -1;  // the failed output
Alan Mishchenko committed
146
} 
Alan Mishchenko committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161

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

  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cec_ManCecSetDefaultParams( Cec_ParCec_t * p )
{
    memset( p, 0, sizeof(Cec_ParCec_t) );
Alan Mishchenko committed
162 163
    p->nBTLimit       =    1000;  // conflict limit at a node
    p->TimeLimit      =       0;  // the runtime limit in seconds
Alan Mishchenko committed
164
//    p->fFirstStop     =       0;  // stop on the first sat output
Alan Mishchenko committed
165 166
    p->fUseSmartCnf   =       0;  // use smart CNF computation
    p->fRewriting     =       0;  // enables AIG rewriting
Alan Mishchenko committed
167 168
    p->fVeryVerbose   =       0;  // verbose stats
    p->fVerbose       =       0;  // verbose stats
169
    p->iOutFail       =      -1;  // the number of failed output
Alan Mishchenko committed
170
}  
Alan Mishchenko committed
171 172 173

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

Alan Mishchenko committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cec_ManCorSetDefaultParams( Cec_ParCor_t * p )
{
    memset( p, 0, sizeof(Cec_ParCor_t) );
    p->nWords         =      15;  // the number of simulation words
    p->nRounds        =      15;  // the number of simulation rounds
    p->nFrames        =       1;  // the number of time frames
    p->nBTLimit       =     100;  // conflict limit at a node
190 191
    p->nLevelMax      =      -1;  // (scorr only) the max number of levels
    p->nStepsMax      =      -1;  // (scorr only) the max number of induction steps
Alan Mishchenko committed
192
    p->fLatchCorr     =       0;  // consider only latch outputs
193
    p->fConstCorr     =       0;  // consider only constants
Alan Mishchenko committed
194 195
    p->fUseRings      =       1;  // combine classes into rings
    p->fUseCSat       =       1;  // use circuit-based solver
Alan Mishchenko committed
196
//    p->fFirstStop     =       0;  // stop on the first sat output
Alan Mishchenko committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
    p->fUseSmartCnf   =       0;  // use smart CNF computation
    p->fVeryVerbose   =       0;  // verbose stats
    p->fVerbose       =       0;  // verbose stats
}  

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

  Synopsis    [This procedure sets default parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cec_ManChcSetDefaultParams( Cec_ParChc_t * p )
{
    memset( p, 0, sizeof(Cec_ParChc_t) );
    p->nWords         =      15;  // the number of simulation words
    p->nRounds        =      15;  // the number of simulation rounds
    p->nBTLimit       =    1000;  // conflict limit at a node
Alan Mishchenko committed
219 220
    p->fUseRings      =       1;  // use rings
    p->fUseCSat       =       0;  // use circuit-based solver
Alan Mishchenko committed
221 222 223 224 225 226
    p->fVeryVerbose   =       0;  // verbose stats
    p->fVerbose       =       0;  // verbose stats
}  

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

Alan Mishchenko committed
227
  Synopsis    [Core procedure for SAT sweeping.]
Alan Mishchenko committed
228 229 230 231 232 233 234 235

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
236
Gia_Man_t * Cec_ManSatSolving( Gia_Man_t * pAig, Cec_ParSat_t * pPars, int f0Proved )
Alan Mishchenko committed
237
{
Alan Mishchenko committed
238 239 240
    Gia_Man_t * pNew;
    Cec_ManPat_t * pPat;
    pPat = Cec_ManPatStart();
241 242 243 244
    if ( pPars->SolverType == -1 )
        Cec_ManSatSolve( pPat, pAig, pPars, NULL, NULL, NULL, f0Proved );
    else
        CecG_ManSatSolve( pPat, pAig, pPars, f0Proved );
Alan Mishchenko committed
245
//    pNew = Gia_ManDupDfsSkip( pAig );
246
    pNew = Gia_ManCleanup( pAig );
Alan Mishchenko committed
247
    Cec_ManPatStop( pPat );
248 249
    pNew->vSeqModelVec = pAig->vSeqModelVec;
    pAig->vSeqModelVec = NULL;
Alan Mishchenko committed
250
    return pNew;
Alan Mishchenko committed
251 252
}

Alan Mishchenko committed
253 254 255 256
/**Function*************************************************************

  Synopsis    [Core procedure for simulation.]

Alan Mishchenko committed
257
  Description [Returns 1 if refinement has happened.]
Alan Mishchenko committed
258 259 260 261 262 263
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
264
int Cec_ManSimulationOne( Gia_Man_t * pAig, Cec_ParSim_t * pPars )
Alan Mishchenko committed
265 266
{
    Cec_ManSim_t * pSim;
267
    int RetValue = 0;
268
    abctime clkTotal = Abc_Clock();
Alan Mishchenko committed
269
    pSim = Cec_ManSimStart( pAig, pPars );
270
    if ( (pAig->pReprs == NULL && (RetValue = Cec_ManSimClassesPrepare( pSim, -1 ))) ||
Alan Mishchenko committed
271
         (RetValue == 0 &&        (RetValue = Cec_ManSimClassesRefine( pSim ))) )
272
        Abc_Print( 1, "The number of failed outputs of the miter = %6d. (Words = %4d. Frames = %4d.)\n", 
Alan Mishchenko committed
273
            pSim->nOuts, pPars->nWords, pPars->nFrames );
Alan Mishchenko committed
274
    if ( pPars->fVerbose )
275
        Abc_PrintTime( 1, "Time", Abc_Clock() - clkTotal );
Alan Mishchenko committed
276
    Cec_ManSimStop( pSim );
Alan Mishchenko committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
    return RetValue;
}

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

  Synopsis    [Core procedure for simulation.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Cec_ManSimulation( Gia_Man_t * pAig, Cec_ParSim_t * pPars )
{
    int r, nLitsOld, nLitsNew, nCountNoRef = 0, fStop = 0;
    Gia_ManRandom( 1 );
    if ( pPars->fSeqSimulate )
296
        Abc_Print( 1, "Performing rounds of random simulation of %d frames with %d words.\n", 
Alan Mishchenko committed
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
            pPars->nRounds, pPars->nFrames, pPars->nWords );
    nLitsOld = Gia_ManEquivCountLits( pAig );
    for ( r = 0; r < pPars->nRounds; r++ )
    {
        if ( Cec_ManSimulationOne( pAig, pPars ) )
        {
            fStop = 1;
            break;
        }
        // decide when to stop
        nLitsNew = Gia_ManEquivCountLits( pAig );
        if ( nLitsOld == 0 || nLitsOld > nLitsNew )
        {
            nLitsOld = nLitsNew;
            nCountNoRef = 0;
        }
        else if ( ++nCountNoRef == pPars->nNonRefines )
        {
            r++;
            break;
        }
        assert( nLitsOld == nLitsNew );
    }
//    if ( pPars->fVerbose )
    if ( r == pPars->nRounds || fStop )
322
        Abc_Print( 1, "Random simulation is stopped after %d rounds.\n", r );
Alan Mishchenko committed
323
    else
324
        Abc_Print( 1, "Random simulation saturated after %d rounds.\n", r );
Alan Mishchenko committed
325 326 327 328
    if ( pPars->fCheckMiter )
    {
        int nNonConsts = Cec_ManCountNonConstOutputs( pAig );
        if ( nNonConsts )
329
            Abc_Print( 1, "The number of POs that are not const-0 candidates = %d.\n", nNonConsts );
Alan Mishchenko committed
330
    }
Alan Mishchenko committed
331
}
Alan Mishchenko committed
332

Alan Mishchenko committed
333 334
/**Function*************************************************************

Alan Mishchenko committed
335
  Synopsis    [Core procedure for SAT sweeping.]
Alan Mishchenko committed
336 337 338 339 340 341 342 343

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
344
Gia_Man_t * Cec_ManSatSweeping( Gia_Man_t * pAig, Cec_ParFra_t * pPars, int fSilent )
Alan Mishchenko committed
345
{
Alan Mishchenko committed
346
    int fOutputResult = 0;
Alan Mishchenko committed
347
    Cec_ParSat_t ParsSat, * pParsSat = &ParsSat;
Alan Mishchenko committed
348 349 350 351
    Cec_ParSim_t ParsSim, * pParsSim = &ParsSim;
    Gia_Man_t * pIni, * pSrm, * pTemp;
    Cec_ManFra_t * p;
    Cec_ManSim_t * pSim;
Alan Mishchenko committed
352
    Cec_ManPat_t * pPat;
353
    int i, fTimeOut = 0, nMatches = 0;
354
    abctime clk, clk2, clkTotal = Abc_Clock();
355 356
    if ( pPars->fVerbose )
        printf( "Simulating %d words for %d rounds. SAT solving with %d conflicts.\n", pPars->nWords, pPars->nRounds, pPars->nBTLimit );
Alan Mishchenko committed
357 358

    // duplicate AIG and transfer equivalence classes
Alan Mishchenko committed
359
    Gia_ManRandom( 1 );
Alan Mishchenko committed
360 361 362
    pIni = Gia_ManDup(pAig);
    pIni->pReprs = pAig->pReprs; pAig->pReprs = NULL;
    pIni->pNexts = pAig->pNexts; pAig->pNexts = NULL;
363 364 365 366 367 368
    if ( pPars->fUseOrigIds )
    {
        Gia_ManOrigIdsInit( pIni );
        Vec_IntFreeP( &pAig->vIdsEquiv );
        pAig->vIdsEquiv = Vec_IntAlloc( 1000 );
    }
369 370 371 372 373
    if ( pAig->vSimsPi )
    {
        pIni->vSimsPi = Vec_WrdDup(pAig->vSimsPi); 
        pIni->nSimWords = pAig->nSimWords;
    }
Alan Mishchenko committed
374 375 376 377

    // prepare the managers
    // SAT sweeping
    p = Cec_ManFraStart( pIni, pPars );
Alan Mishchenko committed
378
    if ( pPars->fDualOut )
Alan Mishchenko committed
379 380 381
        pPars->fColorDiff = 1;
    // simulation
    Cec_ManSimSetDefaultParams( pParsSim );
382
    pParsSim->nWords      = Abc_MaxInt(2*pAig->nSimWords, pPars->nWords);
Alan Mishchenko committed
383
    pParsSim->nFrames     = pPars->nRounds;
Alan Mishchenko committed
384
    pParsSim->fCheckMiter = pPars->fCheckMiter;
385
    pParsSim->fDualOut    = pPars->fDualOut;
Alan Mishchenko committed
386
    pParsSim->fVerbose    = pPars->fVerbose;
387
    pSim = Cec_ManSimStart( pIni, pParsSim );
Alan Mishchenko committed
388
    // SAT solving
Alan Mishchenko committed
389 390 391
    Cec_ManSatSetDefaultParams( pParsSat );
    pParsSat->nBTLimit = pPars->nBTLimit;
    pParsSat->fVerbose = pPars->fVeryVerbose;
Alan Mishchenko committed
392
    // simulation patterns
Alan Mishchenko committed
393
    pPat = Cec_ManPatStart();
394
    //pPat->fVerbose = pPars->fVeryVerbose;
Alan Mishchenko committed
395 396

    // start equivalence classes
397
clk = Abc_Clock();
Alan Mishchenko committed
398 399
    if ( p->pAig->pReprs == NULL )
    {
400
        if ( Cec_ManSimClassesPrepare(pSim, -1) || (!p->pAig->nSimWords && Cec_ManSimClassesRefine(pSim)) )
Alan Mishchenko committed
401 402 403 404 405 406
        {
            Gia_ManStop( p->pAig );
            p->pAig = NULL;
            goto finalize;
        }
    }
407
p->timeSim += Abc_Clock() - clk;
Alan Mishchenko committed
408
    // perform solving
Alan Mishchenko committed
409
    for ( i = 1; i <= pPars->nItersMax; i++ )
Alan Mishchenko committed
410
    {
411
        clk2 = Abc_Clock();
Alan Mishchenko committed
412
        nMatches = 0;
Alan Mishchenko committed
413
        if ( pPars->fDualOut )
Alan Mishchenko committed
414
        {
Alan Mishchenko committed
415 416 417
            nMatches = Gia_ManEquivSetColors( p->pAig, pPars->fVeryVerbose );
//            p->pAig->pIso = Cec_ManDetectIsomorphism( p->pAig );
//            Gia_ManEquivTransform( p->pAig, 1 );
Alan Mishchenko committed
418
        }
Alan Mishchenko committed
419
        pSrm = Cec_ManFraSpecReduction( p ); 
Alan Mishchenko committed
420

421
//        Gia_AigerWrite( pSrm, "gia_srm.aig", 0, 0, 0 );
Alan Mishchenko committed
422

Alan Mishchenko committed
423
        if ( pPars->fVeryVerbose )
424
            Gia_ManPrintStats( pSrm, NULL );
Alan Mishchenko committed
425
        if ( Gia_ManCoNum(pSrm) == 0 )
Alan Mishchenko committed
426
        {
Alan Mishchenko committed
427 428
            Gia_ManStop( pSrm );
            if ( p->pPars->fVerbose )
429
                Abc_Print( 1, "Considered all available candidate equivalences.\n" );
Alan Mishchenko committed
430
            if ( pPars->fDualOut && Gia_ManAndNum(p->pAig) > 0 )
Alan Mishchenko committed
431 432 433 434
            {
                if ( pPars->fColorDiff )
                {
                    if ( p->pPars->fVerbose )
435
                        Abc_Print( 1, "Switching into reduced mode.\n" );
Alan Mishchenko committed
436 437 438 439 440
                    pPars->fColorDiff = 0;
                }
                else
                {
                    if ( p->pPars->fVerbose )
441
                        Abc_Print( 1, "Switching into normal mode.\n" );
Alan Mishchenko committed
442
                    pPars->fDualOut = 0;
Alan Mishchenko committed
443 444 445
                }
                continue;
            }
Alan Mishchenko committed
446
            break;
Alan Mishchenko committed
447
        }
448
clk = Abc_Clock();
449 450 451
        if ( pPars->fRunCSat )
            Cec_ManSatSolveCSat( pPat, pSrm, pParsSat ); 
        else
452
            Cec_ManSatSolve( pPat, pSrm, pParsSat, p->pAig->vIdsOrig, p->vXorNodes, pAig->vIdsEquiv, 0 ); 
453
p->timeSat += Abc_Clock() - clk;
Alan Mishchenko committed
454 455 456 457 458 459 460 461 462 463
        if ( Cec_ManFraClassesUpdate( p, pSim, pPat, pSrm ) )
        {
            Gia_ManStop( pSrm );
            Gia_ManStop( p->pAig );
            p->pAig = NULL;
            goto finalize;
        }
        Gia_ManStop( pSrm );

        // update the manager
Alan Mishchenko committed
464
        pSim->pAig = p->pAig = Gia_ManEquivReduceAndRemap( pTemp = p->pAig, 0, pParsSim->fDualOut );
Alan Mishchenko committed
465
        if ( p->pAig == NULL )
Alan Mishchenko committed
466 467
        {
            p->pAig = pTemp;
Alan Mishchenko committed
468
            break;
Alan Mishchenko committed
469 470
        }
        Gia_ManStop( pTemp );
Alan Mishchenko committed
471
        if ( p->pPars->fVerbose )
Alan Mishchenko committed
472
        {
473
            Abc_Print( 1, "%3d : P =%7d. D =%7d. F =%6d. M = %7d. And =%8d. ", 
Alan Mishchenko committed
474
                i, p->nAllProved, p->nAllDisproved, p->nAllFailed, nMatches, Gia_ManAndNum(p->pAig) );
475
            Abc_PrintTime( 1, "Time", Abc_Clock() - clk2 );
Alan Mishchenko committed
476
        }
Alan Mishchenko committed
477
        if ( Gia_ManAndNum(p->pAig) == 0 )
Alan Mishchenko committed
478
        {
Alan Mishchenko committed
479
            if ( p->pPars->fVerbose )
480
                Abc_Print( 1, "Network after reduction is empty.\n" );
Alan Mishchenko committed
481
            break;
Alan Mishchenko committed
482
        }
Alan Mishchenko committed
483
        // check resource limits
484
        if ( p->pPars->TimeLimit && (Abc_Clock() - clkTotal)/CLOCKS_PER_SEC >= p->pPars->TimeLimit )
Alan Mishchenko committed
485
        {
Alan Mishchenko committed
486
            fTimeOut = 1;
Alan Mishchenko committed
487
            break;
Alan Mishchenko committed
488
        }
Alan Mishchenko committed
489 490 491
//        if ( p->nAllFailed && !p->nAllProved && !p->nAllDisproved )
        if ( p->nAllFailed > p->nAllProved + p->nAllDisproved )
        {
Alan Mishchenko committed
492
            if ( pParsSat->nBTLimit >= 10001 )
Alan Mishchenko committed
493
                break;
494 495 496 497 498 499
            if ( pPars->fSatSweeping )
            {
                if ( p->pPars->fVerbose )
                    Abc_Print( 1, "Exceeded the limit on the number of conflicts (%d).\n", pParsSat->nBTLimit );
                break;
            }
Alan Mishchenko committed
500 501 502 503
            pParsSat->nBTLimit *= 10;
            if ( p->pPars->fVerbose )
            {
                if ( p->pPars->fVerbose )
504
                    Abc_Print( 1, "Increasing conflict limit to %d.\n", pParsSat->nBTLimit );
Alan Mishchenko committed
505 506
                if ( fOutputResult )
                {
507
                    Gia_AigerWrite( p->pAig, "gia_cec_temp.aig", 0, 0, 0 );
508
                    Abc_Print( 1,"The result is written into file \"%s\".\n", "gia_cec_temp.aig" );
Alan Mishchenko committed
509 510 511
                }
            }
        }
Alan Mishchenko committed
512
        if ( pPars->fDualOut && pPars->fColorDiff && (Gia_ManAndNum(p->pAig) < 100000 || p->nAllProved + p->nAllDisproved < 10) )
Alan Mishchenko committed
513 514
        {
            if ( p->pPars->fVerbose )
515
                Abc_Print( 1, "Switching into reduced mode.\n" );
Alan Mishchenko committed
516 517
            pPars->fColorDiff = 0;
        }
Alan Mishchenko committed
518 519
//        if ( pPars->fDualOut && Gia_ManAndNum(p->pAig) < 20000 )
        else if ( pPars->fDualOut && (Gia_ManAndNum(p->pAig) < 20000 || p->nAllProved + p->nAllDisproved < 10) )
Alan Mishchenko committed
520 521
        {
            if ( p->pPars->fVerbose )
522
                Abc_Print( 1, "Switching into normal mode.\n" );
Alan Mishchenko committed
523
            pPars->fColorDiff = 0;
Alan Mishchenko committed
524
            pPars->fDualOut = 0;
Alan Mishchenko committed
525
        }
Alan Mishchenko committed
526
    }
Alan Mishchenko committed
527
finalize:
528 529 530
    if ( pPars->fVerbose )
        printf( "Performed %d SAT calls: P = %d  D = %d  F = %d\n", 
            p->nAllProvedS + p->nAllDisprovedS + p->nAllFailedS, p->nAllProvedS, p->nAllDisprovedS, p->nAllFailedS );
531
    if ( p->pPars->fVerbose && p->pAig )
Alan Mishchenko committed
532
    {
533
        Abc_Print( 1, "NBeg = %d. NEnd = %d. (Gain = %6.2f %%).  RBeg = %d. REnd = %d. (Gain = %6.2f %%).\n", 
Alan Mishchenko committed
534 535 536 537
            Gia_ManAndNum(pAig), Gia_ManAndNum(p->pAig), 
            100.0*(Gia_ManAndNum(pAig)-Gia_ManAndNum(p->pAig))/(Gia_ManAndNum(pAig)?Gia_ManAndNum(pAig):1), 
            Gia_ManRegNum(pAig), Gia_ManRegNum(p->pAig), 
            100.0*(Gia_ManRegNum(pAig)-Gia_ManRegNum(p->pAig))/(Gia_ManRegNum(pAig)?Gia_ManRegNum(pAig):1) );
538 539 540 541
        Abc_PrintTimeP( 1, "Sim ", p->timeSim, Abc_Clock() - (int)clkTotal );
        Abc_PrintTimeP( 1, "Sat ", p->timeSat-pPat->timeTotalSave, Abc_Clock() - (int)clkTotal );
        Abc_PrintTimeP( 1, "Pat ", p->timePat+pPat->timeTotalSave, Abc_Clock() - (int)clkTotal );
        Abc_PrintTime( 1, "Time", (int)(Abc_Clock() - clkTotal) );
Alan Mishchenko committed
542
    }
Alan Mishchenko committed
543

Alan Mishchenko committed
544
    pTemp = p->pAig; p->pAig = NULL;
Alan Mishchenko committed
545
    if ( pTemp == NULL && pSim->iOut >= 0 )
546
    {
547
        if ( !fSilent )
548 549 550
        Abc_Print( 1, "Disproved at least one output of the miter (zero-based number %d).\n", pSim->iOut );
        pPars->iOutFail = pSim->iOut;
    }
551
    else if ( pSim->pCexes && !fSilent )
552
        Abc_Print( 1, "Disproved %d outputs of the miter.\n", pSim->nOuts );
553
    if ( fTimeOut && !fSilent )
554
        Abc_Print( 1, "Timed out after %d seconds.\n", (int)((double)Abc_Clock() - clkTotal)/CLOCKS_PER_SEC );
Alan Mishchenko committed
555 556 557

    pAig->pCexComb = pSim->pCexComb; pSim->pCexComb = NULL;
    Cec_ManSimStop( pSim );
Alan Mishchenko committed
558
    Cec_ManPatStop( pPat );
Alan Mishchenko committed
559
    Cec_ManFraStop( p );
560 561
    if ( pTemp ) ABC_FREE( pTemp->pReprs );
    if ( pTemp ) ABC_FREE( pTemp->pNexts );
Alan Mishchenko committed
562
    return pTemp;
Alan Mishchenko committed
563 564
}

Alan Mishchenko committed
565

Alan Mishchenko committed
566 567 568 569 570
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


571 572
ABC_NAMESPACE_IMPL_END