VIS

src/bmc/bmcCirCUsUtil.c

Go to the documentation of this file.
00001 
00017 #include "bmcInt.h"
00018 #include "sat.h"
00019 
00020 static char rcsid[] UNUSED = "$Id: bmcCirCUsUtil.c,v 1.22 2010/04/10 04:07:06 fabio Exp $";
00021 
00022 /*---------------------------------------------------------------------------*/
00023 /* Constant declarations                                                     */
00024 /*---------------------------------------------------------------------------*/
00025 
00026 #define MAX_LENGTH 320 /* Max. length of a string while reading a file */
00027 
00028 /*---------------------------------------------------------------------------*/
00029 /* Type declarations                                                         */
00030 /*---------------------------------------------------------------------------*/
00031 
00032 /*---------------------------------------------------------------------------*/
00033 /* Structure declarations                                                    */
00034 /*---------------------------------------------------------------------------*/
00035 
00036 /*---------------------------------------------------------------------------*/
00037 /* Variable declarations                                                     */
00038 /*---------------------------------------------------------------------------*/
00039 
00042 /*---------------------------------------------------------------------------*/
00043 /* Static function prototypes                                                */
00044 /*---------------------------------------------------------------------------*/
00045 
00046 static char * getBddName(bdd_manager *bddManager, bdd_node *node);
00047 static bAigEdge_t getAigAtTimeFrame(bAig_Manager_t *manager, bAigEdge_t node, int i, int withInitialState);
00048 static bAigEdge_t getAigOfBddAtState(Ntk_Network_t *network, bdd_node *node, int state, int withInitialState);
00049 
00052 /*---------------------------------------------------------------------------*/
00053 /* Definition of exported functions                                          */
00054 /*---------------------------------------------------------------------------*/
00055 
00056 /*---------------------------------------------------------------------------*/
00057 /* Definition of internal functions                                          */
00058 /*---------------------------------------------------------------------------*/
00059 
00070 void
00071 BmcCirCUsAutLtlCheckTerminalAutomaton(
00072   Ntk_Network_t            *network,
00073   bAig_Manager_t           *aigManager,
00074   st_table                 *nodeToMvfAigTable,
00075   BmcCheckForTermination_t *terminationStatus,
00076   st_table                 *coiIndexTable,
00077   BmcOption_t              *options)
00078 {
00079   long            startTime, endTime;
00080   int             k = terminationStatus->k;
00081   int             returnStatus = 0;
00082   Ltl_Automaton_t *automaton = terminationStatus->automaton;
00083   satInterface_t  *tInterface, *etInterface;
00084   bAigEdge_t      autPath, property;
00085   array_t         *objArray;
00086   array_t         *previousResultArray;
00087 
00088   startTime = util_cpu_ctime();
00089 
00090   if (options->verbosityLevel == BmcVerbosityMax_c) {
00091     (void) fprintf(vis_stdout, "\nBMC: Check for termination\n");
00092   }
00093   etInterface = 0;
00094   tInterface  = 0;
00095     /*
00096     Hold objects
00097   */
00098   objArray = array_alloc(bAigEdge_t, 2);
00099   previousResultArray    = array_alloc(bAigEdge_t, 0);
00100   returnStatus = 0;
00101 
00102   autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00103                                                      0, k+1, nodeToMvfAigTable,
00104                                                      coiIndexTable,
00105                                                      BMC_NO_INITIAL_STATES);
00106 
00107   property = bAig_Not(
00108     BmcCirCUsBdd2Aig(network, automaton->fairSets, k, -1,
00109                      automaton, aigManager,  BMC_NO_INITIAL_STATES));
00110 
00111   property = bAig_And(aigManager, property,
00112                       BmcCirCUsBdd2Aig(network, automaton->fairSets, k+1, -1,
00113                                        automaton, aigManager,  BMC_NO_INITIAL_STATES));
00114   options->cnfPrefix = k+1;
00115   array_insert(bAigEdge_t, objArray, 0, property);
00116   array_insert(bAigEdge_t, objArray, 1, autPath);
00117   tInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network, objArray,
00118                                             previousResultArray, options, tInterface);
00119   if(tInterface->status == SAT_UNSAT){
00120      returnStatus = 1;
00121   }
00122 
00123   /* ===========================
00124      Early termination condition
00125      ===========================
00126   */
00127   if ((options->earlyTermination)&&(returnStatus ==0)) {
00128     if (options->verbosityLevel == BmcVerbosityMax_c) {
00129       (void) fprintf(vis_stdout, "\nChecking the early termination at k= %d\n", k);
00130     }
00131 
00132     autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00133                                                        0, k+1, nodeToMvfAigTable,
00134                                                        coiIndexTable,
00135                                                        BMC_INITIAL_STATES);
00136     array_insert(bAigEdge_t, objArray, 0, autPath);
00137     array_insert(bAigEdge_t, objArray, 1, bAig_One);
00138     options->cnfPrefix = k+1;
00139     etInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network, objArray,
00140                                                previousResultArray, options, etInterface);
00141 
00142     if(etInterface->status == SAT_UNSAT){
00143       (void) fprintf(vis_stdout, "# BMC: by early termination\n");
00144       returnStatus = 1;
00145     }
00146   } /* Early termination */
00147 
00148   if (options->verbosityLevel != BmcVerbosityNone_c) {
00149     endTime = util_cpu_ctime();
00150     fprintf(vis_stdout, "-- Check for termination time time = %10g\n",
00151             (double)(endTime - startTime) / 1000.0);
00152   }
00153   array_free(objArray);
00154   array_free(previousResultArray);
00155 
00156   terminationStatus->action = returnStatus;
00157 
00158 } /* BmcCirCUsAutLtlCheckTerminalAutomaton */
00159 
00160 
00161 
00174 bAigEdge_t
00175 BmcCirCUsBdd2Aig(
00176   Ntk_Network_t   *network,
00177   bdd_t           *function,
00178   int             current,
00179   int             next,
00180   Ltl_Automaton_t *automaton,
00181   bAig_Manager_t  *aigManager,
00182   int             withInitialState)
00183 {
00184   bdd_manager *bddManager;
00185   bdd_node    *node;
00186   bdd_gen     *gen;
00187 
00188   array_t     *cube;
00189   int         i, value;
00190   int         state = current;
00191   bAigEdge_t  aigFunction, andFunction, aigNode;
00192 
00193   if (function == NULL){
00194     return bAig_NULL;
00195   }
00196   /*
00197     If BDD represents a constant value
00198    */
00199   if(bdd_is_tautology(function, 0)){
00200     return bAig_Zero;
00201   }
00202   if(bdd_is_tautology(function, 1)){
00203     return bAig_One;
00204   }
00205 
00206   bddManager = bdd_get_manager(function);
00207   aigFunction = bAig_Zero;
00208   foreach_bdd_cube(function, gen, cube){
00209     andFunction = bAig_One;
00210     arrayForEachItem(int, cube, i, value){
00211       if (value != 2){
00212         int j;
00213         /*
00214           If the BDD varaible is a next state varaible, we use the corresponding
00215           current state varaible but with next state index.
00216         */
00217         if (next != -1 && st_lookup_int(automaton->nsPsTable, (char *)(long)i, &j)){
00218           node = bdd_bdd_ith_var(bddManager, j);
00219           state = next;
00220         } else {
00221           node = bdd_bdd_ith_var(bddManager, i);
00222           state = current;
00223         }
00224         aigNode = getAigOfBddAtState(network, node, state, withInitialState);
00225         if (value == 0){
00226           aigNode = bAig_Not(aigNode);
00227         }
00228         andFunction = bAig_And(aigManager, andFunction, aigNode);
00229       }
00230     }
00231     aigFunction = bAig_Or(aigManager, aigFunction, andFunction);
00232   }/* foreach_bdd_cube */
00233 
00234   return aigFunction;
00235 } /* BmcCirCUsBdd2Aig */
00236 
00237 
00251 bAigEdge_t
00252 BmcCirCUsAutCreateAigForPath(
00253   Ntk_Network_t   *network,
00254   bAig_Manager_t  *aigManager,
00255   Ltl_Automaton_t *automaton,
00256   int             fromState,
00257   int             toState,
00258   int             initialState)
00259 {
00260   int        k;
00261   bAigEdge_t result, aigFunction = bAig_One;
00262 
00263   if(initialState){
00264     result = BmcCirCUsBdd2Aig(network, automaton->initialStates, 0, -1,
00265                               automaton, aigManager, initialState);
00266     aigFunction = result;
00267   }
00268   for(k=fromState; k<toState; k++){
00269    result = BmcCirCUsBdd2Aig(network, automaton->transitionRelation, k, k+1,
00270                               automaton, aigManager, initialState);
00271     aigFunction = bAig_And(aigManager , aigFunction, result);
00272   }
00273   return aigFunction;
00274 
00275 } /* BmcCirCUsAutCreateAigForPath */
00276 
00290 bAigEdge_t
00291 BmcCirCUsAutCreateAigForSimplePath(
00292   Ntk_Network_t   *network,
00293   bAig_Manager_t  *aigManager,
00294   Ltl_Automaton_t *automaton,
00295   int             fromState,
00296   int             toState,
00297   int             initialState)
00298 {
00299   int        i, j, bddID;
00300   bAigEdge_t result, aigFunction, next, current;
00301   mdd_manager        *bddManager = Ntk_NetworkReadMddManager(network);
00302   st_generator       *stGen;
00303 
00304   bdd_node           *node;
00305 
00306 
00307 
00308   aigFunction = BmcCirCUsAutCreateAigForPath(network, aigManager, automaton,
00309                                              fromState, toState, initialState);
00310   /*
00311     The path is simple path
00312   */
00313   for(i = fromState + 1; i <= toState; i++){
00314     for(j=fromState; j < i; j++){
00315       result = bAig_Zero;
00316       st_foreach_item(automaton->psNsTable, stGen,&bddID, NULL) {
00317         node = bdd_bdd_ith_var(bddManager, bddID);
00318 
00319         current = getAigOfBddAtState(network, node, i, initialState);
00320         next    = getAigOfBddAtState(network, node, j, initialState);
00321 
00322         result = bAig_Or(aigManager, result,
00323                          bAig_Not(bAig_Eq(aigManager, current, next)));
00324       }
00325       aigFunction = bAig_And(aigManager, aigFunction, result);
00326     }
00327   }
00328 
00329   return aigFunction;
00330 
00331 } /* BmcCirCUsAutCreateAigForSimplePath */
00332 
00346 bAigEdge_t
00347 BmcCirCUsCreateAigForSimpleCompositePath(
00348   Ntk_Network_t   *network,
00349   bAig_Manager_t  *aigManager,
00350   Ltl_Automaton_t *automaton,
00351   int             fromState,
00352   int             toState,
00353   st_table        *nodeToMvfAigTable,
00354   st_table        *coiIndexTable,
00355   int             initialState)
00356 {
00357   int        i, j, bddID;
00358   bAigEdge_t         result, aigFunction, next, current;
00359   mdd_manager        *bddManager = Ntk_NetworkReadMddManager(network);
00360   st_generator       *stGen;
00361 
00362   bdd_node           *node;
00363 
00364 
00365 
00366   /*
00367     Build a path in the original model
00368    */
00369   bAig_ExpandTimeFrame(network, aigManager, toState+1, initialState);
00370   /*
00371     Build a path in the automaton
00372    */
00373   aigFunction = BmcCirCUsAutCreateAigForPath(network, aigManager, automaton,
00374                                              fromState, toState, initialState);
00375   /*
00376     Constrains the two paths to be simple paths
00377   */
00378   for(i = fromState + 1; i <= toState; i++){
00379     for(j=fromState; j < i; j++){
00380       result = bAig_Zero;
00381 
00382       /*
00383         Unique states in the automaton
00384        */
00385       st_foreach_item(automaton->psNsTable, stGen, &bddID, NULL) {
00386         node = bdd_bdd_ith_var(bddManager, bddID);
00387 
00388         current = BmcCirCUsBdd2Aig(network, bdd_construct_bdd_t(bddManager, node), i, -1,
00389                                    automaton, aigManager,
00390                                    initialState);
00391         next    = BmcCirCUsBdd2Aig(network, bdd_construct_bdd_t(bddManager,node), j, -1,
00392                                    automaton, aigManager,
00393                                    initialState);
00394         /*
00395           next    = BmcCirCUsBdd2Aig(network, bdd_construct_bdd_t(bddManager,node), i, j,
00396                                    automaton, aigManager,
00397                                    initialState);
00398 
00399           result = bAig_Or(aigManager, result,
00400                                    bAig_Not(next));
00401         */
00402         result = bAig_Or(aigManager, result,
00403                          bAig_Not(bAig_Eq(aigManager, current, next)));
00404       }
00405       /*
00406         Unique states in the original model
00407       */
00408       result = bAig_Or(aigManager, result,
00409                        bAig_Not(BmcCirCUsConnectFromStateToState(network, i-1, j,
00410                                                                  nodeToMvfAigTable,
00411                                                                  coiIndexTable,
00412                                                                  initialState)));
00413       aigFunction = bAig_And(aigManager, aigFunction, result);
00414     }
00415   }
00416 
00417   return aigFunction;
00418 
00419 } /* BmcCirCUsCreateAigForSimpleCompositePath */
00420 
00421 
00422 
00447 void
00448 BmcCirCUsAutLtlCheckForTermination(
00449   Ntk_Network_t            *network,
00450   bAig_Manager_t           *aigManager,
00451   st_table                 *nodeToMvfAigTable,
00452   BmcCheckForTermination_t *terminationStatus,
00453   st_table                 *coiIndexTable,
00454   BmcOption_t              *options)
00455 {
00456   long            startTime, endTime;
00457   int             k = terminationStatus->k;
00458   int             returnStatus = 0;
00459   Ltl_Automaton_t *automaton = terminationStatus->automaton;
00460   Ctlsp_Formula_t *externalConstraints = terminationStatus->externalConstraints;
00461   satInterface_t  *tInterface, *etInterface;
00462   bAigEdge_t      autPath, property, tmp;
00463   array_t         *objArray;
00464   array_t         *previousResultArray;
00465   array_t         *previousResultArrayWOI;
00466 
00467   /*
00468     If checkLevel == 0 -->  check for beta' and beta'' only and if either UNSAT, m=k and chekLevel =1
00469     If checkLevel == 1 -->  check for beta  only and if UNSAT, checkLevel = 2.
00470     If checkLevel == 2 -->  check for alpha only and if UNSAT, n=k and checkLevel = 3.
00471     If gama is UNSAT up to (m+n-1) and checkLvel = 3, formula passes.
00472     checkLevel = 4 if (m+n-1) > maxK;
00473    */
00474   startTime = util_cpu_ctime();
00475 
00476   etInterface = 0;
00477   tInterface  = 0;
00478     /*
00479     Hold objects
00480   */
00481   objArray = array_alloc(bAigEdge_t, 2);
00482 
00483   previousResultArray    = array_alloc(bAigEdge_t, 0);
00484   previousResultArrayWOI = array_alloc(bAigEdge_t, 0);
00485 
00486   /* ===========================
00487      Early termination condition
00488      ===========================
00489   */
00490   if (options->earlyTermination) {
00491     if (options->verbosityLevel == BmcVerbosityMax_c) {
00492       (void) fprintf(vis_stdout, "\nChecking the early termination at k= %d\n", k);
00493     }
00494 
00495     autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00496                                                        0, k, nodeToMvfAigTable,
00497                                                        coiIndexTable,
00498                                                        BMC_INITIAL_STATES);
00499     array_insert(bAigEdge_t, objArray, 0, autPath);
00500     array_insert(bAigEdge_t, objArray, 1, bAig_One);
00501     options->cnfPrefix = k;
00502     etInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network, objArray,
00503                                      previousResultArray, options, etInterface);
00504 
00505     if(etInterface->status == SAT_UNSAT){
00506       (void) fprintf(vis_stdout, "# BMC: by early termination\n");
00507       terminationStatus->action = 3;
00508       return;
00509     }
00510   } /* Early termination */
00511   if((!automaton->fairSets) &&
00512      (terminationStatus->checkLevel == 0)) {
00513     /*
00514       All the automaton states are fair states. So, beta' and beta are always UNSAT.
00515     */
00516     terminationStatus->m = 0;
00517     printf("Value of m = %d\n", terminationStatus->m);
00518     terminationStatus->checkLevel = 2;
00519   }
00520 
00521    /*
00522     Check \beta''(k)
00523   */
00524   if(terminationStatus->checkLevel == 0){
00525     int i;
00526 
00527     if (options->verbosityLevel == BmcVerbosityMax_c) {
00528       (void) fprintf(vis_stdout, "# BMC: Check Beta''\n");
00529     }
00530     autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00531                                                        0, k+1, nodeToMvfAigTable,
00532                                                        coiIndexTable, BMC_NO_INITIAL_STATES);
00533     property = bAig_One;
00534     for(i=1; i<=k+1; i++){
00535       tmp = BmcCirCUsBdd2Aig(network, automaton->fairSets, i, -1,
00536                              automaton, aigManager,
00537                              BMC_NO_INITIAL_STATES);
00538 
00539       if(externalConstraints){
00540         tmp = bAig_Or(aigManager, tmp,
00541                       BmcCirCUsCreatebAigOfPropFormula(network, aigManager, i,
00542                                                        externalConstraints,
00543                                                        BMC_NO_INITIAL_STATES));
00544       }
00545       property = bAig_And(aigManager, property, bAig_Not(tmp));
00546     }
00547 
00548     tmp = BmcCirCUsBdd2Aig(network, automaton->fairSets, 0, -1,
00549                            automaton, aigManager,  BMC_NO_INITIAL_STATES);
00550     if(externalConstraints){
00551       tmp = bAig_Or(aigManager, tmp,
00552                     BmcCirCUsCreatebAigOfPropFormula(network, aigManager, 0,
00553                                                      externalConstraints,
00554                                                      BMC_NO_INITIAL_STATES));
00555     }
00556     property = bAig_And(aigManager, property, tmp);
00557 
00558     options->cnfPrefix = k+1;
00559     array_insert(bAigEdge_t, objArray, 0, property);
00560     array_insert(bAigEdge_t, objArray, 1, autPath);
00561     tInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network, objArray,
00562                                     previousResultArray, options, tInterface);
00563     if(tInterface->status == SAT_UNSAT){
00564       terminationStatus->m = k;
00565       (void)fprintf(vis_stderr,"m = %d\n", terminationStatus->m);
00566       terminationStatus->checkLevel = 1;
00567     }
00568   } /* Check for Beta'' */
00569 
00570   /*
00571     Check \beta'(k)
00572   */
00573   if(terminationStatus->checkLevel == 0){
00574     int i;
00575 
00576     if (options->verbosityLevel == BmcVerbosityMax_c) {
00577       (void) fprintf(vis_stdout, "# BMC: Check Beta'\n");
00578     }
00579     autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00580                                                        0, k+1, nodeToMvfAigTable,
00581                                                        coiIndexTable, BMC_NO_INITIAL_STATES);
00582     property = bAig_One;
00583     for(i=0; i<=k; i++){
00584       tmp = BmcCirCUsBdd2Aig(network, automaton->fairSets, i, -1,
00585                              automaton, aigManager,
00586                              BMC_NO_INITIAL_STATES);
00587       if(externalConstraints){
00588         tmp = bAig_Or(aigManager, tmp,
00589                       BmcCirCUsCreatebAigOfPropFormula(network, aigManager, i,
00590                                                        externalConstraints,
00591                                                        BMC_NO_INITIAL_STATES));
00592       }
00593       property = bAig_And(aigManager, property, bAig_Not(tmp));
00594     }
00595     tmp = BmcCirCUsBdd2Aig(network, automaton->fairSets, k+1, -1,
00596                            automaton, aigManager,
00597                            BMC_NO_INITIAL_STATES);
00598     if(externalConstraints){
00599       tmp = bAig_Or(aigManager, tmp,
00600                     BmcCirCUsCreatebAigOfPropFormula(network, aigManager, k+1,
00601                                                      externalConstraints,
00602                                                      BMC_NO_INITIAL_STATES));
00603     }
00604     property = bAig_And(aigManager, property, tmp);
00605 
00606     options->cnfPrefix = k+1;
00607     array_insert(bAigEdge_t, objArray, 0, property);
00608     array_insert(bAigEdge_t, objArray, 1, autPath);
00609     tInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network, objArray,
00610                                     previousResultArray, options, tInterface);
00611     if(tInterface->status == SAT_UNSAT){
00612       terminationStatus->m = k;
00613       (void)fprintf(vis_stderr,"m = %d\n", terminationStatus->m);
00614       terminationStatus->checkLevel = 1;
00615     }
00616   } /* Check for Beta' */
00617 
00618   /*
00619     Check for Beta.
00620   */
00621   if(terminationStatus->checkLevel == 1){
00622 
00623     if (options->verbosityLevel == BmcVerbosityMax_c) {
00624       (void) fprintf(vis_stdout, "# BMC: Check Beta\n");
00625     }
00626     autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00627                                                        0, k+1, nodeToMvfAigTable,
00628                                                        coiIndexTable, BMC_NO_INITIAL_STATES);
00629     property = bAig_One;
00630 
00631     tmp = BmcCirCUsBdd2Aig(network, automaton->fairSets, k, -1,
00632                            automaton, aigManager,  BMC_NO_INITIAL_STATES);
00633 
00634     if(externalConstraints){
00635       tmp = bAig_Or(aigManager, tmp,
00636                     BmcCirCUsCreatebAigOfPropFormula(network, aigManager, k,
00637                                                      externalConstraints,
00638                                                      BMC_NO_INITIAL_STATES));
00639     }
00640     property = bAig_And(aigManager, property, bAig_Not(tmp));
00641 
00642     tmp = BmcCirCUsBdd2Aig(network, automaton->fairSets, k+1, -1,
00643                            automaton, aigManager,  BMC_NO_INITIAL_STATES);
00644     if(externalConstraints){
00645       tmp = bAig_Or(aigManager, tmp,
00646                     BmcCirCUsCreatebAigOfPropFormula(network, aigManager, k+1,
00647                                                      externalConstraints,
00648                                                      BMC_NO_INITIAL_STATES));
00649     }
00650     property = bAig_And(aigManager, property, tmp);
00651 
00652     options->cnfPrefix = k+1;
00653     array_insert(bAigEdge_t, objArray, 0, property);
00654     array_insert(bAigEdge_t, objArray, 1, autPath);
00655     tInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network, objArray,
00656                                     previousResultArray, options, tInterface);
00657     if(tInterface->status == SAT_UNSAT){
00658       terminationStatus->checkLevel = 2;
00659     }
00660   } /* Check Beta*/
00661 
00662   if(terminationStatus->checkLevel == 2){ /* we check Alpha if Beta is unsatisfiable */
00663 
00664     if (options->verbosityLevel == BmcVerbosityMax_c) {
00665       (void) fprintf(vis_stdout, "# BMC: Check Alpha \n");
00666     }
00667     autPath = BmcCirCUsCreateAigForSimpleCompositePath(network, aigManager, automaton,
00668                                                        0, k, nodeToMvfAigTable,
00669                                                        coiIndexTable,
00670                                                        BMC_INITIAL_STATES);
00671     array_insert(bAigEdge_t, objArray, 1, bAig_One);
00672     property = bAig_Zero;
00673     if(automaton->fairSets){
00674       property =  BmcCirCUsBdd2Aig(network, automaton->fairSets, k, -1,
00675                                    automaton, aigManager,  BMC_INITIAL_STATES);
00676       array_insert(bAigEdge_t, objArray, 1, property);
00677     }
00678     if(externalConstraints){
00679       property = bAig_Or(aigManager, property,
00680                          BmcCirCUsCreatebAigOfPropFormula(network, aigManager, k,
00681                                                           externalConstraints,
00682                                                           BMC_INITIAL_STATES));
00683       array_insert(bAigEdge_t, objArray, 1, property);
00684     }
00685     options->cnfPrefix = k;
00686     array_insert(bAigEdge_t, objArray, 0, autPath);
00687     tInterface = 0;
00688     tInterface = BmcCirCUsInterfaceWithObjArr(aigManager, network,
00689                                               objArray, previousResultArray,
00690                                               options, tInterface);
00691     if(tInterface->status == SAT_UNSAT){
00692       terminationStatus->n = k;
00693       terminationStatus->checkLevel = 3;
00694       (void)fprintf(vis_stdout,"Value of m=%d  n=%d\n",terminationStatus->m,terminationStatus->n);
00695       if ((terminationStatus->m+terminationStatus->n-1) <= options->maxK){
00696         terminationStatus->k = terminationStatus->m+terminationStatus->n-1;
00697         if(k==0){
00698           /*
00699             By induction, the property passes.
00700            */
00701           terminationStatus->k = 0;
00702         }
00703         returnStatus = 1;
00704       } else {
00705         terminationStatus->checkLevel = 4;
00706         returnStatus = 2;
00707       }
00708     }
00709   }/* Chek for Alpha */
00710 
00711   if (options->verbosityLevel != BmcVerbosityNone_c) {
00712     endTime = util_cpu_ctime();
00713     fprintf(vis_stdout, "-- Check for termination time time = %10g\n",
00714             (double)(endTime - startTime) / 1000.0);
00715   }
00716 
00717   terminationStatus->action = returnStatus;
00718 
00719 } /* BmcAutLtlCheckForTermination */
00720 
00721 
00734 char *
00735 BmcCirCUsCallCirCUs(
00736   BmcOption_t *options)
00737 {
00738   satOption_t  *satOption;
00739   satManager_t *cm;
00740   int          maxSize;
00741   char         *fileName = NIL(char);
00742 
00743   satOption          = sat_InitOption();
00744   satOption->verbose = options->verbosityLevel-1;
00745 
00746   cm = sat_InitManager(0);
00747   cm->comment = ALLOC(char, 2);
00748   cm->comment[0] = ' ';
00749   cm->comment[1] = '\0';
00750   cm->stdOut = stdout;
00751   cm->stdErr = stderr;
00752 
00753   cm->option = satOption;
00754   cm->each = sat_InitStatistics();
00755 
00756   cm->unitLits = sat_ArrayAlloc(16);
00757   cm->pureLits = sat_ArrayAlloc(16);
00758 
00759   maxSize = 10000 << 8;
00760   cm->nodesArray = ALLOC(bAigEdge_t, maxSize);
00761   cm->maxNodesArraySize = maxSize;
00762   cm->nodesArraySize = satNodeSize;
00763 
00764   sat_AllocLiteralsDB(cm);
00765 
00766   sat_ReadCNF(cm, options->satInFile);
00767 
00768   if (options->verbosityLevel == BmcVerbosityMax_c) {
00769     (void)fprintf(vis_stdout,"Calling SAT solver (CirCUs) ...");
00770     (void) fflush(vis_stdout);
00771   }
00772   sat_Main(cm);
00773   if (options->verbosityLevel == BmcVerbosityMax_c) {
00774     (void) fprintf(vis_stdout," done ");
00775     (void) fprintf(vis_stdout, "(%g s)\n", cm->each->satTime);
00776   }
00777   if(cm->status == SAT_UNSAT) {
00778     if (options->verbosityLevel != BmcVerbosityNone_c){
00779       (void) fprintf(vis_stdout, "# SAT: Counterexample not found\n");
00780 
00781     }
00782     fflush(cm->stdOut);
00783   } else if(cm->status == SAT_SAT) {
00784     if (options->verbosityLevel != BmcVerbosityNone_c){
00785       (void) fprintf(vis_stdout, "# SAT: Counterexample found\n");
00786     }
00787     if (options->verbosityLevel > BmcVerbosityMax_c){
00788       sat_ReportStatistics(cm, cm->each);
00789     }
00790 
00791     if(!(cm->stdOut = fopen(options->satOutFile, "w"))) {
00792       fprintf(stdout, "ERROR : Can't open file %s\n", options->satOutFile);
00793       cm->stdOut = stdout;
00794       cm->stdErr = stderr;
00795     }
00796     sat_PrintSatisfyingAssignment(cm);
00797     fileName = options->satOutFile;
00798   }
00799   sat_FreeManager(cm);
00800 
00801   return fileName;
00802 } /* BmcCallCirCUs */
00803 
00815 char *
00816 BmcCirCUsCallCusp(BmcOption_t *options)
00817 {
00818   FILE        *fp;
00819   static char parseBuffer[1024];
00820   int         satStatus;
00821   char        line[MAX_LENGTH];
00822   int         num = 0;
00823   array_t     *result = NIL(array_t);
00824   char        *tmpStr, *tmpStr1, *tmpStr2;
00825   long        solverStart;
00826   int         satTimeOutPeriod = 0;
00827   char        *fileName = NIL(char);
00828 
00829   /*
00830     Prepare to call external CNF SAT solver
00831    */
00832   strcpy(parseBuffer,"cusp -distill -velim -cnf ");
00833   options->satSolverError = FALSE;  /* assume no error */
00834   if (options->timeOutPeriod > 0) {
00835     /* Compute the residual CPU time and subtract a little time to
00836        give vis a chance to clean up before its own time out expires.
00837     */
00838     satTimeOutPeriod = options->timeOutPeriod - 1 -
00839       (util_cpu_ctime() - options->startTime) / 1000;
00840     if (satTimeOutPeriod <= 0){ /* no time left to run SAT solver */
00841       options->satSolverError=TRUE;
00842       return NIL(char);
00843     }
00844     tmpStr2 = util_inttostr(satTimeOutPeriod);
00845     tmpStr1 = util_strcat3(options->satInFile," -t ", tmpStr2);
00846     tmpStr = util_strcat3(tmpStr1, " >", options->satOutFile);
00847     FREE(tmpStr1);
00848     FREE(tmpStr2);
00849   } else {
00850     tmpStr = util_strcat3(options->satInFile, " >", options->satOutFile);
00851   }
00852   strcat(parseBuffer, tmpStr);
00853   FREE(tmpStr);
00854 
00855   if (options->verbosityLevel == BmcVerbosityMax_c) {
00856     (void)fprintf(vis_stdout,"Calling SAT solver (cusp) ...");
00857     (void) fflush(vis_stdout);
00858     solverStart = util_cpu_ctime();
00859   } else { /* to remove uninitialized variables warning */
00860     solverStart = 0;
00861   }
00862   /* Call Sat Solver */
00863   satStatus = system(parseBuffer);
00864   if (satStatus != 0){
00865     (void) fprintf(vis_stderr, "Can't run external sat solver.  It may not be in your path.  Status = %d\n", satStatus);
00866     options->satSolverError = TRUE;
00867     return NIL(char);
00868   }
00869 
00870   if (options->verbosityLevel == BmcVerbosityMax_c) {
00871     (void) fprintf(vis_stdout," done ");
00872     (void) fprintf(vis_stdout, "(%g s)\n",
00873                    (double) (util_cpu_ctime() - solverStart)/1000.0);
00874   }
00875   fp = Cmd_FileOpen(options->satOutFile, "r", NIL(char *), 0);
00876   if (fp == NIL(FILE)) {
00877     (void) fprintf(vis_stderr, "** bmc error: Cannot open the file %s\n",
00878                    options->satOutFile);
00879     options->satSolverError = TRUE;
00880     return NIL(char);
00881   }
00882   /* Skip the lines until the result */
00883   while(1) {
00884     if (fgets(line, MAX_LENGTH - 1, fp) == NULL) break;
00885     if(strstr(line,"UNSATISFIABLE") ||
00886        strstr(line,"SATISFIABLE") ||
00887        strstr(line,"MEMOUT") ||
00888        strstr(line,"TIMEOUT"))
00889       break;
00890   }
00891 
00892   if(strstr(line,"UNSATISFIABLE") != NIL(char)) {
00893     if (options->verbosityLevel != BmcVerbosityNone_c){
00894       (void) fprintf(vis_stdout, "# SAT: Counterexample not found\n");
00895 
00896     }
00897   } else if(strstr(line,"SATISFIABLE") != NIL(char)) {
00898     if (options->verbosityLevel != BmcVerbosityNone_c){
00899       (void) fprintf(vis_stdout, "# SAT: Counterexample found\n");
00900     }
00901     /* Skip the initial v of the result line */
00902     result = array_alloc(int, 0);
00903     while (fgets(line, MAX_LENGTH - 1, fp) != NULL) {
00904       char *word;
00905       if (line[0] != 'v') {
00906         (void) fprintf(vis_stderr,
00907                        "** bmc error: Cannot find assignment in file %s\n",
00908                        options->satOutFile);
00909         options->satSolverError = TRUE;
00910         return NIL(char);
00911       }
00912       word = strtok(&(line[1])," \n");
00913       while (word != NIL(char)) {
00914         num = atoi(word);
00915         if (num == 0) break;
00916         array_insert_last(int, result, num);
00917         word = strtok(NIL(char)," \n");
00918       }
00919       if (num == 0) break;
00920     }
00921     (void) fclose(fp);
00922     fp = Cmd_FileOpen(options->satOutFile, "w", NIL(char *), 0);
00923     for(num=0; num < array_n(result); num++){
00924       fprintf(fp,"%d ", array_fetch(int, result, num));
00925       if(((num+1) %10) == 0){
00926         fprintf(fp,"\n");
00927       }
00928     }
00929     array_free(result);
00930     (void) fclose(fp);
00931     fileName = options->satOutFile;
00932   } else if(strstr(line,"MEMOUT") != NIL(char)) {
00933     (void) fprintf(vis_stdout,"# SAT: SAT Solver Memory out\n");
00934     options->satSolverError = TRUE;
00935   } else if(strstr(line,"TIMEOUT") != NIL(char)) {
00936     (void) fprintf(vis_stdout,
00937                    "# SAT: SAT Solver Time out occurred after %d seconds.\n",
00938                    satTimeOutPeriod);
00939     options->satSolverError = TRUE;
00940   } else {
00941     (void) fprintf(vis_stdout, "# SAT: SAT Solver failed, try again\n");
00942     options->satSolverError = TRUE;
00943   }
00944   (void) fflush(vis_stdout);
00945 
00946   return fileName;
00947 } /* BmcCirCUsCallCusp */
00948 
00949 
00950 /*---------------------------------------------------------------------------*/
00951 /* Definition of static functions                                            */
00952 /*---------------------------------------------------------------------------*/
00953 
00966 static char *
00967 getBddName(
00968   bdd_manager *bddManager,
00969   bdd_node *node)
00970 {
00971   array_t   *mvar_list  = mdd_ret_mvar_list(bddManager);
00972   array_t   *bvar_list  = mdd_ret_bvar_list(bddManager);
00973   char      name[100];
00974   bvar_type bv;
00975   mvar_type mv;
00976   int       nodeIndex = bdd_node_read_index(node);
00977   int       index, rtnNodeIndex;
00978 
00979   /*
00980     If the node is for a multi-valued varaible.
00981   */
00982   if (nodeIndex < array_n(bvar_list)){
00983     bv = array_fetch(bvar_type, bvar_list, nodeIndex);
00984     /*
00985       get the multi-valued varaible.
00986     */
00987     mv = array_fetch(mvar_type, mvar_list, bv.mvar_id);
00988     arrayForEachItem(int, mv.bvars, index, rtnNodeIndex) {
00989       if (nodeIndex == rtnNodeIndex){
00990         break;
00991       }
00992     }
00993     assert(index < mv.encode_length);
00994     sprintf(name, "%s_%d", mv.name, index);
00995   } else {
00996     sprintf(name, "Bdd_%d", nodeIndex);
00997   }
00998   return util_strsav(name);
00999 }
01000 
01010 static bAigEdge_t
01011 getAigAtTimeFrame(
01012   bAig_Manager_t *manager,
01013   bAigEdge_t node,
01014   int        i,
01015   int withInitialState)
01016 {
01017   bAigTimeFrame_t *timeframe;
01018   bAigEdge_t     result, *li;
01019   int            index;
01020 
01021   result = bAig_NULL;
01022 
01023   if(withInitialState) timeframe = manager->timeframe;
01024   else                 timeframe = manager->timeframeWOI;
01025 
01026   if(st_lookup_int(timeframe->li2index, (char *)node, &index)) {
01027     li = timeframe->latchInputs[i];
01028     result = bAig_GetCanonical(manager, li[index]);
01029   }
01030   else if(st_lookup_int(timeframe->o2index, (char *)node, &index)) {
01031     li = timeframe->outputs[i];
01032     result = bAig_GetCanonical(manager, li[index]);
01033   }
01034   else if(st_lookup_int(timeframe->i2index, (char *)node, &index)) {
01035     li = timeframe->internals[i];
01036     result = bAig_GetCanonical(manager, li[index]);
01037   }
01038   else if(st_lookup_int(timeframe->bli2index, (char *)node, &index)) {
01039     li = timeframe->blatchInputs[i];
01040     result = bAig_GetCanonical(manager, li[index]);
01041   }
01042   else if(st_lookup_int(timeframe->bpi2index, (char *)node, &index)) {
01043     li = timeframe->binputs[i];
01044     result = bAig_GetCanonical(manager, li[index]);
01045   }
01046   return result;
01047 }
01048 
01061 static bAigEdge_t
01062 getAigOfBddAtState(
01063   Ntk_Network_t   *network,
01064   bdd_node        *node,
01065   int             state,
01066   int             withInitialState)
01067 {
01068   mdd_manager      *bddManager = Ntk_NetworkReadMddManager(network);
01069   mAig_Manager_t   *aigManager = Ntk_NetworkReadMAigManager(network);
01070 
01071   char        *nodeName, *nameKey;
01072   char        tmpName[100];
01073   bAigEdge_t  aigNode, rtnAig;
01074 
01075   nodeName = getBddName(bddManager, bdd_regular(node));
01076   aigNode  = bAig_FindNodeByName(aigManager, nodeName);
01077   if(aigNode == bAig_NULL){
01078     sprintf(tmpName, "%s_%d_%d", nodeName, withInitialState, state);
01079     nameKey = util_strsav(tmpName);
01080     aigNode  = bAig_FindNodeByName(aigManager, nameKey);
01081     if(aigNode == bAig_NULL){
01082       aigNode = bAig_CreateVarNode(aigManager, nameKey);
01083     } else {
01084       FREE(nameKey);
01085     }
01086     rtnAig = aigNode;
01087   } else {
01088     aigNode = bAig_GetCanonical(aigManager, aigNode);
01089     rtnAig  = getAigAtTimeFrame(aigManager, aigNode, state, withInitialState);
01090     if(rtnAig == bAig_NULL){
01091       rtnAig = bAig_CreateNode(aigManager, bAig_NULL, bAig_NULL);
01092     }
01093   }
01094   return bAig_GetCanonical(aigManager, rtnAig);
01095 } /* getAigOfBddAtState */