abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ioWriteCnf.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [ioWriteCnf.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Command processing package.]
8 
9  Synopsis [Procedures to output CNF of the miter cone.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: ioWriteCnf.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "ioAbc.h"
22 #include "sat/bsat/satSolver.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static Abc_Ntk_t * s_pNtk = NULL;
32 
33 ////////////////////////////////////////////////////////////////////////
34 /// FUNCTION DEFINITIONS ///
35 ////////////////////////////////////////////////////////////////////////
36 
37 /**Function*************************************************************
38 
39  Synopsis [Write the miter cone into a CNF file for the SAT solver.]
40 
41  Description []
42 
43  SideEffects []
44 
45  SeeAlso []
46 
47 ***********************************************************************/
48 int 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 
89 /**Function*************************************************************
90 
91  Synopsis [Output the mapping of PIs into variable numbers.]
92 
93  Description []
94 
95  SideEffects []
96 
97  SeeAlso []
98 
99 ***********************************************************************/
100 void 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 
114 ////////////////////////////////////////////////////////////////////////
115 /// END OF FILE ///
116 ////////////////////////////////////////////////////////////////////////
117 
118 
120 
static int Abc_NtkIsStrash(Abc_Ntk_t *pNtk)
Definition: abc.h:251
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void sat_solver_delete(sat_solver *s)
Definition: satSolver.c:1141
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
void Io_WriteCnfOutputPiMapping(FILE *pFile, int incrementVars)
Definition: ioWriteCnf.c:100
ABC_DLL void * Abc_NtkMiterSatCreate(Abc_Ntk_t *pNtk, int fAllPrimes)
Definition: abcSat.c:629
int Io_WriteCnf(Abc_Ntk_t *pNtk, char *pFileName, int fAllPrimes)
FUNCTION DEFINITIONS ///.
Definition: ioWriteCnf.c:48
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
Vec_Int_t * Abc_NtkGetCiSatVarNums(Abc_Ntk_t *pNtk)
Definition: abcSat.c:154
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
ABC_DLL int Abc_NtkToBdd(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1160
void Sat_SolverWriteDimacs(sat_solver *p, char *pFileName, lit *assumptionsBegin, lit *assumptionsEnd, int incrementVars)
Definition: satUtil.c:71
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition: abc.h:515
static int Abc_NtkPoNum(Abc_Ntk_t *pNtk)
Definition: abc.h:286
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
static ABC_NAMESPACE_IMPL_START Abc_Ntk_t * s_pNtk
DECLARATIONS ///.
Definition: ioWriteCnf.c:31
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235