ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ioWriteCnf.c
Go to the documentation of this file.
1
20
21#include "ioAbc.h"
22#include "sat/bsat/satSolver.h"
23
25
26
30
31static Abc_Ntk_t * s_pNtk = NULL;
32
36
48int Io_WriteCnf( Abc_Ntk_t * pNtk, char * pFileName, int fAllPrimes )
49{
50 sat_solver * pSat;
51 if ( Abc_NtkIsStrash(pNtk) )
52 printf( "Io_WriteCnf() warning: Generating CNF by applying heuristic AIG to CNF conversion.\n" );
53 else
54 printf( "Io_WriteCnf() warning: Generating CNF by convering logic nodes into CNF clauses.\n" );
55 if ( Abc_NtkPoNum(pNtk) != 1 )
56 {
57 fprintf( stdout, "Io_WriteCnf(): Currently can only process the miter (the network with one PO).\n" );
58 return 0;
59 }
60 if ( Abc_NtkLatchNum(pNtk) != 0 )
61 {
62 fprintf( stdout, "Io_WriteCnf(): Currently can only process the miter for combinational circuits.\n" );
63 return 0;
64 }
65 if ( Abc_NtkNodeNum(pNtk) == 0 )
66 {
67 fprintf( stdout, "The network has no logic nodes. No CNF file is generaled.\n" );
68 return 0;
69 }
70 // convert to logic BDD network
71 if ( Abc_NtkIsLogic(pNtk) )
72 Abc_NtkToBdd( pNtk );
73 // create solver with clauses
74 pSat = (sat_solver *)Abc_NtkMiterSatCreate( pNtk, fAllPrimes );
75 if ( pSat == NULL )
76 {
77 fprintf( stdout, "The problem is trivially UNSAT. No CNF file is generated.\n" );
78 return 1;
79 }
80 // write the clauses
81 s_pNtk = pNtk;
82 Sat_SolverWriteDimacs( pSat, pFileName, 0, 0, 1 );
83 s_pNtk = NULL;
84 // free the solver
85 sat_solver_delete( pSat );
86 return 1;
87}
88
100void Io_WriteCnfOutputPiMapping( FILE * pFile, int incrementVars )
101{
102 extern Vec_Int_t * Abc_NtkGetCiSatVarNums( Abc_Ntk_t * pNtk );
103 Abc_Ntk_t * pNtk = s_pNtk;
104 Vec_Int_t * vCiIds;
105 Abc_Obj_t * pObj;
106 int i;
107 vCiIds = Abc_NtkGetCiSatVarNums( pNtk );
108 fprintf( pFile, "c PI variable numbers: <PI_name> <SAT_var_number>\n" );
109 Abc_NtkForEachCi( pNtk, pObj, i )
110 fprintf( pFile, "c %s %d\n", Abc_ObjName(pObj), Vec_IntEntry(vCiIds, i) + (int)(incrementVars > 0) );
111 Vec_IntFree( vCiIds );
112}
113
117
118
120
Vec_Int_t * Abc_NtkGetCiSatVarNums(Abc_Ntk_t *pNtk)
Definition abcSat.c:189
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL void * Abc_NtkMiterSatCreate(Abc_Ntk_t *pNtk, int fAllPrimes)
Definition abcSat.c:664
ABC_DLL int Abc_NtkToBdd(Abc_Ntk_t *pNtk)
Definition abcFunc.c:1299
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
#define sat_solver
Definition cecSatG2.c:34
void Io_WriteCnfOutputPiMapping(FILE *pFile, int incrementVars)
Definition ioWriteCnf.c:100
int Io_WriteCnf(Abc_Ntk_t *pNtk, char *pFileName, int fAllPrimes)
FUNCTION DEFINITIONS ///.
Definition ioWriteCnf.c:48
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
void Sat_SolverWriteDimacs(sat_solver *p, char *pFileName, lit *assumptionsBegin, lit *assumptionsEnd, int incrementVars)
Definition satUtil.c:74