summaryrefslogtreecommitdiffstats
path: root/src/proof/live/kliveness.c
blob: d9bc416b6d2ef357fc26581a61187b05877a23cf (plain)
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
/**CFile****************************************************************

  FileName    [kliveness.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Liveness property checking.]

  Synopsis        [Main implementation module of the algorithm k-Liveness    ] 
              [invented by Koen Claessen, Niklas Sorensson. Implements]
              [the code for 'kcs'. 'kcs' pre-processes based on switch]
        [and then runs the (absorber circuit >> pdr) loop  ]

  Author      [Sayak Ray]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - October 31, 2012.]

***********************************************************************/

#include <stdio.h>
#include "base/main/main.h"
#include "aig/aig/aig.h"
#include "aig/saig/saig.h"
#include <string.h>
#include "base/main/mainInt.h"
#include "proof/pdr/pdr.h"
#include <time.h>

//#define WITHOUT_CONSTRAINTS

ABC_NAMESPACE_IMPL_START

/***************** Declaration of standard ABC related functions ********************/
extern Aig_Man_t * Abc_NtkToDar( Abc_Ntk_t * pNtk, int fExors, int fRegisters );
extern Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan );
extern Abc_Ntk_t * Abc_NtkMakeOnePo( Abc_Ntk_t * pNtk, int Output, int nRange );
extern void Aig_ManDumpBlif( Aig_Man_t * p, char * pFileName, Vec_Ptr_t * vPiNames, Vec_Ptr_t * vPoNames );
/***********************************************************************************/

/***************** Declaration of kLiveness related functions **********************/
//function defined in kLiveConstraints.c
extern Aig_Man_t *generateWorkingAig( Aig_Man_t *pAig, Abc_Ntk_t *pNtk, int *pIndex0Live );

//function defined in arenaViolation.c
extern Aig_Man_t *generateWorkingAigWithDSC( Aig_Man_t *pAig, Abc_Ntk_t *pNtk, int *pIndex0Live, Vec_Ptr_t *vMasterBarriers );

//function defined in disjunctiveMonotone.c
extern Vec_Ptr_t *findDisjunctiveMonotoneSignals( Abc_Ntk_t *pNtk );
extern Vec_Int_t *createSingletonIntVector( int i );
/***********************************************************************************/
extern Aig_Man_t *generateDisjunctiveTester( Abc_Ntk_t *pNtk, Aig_Man_t *pAig, int combN, int combK );
extern Aig_Man_t *generateGeneralDisjunctiveTester( Abc_Ntk_t *pNtk, Aig_Man_t *pAig, int combK );

//Definition of some macros pertaining to modes/switches
#define SIMPLE_kCS 0
#define kCS_WITH_SAFETY_INVARIANTS 1
#define kCS_WITH_DISCOVER_MONOTONE_SIGNALS 2
#define kCS_WITH_SAFETY_AND_DCS_INVARIANTS 3
#define kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS 4

//unused function
#if 0
Aig_Obj_t *readTargetPinSignal(Aig_Man_t *pAig, Abc_Ntk_t *pNtk)
{
    Aig_Obj_t *pObj;
    int i;

    Saig_ManForEachPo( pAig, pObj, i )
    {
        if( strstr( Abc_ObjName(Abc_NtkPo( pNtk, i )), "0Liveness_" ) != NULL  )
        {
            //return Aig_ObjFanin0(pObj);
            return Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObj), Aig_ObjFaninC0(pObj));
        }
    }    

    return NULL;
}
#endif

Aig_Obj_t *readLiveSignal_0( Aig_Man_t *pAig, int liveIndex_0 )
{
    Aig_Obj_t *pObj;

    pObj = Aig_ManCo( pAig, liveIndex_0 );
    return Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObj), Aig_ObjFaninC0(pObj));
}

Aig_Obj_t *readLiveSignal_k( Aig_Man_t *pAig, int liveIndex_k )
{
    Aig_Obj_t *pObj;

    pObj = Aig_ManCo( pAig, liveIndex_k );
    return Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObj), Aig_ObjFaninC0(pObj));
}

