abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cnfCore.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cnfCore.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG-to-CNF conversion.]
8 
9  Synopsis []
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: cnfCore.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "cnf.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 static Cnf_Man_t * s_pManCnf = NULL;
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 /**Function*************************************************************
36 
37  Synopsis []
38 
39  Description []
40 
41  SideEffects []
42 
43  SeeAlso []
44 
45 ***********************************************************************/
47 {
48  if ( s_pManCnf == NULL )
49  {
50 // printf( "\n\nCreating CNF manager!!!!!\n\n" );
52  }
53 }
55 {
56  return s_pManCnf;
57 }
59 {
60  if ( s_pManCnf == NULL )
61  return;
63  s_pManCnf = NULL;
64 }
65 
66 
67 /**Function*************************************************************
68 
69  Synopsis [Converts AIG into the SAT solver.]
70 
71  Description []
72 
73  SideEffects []
74 
75  SeeAlso []
76 
77 ***********************************************************************/
79 {
80  Vec_Int_t * vResult;
81  Cnf_Man_t * p;
82  Vec_Ptr_t * vMapped;
83  Aig_MmFixed_t * pMemCuts;
84  abctime clk;
85  // allocate the CNF manager
86  p = Cnf_ManStart();
87  p->pManAig = pAig;
88 
89  // generate cuts for all nodes, assign cost, and find best cuts
90 clk = Abc_Clock();
91  pMemCuts = Dar_ManComputeCuts( pAig, 10, 0, 0 );
92 p->timeCuts = Abc_Clock() - clk;
93 
94  // find the mapping
95 clk = Abc_Clock();
96  Cnf_DeriveMapping( p );
97 p->timeMap = Abc_Clock() - clk;
98 // Aig_ManScanMapping( p, 1 );
99 
100  // convert it into CNF
101 clk = Abc_Clock();
102  Cnf_ManTransferCuts( p );
103  vMapped = Cnf_ManScanMapping( p, 1, 0 );
104  vResult = Cnf_ManWriteCnfMapping( p, vMapped );
105  Vec_PtrFree( vMapped );
106  Aig_MmFixedStop( pMemCuts, 0 );
107 p->timeSave = Abc_Clock() - clk;
108 
109  // reset reference counters
110  Aig_ManResetRefs( pAig );
111 //ABC_PRT( "Cuts ", p->timeCuts );
112 //ABC_PRT( "Map ", p->timeMap );
113 //ABC_PRT( "Saving ", p->timeSave );
114  Cnf_ManStop( p );
115  return vResult;
116 }
117 
118 /**Function*************************************************************
119 
120  Synopsis [Converts AIG into the SAT solver.]
121 
122  Description []
123 
124  SideEffects []
125 
126  SeeAlso []
127 
128 ***********************************************************************/
129 Cnf_Dat_t * Cnf_DeriveWithMan( Cnf_Man_t * p, Aig_Man_t * pAig, int nOutputs )
130 {
131  Cnf_Dat_t * pCnf;
132  Vec_Ptr_t * vMapped;
133  Aig_MmFixed_t * pMemCuts;
134  abctime clk;
135  // connect the managers
136  p->pManAig = pAig;
137 
138  // generate cuts for all nodes, assign cost, and find best cuts
139 clk = Abc_Clock();
140  pMemCuts = Dar_ManComputeCuts( pAig, 10, 0, 0 );
141 p->timeCuts = Abc_Clock() - clk;
142 
143  // find the mapping
144 clk = Abc_Clock();
145  Cnf_DeriveMapping( p );
146 p->timeMap = Abc_Clock() - clk;
147 // Aig_ManScanMapping( p, 1 );
148 
149  // convert it into CNF
150 clk = Abc_Clock();
151  Cnf_ManTransferCuts( p );
152  vMapped = Cnf_ManScanMapping( p, 1, 1 );
153  pCnf = Cnf_ManWriteCnf( p, vMapped, nOutputs );
154  Vec_PtrFree( vMapped );
155  Aig_MmFixedStop( pMemCuts, 0 );
156 p->timeSave = Abc_Clock() - clk;
157 
158  // reset reference counters
159  Aig_ManResetRefs( pAig );
160 //ABC_PRT( "Cuts ", p->timeCuts );
161 //ABC_PRT( "Map ", p->timeMap );
162 //ABC_PRT( "Saving ", p->timeSave );
163  return pCnf;
164 }
165 Cnf_Dat_t * Cnf_Derive( Aig_Man_t * pAig, int nOutputs )
166 {
167  Cnf_ManPrepare();
168  return Cnf_DeriveWithMan( s_pManCnf, pAig, nOutputs );
169 }
170 
171 /**Function*************************************************************
172 
173  Synopsis [Converts AIG into the SAT solver.]
174 
175  Description []
176 
177  SideEffects []
178 
179  SeeAlso []
180 
181 ***********************************************************************/
182 Cnf_Dat_t * Cnf_DeriveOtherWithMan( Cnf_Man_t * p, Aig_Man_t * pAig, int fSkipTtMin )
183 {
184  Cnf_Dat_t * pCnf;
185  Vec_Ptr_t * vMapped;
186  Aig_MmFixed_t * pMemCuts;
187  abctime clk;
188  // connect the managers
189  p->pManAig = pAig;
190 
191  // generate cuts for all nodes, assign cost, and find best cuts
192 clk = Abc_Clock();
193  pMemCuts = Dar_ManComputeCuts( pAig, 10, fSkipTtMin, 0 );
194 p->timeCuts = Abc_Clock() - clk;
195 
196  // find the mapping
197 clk = Abc_Clock();
198  Cnf_DeriveMapping( p );
199 p->timeMap = Abc_Clock() - clk;
200 // Aig_ManScanMapping( p, 1 );
201 
202  // convert it into CNF
203 clk = Abc_Clock();
204  Cnf_ManTransferCuts( p );
205  vMapped = Cnf_ManScanMapping( p, 1, 1 );
206  pCnf = Cnf_ManWriteCnfOther( p, vMapped );
207  pCnf->vMapping = Cnf_ManWriteCnfMapping( p, vMapped );
208  Vec_PtrFree( vMapped );
209  Aig_MmFixedStop( pMemCuts, 0 );
210 p->timeSave = Abc_Clock() - clk;
211 
212  // reset reference counters
213  Aig_ManResetRefs( pAig );
214 //ABC_PRT( "Cuts ", p->timeCuts );
215 //ABC_PRT( "Map ", p->timeMap );
216 //ABC_PRT( "Saving ", p->timeSave );
217  return pCnf;
218 }
219 Cnf_Dat_t * Cnf_DeriveOther( Aig_Man_t * pAig, int fSkipTtMin )
220 {
221  Cnf_ManPrepare();
222  return Cnf_DeriveOtherWithMan( s_pManCnf, pAig, fSkipTtMin );
223 }
224 
225 #if 0
226 
227 /**Function*************************************************************
228 
229  Synopsis []
230 
231  Description []
232 
233  SideEffects []
234 
235  SeeAlso []
236 
237 ***********************************************************************/
238 Cnf_Dat_t * Cnf_Derive_old( Aig_Man_t * pAig )
239 {
240 /*
241  // iteratively improve area flow
242  for ( i = 0; i < nIters; i++ )
243  {
244 clk = Abc_Clock();
245  Cnf_ManScanMapping( p, 0 );
246  Cnf_ManMapForCnf( p );
247 ABC_PRT( "iter ", Abc_Clock() - clk );
248  }
249 */
250  // write the file
251  vMapped = Aig_ManScanMapping( p, 1 );
252  Vec_PtrFree( vMapped );
253 
254 clk = Abc_Clock();
256 
258  Cnf_ManScanMapping( p, 0 );
259 /*
260  Cnf_ManPostprocess( p );
261  Cnf_ManScanMapping( p, 0 );
262  Cnf_ManPostprocess( p );
263  Cnf_ManScanMapping( p, 0 );
264 */
265 ABC_PRT( "Ext ", Abc_Clock() - clk );
266 
267 /*
268  vMapped = Cnf_ManScanMapping( p, 1 );
269  pCnf = Cnf_ManWriteCnf( p, vMapped );
270  Vec_PtrFree( vMapped );
271 
272  // clean up
273  Cnf_ManFreeCuts( p );
274  Dar_ManCutsFree( pAig );
275  return pCnf;
276 */
277  Aig_MmFixedStop( pMemCuts, 0 );
278  return NULL;
279 }
280 
281 #endif
282 
283 
284 ////////////////////////////////////////////////////////////////////////
285 /// END OF FILE ///
286 ////////////////////////////////////////////////////////////////////////
287 
288 
290 
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
void Cnf_ManPostprocess(Cnf_Man_t *p)
Definition: cnfPost.c:165
Cnf_Dat_t * Cnf_DeriveWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:129
void Cnf_ManPrepare()
FUNCTION DEFINITIONS ///.
Definition: cnfCore.c:46
Vec_Ptr_t * Cnf_ManScanMapping(Cnf_Man_t *p, int fCollect, int fPreorder)
Definition: cnfUtil.c:170
Vec_Int_t * Cnf_DeriveMappingArray(Aig_Man_t *pAig)
FUNCTION DECLARATIONS ///.
Definition: cnfCore.c:78
void Cnf_ManStop(Cnf_Man_t *p)
Definition: cnfMan.c:82
void Aig_MmFixedStop(Aig_MmFixed_t *p, int fVerbose)
Definition: aigMem.c:132
Vec_Int_t * vMapping
Definition: cnf.h:67
Cnf_Dat_t * Cnf_ManWriteCnfOther(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
Definition: cnfWrite.c:419
static abctime Abc_Clock()
Definition: abc_global.h:279
Definition: cnf.h:56
DECLARATIONS ///.
Definition: aigMem.c:30
Cnf_Dat_t * Cnf_ManWriteCnf(Cnf_Man_t *p, Vec_Ptr_t *vMapped, int nOutputs)
Definition: cnfWrite.c:199
Aig_MmFixed_t * Dar_ManComputeCuts(Aig_Man_t *pAig, int nCutsMax, int fSkipTtMin, int fVerbose)
Definition: darCore.c:287
Cnf_Dat_t * Cnf_DeriveOther(Aig_Man_t *pAig, int fSkipTtMin)
Definition: cnfCore.c:219
void Cnf_DeriveMapping(Cnf_Man_t *p)
Definition: cnfMap.c:100
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
Cnf_Man_t * Cnf_ManRead()
Definition: cnfCore.c:54
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition: cnfPost.c:117
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
Cnf_Dat_t * Cnf_Derive(Aig_Man_t *pAig, int nOutputs)
Definition: cnfCore.c:165
Vec_Int_t * Cnf_ManWriteCnfMapping(Cnf_Man_t *p, Vec_Ptr_t *vMapped)
DECLARATIONS ///.
Definition: cnfWrite.c:45
Cnf_Man_t * Cnf_ManStart()
FUNCTION DEFINITIONS ///.
Definition: cnfMan.c:51
void Cnf_ManFree()
Definition: cnfCore.c:58
Cnf_Dat_t * Cnf_DeriveOtherWithMan(Cnf_Man_t *p, Aig_Man_t *pAig, int fSkipTtMin)
Definition: cnfCore.c:182
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static ABC_NAMESPACE_IMPL_START Cnf_Man_t * s_pManCnf
DECLARATIONS ///.
Definition: cnfCore.c:30
Vec_Ptr_t * Aig_ManScanMapping(Cnf_Man_t *p, int fCollect)
Definition: cnfUtil.c:90
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition: cnf.h:51
ABC_INT64_T abctime
Definition: abc_global.h:278
void Aig_ManResetRefs(Aig_Man_t *p)
Definition: aigUtil.c:122
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223