VIS

src/puresat/puresatFlatIP.c

Go to the documentation of this file.
00001 
00048 #include "maigInt.h"
00049 #include "puresatInt.h"
00050 /*---------------------------------------------------------------------------*/
00051 /* Constant declarations                                                     */
00052 /*---------------------------------------------------------------------------*/
00053 
00054 /*---------------------------------------------------------------------------*/
00055 /* Type declarations                                                         */
00056 /*---------------------------------------------------------------------------*/
00057 
00058 
00059 /*---------------------------------------------------------------------------*/
00060 /* Structure declarations                                                    */
00061 /*---------------------------------------------------------------------------*/
00062 
00063 
00064 /*---------------------------------------------------------------------------*/
00065 /* Variable declarations                                                     */
00066 /*---------------------------------------------------------------------------*/
00067 
00068 /*---------------------------------------------------------------------------*/
00069 /* Macro declarations                                                        */
00070 /*---------------------------------------------------------------------------*/
00071 
00074 /*---------------------------------------------------------------------------*/
00075 /* Static function prototypes                                                */
00076 /*---------------------------------------------------------------------------*/
00077 
00078 
00081 /*---------------------------------------------------------------------------*/
00082 /* Definition of exported functions                                          */
00083 /*---------------------------------------------------------------------------*/
00084 
00085 
00086 /*---------------------------------------------------------------------------*/
00087 /* Definition of internal functions                                          */
00088 /*---------------------------------------------------------------------------*/
00114 boolean PureSatCheckInv_FlatIP(Ntk_Network_t * network,
00115                                Ctlsp_Formula_t *ltlFormula,
00116                                PureSat_Manager_t *pm)
00117 {
00118   int NumofCurrentLatch=0,k;
00119   bAig_Manager_t    *manager;
00120   bAigEdge_t        property;
00121   st_table * nodeToMvfAigTable;
00122   double t1,t2,t0;
00123   int first;
00124   array_t           *previousResultArray;
00125   BmcOption_t  *options = BmcOptionAlloc();
00126   IP_Manager_t * ipm = IPManagerAlloc();
00127   boolean firstTime;
00128   int round=0, oldLength=0, nodes_in_coi=0;
00129   st_table * tmpTable;
00130   int oldPos1;
00131   satManager_t * cm;
00132   bAigEdge_t state, tmpState;
00133   double tIP=0,tCon=0,tUnsat=0;
00134   RTManager_t *rm;
00135 
00136 
00137   pm->CoiTable = st_init_table(st_ptrcmp,st_ptrhash);
00138   PureSatBmcGetCoiForLtlFormula(network, ltlFormula,pm->CoiTable);
00139   ipm->CoiTable = pm->CoiTable;
00140 
00141   options->printInputs = pm->printInputs;
00142   options->dbgOut = pm->dbgOut;
00143   pm->CoiTable = st_init_table(st_ptrcmp,st_ptrhash);
00144   t0 = util_cpu_ctime();
00145   NumofCurrentLatch=0;
00146   t1 = util_cpu_ctime();
00147   PureSatBmcGetCoiForLtlFormula_New(network, ltlFormula,pm->CoiTable);
00148   t2 = util_cpu_ctime();
00149 
00150   manager = Ntk_NetworkReadMAigManager(network);
00151   if (manager == NIL(mAig_Manager_t)) {
00152     (void) fprintf(vis_stdout, "** bmc error: run build_partition_maigs command first\n");
00153     BmcOptionFree(options);
00154     return 1;
00155   }
00156  nodeToMvfAigTable =(st_table *) Ntk_NetworkReadApplInfo(network,
00157                                                          MVFAIG_NETWORK_APPL_KEY);
00158 
00159  previousResultArray    = array_alloc(bAigEdge_t, 0);
00160  first = 0;
00161  manager->ipm = ipm;
00162  t1 = util_cpu_ctime();
00163  manager->test2LevelMini = 1;
00164  bAig_PureSat_InitTimeFrame(network,manager,pm,0);
00165  manager->test2LevelMini = 0;
00166  if(pm->verbosity>=1) {
00167    fprintf(vis_stdout,"after Init timeframe:\n");
00168    PureSat_PrintAigStatus(manager);
00169  }
00170  manager->class_ = 1;
00171  manager->test2LevelMini = 0;
00172  property = PureSatCreatebAigOfPropFormula(network,
00173             manager, 0, ltlFormula, BMC_NO_INITIAL_STATES);
00174  property = bAig_Not(property);
00175  if(property==0)
00176    return TRUE;
00177  if(property==1)
00178    return FALSE;
00179  manager->assertArray = sat_ArrayAlloc(1);
00180  sat_ArrayInsert(manager->assertArray,manager->InitState);
00181  cm = PureSat_SatManagerAlloc(manager,pm,property,previousResultArray);
00182  cm->option->coreGeneration = 0;
00183  cm->option->IP = 0;
00184  if(pm->verbosity>=1)
00185    fprintf(vis_stdout,"test length 0\n");
00186  sat_Main(cm);
00187  manager->NodesArray = cm->nodesArray;
00188  if(cm->status==SAT_SAT){
00189    if(pm->dbgLevel == 1){
00190      fprintf(vis_stdout,"find counter example of length 0\n");
00191      BmcCirCUsPrintCounterExample(network, nodeToMvfAigTable, pm->CoiTable,
00192                                 0, 0,options, BMC_NO_INITIAL_STATES);
00193    }
00194    if(pm->dbgLevel == 2){
00195      BmcCirCUsPrintCounterExampleAiger(network, nodeToMvfAigTable, pm->CoiTable,
00196                                 0, 0,options, BMC_NO_INITIAL_STATES);
00197    }
00198    return FALSE;
00199  }
00200  cm->option->coreGeneration = 1;
00201  PureSat_SatFreeManager(cm);
00202 
00203  manager->test2LevelMini = 1;
00204  bAig_PureSat_ExpandTimeFrame(network, manager,pm,1, BMC_NO_INITIAL_STATES);
00205   manager->class_ = 2;
00206  manager->test2LevelMini = 0;
00207  property = PureSatCreatebAigOfPropFormula(network,
00208                 manager, 1, ltlFormula, BMC_NO_INITIAL_STATES);
00209  property = bAig_Not(property);
00210  if(property==0)
00211    return TRUE;
00212  if(property==1)
00213    return FALSE;
00214  if(pm->verbosity>=1) {
00215    fprintf(vis_stdout,"after Init timeframe:\n");
00216    PureSat_PrintAigStatus(manager);
00217  }
00218  state = manager->InitState;
00219 
00220 
00221  cm = PureSat_SatManagerAlloc(manager,pm,property,previousResultArray);
00222  cm->option->coreGeneration = 0;
00223  cm->option->IP = 0;
00224  if(pm->verbosity>=1) {
00225   fprintf(vis_stdout,"test length 1\n");
00226  }
00227  sat_Main(cm);
00228  manager->NodesArray = cm->nodesArray;
00229   if(cm->status==SAT_SAT){
00230    if(pm->dbgLevel == 1){
00231      fprintf(vis_stdout,"find counter example of length 1\n");
00232      BmcCirCUsPrintCounterExample(network, nodeToMvfAigTable, pm->CoiTable,
00233                         1, 0,options, BMC_NO_INITIAL_STATES);
00234    }
00235    if(pm->dbgLevel == 2){
00236      BmcCirCUsPrintCounterExampleAiger(network, nodeToMvfAigTable, pm->CoiTable,
00237                         1, 0,options, BMC_NO_INITIAL_STATES);
00238    }
00239    return FALSE;
00240  }
00241  cm->option->coreGeneration = 1;
00242  PureSat_SatFreeManager(cm);
00243 
00244  t2 = util_cpu_ctime();
00245  if(pm->verbosity>=2)
00246    fprintf(vis_stdout,"Time for testing Length 0 and 1: %g\n",(double)((t2-t1)/1000.0));
00247 
00248  pm->Length = k;
00249  k = 1;
00250  PureSat_CleanMask(manager,ResetGlobalVarMask);
00251  PureSat_MarkGlobalVar(manager,1);
00252  while(1){
00253    oldLength = k;
00254    if(k==1)
00255      k++;
00256    else
00257      k += round-1;
00258    pm->Length = k;
00259    if(pm->verbosity>=1)
00260      fprintf(vis_stdout,"\nk = %d InitState = %ld\n",k,manager->InitState);
00261    manager->test2LevelMini = 1;
00262    bAig_PureSat_ExpandTimeFrame(network, manager,pm, k, BMC_NO_INITIAL_STATES);
00263    manager->test2LevelMini = 0;
00264    if(pm->verbosity>=1) {
00265      fprintf(vis_stdout,"After expand TF\n");
00266      PureSat_PrintAigStatus(manager);
00267    }
00268 
00269    /*build property aig nodes*/
00270    manager->class_ = k+1;
00271    property = PureSatCreatebAigOfPropFormula(network,
00272               manager, k, ltlFormula, BMC_NO_INITIAL_STATES);
00273    property = bAig_Not(property);
00274    if(property==0)
00275      return TRUE;
00276    if(property==1)
00277      return FALSE;
00278    oldPos1 = manager->nodesArraySize-bAigNodeSize;
00279    if(pm->verbosity>=1) {
00280      fprintf(vis_stdout,"After expanding TF and building property\n");
00281      PureSat_PrintAigStatus(manager);
00282    }
00283    firstTime = TRUE;
00284    round = 0;
00285    state = manager->InitState;
00286 
00287    while(1){
00288      round++;
00289      if(pm->verbosity>=1)
00290        fprintf(vis_stdout,"round:%d for k = %d\n",round,k);
00291      manager->assertArray = sat_ArrayAlloc(1);
00292      if(state!=bAig_One)
00293        sat_ArrayInsert(manager->assertArray,state);
00294      cm = PureSat_SatManagerAlloc(manager,pm,property,previousResultArray);
00295 
00296      if(cm->status==0){
00297        if(pm->verbosity>=1)
00298          fprintf(vis_stdout,"normal COI:\n");
00299        nodes_in_coi = PureSat_CountNodesInCoi(cm);
00300        if(pm->verbosity>=2)
00301          fprintf(vis_stdout,"There are %d node in COI\n",nodes_in_coi);
00302        t1 = util_cpu_ctime();
00303        sat_Main(cm);
00304        if(pm->verbosity>=2)
00305          sat_ReportStatistics(cm,cm->each);
00306 
00307        rm = cm->rm;
00308        t2 = util_cpu_ctime();
00309        tUnsat = tUnsat+t2-t1;
00310        if(pm->verbosity>=2)
00311          fprintf(vis_stdout,"time for Unsat:%g, Total:%g\n",
00312                 (double)((t2-t1)/1000.0),tUnsat/1000);
00313        if(manager->NodesArray!=cm->nodesArray)
00314          /*cm->nodesArray may be reallocated */
00315          manager->NodesArray = cm->nodesArray;
00316      }
00317 
00318      if(cm->status == SAT_SAT){
00319        /*SAT: first time->find bug, otherwise increase length*/
00320        if(firstTime){
00321          if(pm->dbgLevel == 1){
00322            fprintf(vis_stdout,"found CEX of length %d\n",k);
00323            BmcCirCUsPrintCounterExample(network, nodeToMvfAigTable, pm->CoiTable,
00324                       k, 0,options, BMC_NO_INITIAL_STATES);
00325          }
00326          if(pm->dbgLevel == 2){
00327            BmcCirCUsPrintCounterExampleAiger(network, nodeToMvfAigTable, pm->CoiTable,
00328                       k, 0,options, BMC_NO_INITIAL_STATES);
00329          }
00330          sat_ArrayFree(manager->assertArray);
00331          manager->assertArray = 0;
00332          RT_Free(cm->rm);
00333          PureSat_SatFreeManager(cm);
00334          return FALSE;
00335        }
00336        /*find bogus bug, abort, increase length*/
00337        else{
00338          /* BmcCirCUsPrintCounterExample(network, nodeToMvfAigTable, pm->CoiTable,
00339                                       k, 0,options, BMC_NO_INITIAL_STATES);*/
00340          if(pm->verbosity>=1)
00341            fprintf(vis_stdout,"find bogus bug at length k=%d,round=%d,increase length\n",k,round);
00342 
00343          sat_ArrayFree(manager->assertArray);
00344          RT_Free(cm->rm);
00345          PureSat_SatFreeManager(cm);
00346          break;
00347        }
00348      }
00349      else{
00350        /*UNSAT: get IP, add to init states, until reach convergence, which
00351          means property is true
00352          IP generation*/
00353        assert(cm->currentDecision>=-1);
00354        if(cm->currentDecision!=-1)
00355          sat_Backtrack(cm, -1);
00356        /*get rid of Conflict Clauses*/
00357        PureSat_ResetManager(manager,cm,0);
00358 
00359        /*Generate interpolant and test convergence*/
00360        if(cm->option->coreGeneration&&cm->status == SAT_UNSAT){
00361          manager->class_ = 1;
00362          t1 = util_cpu_ctime();
00363          tmpState = sat_GenerateFwdIP(manager,cm,cm->rm->root,1);
00364          manager->IPState = PureSat_MapIP(manager,tmpState,1,0);
00365          ResetRTree(rm);
00366 
00367          /*Wheneven there is baigNode generated, Reset_Manager is necessary,
00368            since NodeArray may be reallocated, # of Nodes changed*/
00369          PureSat_ResetManager(manager,cm,0);
00370          t2 = util_cpu_ctime();
00371          tIP = tIP+t2-t1;
00372          if(pm->verbosity>=2)
00373            fprintf(vis_stdout,"time for generating IP:%g, Total:%g\n",
00374                   (double)((t2-t1)/1000.0),tIP/1000);
00375          if(pm->verbosity>=1){
00376            fprintf(vis_stdout,"After generate IP,%ld:\n",manager->IPState);
00377            PureSat_PrintAigStatus(manager);
00378          }
00379          manager->class_ = 2;
00380          t1 = util_cpu_ctime();
00381          RT_Free(cm->rm);
00382          if(pm->verbosity>=1)
00383            PureSat_PrintAigStatus(manager);
00384 
00385          PureSat_ResetManager(manager,cm,0);
00386        }
00387 
00388        t1 = util_cpu_ctime();
00389 
00390        /*Convergence test for interpolation*/
00391        if(PureSat_TestConvergeForIP(manager,pm,cm,state,manager->IPState)){
00392          t2 = util_cpu_ctime();
00393          tCon = tCon+t2-t1;
00394          if(pm->verbosity>=2)
00395            fprintf(vis_stdout,"time for generating Convergence:%g, Total:%g\n",
00396                   (double)((t2-t1)/1000.0),tCon/1000);
00397          if(pm->verbosity>=1){
00398            fprintf(vis_stdout,"After test convergence:\n");
00399            PureSat_PrintAigStatus(manager);
00400          }
00401          fprintf(vis_stdout,"property is true\n");
00402          PureSat_SatFreeManager(cm);
00403          return TRUE;
00404        }
00405        else{
00406          t2 = util_cpu_ctime();
00407          tCon = tCon+t2-t1;
00408          if(pm->verbosity>=2)
00409            fprintf(vis_stdout,"time for generating Convergence:%g, Total:%g\n",
00410                   (double)((t2-t1)/1000.0),tCon/1000);
00411          if(pm->verbosity>=1){
00412            fprintf(vis_stdout,"After test convergence:\n");
00413            PureSat_PrintAigStatus(manager);
00414          }
00415          manager->class_ = 0;
00416          state = PureSat_Or(manager,state,manager->IPState);
00417          PureSat_ResetManager(manager,cm,0);
00418          if(pm->verbosity>=1)
00419            fprintf(vis_stdout,"new InitState:%ld\n",state);
00420        }
00421      }/*else*/
00422      sat_ArrayFree(manager->assertArray);
00423      manager->assertArray = 0;
00424      PureSat_SatFreeManager(cm);
00425      firstTime = FALSE;
00426    }/*inner While(1){*/
00427  }/*outer While(1){*/
00428  st_free_table(tmpTable);
00429 
00430  sat_ArrayFree(manager->EqArray);
00431  return TRUE;
00432 }