//unused funtion
#if 0
Aig_Obj_t *readTargetPoutSignal(Aig_Man_t *pAig, Abc_Ntk_t *pNtk, int nonFirstIteration)
{
    Aig_Obj_t *pObj;
    int i;

    if( nonFirstIteration == 0 )
        return NULL;
    else
        Saig_ManForEachPo( pAig, pObj, i )
        {
            if( strstr( Abc_ObjName(Abc_NtkPo( pNtk, i )), "kLiveness_" ) != NULL  )
            {
                //return Aig_ObjFanin0(pObj);
                return Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObj), Aig_ObjFaninC0(pObj));
            }
        }    

    return NULL;
}
#endif

//unused function
#if 0
void updateNewNetworkNameManager_kCS( Abc_Ntk_t *pNtk, Aig_Man_t *pAig, Vec_Ptr_t *vPiNames, 
            Vec_Ptr_t *vLoNames, Vec_Ptr_t *vPoNames, Vec_Ptr_t *vLiNames )
{
    Aig_Obj_t *pObj;
    Abc_Obj_t *pNode;
    int i, ntkObjId;

    pNtk->pManName = Nm_ManCreate( Abc_NtkCiNum( pNtk ) );

    if( vPiNames )
    {
        Saig_ManForEachPi( pAig, pObj, i )
        {
            ntkObjId = Abc_NtkCi( pNtk, i )->Id;
            Nm_ManStoreIdName( pNtk->pManName, ntkObjId, Aig_ObjType(pObj), (char *)Vec_PtrEntry(vPiNames, i), NULL );
        }
    }
    if( vLoNames )
    {
        Saig_ManForEachLo( pAig, pObj, i )
        {
            ntkObjId = Abc_NtkCi( pNtk, Saig_ManPiNum( pAig ) + i )->Id;
            Nm_ManStoreIdName( pNtk->pManName, ntkObjId, Aig_ObjType(pObj), (char *)Vec_PtrEntry(vLoNames, i), NULL );
        }
    }

    if( vPoNames )
    {
        Saig_ManForEachPo( pAig, pObj, i )
        {
            ntkObjId = Abc_NtkCo( pNtk, i )->Id;
            Nm_ManStoreIdName( pNtk->pManName, ntkObjId, Aig_ObjType(pObj), (char *)Vec_PtrEntry(vPoNames, i), NULL );    
        }
    }

    if( vLiNames )
    {
        Saig_ManForEachLi( pAig, pObj, i )
        {
            ntkObjId = Abc_NtkCo( pNtk, Saig_ManPoNum( pAig ) + i )->Id;
            Nm_ManStoreIdName( pNtk->pManName, ntkObjId, Aig_ObjType(pObj), (char *)Vec_PtrEntry(vLiNames, i), NULL );
        }
    }

    // assign latch input names
    Abc_NtkForEachLatch(pNtk, pNode, i)
        if ( Nm_ManFindNameById(pNtk->pManName, Abc_ObjFanin0(pNode)->Id) == NULL )
            Abc_ObjAssignName( Abc_ObjFanin0(pNode), Abc_ObjName(Abc_ObjFanin0(pNode)), NULL );
}
#endif

