src/sat/msat/msatRead.c File Reference

#include "msatInt.h"
Include dependency graph for msatRead.c:

Go to the source code of this file.

Functions

static char * Msat_FileRead (FILE *pFile)
static void Msat_ReadWhitespace (char **pIn)
static void Msat_ReadNotWhitespace (char **pIn)
static void skipLine (char **pIn)
static int Msat_ReadInt (char **pIn)
static void Msat_ReadClause (char **pIn, Msat_Solver_t *p, Msat_IntVec_t *pLits)
static bool Msat_ReadDimacs (char *pText, Msat_Solver_t **pS, bool fVerbose)
bool Msat_SolverParseDimacs (FILE *pFile, Msat_Solver_t **p, int fVerbose)

Function Documentation

char * Msat_FileRead ( FILE *  pFile  )  [static]

CFile****************************************************************

FileName [msatRead.c]

PackageName [A C version of SAT solver MINISAT, originally developed in C++ by Niklas Een and Niklas Sorensson, Chalmers University of Technology, Sweden: http://www.cs.chalmers.se/~een/Satzoo.]

Synopsis [The reader of the CNF formula in DIMACS format.]

Author [Alan Mishchenko <alanmi@eecs.berkeley.edu>]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - January 1, 2004.]

Revision [

Id
msatRead.c,v 1.0 2004/01/01 1:00:00 alanmi Exp

] DECLARATIONS ///

FUNCTION DEFINITIONS ///Function*************************************************************

Synopsis [Read the file into the internal buffer.]

Description []

SideEffects []

SeeAlso []

Definition at line 44 of file msatRead.c.

00045 {
00046     int nFileSize;
00047     char * pBuffer;
00048     // get the file size, in bytes
00049     fseek( pFile, 0, SEEK_END );  
00050     nFileSize = ftell( pFile );  
00051     // move the file current reading position to the beginning
00052     rewind( pFile ); 
00053     // load the contents of the file into memory
00054     pBuffer = ALLOC( char, nFileSize + 3 );
00055     fread( pBuffer, nFileSize, 1, pFile );
00056     // terminate the string with '\0'
00057     pBuffer[ nFileSize + 0] = '\n';
00058     pBuffer[ nFileSize + 1] = '\0';
00059     return pBuffer;
00060 }

static void Msat_ReadClause ( char **  pIn,
Msat_Solver_t p,
Msat_IntVec_t pLits 
) [static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 164 of file msatRead.c.

00165 {
00166     int nVars = Msat_SolverReadVarNum( p );
00167     int parsed_lit, var, sign;
00168 
00169     Msat_IntVecClear( pLits );
00170     while ( 1 )
00171     {
00172         parsed_lit = Msat_ReadInt(pIn);
00173         if ( parsed_lit == 0 ) 
00174             break;
00175         var = abs(parsed_lit) - 1;
00176         sign = (parsed_lit > 0);
00177         if ( var >= nVars )
00178         {
00179             printf( "Variable %d is larger than the number of allocated variables (%d).\n", var+1, nVars );
00180             exit(1);
00181         }
00182         Msat_IntVecPush( pLits, MSAT_VAR2LIT(var, !sign) );
00183     }
00184 }

static bool Msat_ReadDimacs ( char *  pText,
Msat_Solver_t **  pS,
bool  fVerbose 
) [static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 197 of file msatRead.c.

00198 {
00199     Msat_Solver_t * p;
00200     Msat_IntVec_t * pLits;
00201     char * pIn = pText;
00202     int nVars, nClas;
00203     while ( 1 )
00204     {
00205         Msat_ReadWhitespace( &pIn );
00206         if ( *pIn == 0 )
00207             break;
00208         else if ( *pIn == 'c' )
00209             skipLine( &pIn );
00210         else if ( *pIn == 'p' )
00211         {
00212             pIn++;
00213             Msat_ReadWhitespace( &pIn );
00214             Msat_ReadNotWhitespace( &pIn );
00215 
00216             nVars = Msat_ReadInt( &pIn );
00217             nClas = Msat_ReadInt( &pIn );
00218             skipLine( &pIn );
00219             // start the solver
00220             p = Msat_SolverAlloc( nVars, 1, 1, 1, 1, 0 ); 
00221             Msat_SolverClean( p, nVars );
00222             Msat_SolverSetVerbosity( p, fVerbose );
00223             // allocate the vector
00224             pLits = Msat_IntVecAlloc( nVars );
00225         }
00226         else
00227         {
00228             if ( p == NULL )
00229             {
00230                 printf( "There is no parameter line.\n" );
00231                 exit(1);
00232             }
00233             Msat_ReadClause( &pIn, p, pLits );
00234             if ( !Msat_SolverAddClause( p, pLits ) )
00235                 return 0;
00236         }
00237     }
00238     Msat_IntVecFree( pLits );
00239     *pS = p;
00240     return Msat_SolverSimplifyDB( p );
00241 }

static int Msat_ReadInt ( char **  pIn  )  [static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 133 of file msatRead.c.

00134 {
00135     int     val = 0;
00136     bool    neg = 0;
00137 
00138     Msat_ReadWhitespace( pIn );
00139     if ( **pIn == '-' ) 
00140         neg = 1, 
00141         (*pIn)++;
00142     else if ( **pIn == '+' ) 
00143         (*pIn)++;
00144     if ( **pIn < '0' || **pIn > '9' ) 
00145         fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", **pIn), 
00146         exit(1);
00147     while ( **pIn >= '0' && **pIn <= '9' )
00148         val = val*10 + (**pIn - '0'),
00149         (*pIn)++;
00150     return neg ? -val : val; 
00151 }

static void Msat_ReadNotWhitespace ( char **  pIn  )  [static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 90 of file msatRead.c.

00091 {
00092     while ( !((**pIn >= 9 && **pIn <= 13) || **pIn == 32) )
00093         (*pIn)++; 
00094 }

static void Msat_ReadWhitespace ( char **  pIn  )  [static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 73 of file msatRead.c.

00074 {
00075     while ((**pIn >= 9 && **pIn <= 13) || **pIn == 32)
00076         (*pIn)++; 
00077 }

bool Msat_SolverParseDimacs ( FILE *  pFile,
Msat_Solver_t **  p,
int  fVerbose 
)

Function*************************************************************

Synopsis [Starts the solver and reads the DIMAC file.]

Description [Returns FALSE upon immediate conflict.]

SideEffects []

SeeAlso []

Definition at line 254 of file msatRead.c.

00255 {
00256     char * pText;
00257     bool Value;
00258     pText = Msat_FileRead( pFile );
00259     Value = Msat_ReadDimacs( pText, p, fVerbose );
00260     free( pText );
00261     return Value;
00262 }

static void skipLine ( char **  pIn  )  [static]

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 107 of file msatRead.c.

00108 {
00109     while ( 1 )
00110     {
00111         if (**pIn == 0) 
00112             return;
00113         if (**pIn == '\n') 
00114         { 
00115             (*pIn)++; 
00116             return; 
00117         }
00118         (*pIn)++; 
00119     } 
00120 }


Generated on Tue Jan 5 12:19:40 2010 for abc70930 by  doxygen 1.6.1