abcSat.c 33 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8
/**CFile****************************************************************

  FileName    [abcSat.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

Alan Mishchenko committed
9
  Synopsis    [Procedures to solve the miter using the internal SAT sat_solver.]
Alan Mishchenko committed
10 11 12 13 14 15 16 17 18 19 20

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21 22 23 24
#include "base/abc/abc.h"
#include "base/main/main.h"
#include "base/cmd/cmd.h"
#include "sat/bsat/satSolver.h"
25 26
#include "aig/gia/gia.h"
#include "aig/gia/giaAig.h"
27 28

#ifdef ABC_USE_CUDD
29
#include "bdd/extrab/extraBdd.h"
30
#endif
Alan Mishchenko committed
31

32 33 34
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
35 36 37 38
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

Alan Mishchenko committed
39 40
static sat_solver * Abc_NtkMiterSatCreateLogic( Abc_Ntk_t * pNtk, int fAllPrimes );
extern Vec_Int_t * Abc_NtkGetCiSatVarNums( Abc_Ntk_t * pNtk );
Alan Mishchenko committed
41
static int nMuxes;
Alan Mishchenko committed
42

Alan Mishchenko committed
43
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
44
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
45 46 47 48
////////////////////////////////////////////////////////////////////////

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

Alan Mishchenko committed
49
  Synopsis    [Attempts to solve the miter using an internal SAT sat_solver.]
Alan Mishchenko committed
50

Alan Mishchenko committed
51
  Description [Returns -1 if timed out; 0 if SAT; 1 if UNSAT.]
Alan Mishchenko committed
52 53 54 55 56 57
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
58
int Abc_NtkMiterSat( Abc_Ntk_t * pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T * pNumConfs, ABC_INT64_T * pNumInspects )
Alan Mishchenko committed
59
{
Alan Mishchenko committed
60
    sat_solver * pSat;
Alan Mishchenko committed
61
    lbool   status;
Alan Mishchenko committed
62
    int RetValue = 0;
63
    abctime clk;
Alan Mishchenko committed
64 65 66 67 68
 
    if ( pNumConfs )
        *pNumConfs = 0;
    if ( pNumInspects )
        *pNumInspects = 0;
Alan Mishchenko committed
69

Alan Mishchenko committed
70 71
    assert( Abc_NtkLatchNum(pNtk) == 0 );

Alan Mishchenko committed
72 73
//    if ( Abc_NtkPoNum(pNtk) > 1 )
//        fprintf( stdout, "Warning: The miter has %d outputs. SAT will try to prove all of them.\n", Abc_NtkPoNum(pNtk) );
Alan Mishchenko committed
74

Alan Mishchenko committed
75
    // load clauses into the sat_solver
76
    clk = Abc_Clock();
77
    pSat = (sat_solver *)Abc_NtkMiterSatCreate( pNtk, 0 );
Alan Mishchenko committed
78 79 80 81 82 83 84
    if ( pSat == NULL )
        return 1;
//printf( "%d \n", pSat->clauses.size );
//sat_solver_delete( pSat );
//return 1;

//    printf( "Created SAT problem with %d variable and %d clauses. ", sat_solver_nvars(pSat), sat_solver_nclauses(pSat) );
85
//    ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
86 87

    // simplify the problem
88
    clk = Abc_Clock();
Alan Mishchenko committed
89 90
    status = sat_solver_simplify(pSat);
//    printf( "Simplified the problem to %d variables and %d clauses. ", sat_solver_nvars(pSat), sat_solver_nclauses(pSat) );
91
//    ABC_PRT( "Time", Abc_Clock() - clk );
Alan Mishchenko committed
92
    if ( status == 0 )
Alan Mishchenko committed
93
    {
Alan Mishchenko committed
94 95 96
        sat_solver_delete( pSat );
//        printf( "The problem is UNSATISFIABLE after simplification.\n" );
        return 1;
Alan Mishchenko committed
97 98 99
    }

    // solve the miter
100
    clk = Abc_Clock();
Alan Mishchenko committed
101 102
    if ( fVerbose )
        pSat->verbosity = 1;
Alan Mishchenko committed
103
    status = sat_solver_solve( pSat, NULL, NULL, (ABC_INT64_T)nConfLimit, (ABC_INT64_T)nInsLimit, (ABC_INT64_T)0, (ABC_INT64_T)0 );
Alan Mishchenko committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
    if ( status == l_Undef )
    {
//        printf( "The problem timed out.\n" );
        RetValue = -1;
    }
    else if ( status == l_True )
    {
//        printf( "The problem is SATISFIABLE.\n" );
        RetValue = 0;
    }
    else if ( status == l_False )
    {
//        printf( "The problem is UNSATISFIABLE.\n" );
        RetValue = 1;
    }
    else
        assert( 0 );
121
//    ABC_PRT( "SAT sat_solver time", Abc_Clock() - clk );
Alan Mishchenko committed
122 123 124 125 126 127 128 129 130 131
//    printf( "The number of conflicts = %d.\n", (int)pSat->sat_solver_stats.conflicts );

    // if the problem is SAT, get the counterexample
    if ( status == l_True )
    {
//        Vec_Int_t * vCiIds = Abc_NtkGetCiIds( pNtk );
        Vec_Int_t * vCiIds = Abc_NtkGetCiSatVarNums( pNtk );
        pNtk->pModel = Sat_SolverGetModel( pSat, vCiIds->pArray, vCiIds->nSize );
        Vec_IntFree( vCiIds );
    }
Alan Mishchenko committed
132
    // free the sat_solver
Alan Mishchenko committed
133 134 135 136 137 138 139 140 141 142 143 144 145
    if ( fVerbose )
        Sat_SolverPrintStats( stdout, pSat );

    if ( pNumConfs )
        *pNumConfs = (int)pSat->stats.conflicts;
    if ( pNumInspects )
        *pNumInspects = (int)pSat->stats.inspects;

sat_solver_store_write( pSat, "trace.cnf" );
sat_solver_store_free( pSat );

    sat_solver_delete( pSat );
    return RetValue;
Alan Mishchenko committed
146 147
}

Alan Mishchenko committed
148 149
/**Function*************************************************************

150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int * Abc_NtkSolveGiaMiter( Gia_Man_t * p )
{
    extern Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan );
    int RetValue = 0;
    int * pResult = NULL;
    Abc_Ntk_t * pNtk;
    Aig_Man_t * pMan;
    pMan = Gia_ManToAig( p, 0 );
    pNtk = Abc_NtkFromAigPhase( pMan );
    pNtk->pName = Extra_UtilStrsav(p->pName);
    Aig_ManStop( pMan );
    RetValue = Abc_NtkMiterSat( pNtk, 1000000, 0, 0, NULL, NULL );
    if ( RetValue == 0 ) // sat
        pResult = pNtk->pModel, pNtk->pModel = NULL;
    Abc_NtkDelete( pNtk );
    return pResult;
}


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

Alan Mishchenko committed
180
  Synopsis    [Returns the array of CI IDs.]
Alan Mishchenko committed
181 182 183 184 185 186 187 188

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
189 190 191 192 193 194 195
Vec_Int_t * Abc_NtkGetCiSatVarNums( Abc_Ntk_t * pNtk )
{
    Vec_Int_t * vCiIds;
    Abc_Obj_t * pObj;
    int i;
    vCiIds = Vec_IntAlloc( Abc_NtkCiNum(pNtk) );
    Abc_NtkForEachCi( pNtk, pObj, i )
Alan Mishchenko committed
196
        Vec_IntPush( vCiIds, (int)(ABC_PTRINT_T)pObj->pCopy );
Alan Mishchenko committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
    return vCiIds;
}


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

  Synopsis    [Adds trivial clause.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkClauseTriv( sat_solver * pSat, Abc_Obj_t * pNode, Vec_Int_t * vVars )
{
//printf( "Adding triv %d.         %d\n", Abc_ObjRegular(pNode)->Id, (int)pSat->sat_solver_stats.clauses );
    vVars->nSize = 0;
Alan Mishchenko committed
217
    Vec_IntPush( vVars, toLitCond( (int)(ABC_PTRINT_T)Abc_ObjRegular(pNode)->pCopy, Abc_ObjIsComplement(pNode) ) );
Alan Mishchenko committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
//    Vec_IntPush( vVars, toLitCond( (int)Abc_ObjRegular(pNode)->Id, Abc_ObjIsComplement(pNode) ) );
    return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
}
 
/**Function*************************************************************

  Synopsis    [Adds trivial clause.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkClauseTop( sat_solver * pSat, Vec_Ptr_t * vNodes, Vec_Int_t * vVars )
Alan Mishchenko committed
234 235
{
    Abc_Obj_t * pNode;
Alan Mishchenko committed
236
    int i;
Alan Mishchenko committed
237 238
//printf( "Adding triv %d.         %d\n", Abc_ObjRegular(pNode)->Id, (int)pSat->sat_solver_stats.clauses );
    vVars->nSize = 0;
239
    Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
Alan Mishchenko committed
240
        Vec_IntPush( vVars, toLitCond( (int)(ABC_PTRINT_T)Abc_ObjRegular(pNode)->pCopy, Abc_ObjIsComplement(pNode) ) );
Alan Mishchenko committed
241 242 243 244 245
//    Vec_IntPush( vVars, toLitCond( (int)Abc_ObjRegular(pNode)->Id, Abc_ObjIsComplement(pNode) ) );
    return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
}
 
/**Function*************************************************************
Alan Mishchenko committed
246

Alan Mishchenko committed
247
  Synopsis    [Adds trivial clause.]
Alan Mishchenko committed
248

Alan Mishchenko committed
249 250 251
  Description []
               
  SideEffects []
Alan Mishchenko committed
252

Alan Mishchenko committed
253 254 255 256 257 258 259 260 261 262 263 264
  SeeAlso     []

***********************************************************************/
int Abc_NtkClauseAnd( sat_solver * pSat, Abc_Obj_t * pNode, Vec_Ptr_t * vSuper, Vec_Int_t * vVars )
{
    int fComp1, Var, Var1, i;
//printf( "Adding AND %d.  (%d)    %d\n", pNode->Id, vSuper->nSize+1, (int)pSat->sat_solver_stats.clauses );

    assert( !Abc_ObjIsComplement( pNode ) );
    assert( Abc_ObjIsNode( pNode ) );

//    nVars = sat_solver_nvars(pSat);
Alan Mishchenko committed
265
    Var = (int)(ABC_PTRINT_T)pNode->pCopy;
Alan Mishchenko committed
266 267 268 269
//    Var = pNode->Id;

//    assert( Var  < nVars ); 
    for ( i = 0; i < vSuper->nSize; i++ )
Alan Mishchenko committed
270
    {
Alan Mishchenko committed
271 272
        // get the predecessor nodes
        // get the complemented attributes of the nodes
273
        fComp1 = Abc_ObjIsComplement((Abc_Obj_t *)vSuper->pArray[i]);
Alan Mishchenko committed
274
        // determine the variable numbers
275
        Var1 = (int)(ABC_PTRINT_T)Abc_ObjRegular((Abc_Obj_t *)vSuper->pArray[i])->pCopy;
Alan Mishchenko committed
276 277 278 279 280 281 282 283 284 285 286 287 288
//        Var1 = (int)Abc_ObjRegular(vSuper->pArray[i])->Id;

        // check that the variables are in the SAT manager
//        assert( Var1 < nVars );

        // suppose the AND-gate is A * B = C
        // add !A => !C   or   A + !C
    //  fprintf( pFile, "%d %d 0%c", Var1, -Var, 10 );
        vVars->nSize = 0;
        Vec_IntPush( vVars, toLitCond(Var1, fComp1) );
        Vec_IntPush( vVars, toLitCond(Var,  1     ) );
        if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
            return 0;
Alan Mishchenko committed
289
    }
Alan Mishchenko committed
290

Alan Mishchenko committed
291 292 293 294 295 296 297
    // add A & B => C   or   !A + !B + C
//  fprintf( pFile, "%d %d %d 0%c", -Var1, -Var2, Var, 10 );
    vVars->nSize = 0;
    for ( i = 0; i < vSuper->nSize; i++ )
    {
        // get the predecessor nodes
        // get the complemented attributes of the nodes
298
        fComp1 = Abc_ObjIsComplement((Abc_Obj_t *)vSuper->pArray[i]);
Alan Mishchenko committed
299
        // determine the variable numbers
300
        Var1 = (int)(ABC_PTRINT_T)Abc_ObjRegular((Abc_Obj_t *)vSuper->pArray[i])->pCopy;
Alan Mishchenko committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
//        Var1 = (int)Abc_ObjRegular(vSuper->pArray[i])->Id;
        // add this variable to the array
        Vec_IntPush( vVars, toLitCond(Var1, !fComp1) );
    }
    Vec_IntPush( vVars, toLitCond(Var, 0) );
    return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
}
 