Aig_Man_t *introduceAbsorberLogic( Aig_Man_t *pAig, int *pLiveIndex_0, int *pLiveIndex_k, int nonFirstIteration )
{
    Aig_Man_t *pNewAig;
    Aig_Obj_t *pObj, *pObjAbsorberLo, *pPInNewArg, *pPOutNewArg;
    Aig_Obj_t *pPIn = NULL, *pPOut = NULL, *pPOutCo = NULL;
    Aig_Obj_t *pFirstAbsorberOr, *pSecondAbsorberOr;
    int i;
    int piCopied = 0, loCreated = 0, loCopied = 0, liCreated = 0, liCopied = 0; 
    int nRegCount;

    assert(*pLiveIndex_0 != -1);
    if(nonFirstIteration == 0)
        assert( *pLiveIndex_k == -1 );
    else
        assert( *pLiveIndex_k != -1  );

    //****************************************************************
    // Step1: create the new manager
    // Note: The new manager is created with "2 * Aig_ManObjNumMax(p)"
    // nodes, but this selection is arbitrary - need to be justified
    //****************************************************************
    pNewAig = Aig_ManStart( Aig_ManObjNumMax(pAig) );
    pNewAig->pName = (char *)malloc( strlen( pAig->pName ) + strlen("_kCS") + 1 );
    sprintf(pNewAig->pName, "%s_%s", pAig->pName, "kCS");
        pNewAig->pSpec = NULL;

    //****************************************************************
    // reading the signal pIn, and pOut
    //****************************************************************

    pPIn = readLiveSignal_0( pAig, *pLiveIndex_0 );
    if( *pLiveIndex_k == -1 )
        pPOut = NULL;
    else
        pPOut = readLiveSignal_k( pAig, *pLiveIndex_k );
    
    //****************************************************************
    // Step 2: map constant nodes
    //****************************************************************
        pObj = Aig_ManConst1( pAig );
        pObj->pData = Aig_ManConst1( pNewAig );

    //****************************************************************
        // Step 3: create true PIs
    //****************************************************************
        Saig_ManForEachPi( pAig, pObj, i )
    {
        piCopied++;
        pObj->pData = Aig_ObjCreateCi(pNewAig);
    }

    //****************************************************************
    // Step 5: create register outputs
    //****************************************************************
        Saig_ManForEachLo( pAig, pObj, i )
        {
        loCopied++;
        pObj->pData = Aig_ObjCreateCi(pNewAig);
        }

    //****************************************************************
    // Step 6: create "D" register output for the ABSORBER logic
    //****************************************************************
    loCreated++;
    pObjAbsorberLo = Aig_ObjCreateCi( pNewAig );

    nRegCount = loCreated + loCopied;

    //********************************************************************
    // Step 7: create internal nodes
    //********************************************************************
        Aig_ManForEachNode( pAig, pObj, i )
    {
        pObj->pData = Aig_And( pNewAig, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
    }

    //****************************************************************
    // Step 8: create the two OR gates of the OBSERVER logic
    //****************************************************************
    if( nonFirstIteration == 0 )
    {
        assert(pPIn);
        
        pPInNewArg = !Aig_IsComplement(pPIn)? 
                (Aig_Obj_t *)((Aig_Regular(pPIn))->pData) : 
                Aig_Not((Aig_Obj_t *)((Aig_Regular(pPIn))->pData));

        pFirstAbsorberOr = Aig_Or( pNewAig, Aig_Not(pPInNewArg), pObjAbsorberLo );
        pSecondAbsorberOr = Aig_Or( pNewAig, pPInNewArg, Aig_Not(pObjAbsorberLo) );
    }
    else
    {
        assert( pPOut );

        pPInNewArg = !Aig_IsComplement(pPIn)? 
                (Aig_Obj_t *)((Aig_Regular(pPIn))->pData) : 
                Aig_Not((Aig_Obj_t *)((Aig_Regular(pPIn))->pData));
        pPOutNewArg = !Aig_IsComplement(pPOut)? 
                (Aig_Obj_t *)((Aig_Regular(pPOut))->pData) : 
                Aig_Not((Aig_Obj_t *)((Aig_Regular(pPOut))->pData));
        
        pFirstAbsorberOr = Aig_Or( pNewAig, Aig_Not(pPOutNewArg), pObjAbsorberLo );
        pSecondAbsorberOr = Aig_Or( pNewAig, pPInNewArg, Aig_Not(pObjAbsorberLo) );
    }    
    
    //********************************************************************
    // Step 9: create primary outputs 
    //********************************************************************
    Saig_ManForEachPo( pAig, pObj, i )
    {
        pObj->pData = Aig_ObjCreateCo( pNewAig, Aig_ObjChild0Copy(pObj) ); 
        if( i == *pLiveIndex_k )
            pPOutCo = (Aig_Obj_t *)(pObj->pData);
    }

    //create new po
    if( nonFirstIteration == 0 )
    {
        assert(pPOutCo == NULL);
        pPOutCo = Aig_ObjCreateCo( pNewAig, pSecondAbsorberOr );     

        *pLiveIndex_k = i;
    }    
    else
    {
        assert( pPOutCo != NULL );
        //pPOutCo = Aig_ObjCreateCo( pNewAig, pSecondAbsorberOr );     
        //*pLiveIndex_k = Saig_ManPoNum(pAig);

        Aig_ObjPatchFanin0( pNewAig, pPOutCo, pSecondAbsorberOr );
    }

    Saig_ManForEachLi( pAig, pObj, i )
    {
        liCopied++;
        Aig_ObjCreateCo( pNewAig, Aig_ObjChild0Copy(pObj) );
    }

    //create new li
    liCreated++;
    Aig_ObjCreateCo( pNewAig, pFirstAbsorberOr );

    Aig_ManSetRegNum( pNewAig, nRegCount );
    Aig_ManCleanup( pNewAig );
    
    assert( Aig_ManCheck( pNewAig ) );

    assert( *pLiveIndex_k != - 1);
    return pNewAig;
}

void modifyAigToApplySafetyInvar(Aig_Man_t *pAig, int csTarget, int safetyInvarPO)
{
    Aig_Obj_t *pObjPOSafetyInvar, *pObjSafetyInvar;
    Aig_Obj_t *pObjPOCSTarget, *pObjCSTarget;
    Aig_Obj_t *pObjCSTargetNew;

    pObjPOSafetyInvar = Aig_ManCo( pAig, safetyInvarPO );
    pObjSafetyInvar =  Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObjPOSafetyInvar), Aig_ObjFaninC0(pObjPOSafetyInvar));    
    pObjPOCSTarget = Aig_ManCo( pAig, csTarget );
    pObjCSTarget = Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObjPOCSTarget), Aig_ObjFaninC0(pObjPOCSTarget));    

    pObjCSTargetNew = Aig_And( pAig, pObjSafetyInvar, pObjCSTarget );
    Aig_ObjPatchFanin0( pAig, pObjPOCSTarget, pObjCSTargetNew );
}

