fraSat.c 17.5 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**CFile****************************************************************

  FileName    [fraSat.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [New FRAIG package.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 30, 2007.]

  Revision    [$Id: fraSat.c,v 1.00 2007/06/30 00:00:00 alanmi Exp $]

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

Alan Mishchenko committed
21
#include <math.h>
Alan Mishchenko committed
22 23
#include "fra.h"

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
31
static int Fra_SetActivityFactors( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew );
Alan Mishchenko committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

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

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

  Synopsis    [Runs equivalence test for the two nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
48
int Fra_NodesAreEquiv( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew )
Alan Mishchenko committed
49
{
50
    int pLits[4], RetValue, RetValue1, nBTLimit;
51
    abctime clk;//, clk2 = Abc_Clock();
Alan Mishchenko committed
52
    int status;
Alan Mishchenko committed
53 54

    // make sure the nodes are not complemented
Alan Mishchenko committed
55 56
    assert( !Aig_IsComplement(pNew) );
    assert( !Aig_IsComplement(pOld) );
Alan Mishchenko committed
57 58 59 60 61 62
    assert( pNew != pOld );

    // if at least one of the nodes is a failed node, perform adjustments:
    // if the backtrack limit is small, simply skip this node
    // if the backtrack limit is > 10, take the quare root of the limit
    nBTLimit = p->pPars->nBTLimitNode;
Alan Mishchenko committed
63
    if ( !p->pPars->fSpeculate && p->pPars->nFramesK == 0 && (nBTLimit > 0 && (pOld->fMarkB || pNew->fMarkB)) )
Alan Mishchenko committed
64 65 66 67 68 69 70 71
    {
        p->nSatFails++;
        // fail immediately
//        return -1;
        if ( nBTLimit <= 10 )
            return -1;
        nBTLimit = (int)pow(nBTLimit, 0.7);
    }
Alan Mishchenko committed
72

Alan Mishchenko committed
73
    p->nSatCalls++;
Alan Mishchenko committed
74
    p->nSatCallsRecent++;
Alan Mishchenko committed
75 76 77 78 79 80 81

    // make sure the solver is allocated and has enough variables
    if ( p->pSat == NULL )
    {
        p->pSat = sat_solver_new();
        p->nSatVars = 1;
        sat_solver_setnvars( p->pSat, 1000 );
Alan Mishchenko committed
82 83 84
        // var 0 is reserved for const1 node - add the clause
        pLits[0] = toLit( 0 );
        sat_solver_addclause( p->pSat, pLits, pLits + 1 );
Alan Mishchenko committed
85 86 87
    }

    // if the nodes do not have SAT variables, allocate them
Alan Mishchenko committed
88
    Fra_CnfNodeAddToSolver( p, pOld, pNew );
Alan Mishchenko committed
89

Alan Mishchenko committed
90 91 92 93 94 95 96
    if ( p->pSat->qtail != p->pSat->qhead )
    {
        status = sat_solver_simplify(p->pSat);
        assert( status != 0 );
        assert( p->pSat->qtail == p->pSat->qhead );
    }

Alan Mishchenko committed
97
    // prepare variable activity
Alan Mishchenko committed
98 99
    if ( p->pPars->fConeBias )
        Fra_SetActivityFactors( p, pOld, pNew ); 
Alan Mishchenko committed
100 101 102

    // solve under assumptions
    // A = 1; B = 0     OR     A = 1; B = 1 
103
clk = Abc_Clock();
Alan Mishchenko committed
104 105 106 107
    pLits[0] = toLitCond( Fra_ObjSatNum(pOld), 0 );
    pLits[1] = toLitCond( Fra_ObjSatNum(pNew), pOld->fPhase == pNew->fPhase );
//Sat_SolverWriteDimacs( p->pSat, "temp.cnf", pLits, pLits + 2, 1 );
    RetValue1 = sat_solver_solve( p->pSat, pLits, pLits + 2, 
Alan Mishchenko committed
108
        (ABC_INT64_T)nBTLimit, (ABC_INT64_T)0, 
Alan Mishchenko committed
109
        p->nBTLimitGlobal, p->nInsLimitGlobal );
110
p->timeSat += Abc_Clock() - clk;
Alan Mishchenko committed
111 112
    if ( RetValue1 == l_False )
    {
113
p->timeSatUnsat += Abc_Clock() - clk;
Alan Mishchenko committed
114 115 116 117 118 119 120 121 122
        pLits[0] = lit_neg( pLits[0] );
        pLits[1] = lit_neg( pLits[1] );
        RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 2 );
        assert( RetValue );
        // continue solving the other implication
        p->nSatCallsUnsat++;
    }
    else if ( RetValue1 == l_True )
    {
123
p->timeSatSat += Abc_Clock() - clk;
Alan Mishchenko committed
124
        Fra_SmlSavePattern( p );
Alan Mishchenko committed
125 126 127 128 129
        p->nSatCallsSat++;
        return 0;
    }
    else // if ( RetValue1 == l_Undef )
    {
130
p->timeSatFail += Abc_Clock() - clk;
Alan Mishchenko committed
131
        // mark the node as the failed node
Alan Mishchenko committed
132 133 134
        if ( pOld != p->pManFraig->pConst1 ) 
            pOld->fMarkB = 1;
        pNew->fMarkB = 1;
Alan Mishchenko committed
135 136 137 138 139 140 141 142 143 144 145 146 147
        p->nSatFailsReal++;
        return -1;
    }

    // if the old node was constant 0, we already know the answer
    if ( pOld == p->pManFraig->pConst1 )
    {
        p->nSatProof++;
        return 1;
    }

    // solve under assumptions
    // A = 0; B = 1     OR     A = 0; B = 0 
148
clk = Abc_Clock();
Alan Mishchenko committed
149 150 151
    pLits[0] = toLitCond( Fra_ObjSatNum(pOld), 1 );
    pLits[1] = toLitCond( Fra_ObjSatNum(pNew), pOld->fPhase ^ pNew->fPhase );
    RetValue1 = sat_solver_solve( p->pSat, pLits, pLits + 2, 
Alan Mishchenko committed
152
        (ABC_INT64_T)nBTLimit, (ABC_INT64_T)0, 
Alan Mishchenko committed
153
        p->nBTLimitGlobal, p->nInsLimitGlobal );
154
p->timeSat += Abc_Clock() - clk;
Alan Mishchenko committed
155 156
    if ( RetValue1 == l_False )
    {
157
p->timeSatUnsat += Abc_Clock() - clk;
Alan Mishchenko committed
158 159 160 161 162 163 164 165
        pLits[0] = lit_neg( pLits[0] );
        pLits[1] = lit_neg( pLits[1] );
        RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 2 );
        assert( RetValue );
        p->nSatCallsUnsat++;
    }
    else if ( RetValue1 == l_True )
    {
166
p->timeSatSat += Abc_Clock() - clk;
Alan Mishchenko committed
167
        Fra_SmlSavePattern( p );
Alan Mishchenko committed
168 169 170 171 172
        p->nSatCallsSat++;
        return 0;
    }
    else // if ( RetValue1 == l_Undef )
    {
173
p->timeSatFail += Abc_Clock() - clk;
Alan Mishchenko committed
174
        // mark the node as the failed node
Alan Mishchenko committed
175 176
        pOld->fMarkB = 1;
        pNew->fMarkB = 1;
Alan Mishchenko committed
177 178 179 180 181 182 183
        p->nSatFailsReal++;
        return -1;
    }
/*
    // check BDD proof
    {
        int RetVal;
184 185
        ABC_PRT( "Sat", Abc_Clock() - clk2 );
        clk2 = Abc_Clock();
Alan Mishchenko committed
186 187 188
        RetVal = Fra_NodesAreEquivBdd( pOld, pNew );
//        printf( "%d ", RetVal );
        assert( RetVal );
189
        ABC_PRT( "Bdd", Abc_Clock() - clk2 );
Alan Mishchenko committed
190 191 192 193 194 195 196 197 198 199
        printf( "\n" );
    }
*/
    // return SAT proof
    p->nSatProof++;
    return 1;
}

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

Alan Mishchenko committed
200 201 202 203 204 205 206 207 208 209 210
  Synopsis    [Runs the result of test for pObj => pNew.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Fra_NodesAreImp( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew, int fComplL, int fComplR )
{
211
    int pLits[4], RetValue, RetValue1, nBTLimit;
212
    abctime clk;//, clk2 = Abc_Clock();
Alan Mishchenko committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
    int status;

    // make sure the nodes are not complemented
    assert( !Aig_IsComplement(pNew) );
    assert( !Aig_IsComplement(pOld) );
    assert( pNew != pOld );

    // if at least one of the nodes is a failed node, perform adjustments:
    // if the backtrack limit is small, simply skip this node
    // if the backtrack limit is > 10, take the quare root of the limit
    nBTLimit = p->pPars->nBTLimitNode;
/*
    if ( !p->pPars->fSpeculate && p->pPars->nFramesK == 0 && (nBTLimit > 0 && (pOld->fMarkB || pNew->fMarkB)) )
    {
        p->nSatFails++;
        // fail immediately
//        return -1;
        if ( nBTLimit <= 10 )
            return -1;
        nBTLimit = (int)pow(nBTLimit, 0.7);
    }
*/
    p->nSatCalls++;

    // make sure the solver is allocated and has enough variables
    if ( p->pSat == NULL )
    {
        p->pSat = sat_solver_new();
        p->nSatVars = 1;
        sat_solver_setnvars( p->pSat, 1000 );
Alan Mishchenko committed
243 244 245
        // var 0 is reserved for const1 node - add the clause
        pLits[0] = toLit( 0 );
        sat_solver_addclause( p->pSat, pLits, pLits + 1 );
Alan Mishchenko committed
246 247 248
    }

    // if the nodes do not have SAT variables, allocate them
Alan Mishchenko committed
249
    Fra_CnfNodeAddToSolver( p, pOld, pNew );
Alan Mishchenko committed
250 251 252 253 254 255 256 257 258 259 260 261 262 263

    if ( p->pSat->qtail != p->pSat->qhead )
    {
        status = sat_solver_simplify(p->pSat);
        assert( status != 0 );
        assert( p->pSat->qtail == p->pSat->qhead );
    }

    // prepare variable activity
    if ( p->pPars->fConeBias )
        Fra_SetActivityFactors( p, pOld, pNew ); 

    // solve under assumptions
    // A = 1; B = 0     OR     A = 1; B = 1 
264
clk = Abc_Clock();
Alan Mishchenko committed
265 266 267 268 269 270
//    pLits[0] = toLitCond( Fra_ObjSatNum(pOld), 0 );
//    pLits[1] = toLitCond( Fra_ObjSatNum(pNew), pOld->fPhase == pNew->fPhase );
    pLits[0] = toLitCond( Fra_ObjSatNum(pOld),  fComplL );
    pLits[1] = toLitCond( Fra_ObjSatNum(pNew), !fComplR );
//Sat_SolverWriteDimacs( p->pSat, "temp.cnf", pLits, pLits + 2, 1 );
    RetValue1 = sat_solver_solve( p->pSat, pLits, pLits + 2, 
Alan Mishchenko committed
271
        (ABC_INT64_T)nBTLimit, (ABC_INT64_T)0, 
Alan Mishchenko committed
272
        p->nBTLimitGlobal, p->nInsLimitGlobal );
273
p->timeSat += Abc_Clock() - clk;
Alan Mishchenko committed
274 275
    if ( RetValue1 == l_False )
    {
276
p->timeSatUnsat += Abc_Clock() - clk;
Alan Mishchenko committed
277 278 279 280 281 282 283 284 285
        pLits[0] = lit_neg( pLits[0] );
        pLits[1] = lit_neg( pLits[1] );
        RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 2 );
        assert( RetValue );
        // continue solving the other implication
        p->nSatCallsUnsat++;
    }
    else if ( RetValue1 == l_True )
    {
286
p->timeSatSat += Abc_Clock() - clk;
Alan Mishchenko committed
287
        Fra_SmlSavePattern( p );
Alan Mishchenko committed
288 289 290 291 292
        p->nSatCallsSat++;
        return 0;
    }
    else // if ( RetValue1 == l_Undef )
    {
293
p->timeSatFail += Abc_Clock() - clk;
Alan Mishchenko committed
294
        // mark the node as the failed node
Alan Mishchenko committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318
        if ( pOld != p->pManFraig->pConst1 ) 
            pOld->fMarkB = 1;
        pNew->fMarkB = 1;
        p->nSatFailsReal++;
        return -1;
    }
    // return SAT proof
    p->nSatProof++;
    return 1;
}

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

  Synopsis    [Runs the result of test for pObj => pNew.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Fra_NodesAreClause( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew, int fComplL, int fComplR )
{
319
    int pLits[4], RetValue, RetValue1, nBTLimit;
320
    abctime clk;//, clk2 = Abc_Clock();
Alan Mishchenko committed
321 322 323 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 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    int status;

    // make sure the nodes are not complemented
    assert( !Aig_IsComplement(pNew) );
    assert( !Aig_IsComplement(pOld) );
    assert( pNew != pOld );

    // if at least one of the nodes is a failed node, perform adjustments:
    // if the backtrack limit is small, simply skip this node
    // if the backtrack limit is > 10, take the quare root of the limit
    nBTLimit = p->pPars->nBTLimitNode;
/*
    if ( !p->pPars->fSpeculate && p->pPars->nFramesK == 0 && (nBTLimit > 0 && (pOld->fMarkB || pNew->fMarkB)) )
    {
        p->nSatFails++;
        // fail immediately
//        return -1;
        if ( nBTLimit <= 10 )
            return -1;
        nBTLimit = (int)pow(nBTLimit, 0.7);
    }
*/
    p->nSatCalls++;

    // make sure the solver is allocated and has enough variables
    if ( p->pSat == NULL )
    {
        p->pSat = sat_solver_new();
        p->nSatVars = 1;
        sat_solver_setnvars( p->pSat, 1000 );
        // var 0 is reserved for const1 node - add the clause
        pLits[0] = toLit( 0 );
        sat_solver_addclause( p->pSat, pLits, pLits + 1 );
    }

    // if the nodes do not have SAT variables, allocate them
    Fra_CnfNodeAddToSolver( p, pOld, pNew );

    if ( p->pSat->qtail != p->pSat->qhead )
    {
        status = sat_solver_simplify(p->pSat);
        assert( status != 0 );
        assert( p->pSat->qtail == p->pSat->qhead );
    }

    // prepare variable activity
    if ( p->pPars->fConeBias )
        Fra_SetActivityFactors( p, pOld, pNew ); 

    // solve under assumptions
    // A = 1; B = 0     OR     A = 1; B = 1 
372
clk = Abc_Clock();
Alan Mishchenko committed
373 374 375 376 377 378
//    pLits[0] = toLitCond( Fra_ObjSatNum(pOld), 0 );
//    pLits[1] = toLitCond( Fra_ObjSatNum(pNew), pOld->fPhase == pNew->fPhase );
    pLits[0] = toLitCond( Fra_ObjSatNum(pOld), !fComplL );
    pLits[1] = toLitCond( Fra_ObjSatNum(pNew), !fComplR );
//Sat_SolverWriteDimacs( p->pSat, "temp.cnf", pLits, pLits + 2, 1 );
    RetValue1 = sat_solver_solve( p->pSat, pLits, pLits + 2, 
Alan Mishchenko committed
379
        (ABC_INT64_T)nBTLimit, (ABC_INT64_T)0, 
Alan Mishchenko committed
380
        p->nBTLimitGlobal, p->nInsLimitGlobal );
381
p->timeSat += Abc_Clock() - clk;
Alan Mishchenko committed
382 383
    if ( RetValue1 == l_False )
    {
384
p->timeSatUnsat += Abc_Clock() - clk;
Alan Mishchenko committed
385 386 387 388 389 390 391 392 393
        pLits[0] = lit_neg( pLits[0] );
        pLits[1] = lit_neg( pLits[1] );
        RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 2 );
        assert( RetValue );
        // continue solving the other implication
        p->nSatCallsUnsat++;
    }
    else if ( RetValue1 == l_True )
    {
394
p->timeSatSat += Abc_Clock() - clk;
Alan Mishchenko committed
395 396 397 398 399 400
        Fra_SmlSavePattern( p );
        p->nSatCallsSat++;
        return 0;
    }
    else // if ( RetValue1 == l_Undef )
    {
401
p->timeSatFail += Abc_Clock() - clk;
Alan Mishchenko committed
402
        // mark the node as the failed node
Alan Mishchenko committed
403 404 405 406 407 408 409 410 411 412 413 414 415
        if ( pOld != p->pManFraig->pConst1 ) 
            pOld->fMarkB = 1;
        pNew->fMarkB = 1;
        p->nSatFailsReal++;
        return -1;
    }
    // return SAT proof
    p->nSatProof++;
    return 1;
}

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

Alan Mishchenko committed
416 417 418 419 420 421 422 423 424
  Synopsis    [Runs equivalence test for one node.]

  Description [Returns the fraiged node.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
425
int Fra_NodeIsConst( Fra_Man_t * p, Aig_Obj_t * pNew )
Alan Mishchenko committed
426
{
427
    int pLits[2], RetValue1, RetValue;
428
    abctime clk;
Alan Mishchenko committed
429 430

    // make sure the nodes are not complemented
Alan Mishchenko committed
431
    assert( !Aig_IsComplement(pNew) );
Alan Mishchenko committed
432 433 434 435 436 437 438 439 440
    assert( pNew != p->pManFraig->pConst1 );
    p->nSatCalls++;

    // make sure the solver is allocated and has enough variables
    if ( p->pSat == NULL )
    {
        p->pSat = sat_solver_new();
        p->nSatVars = 1;
        sat_solver_setnvars( p->pSat, 1000 );
Alan Mishchenko committed
441 442 443
        // var 0 is reserved for const1 node - add the clause
        pLits[0] = toLit( 0 );
        sat_solver_addclause( p->pSat, pLits, pLits + 1 );
Alan Mishchenko committed
444 445 446
    }

    // if the nodes do not have SAT variables, allocate them
Alan Mishchenko committed
447
    Fra_CnfNodeAddToSolver( p, NULL, pNew );
Alan Mishchenko committed
448 449

    // prepare variable activity
Alan Mishchenko committed
450 451
    if ( p->pPars->fConeBias )
        Fra_SetActivityFactors( p, NULL, pNew ); 
Alan Mishchenko committed
452 453

    // solve under assumptions
454
clk = Abc_Clock();
Alan Mishchenko committed
455 456
    pLits[0] = toLitCond( Fra_ObjSatNum(pNew), pNew->fPhase );
    RetValue1 = sat_solver_solve( p->pSat, pLits, pLits + 1, 
Alan Mishchenko committed
457
        (ABC_INT64_T)p->pPars->nBTLimitMiter, (ABC_INT64_T)0, 
Alan Mishchenko committed
458
        p->nBTLimitGlobal, p->nInsLimitGlobal );
459
p->timeSat += Abc_Clock() - clk;
Alan Mishchenko committed
460 461
    if ( RetValue1 == l_False )
    {
462
p->timeSatUnsat += Abc_Clock() - clk;
Alan Mishchenko committed
463 464 465 466 467 468 469 470
        pLits[0] = lit_neg( pLits[0] );
        RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 1 );
        assert( RetValue );
        // continue solving the other implication
        p->nSatCallsUnsat++;
    }
    else if ( RetValue1 == l_True )
    {
471
p->timeSatSat += Abc_Clock() - clk;
Alan Mishchenko committed
472
        if ( p->pPatWords )
Alan Mishchenko committed
473
            Fra_SmlSavePattern( p );
Alan Mishchenko committed
474 475 476 477 478
        p->nSatCallsSat++;
        return 0;
    }
    else // if ( RetValue1 == l_Undef )
    {
479
p->timeSatFail += Abc_Clock() - clk;
Alan Mishchenko committed
480
        // mark the node as the failed node
Alan Mishchenko committed
481
        pNew->fMarkB = 1;
Alan Mishchenko committed
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
        p->nSatFailsReal++;
        return -1;
    }

    // return SAT proof
    p->nSatProof++;
    return 1;
}

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

  Synopsis    [Sets variable activities in the cone.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
502
int Fra_SetActivityFactors_rec( Fra_Man_t * p, Aig_Obj_t * pObj, int LevelMin, int LevelMax )
Alan Mishchenko committed
503 504
{
    Vec_Ptr_t * vFanins;
Alan Mishchenko committed
505
    Aig_Obj_t * pFanin;
Alan Mishchenko committed
506
    int i, Counter = 0;
Alan Mishchenko committed
507
    assert( !Aig_IsComplement(pObj) );
Alan Mishchenko committed
508 509
    assert( Fra_ObjSatNum(pObj) );
    // skip visited variables
Alan Mishchenko committed
510
    if ( Aig_ObjIsTravIdCurrent(p->pManFraig, pObj) )
Alan Mishchenko committed
511
        return 0;
Alan Mishchenko committed
512
    Aig_ObjSetTravIdCurrent(p->pManFraig, pObj);
Alan Mishchenko committed
513
    // add the PI to the list
514
    if ( pObj->Level <= (unsigned)LevelMin || Aig_ObjIsCi(pObj) )
Alan Mishchenko committed
515 516 517
        return 0;
    // set the factor of this variable
    // (LevelMax-LevelMin) / (pObj->Level-LevelMin) = p->pPars->dActConeBumpMax / ThisBump
518
    if ( p->pSat->factors == NULL )
519
        p->pSat->factors = ABC_CALLOC( double, p->pSat->cap );
Alan Mishchenko committed
520 521 522 523
    p->pSat->factors[Fra_ObjSatNum(pObj)] = p->pPars->dActConeBumpMax * (pObj->Level - LevelMin)/(LevelMax - LevelMin);
    veci_push(&p->pSat->act_vars, Fra_ObjSatNum(pObj));
    // explore the fanins
    vFanins = Fra_ObjFaninVec( pObj );
524
    Vec_PtrForEachEntry( Aig_Obj_t *, vFanins, pFanin, i )
Alan Mishchenko committed
525
        Counter += Fra_SetActivityFactors_rec( p, Aig_Regular(pFanin), LevelMin, LevelMax );
Alan Mishchenko committed
526 527 528 529 530 531 532 533 534 535 536 537 538 539
    return 1 + Counter;
}

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

  Synopsis    [Sets variable activities in the cone.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
540
int Fra_SetActivityFactors( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew )
Alan Mishchenko committed
541
{
542
    int LevelMin, LevelMax;
543
    abctime clk;
Alan Mishchenko committed
544
    assert( pOld || pNew );
545
clk = Abc_Clock(); 
Alan Mishchenko committed
546 547 548
    // reset the active variables
    veci_resize(&p->pSat->act_vars, 0);
    // prepare for traversal
Alan Mishchenko committed
549
    Aig_ManIncrementTravId( p->pManFraig );
Alan Mishchenko committed
550 551
    // determine the min and max level to visit
    assert( p->pPars->dActConeRatio > 0 && p->pPars->dActConeRatio < 1 );
552
    LevelMax = Abc_MaxInt( (pNew ? pNew->Level : 0), (pOld ? pOld->Level : 0) );
Alan Mishchenko committed
553 554
    LevelMin = (int)(LevelMax * (1.0 - p->pPars->dActConeRatio));
    // traverse
Alan Mishchenko committed
555
    if ( pOld && !Aig_ObjIsConst1(pOld) )
Alan Mishchenko committed
556
        Fra_SetActivityFactors_rec( p, pOld, LevelMin, LevelMax );
Alan Mishchenko committed
557
    if ( pNew && !Aig_ObjIsConst1(pNew) )
Alan Mishchenko committed
558 559
        Fra_SetActivityFactors_rec( p, pNew, LevelMin, LevelMax );
//Fra_PrintActivity( p );
560
p->timeTrav += Abc_Clock() - clk;
Alan Mishchenko committed
561 562 563 564 565 566 567 568 569
    return 1;
}


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


570 571
ABC_NAMESPACE_IMPL_END