ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaSatMap.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "sat/bsat/satStore.h"
23#include "misc/vec/vecWec.h"
24#include "misc/util/utilNam.h"
25#include "map/scl/sclCon.h"
26
28
29
33
34
35// operation manager
36typedef struct Sbm_Man_t_ Sbm_Man_t;
38{
39 sat_solver * pSat; // SAT solver
40 Vec_Int_t * vCardVars; // candinality variables
41 int LogN; // max vars
42 int FirstVar; // first variable to be used
43 int LitShift; // shift in terms of literals (2*Gia_ManCiNum(pGia)+2)
44 int nInputs; // the number of inputs
45 // window
46 Vec_Int_t * vRoots; // output drivers to be mapped (root -> lit)
47 Vec_Wec_t * vCuts; // cuts (cut -> node lit + fanin lits)
48 Vec_Wec_t * vObjCuts; // cuts (obj -> node lit + cut lits)
49 Vec_Int_t * vSolCuts; // current solution (index -> cut)
50 Vec_Int_t * vCutGates; // gates (cut -> gate)
51 Vec_Wrd_t * vCutAreas; // area of each cut
52 // solver
53 Vec_Int_t * vAssump; // assumptions (root nodes)
54 Vec_Int_t * vPolar; // polarity of nodes and cuts
55 // timing
56 Vec_Int_t * vArrs; // arrivals for the inputs (input -> time)
57 Vec_Int_t * vReqs; // required for the outputs (root -> time)
58 // internal
59 Vec_Int_t * vLit2Used; // current solution (lit -> used)
60 Vec_Int_t * vDelays; // node arrivals (lit -> time)
61 Vec_Int_t * vReason; // timing reasons (lit -> cut)
62};
63
64/*
65 Cuts in p->vCuts have 0-based numbers and are expressed in terms of object literals.
66 Cuts in p->vObjCuts are expressed in terms of the obj-lit + cut-lits (i + p->FirstVar)
67 Unit cuts for each polarity are ordered in the end.
68*/
69
73
86{
87 //int K = Vec_IntSize(vSol) - 1;
88 int i, j, Lit, Cut;
89 int RetValue = 1;
90 Vec_Int_t * vCut;
91 // clear polarity and assumptions
92 Vec_IntClear( p->vPolar );
93 // mark used literals
94 Vec_IntFill( p->vLit2Used, Vec_WecSize(p->vObjCuts) + p->nInputs, 0 );
95 Vec_IntForEachEntry( p->vSolCuts, Cut, i )
96 {
97 if ( Cut < 0 ) // input inverter variable
98 {
99 Vec_IntWriteEntry( p->vLit2Used, -Cut, 1 );
100 Vec_IntPush( p->vPolar, -Cut );
101 continue;
102 }
103 Vec_IntPush( p->vPolar, p->FirstVar + Cut );
104 vCut = Vec_WecEntry( p->vCuts, Cut );
105 Lit = Vec_IntEntry( vCut, 0 ) - p->LitShift; // obj literal
106 if ( Vec_IntEntry(p->vLit2Used, Lit) )
107 continue;
108 Vec_IntWriteEntry( p->vLit2Used, Lit, 1 );
109 Vec_IntPush( p->vPolar, Lit ); // literal variable
110 }
111 // check that the output literals are used
112 Vec_IntForEachEntry( p->vRoots, Lit, i )
113 {
114 if ( Vec_IntEntry(p->vLit2Used, Lit) == 0 )
115 printf( "Output literal %d has no cut.\n", Lit ), RetValue = 0;
116 }
117 // check internal nodes
118 Vec_IntForEachEntry( p->vSolCuts, Cut, i )
119 {
120 if ( Cut < 0 )
121 continue;
122 vCut = Vec_WecEntry( p->vCuts, Cut );
123 Vec_IntForEachEntryStart( vCut, Lit, j, 1 )
124 if ( Lit - p->LitShift < 0 )
125 {
126 assert( Abc_LitIsCompl(Lit) );
127 if ( Vec_IntEntry(p->vLit2Used, Vec_WecSize(p->vObjCuts) + Abc_Lit2Var(Lit)-1) == 0 )
128 printf( "Inverter of input %d of cut %d is not mapped.\n", Abc_Lit2Var(Lit)-1, Cut ), RetValue = 0;
129 }
130 else if ( Vec_IntEntry(p->vLit2Used, Lit - p->LitShift) == 0 )
131 printf( "Internal literal %d of cut %d is not mapped.\n", Lit - p->LitShift, Cut ), RetValue = 0;
132 // create polarity
133 Vec_IntPush( p->vPolar, p->FirstVar + Cut ); // cut variable
134 }
135 return RetValue;
136}
137
150{
151 int i, k, Lit, Lits[2], value;
152 Vec_Int_t * vLits, * vCutOne, * vLitsPrev;
153 // sat_solver_rollback( p->Sat );
154 if ( !Sbm_ManCheckSol(p, p->vSolCuts) )
155 return 0;
156 // increase var count
157 assert( p->FirstVar == sat_solver_nvars(p->pSat) );
158 sat_solver_setnvars( p->pSat, sat_solver_nvars(p->pSat) + Vec_WecSize(p->vCuts) );
159 // iterate over arrays containing obj-lit cuts (neg-obj-lit cut-lits followed by pos-obj-lit cut-lits)
160 vLitsPrev = NULL;
161 Vec_WecForEachLevel( p->vObjCuts, vLits, i )
162 {
163 assert( Vec_IntSize(vLits) >= 2 );
164 value = sat_solver_addclause( p->pSat, Vec_IntArray(vLits), Vec_IntLimit(vLits) );
165 assert( value );
166/*
167 // for each cut, add implied nodes
168 Lits[0] = Abc_LitNot( Vec_IntEntry(vLits, 0) );
169 assert( Lits[0] < 2*p->FirstVar );
170 Vec_IntForEachEntryStart( vLits, Lit, k, 1 )
171 {
172 assert( Lit >= 2*p->FirstVar );
173 Lits[1] = Abc_LitNot( Lit );
174 value = sat_solver_addclause( p->pSat, Lits, Lits + 2 );
175 assert( value );
176 //printf( "Adding clause %d + %d.\n", Lits[0], Lits[1]-2*p->FirstVar );
177 }
178*/
179 //printf( "\n" );
180 // create invertor exclusivity clause
181 if ( i & 1 )
182 {
183 Lits[0] = Abc_LitNot( Vec_IntEntryLast(vLits) );
184 Lits[1] = Abc_LitNot( Vec_IntEntryLast(vLitsPrev) );
185 value = sat_solver_addclause( p->pSat, Lits, Lits + 2 );
186 assert( value );
187 //printf( "Adding exclusivity clause %d + %d.\n", Lits[0]-2*p->FirstVar, Lits[1]-2*p->FirstVar );
188 }
189 vLitsPrev = vLits;
190 }
191 // add inverters
192 Vec_WecForEachLevel( p->vCuts, vCutOne, i )
193 Vec_IntForEachEntry( vCutOne, Lit, k )
194 if ( Abc_Lit2Var(Lit)-1 < p->nInputs ) // input
195 {
196 assert( k > 0 );
197 Lits[0] = Abc_Var2Lit( Vec_WecSize(p->vObjCuts) + Abc_Lit2Var(Lit)-1, 0 );
198 Lits[1] = Abc_Var2Lit( p->FirstVar + i, 1 );
199 value = sat_solver_addclause( p->pSat, Lits, Lits + 2 );
200 assert( value );
201 }
202 else // internal node
203 {
204 Lits[0] = Abc_Var2Lit( Lit-p->LitShift, 0 );
205 Lits[1] = Abc_Var2Lit( p->FirstVar + i, 1 );
206 value = sat_solver_addclause( p->pSat, Lits, Lits + 2 );
207 assert( value );
208 }
209
210 sat_solver_set_polarity( p->pSat, Vec_IntArray(p->vPolar), Vec_IntSize(p->vPolar) );
211 return 1;
212}
213
225static inline int sat_solver_add_and1( sat_solver * pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl )
226{
227 lit Lits[3];
228 int Cid;
229
230 Lits[0] = toLitCond( iVar, !fCompl );
231 Lits[1] = toLitCond( iVar0, fCompl0 );
232 Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
233 assert( Cid );
234
235 Lits[0] = toLitCond( iVar, !fCompl );
236 Lits[1] = toLitCond( iVar1, fCompl1 );
237 Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
238 assert( Cid );
239/*
240 Lits[0] = toLitCond( iVar, fCompl );
241 Lits[1] = toLitCond( iVar0, !fCompl0 );
242 Lits[2] = toLitCond( iVar1, !fCompl1 );
243 Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
244 assert( Cid );
245*/
246 return 3;
247}
248
249static inline int sat_solver_add_and2( sat_solver * pSat, int iVar, int iVar0, int iVar1, int fCompl0, int fCompl1, int fCompl )
250{
251 lit Lits[3];
252 int Cid;
253/*
254 Lits[0] = toLitCond( iVar, !fCompl );
255 Lits[1] = toLitCond( iVar0, fCompl0 );
256 Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
257 assert( Cid );
258
259 Lits[0] = toLitCond( iVar, !fCompl );
260 Lits[1] = toLitCond( iVar1, fCompl1 );
261 Cid = sat_solver_addclause( pSat, Lits, Lits + 2 );
262 assert( Cid );
263*/
264 Lits[0] = toLitCond( iVar, fCompl );
265 Lits[1] = toLitCond( iVar0, !fCompl0 );
266 Lits[2] = toLitCond( iVar1, !fCompl1 );
267 Cid = sat_solver_addclause( pSat, Lits, Lits + 3 );
268 assert( Cid );
269 return 3;
270}
271
272
284static inline int Card_AddClause( Vec_Int_t * p, int* begin, int* end )
285{
286 Vec_IntPush( p, (int)(end-begin) );
287 while ( begin < end )
288 Vec_IntPush( p, (int)*begin++ );
289 return 1;
290}
291static inline int Card_AddHalfSorter( Vec_Int_t * p, int iVarA, int iVarB, int iVar0, int iVar1 )
292{
293 lit Lits[3];
294 int Cid;
295
296 Lits[0] = toLitCond( iVarA, 0 );
297 Lits[1] = toLitCond( iVar0, 1 );
298 Cid = Card_AddClause( p, Lits, Lits + 2 );
299 assert( Cid );
300
301 Lits[0] = toLitCond( iVarA, 0 );
302 Lits[1] = toLitCond( iVar1, 1 );
303 Cid = Card_AddClause( p, Lits, Lits + 2 );
304 assert( Cid );
305
306 Lits[0] = toLitCond( iVarB, 0 );
307 Lits[1] = toLitCond( iVar0, 1 );
308 Lits[2] = toLitCond( iVar1, 1 );
309 Cid = Card_AddClause( p, Lits, Lits + 3 );
310 assert( Cid );
311 return 3;
312}
313static inline void Card_AddSorter( Vec_Int_t * p, int * pVars, int i, int k, int * pnVars )
314{
315 int iVar1 = (*pnVars)++;
316 int iVar2 = (*pnVars)++;
317 Card_AddHalfSorter( p, iVar1, iVar2, pVars[i], pVars[k] );
318 pVars[i] = iVar1;
319 pVars[k] = iVar2;
320}
321static inline void Card_AddCardinConstrMerge( Vec_Int_t * p, int * pVars, int lo, int hi, int r, int * pnVars )
322{
323 int i, step = r * 2;
324 if ( step < hi - lo )
325 {
326 Card_AddCardinConstrMerge( p, pVars, lo, hi-r, step, pnVars );
327 Card_AddCardinConstrMerge( p, pVars, lo+r, hi, step, pnVars );
328 for ( i = lo+r; i < hi-r; i += step )
329 Card_AddSorter( p, pVars, i, i+r, pnVars );
330 for ( i = lo+r; i < hi-r-1; i += r )
331 {
332 lit Lits[2] = { Abc_Var2Lit(pVars[i], 0), Abc_Var2Lit(pVars[i+r], 1) };
333 int Cid = Card_AddClause( p, Lits, Lits + 2 );
334 assert( Cid );
335 }
336 }
337}
338static inline void Card_AddCardinConstrRange( Vec_Int_t * p, int * pVars, int lo, int hi, int * pnVars )
339{
340 if ( hi - lo >= 1 )
341 {
342 int i, mid = lo + (hi - lo) / 2;
343 for ( i = lo; i <= mid; i++ )
344 Card_AddSorter( p, pVars, i, i + (hi - lo + 1) / 2, pnVars );
345 Card_AddCardinConstrRange( p, pVars, lo, mid, pnVars );
346 Card_AddCardinConstrRange( p, pVars, mid+1, hi, pnVars );
347 Card_AddCardinConstrMerge( p, pVars, lo, hi, 1, pnVars );
348 }
349}
351{
352 int nVars = Vec_IntSize(vVars);
353 Card_AddCardinConstrRange( p, Vec_IntArray(vVars), 0, nVars - 1, &nVars );
354 return nVars;
355}
356int Card_AddCardinSolver( int LogN, Vec_Int_t ** pvVars, Vec_Int_t ** pvRes )
357{
358 int nVars = 1 << LogN;
359 int nVarsAlloc = nVars + 2 * (nVars * LogN * (LogN-1) / 4 + nVars - 1);
360 Vec_Int_t * vRes = Vec_IntAlloc( 1000 );
361 Vec_Int_t * vVars = Vec_IntStartNatural( nVars );
362 int nVarsReal = Card_AddCardinConstrPairWise( vRes, vVars );
363 assert( nVarsReal == nVarsAlloc );
364 Vec_IntPush( vRes, -1 );
365 *pvVars = vVars;
366 *pvRes = vRes;
367 return nVarsReal;
368}
369sat_solver * Sbm_AddCardinSolver2( int LogN, Vec_Int_t ** pvVars, Vec_Int_t ** pvRes )
370{
371 Vec_Int_t * vVars = NULL;
372 Vec_Int_t * vRes = NULL;
373 int nVarsReal = Card_AddCardinSolver( LogN, &vVars, &vRes ), i, size;
374 sat_solver * pSat = sat_solver_new();
375 sat_solver_setnvars( pSat, nVarsReal );
376 for ( i = 0, size = Vec_IntEntry(vRes, i++); i < Vec_IntSize(vRes); i += size, size = Vec_IntEntry(vRes, i++) )
377 sat_solver_addclause( pSat, Vec_IntEntryP(vRes, i), Vec_IntEntryP(vRes, i+size) );
378 if ( pvVars ) *pvVars = vVars;
379 if ( pvRes ) *pvRes = vRes;
380 return pSat;
381}
382
383
395static inline void Sbm_AddSorter( sat_solver * p, int * pVars, int i, int k, int * pnVars )
396{
397 int iVar1 = (*pnVars)++;
398 int iVar2 = (*pnVars)++;
399 int fVerbose = 0;
400 if ( fVerbose )
401 {
402 int v;
403 for ( v = 0; v < i; v++ )
404 printf( " " );
405 printf( "<" );
406 for ( v = i+1; v < k; v++ )
407 printf( "-" );
408 printf( ">" );
409 for ( v = k+1; v < 8; v++ )
410 printf( " " );
411 printf( " " );
412 printf( "[%3d :%3d ] -> [%3d :%3d ]\n", pVars[i], pVars[k], iVar1, iVar2 );
413 }
414// sat_solver_add_and1( p, iVar1, pVars[i], pVars[k], 1, 1, 1 );
415// sat_solver_add_and2( p, iVar2, pVars[i], pVars[k], 0, 0, 0 );
416 sat_solver_add_half_sorter( p, iVar1, iVar2, pVars[i], pVars[k] );
417 pVars[i] = iVar1;
418 pVars[k] = iVar2;
419}
420static inline void Sbm_AddCardinConstrMerge( sat_solver * p, int * pVars, int lo, int hi, int r, int * pnVars )
421{
422 int i, step = r * 2;
423 if ( step < hi - lo )
424 {
425 Sbm_AddCardinConstrMerge( p, pVars, lo, hi-r, step, pnVars );
426 Sbm_AddCardinConstrMerge( p, pVars, lo+r, hi, step, pnVars );
427 for ( i = lo+r; i < hi-r; i += step )
428 Sbm_AddSorter( p, pVars, i, i+r, pnVars );
429 for ( i = lo+r; i < hi-r-1; i += r )
430 {
431 lit Lits[2] = { Abc_Var2Lit(pVars[i], 0), Abc_Var2Lit(pVars[i+r], 1) };
432 int Cid = sat_solver_addclause( p, Lits, Lits + 2 );
433 assert( Cid );
434 }
435 }
436}
437static inline void Sbm_AddCardinConstrRange( sat_solver * p, int * pVars, int lo, int hi, int * pnVars )
438{
439 if ( hi - lo >= 1 )
440 {
441 int i, mid = lo + (hi - lo) / 2;
442 for ( i = lo; i <= mid; i++ )
443 Sbm_AddSorter( p, pVars, i, i + (hi - lo + 1) / 2, pnVars );
444 Sbm_AddCardinConstrRange( p, pVars, lo, mid, pnVars );
445 Sbm_AddCardinConstrRange( p, pVars, mid+1, hi, pnVars );
446 Sbm_AddCardinConstrMerge( p, pVars, lo, hi, 1, pnVars );
447 }
448}
450{
451 int nVars = Vec_IntSize(vVars);
452 Sbm_AddCardinConstrRange( p, Vec_IntArray(vVars), 0, nVars - 1, &nVars );
453 sat_solver_bookmark( p );
454 return nVars;
455}
457{
458 int nVars = 1 << LogN;
459 int nVarsAlloc = nVars + 2 * (nVars * LogN * (LogN-1) / 4 + nVars - 1), nVarsReal;
460 Vec_Int_t * vVars = Vec_IntStartNatural( nVars );
461 sat_solver * pSat = sat_solver_new();
462 sat_solver_setnvars( pSat, nVarsAlloc );
463 nVarsReal = Sbm_AddCardinConstrPairWise( pSat, vVars, 2 );
464 assert( nVarsReal == nVarsAlloc );
465 *pvVars = vVars;
466 return pSat;
467}
468
470{
471 int LogN = 3, nVars = 1 << LogN, K = 2, Count = 1;
472 Vec_Int_t * vVars, * vLits = Vec_IntAlloc( nVars );
473 sat_solver * pSat = Sbm_AddCardinSolver( LogN, &vVars );
474 int nVarsReal = sat_solver_nvars( pSat );
475
476 int Lit = Abc_Var2Lit( Vec_IntEntry(vVars, K), 1 );
477 printf( "LogN = %d. N = %3d. Vars = %5d. Clauses = %6d. Comb = %d.\n", LogN, nVars, nVarsReal, sat_solver_nclauses(pSat), nVars * (nVars-1)/2 + nVars + 1 );
478 while ( 1 )
479 {
480 int i, status = sat_solver_solve( pSat, &Lit, &Lit+1, 0, 0, 0, 0 );
481 if ( status != l_True )
482 break;
483 Vec_IntClear( vLits );
484 printf( "%3d : ", Count++ );
485 for ( i = 0; i < nVars; i++ )
486 {
487 Vec_IntPush( vLits, Abc_Var2Lit(i, sat_solver_var_value(pSat, i)) );
488 printf( "%d", sat_solver_var_value(pSat, i) );
489 }
490 printf( "\n" );
491 status = sat_solver_addclause( pSat, Vec_IntArray(vLits), Vec_IntArray(vLits) + nVars );
492 if ( status == 0 )
493 break;
494 }
495
496 sat_solver_delete( pSat );
497 Vec_IntFree( vVars );
498 Vec_IntFree( vLits );
499}
500
513{
515 p->pSat = Sbm_AddCardinSolver( LogN, &p->vCardVars );
516 p->LogN = LogN;
517 p->FirstVar = sat_solver_nvars( p->pSat );
518 // window
519 p->vRoots = Vec_IntAlloc( 100 );
520 p->vCuts = Vec_WecAlloc( 1000 );
521 p->vObjCuts = Vec_WecAlloc( 1000 );
522 p->vSolCuts = Vec_IntAlloc( 100 );
523 p->vCutGates = Vec_IntAlloc( 100 );
524 p->vCutAreas = Vec_WrdAlloc( 100 );
525 // solver
526 p->vAssump = Vec_IntAlloc( 100 );
527 p->vPolar = Vec_IntAlloc( 100 );
528 // timing
529 p->vArrs = Vec_IntAlloc( 100 );
530 p->vReqs = Vec_IntAlloc( 100 );
531 // internal
532 p->vLit2Used = Vec_IntAlloc( 100 );
533 p->vDelays = Vec_IntAlloc( 100 );
534 p->vReason = Vec_IntAlloc( 100 );
535 return p;
536}
537
539{
540 sat_solver_delete( p->pSat );
541 Vec_IntFree( p->vCardVars );
542 // internal
543 Vec_IntFree( p->vRoots );
544 Vec_WecFree( p->vCuts );
545 Vec_WecFree( p->vObjCuts );
546 Vec_IntFree( p->vSolCuts );
547 Vec_IntFree( p->vCutGates );
548 Vec_WrdFree( p->vCutAreas );
549 // internal
550 Vec_IntFree( p->vAssump );
551 Vec_IntFree( p->vPolar );
552 // internal
553 Vec_IntFree( p->vArrs );
554 Vec_IntFree( p->vReqs );
555 // internal
556 Vec_IntFree( p->vLit2Used );
557 Vec_IntFree( p->vDelays );
558 Vec_IntFree( p->vReason );
559 ABC_FREE( p );
560}
561
562int Sbm_ManTestSat( void * pMan )
563{
564 abctime clk = Abc_Clock(), clk2;
565 int i, k, Lit, LogN = 7, nVars = 1 << LogN, status, Root;
566 Sbm_Man_t * p = Sbm_ManAlloc( LogN );
567 word InvArea = 0;
568 int fKeepTrying = 1;
569 int StartSol;
570 // derive window
571 extern int Nf_ManExtractWindow( void * pMan, Vec_Int_t * vRoots, Vec_Wec_t * vCuts, Vec_Wec_t * vObjCuts, Vec_Int_t * vSolCuts, Vec_Int_t * vCutGates, Vec_Wrd_t * vCutAreas, word * pInvArea, int StartVar, int nVars );
572 p->nInputs = Nf_ManExtractWindow( pMan, p->vRoots, p->vCuts, p->vObjCuts, p->vSolCuts, p->vCutGates, p->vCutAreas, &InvArea, p->FirstVar, nVars );
573 p->LitShift = 2*p->nInputs+2;
574 assert( Vec_WecSize(p->vObjCuts) + p->nInputs <= nVars );
575
576 // print-out
577// Vec_WecPrint( p->vCuts, 0 );
578// printf( "\n" );
579// Vec_WecPrint( p->vObjCuts, 0 );
580// printf( "\n" );
581 Vec_IntPrint( p->vSolCuts );
582 printf( "All clauses = %d. Multi clauses = %d. Binary clauses = %d. Other clauses = %d.\n",
583 sat_solver_nclauses(p->pSat), Vec_WecSize(p->vObjCuts), Vec_WecSizeSize(p->vCuts),
584 sat_solver_nclauses(p->pSat) - Vec_WecSize(p->vObjCuts) - Vec_WecSizeSize(p->vCuts) );
585
586 // creating CNF
587 if ( !Sbm_ManCreateCnf(p) )
588 return 0;
589
590 // create assumptions
591 // cardinality
592 Vec_IntClear( p->vAssump );
593 Vec_IntPush( p->vAssump, -1 );
594 // unused variables
595 for ( i = Vec_WecSize(p->vObjCuts) + p->nInputs; i < nVars; i++ )
596 Vec_IntPush( p->vAssump, Abc_Var2Lit(i, 1) );
597 // root variables
598 Vec_IntForEachEntry( p->vRoots, Root, i )
599 Vec_IntPush( p->vAssump, Abc_Var2Lit(Root, 0) );
600// Vec_IntPrint( p->vAssump );
601
602 StartSol = Vec_IntSize(p->vSolCuts);
603// StartSol = 30;
604 while ( fKeepTrying && StartSol-fKeepTrying > 0 )
605 {
606 printf( "Trying to find mapping with %d gates.\n", StartSol-fKeepTrying );
607 // for ( i = Vec_IntSize(p->vSolCuts)-5; i < nVars; i++ )
608 // Vec_IntPush( p->vAssump, Abc_Var2Lit(Vec_IntEntry(p->vCardVars, i), 1) );
609 Vec_IntWriteEntry( p->vAssump, 0, Abc_Var2Lit(Vec_IntEntry(p->vCardVars, StartSol-fKeepTrying), 1) );
610 // solve the problem
611 clk2 = Abc_Clock();
612 status = sat_solver_solve( p->pSat, Vec_IntArray(p->vAssump), Vec_IntLimit(p->vAssump), 0, 0, 0, 0 );
613 if ( status == l_True )
614 {
615 word AreaNew = 0;
616 int Count = 0;
617 printf( "AND Lits = %d. Inputs = %d. Vars = %d. All vars = %d.\n", Vec_WecSize(p->vObjCuts), p->nInputs, Vec_WecSize(p->vObjCuts) + p->nInputs, nVars );
618// for ( i = 0; i < nVars; i++ )
619// printf( "%d", sat_solver_var_value(p->pSat, i) );
620// printf( "\n" );
621 for ( i = 0; i < nVars; i++ )
622 if ( sat_solver_var_value(p->pSat, i) )
623 {
624 printf( "%d=%d ", i, sat_solver_var_value(p->pSat, i) );
625 Count++;
626 if ( i >= Vec_WecSize(p->vObjCuts) )
627 AreaNew += InvArea;
628 }
629 printf( "Count = %d\n", Count );
630// for ( i = p->FirstVar; i < sat_solver_nvars(p->pSat); i++ )
631// printf( "%d", sat_solver_var_value(p->pSat, i) );
632// printf( "\n" );
633 Count = 1;
634 for ( i = p->FirstVar; i < sat_solver_nvars(p->pSat); i++ )
635 if ( sat_solver_var_value(p->pSat, i) )
636 {
637 Vec_Int_t * vCutOne = Vec_WecEntry(p->vCuts, i-p->FirstVar);
638 printf( "%2d : Cut %3d (Gate %2d) ", Count, i-p->FirstVar, Vec_IntEntry(p->vCutGates, i-p->FirstVar) );
639 Vec_IntForEachEntry( vCutOne, Lit, k )
640 printf( "%d(%d) ", Lit - 2*(p->nInputs+1), Abc_Lit2Var(Lit) );
641 printf( "\n" );
642 Count++;
643 AreaNew += Vec_WrdEntry(p->vCutAreas, i-p->FirstVar);
644 }
645 printf( "Area = %7.2f\n", Scl_Int2Flt((int)AreaNew) );
646 }
647 if ( status == l_False )
648 printf( "UNSAT " ), fKeepTrying = 0;
649 else if ( status == l_True )
650 printf( "SAT " ), fKeepTrying++;
651 Abc_PrintTime( 1, "Time", Abc_Clock() - clk2 );
652 Abc_PrintTime( 1, "Total time", Abc_Clock() - clk );
653 printf( "\n" );
654 }
655 Sbm_ManStop( p );
656 return 1;
657}
658
659
663
664
666
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#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 l_True
Definition bmcBmcS.c:35
#define l_False
Definition bmcBmcS.c:36
ABC_NAMESPACE_IMPL_START typedef signed char value
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
Cube * p
Definition exorList.c:222
int Nf_ManExtractWindow(void *pMan, Vec_Int_t *vRoots, Vec_Wec_t *vCuts, Vec_Wec_t *vObjCuts, Vec_Int_t *vSolCuts, Vec_Int_t *vCutGates, Vec_Wrd_t *vCutAreas, word *pInvArea, int StartVar, int nVars)
Definition giaNf.c:2381
int Sbm_ManTestSat(void *pMan)
Definition giaSatMap.c:562
int Card_AddCardinConstrPairWise(Vec_Int_t *p, Vec_Int_t *vVars)
Definition giaSatMap.c:350
void Sbm_ManStop(Sbm_Man_t *p)
Definition giaSatMap.c:538
int Sbm_ManCheckSol(Sbm_Man_t *p, Vec_Int_t *vSol)
FUNCTION DEFINITIONS ///.
Definition giaSatMap.c:85
void Sbm_AddCardinConstrTest()
Definition giaSatMap.c:469
sat_solver * Sbm_AddCardinSolver(int LogN, Vec_Int_t **pvVars)
Definition giaSatMap.c:456
typedefABC_NAMESPACE_IMPL_START struct Sbm_Man_t_ Sbm_Man_t
DECLARATIONS ///.
Definition giaSatMap.c:36
int Sbm_AddCardinConstrPairWise(sat_solver *p, Vec_Int_t *vVars, int K)
Definition giaSatMap.c:449
sat_solver * Sbm_AddCardinSolver2(int LogN, Vec_Int_t **pvVars, Vec_Int_t **pvRes)
Definition giaSatMap.c:369
int Sbm_ManCreateCnf(Sbm_Man_t *p)
Definition giaSatMap.c:149
int Card_AddCardinSolver(int LogN, Vec_Int_t **pvVars, Vec_Int_t **pvRes)
Definition giaSatMap.c:356
Sbm_Man_t * Sbm_ManAlloc(int LogN)
Definition giaSatMap.c:512
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_nclauses(sat_solver *s)
Definition satSolver.c:2375
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
int sat_solver_nvars(sat_solver *s)
Definition satSolver.c:2369
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
int lit
Definition satVec.h:130
Vec_Int_t * vArrs
Definition giaSatMap.c:56
int FirstVar
Definition giaSatMap.c:42
int LitShift
Definition giaSatMap.c:43
Vec_Wec_t * vCuts
Definition giaSatMap.c:47
Vec_Int_t * vRoots
Definition giaSatMap.c:46
Vec_Int_t * vReason
Definition giaSatMap.c:61
Vec_Wec_t * vObjCuts
Definition giaSatMap.c:48
Vec_Int_t * vCardVars
Definition giaSatMap.c:40
Vec_Int_t * vReqs
Definition giaSatMap.c:57
Vec_Int_t * vSolCuts
Definition giaSatMap.c:49
Vec_Int_t * vPolar
Definition giaSatMap.c:54
Vec_Int_t * vLit2Used
Definition giaSatMap.c:59
int nInputs
Definition giaSatMap.c:44
Vec_Wrd_t * vCutAreas
Definition giaSatMap.c:51
sat_solver * pSat
Definition giaSatMap.c:39
Vec_Int_t * vAssump
Definition giaSatMap.c:53
Vec_Int_t * vDelays
Definition giaSatMap.c:60
Vec_Int_t * vCutGates
Definition giaSatMap.c:50
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42