int flipConePdr( Aig_Man_t *pAig, int directive, int targetCSPropertyIndex, int safetyInvariantPOIndex, int absorberCount )
{
    int RetValue, i;
    Aig_Obj_t *pObjTargetPo;
    Aig_Man_t *pAigDupl;
    Pdr_Par_t Pars, * pPars = &Pars;
    Abc_Cex_t * pCex = NULL;

    char *fileName;
    
    fileName = (char *)malloc(sizeof(char) * 50);
    sprintf(fileName, "%s_%d.%s", "kLive", absorberCount, "blif" );

    if( directive == kCS_WITH_SAFETY_INVARIANTS || directive == kCS_WITH_SAFETY_AND_DCS_INVARIANTS || directive == kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS )
    {
        assert( safetyInvariantPOIndex != -1 );
        modifyAigToApplySafetyInvar(pAig, targetCSPropertyIndex, safetyInvariantPOIndex);
    }

    pAigDupl = pAig;
    pAig = Aig_ManDupSimple( pAigDupl );

    for( i=0; i<Saig_ManPoNum(pAig); i++ )
    {
        pObjTargetPo = Aig_ManCo( pAig, i );
        Aig_ObjChild0Flip( pObjTargetPo );
    }

    Pdr_ManSetDefaultParams( pPars );
    pPars->fVerbose = 1;
    pPars->fNotVerbose = 1;
    pPars->fSolveAll = 1;
    pAig->vSeqModelVec = NULL;

    Aig_ManCleanup( pAig );
    assert( Aig_ManCheck( pAig ) );

    Pdr_ManSolve( pAig, pPars );    

    if( pAig->vSeqModelVec )
    {
        pCex = (Abc_Cex_t *)Vec_PtrEntry( pAig->vSeqModelVec, targetCSPropertyIndex );
        if( pCex == NULL )
        {
            RetValue = 1;
        }
        else
            RetValue = 0;
    }
    else
    {
        RetValue = -1;
        exit(0);
    }

    free(fileName);

    for( i=0; i<Saig_ManPoNum(pAig); i++ )
    {
        pObjTargetPo = Aig_ManCo( pAig, i );
        Aig_ObjChild0Flip( pObjTargetPo );
    }
    
    Aig_ManStop( pAig );
    return RetValue;
}

//unused function
#if 0
int read0LiveIndex( Abc_Ntk_t *pNtk )
{
    Abc_Obj_t *pObj;
    int i;

    Abc_NtkForEachPo( pNtk, pObj, i )
    {
        if( strstr( Abc_ObjName( pObj ), "0Liveness_" ) != NULL )
            return i;
    }        

    return -1;
}
#endif

int collectSafetyInvariantPOIndex(Abc_Ntk_t *pNtk)
{
    Abc_Obj_t *pObj;
    int i;

    Abc_NtkForEachPo( pNtk, pObj, i )
    {
        if( strstr( Abc_ObjName( pObj ), "csSafetyInvar_" ) != NULL )
            return i;
    }        

    return -1;
}

Vec_Ptr_t *collectUserGivenDisjunctiveMonotoneSignals( Abc_Ntk_t *pNtk )
{
    Abc_Obj_t *pObj;
    int i;
    Vec_Ptr_t *monotoneVector;
    Vec_Int_t *newIntVector;

    monotoneVector = Vec_PtrAlloc(0);    
    Abc_NtkForEachPo( pNtk, pObj, i )
    {
        if( strstr( Abc_ObjName( pObj ), "csLevel1Stabil_" ) != NULL )
        {
            newIntVector = createSingletonIntVector(i);
            Vec_PtrPush(monotoneVector, newIntVector);
        }
    }

    if( Vec_PtrSize(monotoneVector) > 0 )
        return monotoneVector;
    else
        return NULL;

}

void deallocateMasterBarrierDisjunctInt(Vec_Ptr_t *vMasterBarrierDisjunctsArg)
{
    Vec_Int_t *vInt;
    int i;

    if(vMasterBarrierDisjunctsArg)
    {
        Vec_PtrForEachEntry(Vec_Int_t *, vMasterBarrierDisjunctsArg, vInt, i)
        {    
            Vec_IntFree(vInt);
        }
        Vec_PtrFree(vMasterBarrierDisjunctsArg);
    }
}

void deallocateMasterBarrierDisjunctVecPtrVecInt(Vec_Ptr_t *vMasterBarrierDisjunctsArg)
{
    Vec_Int_t *vInt;
    Vec_Ptr_t *vPtr;
    int i, j, k, iElem;

    if(vMasterBarrierDisjunctsArg)
    {
        Vec_PtrForEachEntry(Vec_Ptr_t *, vMasterBarrierDisjunctsArg, vPtr, i)
        {    
            assert(vPtr);
            Vec_PtrForEachEntry( Vec_Int_t *, vPtr, vInt, j )
            {
                //Vec_IntFree(vInt);
                Vec_IntForEachEntry( vInt, iElem, k )
                    printf("%d - ", iElem);
                //printf("Chung Chang j = %d\n", j);
            }
            Vec_PtrFree(vPtr);
        }
        Vec_PtrFree(vMasterBarrierDisjunctsArg);
    }
}

Vec_Ptr_t *getVecOfVecFairness(FILE *fp)
{
    Vec_Ptr_t *masterVector = Vec_PtrAlloc(0);
    //Vec_Ptr_t *currSignalVector;
    char stringBuffer[100];
    //int i;
    
    while(fgets(stringBuffer, 50, fp))
    {
        if(strstr(stringBuffer, ":"))
        {

        }
        else
        {
                
        }
    }

    return masterVector;
}


int Abc_CommandCS_kLiveness( Abc_Frame_t * pAbc, int argc, char ** argv )
{
        Abc_Ntk_t * pNtk, * pNtkTemp;
    Aig_Man_t * pAig, *pAigCS, *pAigCSNew;
    int absorberCount;
    int absorberLimit = 500;
    int RetValue;
    int liveIndex_0 = -1, liveIndex_k = -1;
    int fVerbose = 1;
    int directive = -1;
    int c;
    int safetyInvariantPO = -1;
    abctime beginTime, endTime;
    double time_spent;
    Vec_Ptr_t *vMasterBarrierDisjuncts = NULL;
    Aig_Man_t *pWorkingAig;
    //FILE *fp;

    pNtk = Abc_FrameReadNtk(pAbc);

    //fp = fopen("propFile.txt", "r");
    //if( fp )
    //    getVecOfVecFairness(fp);
    //exit(0);

    /*************************************************
    Extraction of Command Line Argument    
    *************************************************/
    if( argc == 1 )
    {
        assert( directive == -1 );
        directive = SIMPLE_kCS;
    }
    else
    {
        Extra_UtilGetoptReset();
        while ( ( c = Extra_UtilGetopt( argc, argv, "cmCgh" ) ) != EOF )
        {
            switch( c )
            {
            case 'c':
                directive = kCS_WITH_SAFETY_INVARIANTS; 
                break;
            case 'm':
                directive = kCS_WITH_DISCOVER_MONOTONE_SIGNALS; 
                break;
            case 'C':
                directive = kCS_WITH_SAFETY_AND_DCS_INVARIANTS;
                break;
            case 'g':
                directive = kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
            }
        }
    }
    /*************************************************
    Extraction of Command Line Argument Ends    
    *************************************************/

    if( !Abc_NtkIsStrash( pNtk ) )
    {
        printf("The input network was not strashed, strashing....\n");
        pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
        pAig = Abc_NtkToDar( pNtkTemp, 0, 1 );
    }
    else
    {
        pAig = Abc_NtkToDar( pNtk, 0, 1 );
        pNtkTemp = pNtk;
    }

    if( directive == kCS_WITH_SAFETY_INVARIANTS )
    {
        safetyInvariantPO = collectSafetyInvariantPOIndex(pNtkTemp);            
        assert( safetyInvariantPO != -1 );
    }

    if(directive == kCS_WITH_DISCOVER_MONOTONE_SIGNALS)
    {
        beginTime = Abc_Clock();
        vMasterBarrierDisjuncts = findDisjunctiveMonotoneSignals( pNtk );
        endTime = Abc_Clock();
        time_spent = (double)(endTime - beginTime)/CLOCKS_PER_SEC;
        printf("pre-processing time = %f\n",time_spent); 
        return 0;
    }

    if(directive == kCS_WITH_SAFETY_AND_DCS_INVARIANTS)
    {
        safetyInvariantPO = collectSafetyInvariantPOIndex(pNtkTemp);            
        assert( safetyInvariantPO != -1 );

        beginTime = Abc_Clock();
        vMasterBarrierDisjuncts = findDisjunctiveMonotoneSignals( pNtk );
        endTime = Abc_Clock();
        time_spent = (double)(endTime - beginTime)/CLOCKS_PER_SEC;
        printf("pre-processing time = %f\n",time_spent); 

        assert( vMasterBarrierDisjuncts != NULL );
        assert( Vec_PtrSize(vMasterBarrierDisjuncts) > 0 );
    }

    if(directive == kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS)
    {
        safetyInvariantPO = collectSafetyInvariantPOIndex(pNtkTemp);            
        assert( safetyInvariantPO != -1 );

        beginTime = Abc_Clock();
        vMasterBarrierDisjuncts = collectUserGivenDisjunctiveMonotoneSignals( pNtk );
        endTime = Abc_Clock();
        time_spent = (double)(endTime - beginTime)/CLOCKS_PER_SEC;
        printf("pre-processing time = %f\n",time_spent); 

        assert( vMasterBarrierDisjuncts != NULL );
        assert( Vec_PtrSize(vMasterBarrierDisjuncts) > 0 );
    }

    if(directive == kCS_WITH_SAFETY_AND_DCS_INVARIANTS || directive == kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS)
    {
        assert( vMasterBarrierDisjuncts != NULL );
        pWorkingAig = generateWorkingAigWithDSC( pAig, pNtk, &liveIndex_0, vMasterBarrierDisjuncts );
        pAigCS = introduceAbsorberLogic(pWorkingAig, &liveIndex_0, &liveIndex_k, 0);
    }
    else
    {
        pWorkingAig = generateWorkingAig( pAig, pNtk, &liveIndex_0 );
        pAigCS = introduceAbsorberLogic(pWorkingAig, &liveIndex_0, &liveIndex_k, 0);
    }

    Aig_ManStop(pWorkingAig);

    for( absorberCount=1; absorberCount<absorberLimit; absorberCount++ )
    {
        //printf( "\nindex of the liveness output = %d\n", liveIndex_k );
        RetValue = flipConePdr( pAigCS, directive, liveIndex_k, safetyInvariantPO, absorberCount );

        if ( RetValue == 1 )
        {
                Abc_Print( 1, "k = %d, Property proved\n", absorberCount );
            break;
        }
            else if ( RetValue == 0 )
        {
            if( fVerbose )
            {
                Abc_Print( 1, "k = %d, Property DISPROVED\n", absorberCount );
            }
        }
            else if ( RetValue == -1 )
        {
                Abc_Print( 1, "Property UNDECIDED with k = %d.\n", absorberCount );
        }
            else
                assert( 0 );

        pAigCSNew = introduceAbsorberLogic(pAigCS, &liveIndex_0, &liveIndex_k, absorberCount);
        Aig_ManStop(pAigCS);
        pAigCS = pAigCSNew;
    }

    Aig_ManStop(pAigCS);
    Aig_ManStop(pAig);

    if(directive == kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS)
    {
        deallocateMasterBarrierDisjunctInt(vMasterBarrierDisjuncts);
    }
    else
    {
        //if(vMasterBarrierDisjuncts)
        //    Vec_PtrFree(vMasterBarrierDisjuncts);
        //deallocateMasterBarrierDisjunctVecPtrVecInt(vMasterBarrierDisjuncts);
        deallocateMasterBarrierDisjunctInt(vMasterBarrierDisjuncts);
    }
    return 0;

    usage:
        fprintf( stdout, "usage: kcs [-cmgCh]\n" );
            fprintf( stdout, "\timplements Claessen-Sorensson's k-Liveness algorithm\n" );
        fprintf( stdout, "\t-c : verification with constraints, looks for POs prefixed with csSafetyInvar_\n");
        fprintf( stdout, "\t-m : discovers monotone signals\n");
            fprintf( stdout, "\t-g : verification with user-supplied barriers, looks for POs prefixed with csLevel1Stabil_\n");
        fprintf( stdout, "\t-C : verification with discovered monotone signals\n");
        fprintf( stdout, "\t-h : print usage\n");
            return 1;

}

int Abc_CommandNChooseK( Abc_Frame_t * pAbc, int argc, char ** argv )
{
    Abc_Ntk_t * pNtk, * pNtkTemp, *pNtkCombStabil;
    Aig_Man_t * pAig, *pAigCombStabil;
    int directive = -1;
    int c;
    int parameterizedCombK;

    pNtk = Abc_FrameReadNtk(pAbc);


    /*************************************************
    Extraction of Command Line Argument    
    *************************************************/
    if( argc == 1 )
    {
        assert( directive == -1 );
        directive = SIMPLE_kCS;
    }
    else
    {
        Extra_UtilGetoptReset();
        while ( ( c = Extra_UtilGetopt( argc, argv, "cmCgh" ) ) != EOF )
        {
            switch( c )
            {
            case 'c':
                directive = kCS_WITH_SAFETY_INVARIANTS; 
                break;
            case 'm':
                directive = kCS_WITH_DISCOVER_MONOTONE_SIGNALS; 
                break;
            case 'C':
                directive = kCS_WITH_SAFETY_AND_DCS_INVARIANTS;
                break;
            case 'g':
                directive = kCS_WITH_SAFETY_AND_USER_GIVEN_DCS_INVARIANTS;
                break;
            case 'h':
                goto usage;
                break;
            default:
                goto usage;
            }
        }
    }
    /*************************************************
    Extraction of Command Line Argument Ends    
    *************************************************/

    if( !Abc_NtkIsStrash( pNtk ) )
    {
        printf("The input network was not strashed, strashing....\n");
        pNtkTemp = Abc_NtkStrash( pNtk, 0, 0, 0 );
        pAig = Abc_NtkToDar( pNtkTemp, 0, 1 );
    }
    else
    {
        pAig = Abc_NtkToDar( pNtk, 0, 1 );
        pNtkTemp = pNtk;
    }

/**********************Code for generation of nCk outputs**/
    //combCount = countCombination(1000, 3);
    //pAigCombStabil = generateDisjunctiveTester( pNtk, pAig, 7, 2 );
    printf("Enter parameterizedCombK = " );
    if( scanf("%d", &parameterizedCombK) != 1 )
    {
        printf("\nFailed to read integer!\n");
        return 0;
    }
    printf("\n");

    pAigCombStabil = generateGeneralDisjunctiveTester( pNtk, pAig, parameterizedCombK );
    Aig_ManPrintStats(pAigCombStabil);
    pNtkCombStabil = Abc_NtkFromAigPhase( pAigCombStabil );
    pNtkCombStabil->pName = Abc_UtilStrsav( pAigCombStabil->pName );
    if ( !Abc_NtkCheck( pNtkCombStabil ) )
            fprintf( stdout, "Abc_NtkCreateCone(): Network check has failed.\n" );
    Abc_FrameSetCurrentNetwork( pAbc, pNtkCombStabil );

    Aig_ManStop( pAigCombStabil );
    Aig_ManStop( pAig );

    return 1;
    //printf("\ncombCount = %d\n", combCount);
    //exit(0);
/**********************************************************/

    usage:
        fprintf( stdout, "usage: nck [-cmgCh]\n" );
            fprintf( stdout, "\tgenerates combinatorial signals for stabilization\n" );
        fprintf( stdout, "\t-h : print usage\n");
            return 1;

}


ABC_NAMESPACE_IMPL_END