/**Function*************************************************************

  Synopsis    [Adds trivial clause.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkClauseMux( sat_solver * pSat, Abc_Obj_t * pNode, Abc_Obj_t * pNodeC, Abc_Obj_t * pNodeT, Abc_Obj_t * pNodeE, Vec_Int_t * vVars )
{
    int VarF, VarI, VarT, VarE, fCompT, fCompE;
//printf( "Adding mux %d.         %d\n", pNode->Id, (int)pSat->sat_solver_stats.clauses );

    assert( !Abc_ObjIsComplement( pNode ) );
    assert( Abc_NodeIsMuxType( pNode ) );
    // get the variable numbers
Alan Mishchenko committed
328 329 330 331
    VarF = (int)(ABC_PTRINT_T)pNode->pCopy;
    VarI = (int)(ABC_PTRINT_T)pNodeC->pCopy;
    VarT = (int)(ABC_PTRINT_T)Abc_ObjRegular(pNodeT)->pCopy;
    VarE = (int)(ABC_PTRINT_T)Abc_ObjRegular(pNodeE)->pCopy;
Alan Mishchenko committed
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 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 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 421 422 423
//    VarF = (int)pNode->Id;
//    VarI = (int)pNodeC->Id;
//    VarT = (int)Abc_ObjRegular(pNodeT)->Id;
//    VarE = (int)Abc_ObjRegular(pNodeE)->Id;

    // get the complementation flags
    fCompT = Abc_ObjIsComplement(pNodeT);
    fCompE = Abc_ObjIsComplement(pNodeE);

    // f = ITE(i, t, e)
    // i' + t' + f
    // i' + t  + f'
    // i  + e' + f
    // i  + e  + f'
    // create four clauses
    vVars->nSize = 0;
    Vec_IntPush( vVars, toLitCond(VarI,  1) );
    Vec_IntPush( vVars, toLitCond(VarT,  1^fCompT) );
    Vec_IntPush( vVars, toLitCond(VarF,  0) );
    if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
        return 0;
    vVars->nSize = 0;
    Vec_IntPush( vVars, toLitCond(VarI,  1) );
    Vec_IntPush( vVars, toLitCond(VarT,  0^fCompT) );
    Vec_IntPush( vVars, toLitCond(VarF,  1) );
    if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
        return 0;
    vVars->nSize = 0;
    Vec_IntPush( vVars, toLitCond(VarI,  0) );
    Vec_IntPush( vVars, toLitCond(VarE,  1^fCompE) );
    Vec_IntPush( vVars, toLitCond(VarF,  0) );
    if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
        return 0;
    vVars->nSize = 0;
    Vec_IntPush( vVars, toLitCond(VarI,  0) );
    Vec_IntPush( vVars, toLitCond(VarE,  0^fCompE) );
    Vec_IntPush( vVars, toLitCond(VarF,  1) );
    if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
        return 0;
 
    if ( VarT == VarE )
    {
//        assert( fCompT == !fCompE );
        return 1;
    }

    // two additional clauses
    // t' & e' -> f'       t  + e   + f'
    // t  & e  -> f        t' + e'  + f 
    vVars->nSize = 0;
    Vec_IntPush( vVars, toLitCond(VarT,  0^fCompT) );
    Vec_IntPush( vVars, toLitCond(VarE,  0^fCompE) );
    Vec_IntPush( vVars, toLitCond(VarF,  1) );
    if ( !sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize ) )
        return 0;
    vVars->nSize = 0;
    Vec_IntPush( vVars, toLitCond(VarT,  1^fCompT) );
    Vec_IntPush( vVars, toLitCond(VarE,  1^fCompE) );
    Vec_IntPush( vVars, toLitCond(VarF,  0) );
    return sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
}

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

  Synopsis    [Returns the array of nodes to be combined into one multi-input AND-gate.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkCollectSupergate_rec( Abc_Obj_t * pNode, Vec_Ptr_t * vSuper, int fFirst, int fStopAtMux )
{
    int RetValue1, RetValue2, i;
    // check if the node is visited
    if ( Abc_ObjRegular(pNode)->fMarkB )
    {
        // check if the node occurs in the same polarity
        for ( i = 0; i < vSuper->nSize; i++ )
            if ( vSuper->pArray[i] == pNode )
                return 1;
        // check if the node is present in the opposite polarity
        for ( i = 0; i < vSuper->nSize; i++ )
            if ( vSuper->pArray[i] == Abc_ObjNot(pNode) )
                return -1;
        assert( 0 );
        return 0;
    }
    // if the new node is complemented or a PI, another gate begins
    if ( !fFirst )
Alan Mishchenko committed
424 425 426 427 428 429
        if ( Abc_ObjIsComplement(pNode) || !Abc_ObjIsNode(pNode) || Abc_ObjFanoutNum(pNode) > 1 || (fStopAtMux && Abc_NodeIsMuxType(pNode)) )
        {
            Vec_PtrPush( vSuper, pNode );
            Abc_ObjRegular(pNode)->fMarkB = 1;
            return 0;
        }
Alan Mishchenko committed
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 491 492 493 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
    assert( !Abc_ObjIsComplement(pNode) );
    assert( Abc_ObjIsNode(pNode) );
    // go through the branches
    RetValue1 = Abc_NtkCollectSupergate_rec( Abc_ObjChild0(pNode), vSuper, 0, fStopAtMux );
    RetValue2 = Abc_NtkCollectSupergate_rec( Abc_ObjChild1(pNode), vSuper, 0, fStopAtMux );
    if ( RetValue1 == -1 || RetValue2 == -1 )
        return -1;
    // return 1 if at least one branch has a duplicate
    return RetValue1 || RetValue2;
}

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

  Synopsis    [Returns the array of nodes to be combined into one multi-input AND-gate.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkCollectSupergate( Abc_Obj_t * pNode, int fStopAtMux, Vec_Ptr_t * vNodes )
{
    int RetValue, i;
    assert( !Abc_ObjIsComplement(pNode) );
    // collect the nodes in the implication supergate
    Vec_PtrClear( vNodes );
    RetValue = Abc_NtkCollectSupergate_rec( pNode, vNodes, 1, fStopAtMux );
    assert( vNodes->nSize > 1 );
    // unmark the visited nodes
    for ( i = 0; i < vNodes->nSize; i++ )
        Abc_ObjRegular((Abc_Obj_t *)vNodes->pArray[i])->fMarkB = 0;
    // if we found the node and its complement in the same implication supergate, 
    // return empty set of nodes (meaning that we should use constant-0 node)
    if ( RetValue == -1 )
        vNodes->nSize = 0;
}


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

  Synopsis    [Computes the factor of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkNodeFactor( Abc_Obj_t * pObj, int nLevelMax )
{
//  nLevelMax = ((nLevelMax)/2)*3;
    assert( (int)pObj->Level <= nLevelMax );
//    return (int)(100000000.0 * pow(0.999, nLevelMax - pObj->Level));
    return (int)(100000000.0 * (1 + 0.01 * pObj->Level));
//    return (int)(100000000.0 / ((nLevelMax)/2)*3 - pObj->Level);
}

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

  Synopsis    [Sets up the SAT sat_solver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkMiterSatCreateInt( sat_solver * pSat, Abc_Ntk_t * pNtk )
{
    Abc_Obj_t * pNode, * pFanin, * pNodeC, * pNodeT, * pNodeE;
    Vec_Ptr_t * vNodes, * vSuper;
    Vec_Int_t * vVars;
    int i, k, fUseMuxes = 1;
//    int fOrderCiVarsFirst = 0;
    int RetValue = 0;

    assert( Abc_NtkIsStrash(pNtk) );

    // clean the CI node pointers
    Abc_NtkForEachCi( pNtk, pNode, i )
        pNode->pCopy = NULL;

    // start the data structures
    vNodes  = Vec_PtrAlloc( 1000 );   // the nodes corresponding to vars in the sat_solver
    vSuper  = Vec_PtrAlloc( 100 );    // the nodes belonging to the given implication supergate
    vVars   = Vec_IntAlloc( 100 );    // the temporary array for variables in the clause

    // add the clause for the constant node
    pNode = Abc_AigConst1(pNtk);
    pNode->fMarkA = 1;
Alan Mishchenko committed
524
    pNode->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
Alan Mishchenko committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
    Vec_PtrPush( vNodes, pNode );
    Abc_NtkClauseTriv( pSat, pNode, vVars );
/*
    // add the PI variables first
    Abc_NtkForEachCi( pNtk, pNode, i )
    {
        pNode->fMarkA = 1;
        pNode->pCopy = (Abc_Obj_t *)vNodes->nSize;
        Vec_PtrPush( vNodes, pNode );
    }
*/
    // collect the nodes that need clauses and top-level assignments
    Vec_PtrClear( vSuper );
    Abc_NtkForEachCo( pNtk, pNode, i )
    {
        // get the fanin
        pFanin = Abc_ObjFanin0(pNode);
        // create the node's variable
        if ( pFanin->fMarkA == 0 )
        {
            pFanin->fMarkA = 1;
Alan Mishchenko committed
546
            pFanin->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
Alan Mishchenko committed
547 548 549 550 551 552 553 554 555 556
            Vec_PtrPush( vNodes, pFanin );
        }
        // add the trivial clause
        Vec_PtrPush( vSuper, Abc_ObjChild0(pNode) );
    }
    if ( !Abc_NtkClauseTop( pSat, vSuper, vVars ) )
        goto Quits;


    // add the clauses
