00001
00021 #include "io.h"
00022 #include "satSolver.h"
00023
00027
00028 static Abc_Ntk_t * s_pNtk = NULL;
00029
00033
00045 int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes )
00046 {
00047 sat_solver * pSat;
00048 if ( Abc_NtkIsStrash(pNtk) )
00049 printf( "Io_WriteCnf() warning: Generating CNF by applying heuristic AIG to CNF conversion.\n" );
00050 else
00051 printf( "Io_WriteCnf() warning: Generating CNF by convering logic nodes into CNF clauses.\n" );
00052 if ( Abc_NtkPoNum(pNtk) != 1 )
00053 {
00054 fprintf( stdout, "Io_WriteCnf(): Currently can only process the miter (the network with one PO).\n" );
00055 return 0;
00056 }
00057 if ( Abc_NtkLatchNum(pNtk) != 0 )
00058 {
00059 fprintf( stdout, "Io_WriteCnf(): Currently can only process the miter for combinational circuits.\n" );
00060 return 0;
00061 }
00062 if ( Abc_NtkNodeNum(pNtk) == 0 )
00063 {
00064 fprintf( stdout, "The network has no logic nodes. No CNF file is generaled.\n" );
00065 return 0;
00066 }
00067
00068 if ( Abc_NtkIsLogic(pNtk) )
00069 Abc_NtkToBdd( pNtk );
00070
00071 pSat = Abc_NtkMiterSatCreate( pNtk, fAllPrimes );
00072 if ( pSat == NULL )
00073 {
00074 fprintf( stdout, "The problem is trivially UNSAT. No CNF file is generated.\n" );
00075 return 1;
00076 }
00077
00078 s_pNtk = pNtk;
00079 Sat_SolverWriteDimacs( pSat, pFileName, 0, 0, 1 );
00080 s_pNtk = NULL;
00081
00082 sat_solver_delete( pSat );
00083 return 1;
00084 }
00085
00097 void Io_WriteCnfOutputPiMapping( FILE * pFile, int incrementVars )
00098 {
00099 extern Vec_Int_t * Abc_NtkGetCiSatVarNums( Abc_Ntk_t * pNtk );
00100 Abc_Ntk_t * pNtk = s_pNtk;
00101 Vec_Int_t * vCiIds;
00102 Abc_Obj_t * pObj;
00103 int i;
00104 vCiIds = Abc_NtkGetCiSatVarNums( pNtk );
00105 fprintf( pFile, "c PI variable numbers: <PI_name> <SAT_var_number>\n" );
00106 Abc_NtkForEachCi( pNtk, pObj, i )
00107 fprintf( pFile, "c %s %d\n", Abc_ObjName(pObj), Vec_IntEntry(vCiIds, i) + (int)(incrementVars > 0) );
00108 Vec_IntFree( vCiIds );
00109 }
00110
00114
00115