1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
/**CFile****************************************************************
FileName [giaCsat1.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Scalable AIG package.]
Synopsis [Circuit-based SAT solver.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: giaCsat1.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "gia.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct Css_Fan_t_ Css_Fan_t;
struct Css_Fan_t_
{
unsigned iFan : 31; // ID of the fanin/fanout
unsigned fCompl : 1; // complemented attribute
};
typedef struct Css_Obj_t_ Css_Obj_t;
struct Css_Obj_t_
{
unsigned fCi : 1; // terminal node CI
unsigned fCo : 1; // terminal node CO
unsigned fAssign : 1; // assigned variable
unsigned fValue : 1; // variable value
unsigned fPhase : 1; // value under 000 pattern
unsigned nFanins : 5; // the number of fanins
unsigned nFanouts : 22; // total number of fanouts
unsigned hHandle; // application specific data
union {
unsigned iFanouts; // application specific data
int TravId; // ID of the node
};
Css_Fan_t Fanios[0]; // the array of fanins/fanouts
};
typedef struct Css_Man_t_ Css_Man_t;
struct Css_Man_t_
{
Gia_Man_t * pGia; // the original AIG manager
Vec_Int_t * vCis; // the vector of CIs (PIs + LOs)
Vec_Int_t * vCos; // the vector of COs (POs + LIs)
int nObjs; // the number of objects
int nNodes; // the number of nodes
int * pObjData; // the logic network defined for the AIG
int nObjData; // the size of array to store the logic network
int * pLevels; // the linked lists of levels
int nLevels; // the max number of logic levels
int nTravIds; // traversal ID to mark the cones
Vec_Int_t * vTrail; // sequence of assignments
int nConfsMax; // max number of conflicts
};
static inline unsigned Gia_ObjHandle( Gia_Obj_t * pObj ) { return pObj->Value; }
static inline int Css_ObjIsCi( Css_Obj_t * pObj ) { return pObj->fCi; }
static inline int Css_ObjIsCo( Css_Obj_t * pObj ) { return pObj->fCo; }
static inline int Css_ObjIsNode( Css_Obj_t * pObj ) { return!pObj->fCi &&!pObj->fCo && pObj->nFanins > 0; }
static inline int Css_ObjIsConst0( Css_Obj_t * pObj ) { return!pObj->fCi &&!pObj->fCo && pObj->nFanins == 0;}
static inline int Css_ObjFaninNum( Css_Obj_t * pObj ) { return pObj->nFanins; }
static inline int Css_ObjFanoutNum( Css_Obj_t * pObj ) { return pObj->nFanouts; }
static inline int Css_ObjSize( Css_Obj_t * pObj ) { return sizeof(Css_Obj_t) / 4 + pObj->nFanins + pObj->nFanouts; }
static inline int Css_ObjId( Css_Obj_t * pObj ) { assert( 0 ); return -1; }
static inline Css_Obj_t * Css_ManObj( Css_Man_t * p, unsigned iHandle ) { return (Css_Obj_t *)(p->pObjData + iHandle); }
static inline Css_Obj_t * Css_ObjFanin( Css_Obj_t * pObj, int i ) { return (Css_Obj_t *)(((int *)pObj) - pObj->Fanios[i].iFan); }
static inline Css_Obj_t * Css_ObjFanout( Css_Obj_t * pObj, int i ) { return (Css_Obj_t *)(((int *)pObj) + pObj->Fanios[pObj->nFanins+i].iFan); }
static inline int Css_ObjFaninC( Css_Obj_t * pObj, int i ) { return pObj->Fanios[i].fCompl; }
static inline int Css_ObjFanoutC( Css_Obj_t * pObj, int i ) { return pObj->Fanios[pObj->nFanins+i].fCompl; }
static inline int Css_ManObjNum( Css_Man_t * p ) { return p->nObjs; }
static inline int Css_ManNodeNum( Css_Man_t * p ) { return p->nNodes; }
static inline void Css_ManIncrementTravId( Css_Man_t * p ) { p->nTravIds++; }
static inline void Css_ObjSetTravId( Css_Obj_t * pObj, int TravId ) { pObj->TravId = TravId; }
static inline void Css_ObjSetTravIdCurrent( Css_Man_t * p, Css_Obj_t * pObj ) { pObj->TravId = p->nTravIds; }
static inline void Css_ObjSetTravIdPrevious( Css_Man_t * p, Css_Obj_t * pObj ) { pObj->TravId = p->nTravIds - 1; }
static inline int Css_ObjIsTravIdCurrent( Css_Man_t * p, Css_Obj_t * pObj ) { return ((int)pObj->TravId == p->nTravIds); }
static inline int Css_ObjIsTravIdPrevious( Css_Man_t * p, Css_Obj_t * pObj ) { return ((int)pObj->TravId == p->nTravIds - 1); }
static inline int Css_VarIsAssigned( Css_Obj_t * pVar ) { return pVar->fAssign; }
static inline void Css_VarAssign( Css_Obj_t * pVar ) { assert(!pVar->fAssign); pVar->fAssign = 1; }
static inline void Css_VarUnassign( Css_Obj_t * pVar ) { assert(pVar->fAssign); pVar->fAssign = 0; }
static inline int Css_VarValue( Css_Obj_t * pVar ) { assert(pVar->fAssign); return pVar->fValue; }
static inline void Css_VarSetValue( Css_Obj_t * pVar, int v ) { assert(pVar->fAssign); pVar->fValue = v; }
#define Css_ManForEachObj( p, pObj, i ) \
for ( i = 0; (i < p->nObjData) && (pObj = Css_ManObj(p,i)); i += Css_ObjSize(pObj) )
#define Css_ManForEachObjVecStart( vVec, p, pObj, i, iStart ) \
for ( i = iStart; (i < Vec_IntSize(vVec)) && (pObj = Css_ManObj(p,Vec_IntEntry(vVec,i))); i++ )
#define Css_ManForEachNode( p, pObj, i ) \
for ( i = 0; (i < p->nObjData) && (pObj = Css_ManObj(p,i)); i += Css_ObjSize(pObj) ) if ( Css_ObjIsTerm(pObj) ) {} else
#define Css_ObjForEachFanin( pObj, pNext, i ) \
for ( i = 0; (i < (int)pObj->nFanins) && (pNext = Css_ObjFanin(pObj,i)); i++ )
#define Css_ObjForEachFanout( pObj, pNext, i ) \
for ( i = 0; (i < (int)pObj->nFanouts) && (pNext = Css_ObjFanout(pObj,i)); i++ )
#define Css_ObjForEachFaninLit( pObj, pNext, fCompl, i ) \
for ( i = 0; (i < (int)pObj->nFanins) && (pNext = Css_ObjFanin(pObj,i)) && ((fCompl = Css_ObjFaninC(pObj,i)),1); i++ )
#define Css_ObjForEachFanoutLit( pObj, pNext, fCompl, i ) \
for ( i = 0; (i < (int)pObj->nFanouts) && (pNext = Css_ObjFanout(pObj,i)) && ((fCompl = Css_ObjFanoutC(pObj,i)),1); i++ )
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Creates logic network isomorphic to the given AIG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Css_Man_t * Css_ManCreateLogicSimple( Gia_Man_t * pGia )
{
Css_Man_t * p;
Css_Obj_t * pObjLog, * pFanLog;
Gia_Obj_t * pObj;
int i, iHandle = 0;
p = ABC_CALLOC( Css_Man_t, 1 );
p->pGia = pGia;
p->vCis = Vec_IntAlloc( Gia_ManCiNum(pGia) );
p->vCos = Vec_IntAlloc( Gia_ManCoNum(pGia) );
p->nObjData = (sizeof(Css_Obj_t) / 4) * Gia_ManObjNum(pGia) + 4 * Gia_ManAndNum(pGia) + 2 * Gia_ManCoNum(pGia);
p->pObjData = ABC_CALLOC( int, p->nObjData );
ABC_FREE( pGia->pRefs );
Gia_ManCreateRefs( pGia );
Gia_ManForEachObj( pGia, pObj, i )
{
pObj->Value = iHandle;
pObjLog = Css_ManObj( p, iHandle );
pObjLog->nFanins = 0;
pObjLog->nFanouts = Gia_ObjRefs( pGia, pObj );
pObjLog->hHandle = iHandle;
pObjLog->iFanouts = 0;
if ( Gia_ObjIsAnd(pObj) )
{
pFanLog = Css_ManObj( p, Gia_ObjHandle(Gia_ObjFanin0(pObj)) );
pFanLog->Fanios[pFanLog->nFanins + pFanLog->iFanouts].iFan =
pObjLog->Fanios[pObjLog->nFanins].iFan = pObjLog->hHandle - pFanLog->hHandle;
pFanLog->Fanios[pFanLog->nFanins + pFanLog->iFanouts++].fCompl =
pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC0(pObj);
pFanLog = Css_ManObj( p, Gia_ObjHandle(Gia_ObjFanin1(pObj)) );
pFanLog->Fanios[pFanLog->nFanins + pFanLog->iFanouts].iFan =
pObjLog->Fanios[pObjLog->nFanins].iFan = pObjLog->hHandle - pFanLog->hHandle;
pFanLog->Fanios[pFanLog->nFanins + pFanLog->iFanouts++].fCompl =
pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC1(pObj);
p->nNodes++;
}
else if ( Gia_ObjIsCo(pObj) )
{
pFanLog = Css_ManObj( p, Gia_ObjHandle(Gia_ObjFanin0(pObj)) );
pFanLog->Fanios[pFanLog->nFanins + pFanLog->iFanouts].iFan =
pObjLog->Fanios[pObjLog->nFanins].iFan = pObjLog->hHandle - pFanLog->hHandle;
pFanLog->Fanios[pFanLog->nFanins + pFanLog->iFanouts++].fCompl =
pObjLog->Fanios[pObjLog->nFanins++].fCompl = Gia_ObjFaninC0(pObj);
pObjLog->fCo = 1;
Vec_IntPush( p->vCos, iHandle );
}
else if ( Gia_ObjIsCi(pObj) )
{
pObjLog->fCi = 1;
Vec_IntPush( p->vCis, iHandle );
}
iHandle += Css_ObjSize( pObjLog );
p->nObjs++;
}
assert( iHandle == p->nObjData );
Gia_ManForEachObj( pGia, pObj, i )
{
pObjLog = Css_ManObj( p, Gia_ObjHandle(pObj) );
assert( pObjLog->nFanouts == pObjLog->iFanouts );
pObjLog->TravId = 0;
}
p->nTravIds = 1;
p->vTrail = Vec_IntAlloc( 100 );
return p;
}
/**Function*************************************************************
Synopsis [Creates logic network isomorphic to the given AIG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Css_ManStop( Css_Man_t * p )
{
Vec_IntFree( p->vTrail );
Vec_IntFree( p->vCis );
Vec_IntFree( p->vCos );
ABC_FREE( p->pObjData );
ABC_FREE( p->pLevels );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Propagates implications for the net.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Css_ManImplyNet_rec( Css_Man_t * p, Css_Obj_t * pVar, unsigned Value )
{
static inline Css_ManImplyNode_rec( Css_Man_t * p, Css_Obj_t * pVar );
Css_Obj_t * pNext;
int i;
if ( !Css_ObjIsTravIdCurrent(p, pVar) )
return 0;
// assign the variable
assert( !Css_VarIsAssigned(pVar) );
Css_VarAssign( pVar );
Css_VarSetValue( pVar, Value );
Vec_IntPush( p->vTrail, pVar->hHandle );
// propagate fanouts, then fanins
Css_ObjForEachFanout( pVar, pNext, i )
if ( Css_ManImplyNode_rec( p, pNext ) )
return 1;
Css_ObjForEachFanin( pVar, pNext, i )
if ( Css_ManImplyNode_rec( p, pNext ) )
return 1;
return 0;
}
/**Function*************************************************************
Synopsis [Propagates implications for the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Css_ManImplyNode_rec( Css_Man_t * p, Css_Obj_t * pVar )
{
Css_Obj_t * pFan0, * pFan1;
if ( Css_ObjIsCi(pVar) )
return 0;
pFan0 = Css_ObjFanin(pVar, 0);
pFan1 = Css_ObjFanin(pVar, 1);
if ( !Css_VarIsAssigned(pVar) )
{
if ( Css_VarIsAssigned(pFan0) )
{
if ( Css_VarValue(pFan0) == Css_ObjFaninC(pVar,0) ) // negative -> propagate
return Css_ManImplyNet_rec(p, pVar, 0);
// assigned positive
if ( Css_VarIsAssigned(pFan1) )
{
if ( Css_VarValue(pFan1) == Css_ObjFaninC(pVar,1) ) // negative -> propagate
return Css_ManImplyNet_rec(p, pVar, 0);
// asigned positive -> propagate
return Css_ManImplyNet_rec(p, pVar, 1);
}
return 0;
}
if ( Css_VarIsAssigned(pFan1) )
{
if ( Css_VarValue(pFan1) == Css_ObjFaninC(pVar,1) ) // negative -> propagate
return Css_ManImplyNet_rec(p, pVar, 0);
return 0;
}
assert( 0 );
return 0;
}
if ( Css_VarValue(pVar) ) // positive
{
if ( Css_VarIsAssigned(pFan0) )
{
if ( Css_VarValue(pFan0) == Css_ObjFaninC(pVar,0) ) // negative -> conflict
return 1;
// check second var
if ( Css_VarIsAssigned(pFan1) )
{
if ( Css_VarValue(pFan1) == Css_ObjFaninC(pVar,1) ) // negative -> conflict
return 1;
// positive + positive -> nothing to do
return 0;
}
}
else
{
// pFan0 unassigned -> enqueue first var
// Css_ManEnqueue( p, pFan0, !Css_ObjFaninC(pVar,0) );
if ( Css_ManImplyNet_rec( p, pFan0, !Css_ObjFaninC(pVar,0) ) )
return 1;
// check second var
if ( Css_VarIsAssigned(pFan1) )
{
if ( Css_VarValue(pFan1) == Css_ObjFaninC(pVar,1) ) // negative -> conflict
return 1;
// positive + positive -> nothing to do
return 0;
}
}
// unassigned -> enqueue second var
// Css_ManEnqueue( p, pFan1, !Css_ObjFaninC(pVar,1) );
return Css_ManImplyNet_rec( p, pFan1, !Css_ObjFaninC(pVar,1) );
}
else // negative
{
if ( Css_VarIsAssigned(pFan0) )
{
if ( Css_VarValue(pFan0) == Css_ObjFaninC(pVar,0) ) // negative -> nothing to do
return 0;
if ( Css_VarIsAssigned(pFan1) )
{
if ( Css_VarValue(pFan1) == Css_ObjFaninC(pVar,1) ) // negative -> nothing to do
return 0;
// positive + positive -> conflict
return 1;
}
// positive + unassigned -> enqueue second var
// Css_ManEnqueue( p, pFan1, Css_ObjFaninC(pVar,1) );
return Css_ManImplyNet_rec( p, pFan1, Css_ObjFaninC(pVar,1) );
}
else
{
if ( Css_VarIsAssigned(pFan1) )
{
if ( Css_VarValue(pFan1) == Css_ObjFaninC(pVar,1) ) // negative -> nothing to do
return 0;
// unassigned + positive -> enqueue first var
// Css_ManEnqueue( p, pFan0, Css_ObjFaninC(pVar,0) );
return Css_ManImplyNet_rec( p, pFan0, Css_ObjFaninC(pVar,0) );
}
}
}
return 0;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Css_ManCancelUntil( Css_Man_t * p, int iBound, Vec_Int_t * vCex )
{
Css_Obj_t * pVar;
int i;
Css_ManForEachObjVecStart( p->vTrail, p, pVar, i, iBound )
{
if ( vCex )
Vec_IntPush( vCex, Gia_Var2Lit(Css_ObjId(pVar), !pVar->fValue) );
Css_VarUnassign( pVar );
}
Vec_IntShrink( p->vTrail, iBound );
}
/**Function*************************************************************
Synopsis [Justifies assignments.]
Description [Returns 1 for UNSAT, 0 for SAT, -1 for UNDECIDED.]
SideEffects []
SeeAlso []
***********************************************************************/
int Css_ManJustify( Css_Man_t * p, int iBegin )
{
Css_Obj_t * pVar, * pFan0, * pFan1;
int iState, iThis;
if ( p->nConfsMax == 0 )
return 1;
// get the next variable to justify
Css_ManForEachObjVecStart( p->vTrail, p, pVar, iThis, iBegin )
{
assert( Css_VarIsAssigned(pVar) );
if ( Css_VarValue(pVar) || Css_ObjIsCi(pVar) )
continue;
pFan0 = Css_ObjFanin(pVar,0);
pFan1 = Css_ObjFanin(pVar,0);
if ( !Css_VarIsAssigned(pFan0) && !Css_VarIsAssigned(pFan1) )
break;
}
if ( iThis == Vec_IntSize(p->vTrail) ) // could not find
return 0;
// found variable to justify
assert( !Css_VarValue(pVar) && !Css_VarIsAssigned(pFan0) && !Css_VarIsAssigned(pFan1) );
// remember the state of the stack
iState = Vec_IntSize( p->vTrail );
// try to justify by setting first fanin to 0
if ( !Css_ManImplyNet_rec(p, pFan0, 0) && !Css_ManJustify(p, iThis) )
return 0;
Css_ManCancelUntil( p, iState, NULL );
if ( p->nConfsMax == 0 )
return 1;
// try to justify by setting second fanin to 0
if ( !Css_ManImplyNet_rec(p, pFan1, 0) && !Css_ManJustify(p, iThis) )
return 0;
Css_ManCancelUntil( p, iState, NULL );
if ( p->nConfsMax == 0 )
return 1;
p->nConfsMax--;
return 1;
}
/**Function*************************************************************
Synopsis [Marsk logic cone.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Css_ManMarkCone_rec( Css_Man_t * p, Css_Obj_t * pVar )
{
if ( Css_ObjIsTravIdCurrent(p, pVar) )
return;
Css_ObjSetTravIdCurrent(p, pVar);
assert( !Css_VarIsAssigned(pVar) );
if ( Css_ObjIsCi(pVar) )
return;
else
{
Css_Obj_t * pNext;
int i;
Css_ObjForEachFanin( pVar, pNext, i )
Css_ManMarkCone_rec( p, pNext );
}
}
/**Function*************************************************************
Synopsis [Runs one call to the SAT solver.]
Description [Returns 1 for UNSAT, 0 for SAT, -1 for UNDECIDED.]
SideEffects []
SeeAlso []
***********************************************************************/
int Css_ManPrepare( Css_Man_t * p, int * pLits, int nLits )
{
Css_Obj_t * pVar;
int i;
// mark the cone
Css_ManIncrementTravId( p );
for ( i = 0; i < nLits; i++ )
{
pVar = Css_ManObj( p, Gia_Lit2Var(pLits[i]) );
Css_ManMarkCone_rec( p, pVar );
}
// assign literals
Vec_IntClear( p->vTrail );
for ( i = 0; i < nLits; i++ )
{
pVar = Css_ManObj( p, Gia_Lit2Var(pLits[i]) );
if ( Css_ManImplyNet_rec( p, pVar, !Gia_LitIsCompl(pLits[i]) ) )
{
Css_ManCancelUntil( p, 0, NULL );
return 1;
}
}
return 0;
}
/**Function*************************************************************
Synopsis [Runs one call to the SAT solver.]
Description [Returns 1 for UNSAT, 0 for SAT, -1 for UNDECIDED.]
SideEffects []
SeeAlso []
***********************************************************************/
int Css_ManSolve( Css_Man_t * p, int * pLits, int nLits, int nConfsMax, Vec_Int_t * vCex )
{
// propagate the assignments
if ( Css_ManPrepare( p, pLits, nLits ) )
return 1;
// justify the assignments
p->nConfsMax = nConfsMax;
if ( Css_ManJustify( p, 0 ) )
return p->nConfsMax? 1 : -1;
// derive model and return the solver to the initial state
Vec_IntClear( vCex );
Css_ManCancelUntil( p, 0, vCex );
return 0;
}
/**Function*************************************************************
Synopsis [Procedure to test the new SAT solver.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_SatSolveTest2( Gia_Man_t * pGia )
{
extern void Gia_SatVerifyPattern( Gia_Man_t * p, Gia_Obj_t * pRoot, Vec_Int_t * vCex, Vec_Int_t * vVisit );
int nConfsMax = 1000;
int CountUnsat, CountSat, CountUndec;
Css_Man_t * p;
Vec_Int_t * vCex;
Vec_Int_t * vVisit;
Gia_Obj_t * pRoot;
int i, RetValue, iLit, clk = clock();
// create logic network
p = Css_ManCreateLogicSimple( pGia );
// prepare AIG
Gia_ManCleanValue( pGia );
Gia_ManCleanMark0( pGia );
Gia_ManCleanMark1( pGia );
vCex = Vec_IntAlloc( 100 );
vVisit = Vec_IntAlloc( 100 );
// solve for each output
CountUnsat = CountSat = CountUndec = 0;
Gia_ManForEachCo( pGia, pRoot, i )
{
if ( Gia_ObjIsConst0(Gia_ObjFanin0(pRoot)) )
continue;
//printf( "Output %6d : ", i );
iLit = Gia_Var2Lit( Gia_ObjHandle(Gia_ObjFanin0(pRoot)), Gia_ObjFaninC0(pRoot) );
RetValue = Css_ManSolve( p, &iLit, 1, nConfsMax, vCex );
if ( RetValue == 1 )
CountUnsat++;
else if ( RetValue == -1 )
CountUndec++;
else
{
// Gia_Obj_t * pTemp;
// int k;
assert( RetValue == 0 );
CountSat++;
/*
Vec_PtrForEachEntry( vCex, pTemp, k )
// printf( "%s%d ", Gia_IsComplement(pTemp)? "!": "", Gia_ObjCioId(Gia_Regular(pTemp)) );
printf( "%s%d ", Gia_IsComplement(pTemp)? "!": "", Gia_ObjId(p,Gia_Regular(pTemp)) );
printf( "\n" );
*/
Gia_SatVerifyPattern( pGia, pRoot, vCex, vVisit );
}
// Gia_ManCheckMark0( p );
// Gia_ManCheckMark1( p );
}
Css_ManStop( p );
Vec_IntFree( vCex );
Vec_IntFree( vVisit );
printf( "Unsat = %d. Sat = %d. Undec = %d. ", CountUnsat, CountSat, CountUndec );
ABC_PRT( "Time", clock() - clk );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|