⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 enumerate.cpp

📁 clique code with sample data set. clique is a data clustering algorithm which follows hierarchical c
💻 CPP
📖 第 1 页 / 共 2 页
字号:
               ++nj;
               break;
            case notequal:
               if (closed_type == cmax) get_max_join(*ni, *nj, join, iter);
               neq->add_node(join);               
               ++nj;
               break;
            case equals:
               //add nj to all elements in eq by adding nj to prefix
               neq->prefix().push_back((*nj)->val); 
               //neq->closedsupport() = join->support();
               delete *nj;
               nj = eq->nlist().erase(nj); //remove nj
               //cout << "EQUAL " << *join << endl;
               delete join;
               break;
            case superset:
               if (closed_type == cmax) get_max_join(*ni, *nj, join, iter);
               delete *nj;
               nj = eq->nlist().erase(nj); //remove nj
               //++nj;
               neq->add_node(join);            
               break;
            }
         }
      }
      
      cflg = true;
      if (closed_type == cmax){
         cflg = maxtest.check_closed(*ni);
         if (cflg){
            maxtest.add(neq->prefix(), -1, (*ni)->support());
            newmax.push_back(maxtest.maxcount-1);
         }
      }
      else if (closed_type == chash){
         cflg = hashtest.add(neq->prefix(), -1, (*ni)->support(), 
                             (*ni)->hval);
      }

      if (cflg){
         stats.incrmax(neq->prefix().size()-1);
         if (output){
            cout << "CLOSEDxy ";
            neq->print_prefix(true);
            cout << endl;
         }
      }
      
      stats.incrtime(iter-1, tt.Stop());
      //if (output) cout << *neq;
      if (neq->nlist().size() > 1){
         enumerate_closed_freq(neq, iter+1, newmax);
      }
      else if (neq->nlist().size() == 1){
         cflg = true;
         if (closed_type == cmax){
            cflg = maxtest.check_closed(neq->nlist().front());
            if (cflg){
               maxtest.add(neq->prefix(), neq->nlist().front()->val, 
                           neq->nlist().front()->sup);
               newmax.push_back(maxtest.maxcount-1);
            }
         }
         else if (closed_type == chash){
            cflg = hashtest.add(neq->prefix(), neq->nlist().front()->val, 
                                neq->nlist().front()->sup, 
                                neq->nlist().front()->hval);
         }
         
         if (cflg){
            if (output) cout << "CLOSEDy " << *neq;
            stats.incrmax(neq->prefix().size());
         }
      }
      delete neq;
   }
}

void enumerate_freq(Eqclass *eq, int iter)
{
   TimeTracker tt;
   Eqclass *neq;
   list<Eqnode *>::iterator ni, nj;
   Eqnode *join;

   for (ni = eq->nlist().begin(); ni != eq->nlist().end(); ++ni){
      neq = new Eqclass;
      neq->set_prefix(eq->prefix(),*(*ni));
      tt.Start();
      nj = ni;
      for (++nj; nj != eq->nlist().end(); ++nj){ 
         join = new Eqnode ((*nj)->val);
         get_join(*ni, *nj, join, iter);
         stats.incrcand(iter-1);
         if (notfrequent(*join)) delete join;
         else{
            neq->add_node(join);
            stats.incrlarge(iter-1);
         }
      }
      stats.incrtime(iter-1, tt.Stop());
      if (output) cout << *neq;
      if (neq->nlist().size()> 1){
         enumerate_freq(neq, iter+1);
      }
      delete neq;
   }
}