557
    Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
Alan Mishchenko committed
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
    {
        assert( !Abc_ObjIsComplement(pNode) );
        if ( !Abc_AigNodeIsAnd(pNode) )
            continue;
//printf( "%d ", pNode->Id );

        // add the clauses
        if ( fUseMuxes && Abc_NodeIsMuxType(pNode) )
        {
            nMuxes++;

            pNodeC = Abc_NodeRecognizeMux( pNode, &pNodeT, &pNodeE );
            Vec_PtrClear( vSuper );
            Vec_PtrPush( vSuper, pNodeC );
            Vec_PtrPush( vSuper, pNodeT );
            Vec_PtrPush( vSuper, pNodeE );
            // add the fanin nodes to explore
575
            Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pFanin, k )
Alan Mishchenko committed
576 577 578 579 580
            {
                pFanin = Abc_ObjRegular(pFanin);
                if ( pFanin->fMarkA == 0 )
                {
                    pFanin->fMarkA = 1;
Alan Mishchenko committed
581
                    pFanin->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
Alan Mishchenko committed
582 583 584 585 586 587 588 589 590 591 592 593
                    Vec_PtrPush( vNodes, pFanin );
                }
            }
            // add the clauses
            if ( !Abc_NtkClauseMux( pSat, pNode, pNodeC, pNodeT, pNodeE, vVars ) )
                goto Quits;
        }
        else
        {
            // get the supergate
            Abc_NtkCollectSupergate( pNode, fUseMuxes, vSuper );
            // add the fanin nodes to explore
594
            Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pFanin, k )
Alan Mishchenko committed
595 596 597 598 599
            {
                pFanin = Abc_ObjRegular(pFanin);
                if ( pFanin->fMarkA == 0 )
                {
                    pFanin->fMarkA = 1;
Alan Mishchenko committed
600
                    pFanin->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)vNodes->nSize;
Alan Mishchenko committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621
                    Vec_PtrPush( vNodes, pFanin );
                }
            }
            // add the clauses
            if ( vSuper->nSize == 0 )
            {
                if ( !Abc_NtkClauseTriv( pSat, Abc_ObjNot(pNode), vVars ) )
//                if ( !Abc_NtkClauseTriv( pSat, pNode, vVars ) )
                    goto Quits;
            }
            else
            {
                if ( !Abc_NtkClauseAnd( pSat, pNode, vSuper, vVars ) )
                    goto Quits;
            }
        }
    }
/*
    // set preferred variables
    if ( fOrderCiVarsFirst )
    {
Alan Mishchenko committed
622
        int * pPrefVars = ABC_ALLOC( int, Abc_NtkCiNum(pNtk) );
Alan Mishchenko committed
623 624 625 626 627 628 629
        int nVars = 0;
        Abc_NtkForEachCi( pNtk, pNode, i )
        {
            if ( pNode->fMarkA == 0 )
                continue;
            pPrefVars[nVars++] = (int)pNode->pCopy;
        }
630
        nVars = Abc_MinInt( nVars, 10 );
Alan Mishchenko committed
631 632 633
        ASat_SolverSetPrefVars( pSat, pPrefVars, nVars );
    }
*/
Alan Mishchenko committed
634 635 636 637 638 639 640 641 642 643
/*
    Abc_NtkForEachObj( pNtk, pNode, i )
    {
        if ( !pNode->fMarkA )
            continue;
        printf( "%10s : ", Abc_ObjName(pNode) );
        printf( "%3d\n", (int)pNode->pCopy );
    }
    printf( "\n" );
*/
Alan Mishchenko committed
644 645
    RetValue = 1;
Quits :
Alan Mishchenko committed
646 647
    // delete
    Vec_IntFree( vVars );
Alan Mishchenko committed
648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
    Vec_PtrFree( vNodes );
    Vec_PtrFree( vSuper );
    return RetValue;
}

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

  Synopsis    [Sets up the SAT sat_solver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void * Abc_NtkMiterSatCreate( Abc_Ntk_t * pNtk, int fAllPrimes )
{
    sat_solver * pSat;
    Abc_Obj_t * pNode;
668
    int RetValue, i; //, clk = Abc_Clock();
Alan Mishchenko committed
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688

    assert( Abc_NtkIsStrash(pNtk) || Abc_NtkIsBddLogic(pNtk) );
    if ( Abc_NtkIsBddLogic(pNtk) )
        return Abc_NtkMiterSatCreateLogic(pNtk, fAllPrimes);

    nMuxes = 0;
    pSat = sat_solver_new();
//sat_solver_store_alloc( pSat );
    RetValue = Abc_NtkMiterSatCreateInt( pSat, pNtk );
sat_solver_store_mark_roots( pSat );

    Abc_NtkForEachObj( pNtk, pNode, i )
        pNode->fMarkA = 0;
//    ASat_SolverWriteDimacs( pSat, "temp_sat.cnf", NULL, NULL, 1 );
    if ( RetValue == 0 )
    {
        sat_solver_delete(pSat);
        return NULL;
    }
//    printf( "Ands = %6d.  Muxes = %6d (%5.2f %%).  ", Abc_NtkNodeNum(pNtk), nMuxes, 300.0*nMuxes/Abc_NtkNodeNum(pNtk) );
689
//    ABC_PRT( "Creating sat_solver", Abc_Clock() - clk );
Alan Mishchenko committed
690 691 692
    return pSat;
}

Alan Mishchenko committed
693 694


695
#ifdef ABC_USE_CUDD
Alan Mishchenko committed
696

Alan Mishchenko committed
697 698 699 700 701 702 703 704 705 706 707
/**Function*************************************************************

  Synopsis    [Adds clauses for the internal node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
708
int Abc_NodeAddClauses( sat_solver * pSat, char * pSop0, char * pSop1, Abc_Obj_t * pNode, Vec_Int_t * vVars )
Alan Mishchenko committed
709 710 711
{
    Abc_Obj_t * pFanin;
    int i, c, nFanins;
Alan Mishchenko committed
712
    int RetValue = 0;
Alan Mishchenko committed
713 714 715 716
    char * pCube;

    nFanins = Abc_ObjFaninNum( pNode );
    assert( nFanins == Abc_SopGetVarNum( pSop0 ) );
Alan Mishchenko committed
717 718

//    if ( nFanins == 0 )
719
    if ( Cudd_Regular((Abc_Obj_t *)pNode->pData) == Cudd_ReadOne((DdManager *)pNode->pNtk->pManFunc) )
Alan Mishchenko committed
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734
    {
        vVars->nSize = 0;
//        if ( Abc_SopIsConst1(pSop1) )
        if ( !Cudd_IsComplement(pNode->pData) )
            Vec_IntPush( vVars, toLit(pNode->Id) );
        else
            Vec_IntPush( vVars, lit_neg(toLit(pNode->Id)) );
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
        }
        return 1;
    }
Alan Mishchenko committed
735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
 
    // add clauses for the negative phase
    for ( c = 0; ; c++ )
    {
        // get the cube
        pCube = pSop0 + c * (nFanins + 3);
        if ( *pCube == 0 )
            break;
        // add the clause
        vVars->nSize = 0;
        Abc_ObjForEachFanin( pNode, pFanin, i )
        {
            if ( pCube[i] == '0' )
                Vec_IntPush( vVars, toLit(pFanin->Id) );
            else if ( pCube[i] == '1' )
Alan Mishchenko committed
750 751 752 753 754 755 756 757
                Vec_IntPush( vVars, lit_neg(toLit(pFanin->Id)) );
        }
        Vec_IntPush( vVars, lit_neg(toLit(pNode->Id)) );
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
Alan Mishchenko committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774
        }
    }

    // add clauses for the positive phase
    for ( c = 0; ; c++ )
    {
        // get the cube
        pCube = pSop1 + c * (nFanins + 3);
        if ( *pCube == 0 )
            break;
        // add the clause
        vVars->nSize = 0;
        Abc_ObjForEachFanin( pNode, pFanin, i )
        {
            if ( pCube[i] == '0' )
                Vec_IntPush( vVars, toLit(pFanin->Id) );
            else if ( pCube[i] == '1' )
Alan Mishchenko committed
775
                Vec_IntPush( vVars, lit_neg(toLit(pFanin->Id)) );
Alan Mishchenko committed
776 777
        }
        Vec_IntPush( vVars, toLit(pNode->Id) );
Alan Mishchenko committed
778 779 780 781 782 783
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
        }
Alan Mishchenko committed
784
    }
Alan Mishchenko committed
785
    return 1;
Alan Mishchenko committed
786 787 788 789 790 791 792 793 794 795 796 797 798
}

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

  Synopsis    [Adds clauses for the PO node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
799
int Abc_NodeAddClausesTop( sat_solver * pSat, Abc_Obj_t * pNode, Vec_Int_t * vVars )
Alan Mishchenko committed
800 801
{
    Abc_Obj_t * pFanin;
Alan Mishchenko committed
802
    int RetValue = 0;
Alan Mishchenko committed
803 804 805 806 807 808 809

    pFanin = Abc_ObjFanin0(pNode);
    if ( Abc_ObjFaninC0(pNode) )
    {
        vVars->nSize = 0;
        Vec_IntPush( vVars, toLit(pFanin->Id) );
        Vec_IntPush( vVars, toLit(pNode->Id) );
Alan Mishchenko committed
810 811 812 813 814 815
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
        }
Alan Mishchenko committed
816 817

        vVars->nSize = 0;
Alan Mishchenko committed
818 819 820 821 822 823 824 825
        Vec_IntPush( vVars, lit_neg(toLit(pFanin->Id)) );
        Vec_IntPush( vVars, lit_neg(toLit(pNode->Id)) );
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
        }
Alan Mishchenko committed
826 827 828 829
    }
    else
    {
        vVars->nSize = 0;
Alan Mishchenko committed
830
        Vec_IntPush( vVars, lit_neg(toLit(pFanin->Id)) );
Alan Mishchenko committed
831
        Vec_IntPush( vVars, toLit(pNode->Id) );
Alan Mishchenko committed
832 833 834 835 836 837
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
        }
Alan Mishchenko committed
838 839 840

        vVars->nSize = 0;
        Vec_IntPush( vVars, toLit(pFanin->Id) );
Alan Mishchenko committed
841 842 843 844 845 846 847
        Vec_IntPush( vVars, lit_neg(toLit(pNode->Id)) );
        RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
        if ( !RetValue ) 
        {
            printf( "The CNF is trivially UNSAT.\n" );
            return 0;
        }
Alan Mishchenko committed
848 849 850 851
    }

    vVars->nSize = 0;
    Vec_IntPush( vVars, toLit(pNode->Id) );
Alan Mishchenko committed
852 853 854 855 856 857 858
    RetValue = sat_solver_addclause( pSat, vVars->pArray, vVars->pArray + vVars->nSize );
    if ( !RetValue ) 
    {
        printf( "The CNF is trivially UNSAT.\n" );
        return 0;
    }
    return 1;
Alan Mishchenko committed
859 860
}

Alan Mishchenko committed
861 862 863 864 865 866 867 868 869 870 871 872 873 874
/**Function*************************************************************

  Synopsis    [Sets up the SAT sat_solver.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
sat_solver * Abc_NtkMiterSatCreateLogic( Abc_Ntk_t * pNtk, int fAllPrimes )
{
    sat_solver * pSat;
875
    Mem_Flex_t * pMmFlex;
Alan Mishchenko committed
876 877 878 879 880 881 882 883 884 885
    Abc_Obj_t * pNode;
    Vec_Str_t * vCube;
    Vec_Int_t * vVars;
    char * pSop0, * pSop1;
    int i;

    assert( Abc_NtkIsBddLogic(pNtk) );

    // transfer the IDs to the copy field
    Abc_NtkForEachPi( pNtk, pNode, i )
886
        pNode->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)pNode->Id;
Alan Mishchenko committed
887 888 889 890

    // start the data structures
    pSat    = sat_solver_new();
sat_solver_store_alloc( pSat );
891
    pMmFlex = Mem_FlexStart();
Alan Mishchenko committed
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923
    vCube   = Vec_StrAlloc( 100 );
    vVars   = Vec_IntAlloc( 100 );

    // add clauses for each internal nodes
    Abc_NtkForEachNode( pNtk, pNode, i )
    {
        // derive SOPs for both phases of the node
        Abc_NodeBddToCnf( pNode, pMmFlex, vCube, fAllPrimes, &pSop0, &pSop1 );
        // add the clauses to the sat_solver
        if ( !Abc_NodeAddClauses( pSat, pSop0, pSop1, pNode, vVars ) )
        {
            sat_solver_delete( pSat );
            pSat = NULL;
            goto finish;
        }
    }
    // add clauses for each PO
    Abc_NtkForEachPo( pNtk, pNode, i )
    {
        if ( !Abc_NodeAddClausesTop( pSat, pNode, vVars ) )
        {
            sat_solver_delete( pSat );
            pSat = NULL;
            goto finish;
        }
    }
sat_solver_store_mark_roots( pSat );

finish:
    // delete
    Vec_StrFree( vCube );
    Vec_IntFree( vVars );
924
    Mem_FlexStop( pMmFlex, 0 );
Alan Mishchenko committed
925 926 927
    return pSat;
}

928 929 930
#else

sat_solver * Abc_NtkMiterSatCreateLogic( Abc_Ntk_t * pNtk, int fAllPrimes ) { return NULL; }
Alan Mishchenko committed
931

932
#endif
Alan Mishchenko committed
933

Alan Mishchenko committed
934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
/**Function*************************************************************

  Synopsis    [Writes CNF for the sorter with N inputs asserting Q ones.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkWriteSorterCnf( char * pFileName, int nVars, int nQueens )
{
    char Command[100];
    void * pAbc;
    Abc_Ntk_t * pNtk;
    Abc_Obj_t * pObj, * ppNodes[2], * ppRoots[2];
    Vec_Ptr_t * vNodes;
    FILE * pFile;
    int i, Counter;

    if ( nQueens <= 0 && nQueens >= nVars )
    {
Alan Mishchenko committed
957
        printf( "The number of queens (Q = %d) should belong to the interval: 0 < Q < %d.\n", nQueens, nQueens);
Alan Mishchenko committed
958 959 960 961 962 963
        return;
    }
    assert( nQueens > 0 && nQueens < nVars );
    pAbc = Abc_FrameGetGlobalFrame();
    // generate sorter
    sprintf( Command, "gen -s -N %d sorter%d.blif", nVars, nVars );
964
    if ( Cmd_CommandExecute( (Abc_Frame_t *)pAbc, Command ) )
Alan Mishchenko committed
965 966 967 968 969 970
    {
        fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
        return;
    }
    // read the file
    sprintf( Command, "read sorter%d.blif; strash", nVars );
971
    if ( Cmd_CommandExecute( (Abc_Frame_t *)pAbc, Command ) )
Alan Mishchenko committed
972 973 974 975 976 977
    {
        fprintf( stdout, "Cannot execute command \"%s\".\n", Command );
        return;
    }

    // get the current network
978
    pNtk = Abc_FrameReadNtk((Abc_Frame_t *)pAbc);
Alan Mishchenko committed
979 980 981 982 983 984 985 986 987 988
    // collect the nodes for the given two primary outputs
    ppNodes[0] = Abc_NtkPo( pNtk, nVars - nQueens - 1 );
    ppNodes[1] = Abc_NtkPo( pNtk, nVars - nQueens );
    ppRoots[0] = Abc_ObjFanin0( ppNodes[0] );
    ppRoots[1] = Abc_ObjFanin0( ppNodes[1] );
    vNodes = Abc_NtkDfsNodes( pNtk, ppRoots, 2 );

    // assign CNF variables
    Counter = 0;
    Abc_NtkForEachObj( pNtk, pObj, i )
989
        pObj->pCopy = (Abc_Obj_t *)~0;
Alan Mishchenko committed
990
    Abc_NtkForEachPi( pNtk, pObj, i )
991 992 993
        pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)Counter++;
    Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
        pObj->pCopy = (Abc_Obj_t *)(ABC_PTRINT_T)Counter++;
Alan Mishchenko committed
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017

/*
        OutVar   = pCnf->pVarNums[ pObj->Id ];
        pVars[0] = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ];
        pVars[1] = pCnf->pVarNums[ Aig_ObjFanin1(pObj)->Id ];

        // positive phase
        *pClas++ = pLits;
        *pLits++ = 2 * OutVar; 
        *pLits++ = 2 * pVars[0] + !Aig_ObjFaninC0(pObj); 
        *pLits++ = 2 * pVars[1] + !Aig_ObjFaninC1(pObj); 
        // negative phase
        *pClas++ = pLits;
        *pLits++ = 2 * OutVar + 1; 
        *pLits++ = 2 * pVars[0] + Aig_ObjFaninC0(pObj); 
        *pClas++ = pLits;
        *pLits++ = 2 * OutVar + 1; 
        *pLits++ = 2 * pVars[1] + Aig_ObjFaninC1(pObj); 
*/

    // add clauses for these nodes
    pFile = fopen( pFileName, "w" );
    fprintf( pFile, "c CNF for %d-bit sorter with %d bits set to 1 generated by ABC.\n", nVars, nQueens );
    fprintf( pFile, "p cnf %d %d\n", Counter, 3 * Vec_PtrSize(vNodes) + 2 );
1018
    Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
1019 1020
    {
        // positive phase
Alan Mishchenko committed
1021 1022 1023
        fprintf( pFile, "%d %s%d %s%d 0\n", 1+(int)(ABC_PTRINT_T)pObj->pCopy,
            Abc_ObjFaninC0(pObj)? "" : "-", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy,
            Abc_ObjFaninC1(pObj)? "" : "-", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy );
Alan Mishchenko committed
1024
        // negative phase
Alan Mishchenko committed
1025 1026 1027 1028
        fprintf( pFile, "-%d %s%d 0\n",     1+(int)(ABC_PTRINT_T)pObj->pCopy,
            Abc_ObjFaninC0(pObj)? "-" : "", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(pObj)->pCopy );
        fprintf( pFile, "-%d %s%d 0\n",     1+(int)(ABC_PTRINT_T)pObj->pCopy,
            Abc_ObjFaninC1(pObj)? "-" : "", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin1(pObj)->pCopy );
Alan Mishchenko committed
1029 1030 1031 1032 1033 1034 1035 1036 1037
    }
    Vec_PtrFree( vNodes );

/*
    *pClas++ = pLits;
    *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj); 
*/
    // assert the first literal to zero
    fprintf( pFile, "%s%d 0\n", 
Alan Mishchenko committed
1038
        Abc_ObjFaninC0(ppNodes[0])? "" : "-", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(ppNodes[0])->pCopy );
Alan Mishchenko committed
1039 1040
    // assert the second literal to one
    fprintf( pFile, "%s%d 0\n", 
Alan Mishchenko committed
1041
        Abc_ObjFaninC0(ppNodes[1])? "-" : "", 1+(int)(ABC_PTRINT_T)Abc_ObjFanin0(ppNodes[1])->pCopy );
Alan Mishchenko committed
1042 1043 1044
    fclose( pFile );
}

Alan Mishchenko committed
1045

Alan Mishchenko committed
1046 1047 1048 1049 1050
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


1051 1052
ABC_NAMESPACE_IMPL_END