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

  FileName    [satTrace.c]

  SystemName  [ABC: Logic synthesis and verification system.]

Alan Mishchenko committed
7
  PackageName [SAT sat_solver.]
Alan Mishchenko committed
8 9 10 11 12 13 14 15 16 17 18 19 20

  Synopsis    [Records the trace of SAT solving in the CNF form.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

  Revision    [$Id: satTrace.c,v 1.4 2005/09/16 22:55:03 casem Exp $]

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

Alan Mishchenko committed
21
#include "satSolver.h"
Alan Mishchenko committed
22

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 43 44 45 46 47 48 49 50 51 52
/*
    The trace of SAT solving contains the original clause of the problem
    along with the learned clauses derived during SAT solving.
    The first line of the resulting file contains 3 numbers instead of 2:
    c <num_vars> <num_all_clauses> <num_root_clauses>
*/

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


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

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

  Synopsis    [Start the trace recording.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
53
void Sat_SolverTraceStart( sat_solver * pSat, char * pName )
Alan Mishchenko committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
{
    assert( pSat->pFile == NULL );
    pSat->pFile = fopen( pName, "w" );
    fprintf( pSat->pFile, "                                        \n" );
    pSat->nClauses = 0;
    pSat->nRoots = 0;
}   

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

  Synopsis    [Stops the trace recording.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
73
void Sat_SolverTraceStop( sat_solver * pSat )
Alan Mishchenko committed
74 75 76 77
{
    if ( pSat->pFile == NULL )
        return;
    rewind( pSat->pFile );
Alan Mishchenko committed
78
    fprintf( pSat->pFile, "p %d %d %d", sat_solver_nvars(pSat), pSat->nClauses, pSat->nRoots );
Alan Mishchenko committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
    fclose( pSat->pFile );
    pSat->pFile = NULL;
}


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

  Synopsis    [Writes one clause into the trace file.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
95
void Sat_SolverTraceWrite( sat_solver * pSat, int * pBeg, int * pEnd, int fRoot )
Alan Mishchenko committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
{
    if ( pSat->pFile == NULL )
        return;
    pSat->nClauses++;
    pSat->nRoots += fRoot;
    for ( ; pBeg < pEnd ; pBeg++ )
        fprintf( pSat->pFile, " %d", lit_print(*pBeg) );
    fprintf( pSat->pFile, " 0\n" );
}

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


111 112
ABC_NAMESPACE_IMPL_END