void form_closed_f2_lists(Eqclass *eq)
{
   static bit_vector *bvec = NULL;
   if (bvec == NULL){
      bvec = new bit_vector(DCB->NumF1, true);
   }
   
   subset_vals sval;
   list<Eqnode *>::iterator ni;
   Eqnode *l1, *l2;
   int pit, nit;
   TimeTracker tt;
   bool extend = false;
   bool cflg;
   
   tt.Start();
   pit = eq->prefix()[0];
   l1 = DCB->ParentClass[pit];

   if (!(*bvec)[pit]){
      eq->nlist().clear();
     return;
   }
   
   if (alg_type == maxcharm){
      cflg = maxtest.subset_test_f2(eq);
      if (cflg){
         eq->nlist().clear();
         return;
      }
   }
   
   for (ni=eq->nlist().begin(); ni != eq->nlist().end(); ){
      nit = (*ni)->val;
      if (!(*bvec)[nit]){
         ++ni;
         continue;
      }
      l2 = DCB->ParentClass[nit];
      sval = get_join(l1, l2, (*ni), 2);
      //cout << "SVAL " << (int)sval << endl;
      switch(sval){
      case subset:
         //add nj to all elements in eq by adding nj to prefix
         eq->prefix().push_back((*ni)->val);               
         extend = true;
         //eq->closedsupport() = (*ni)->support();
         delete *ni;
         ni = eq->nlist().erase(ni); //remove ni
         //cout << "CAME HERE " << eq->nlist().size() << endl;
         break;
      case notequal:
         if (alg_type == maxcharm || closed_type == cmax) 
            get_max_join(l1, l2, (*ni), 2);
         ++ni;
         break;
      case equals:
         //add nj to all elements in eq by adding nj to prefix
         eq->prefix().push_back((*ni)->val); 
         extend = true;
         //eq->closedsupport() = (*ni)->support();
         delete *ni;
         ni = eq->nlist().erase(ni); //remove ni
         (*bvec)[nit] = false;
         //cout << "CAME HERE " << eq->nlist().size() << endl;
         break;
      case superset:
         (*bvec)[nit] = false;
         if (alg_type == maxcharm || closed_type == cmax) 
            get_max_join(l1, l2, (*ni), 2);
         ++ni;
         break;
      }
   }
   
   if (alg_type == charm){

      cflg = true;
      if (closed_type == cmax){
         cflg = maxtest.check_closed(l1);
         if (cflg) maxtest.add(eq->prefix(), -1, l1->support());
      }
      else if (closed_type == chash){
         cflg = hashtest.add(eq->prefix(), -1, l1->support(), 
                             l1->hval);
      }

      if (cflg){
         stats.incrmax(eq->prefix().size()-1);
         if (output){
            cout << "CLOSEDzx ";
            eq->print_prefix(true);
            cout << endl;
         }
      }
      
      
      if (eq->nlist().size() == 1){
         cflg = true;
         if (closed_type == cmax){
            cflg = maxtest.check_closed(eq->nlist().front());
            if (cflg){
               maxtest.add(eq->prefix(), eq->nlist().front()->val, 
                           eq->nlist().front()->sup);
            }
         }
         else if (closed_type == chash){
            cflg = hashtest.add(eq->prefix(), eq->nlist().front()->val, 
                                eq->nlist().front()->sup, 
                                eq->nlist().front()->hval);
         }

         if (cflg){
            if (output){
               cout << "CLOSEDz ";
               cout << *eq;
            }
            
            stats.incrmax(eq->prefix().size());
         }
         eq->nlist().clear();
      }
   }
   else if (alg_type == maxcharm){
      if (eq->nlist().empty() && l1->maxsupport() == 0){
         if (output)
            eq->print_prefix() << endl;
         maxtest.add(eq->prefix(), -1);
         stats.incrmax(eq->prefix().size()-1);
      }
      else if (eq->nlist().size() == 1){
         l1 = eq->nlist().front();
         if (l1->maxsupport() == 0){
            if (output)
               eq->print_node(*l1) << endl;
            maxtest.add(eq->prefix(), l1->val);
            stats.incrmax(eq->prefix().size()); 
         }
         eq->nlist().clear();
      }
   }

   //cout << "F2 " << *eq << endl;
   stats.incrtime(1,tt.Stop());   
   //delete l1;
}



void form_f2_lists(Eqclass *eq)
{
   list<Eqnode *>::iterator ni;
   Eqnode *l1, *l2;
   int pit, nit;
   TimeTracker tt;
   
   tt.Start();
   pit = eq->prefix()[0];
   l1 = DCB->ParentClass[pit];
   for (ni=eq->nlist().begin(); ni != eq->nlist().end(); ++ni){
      nit = (*ni)->val;
      l2 = DCB->ParentClass[nit];

      get_join(l1, l2, (*ni), 2);
      if (alg_type == basicmax) 
         get_max_join(l1, l2, (*ni), 2);
   }
   stats.incrtime(1,tt.Stop());   
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -