count_support.h

00001 /*
00002  *  Copyright (C) 2005 M.J. Zaki <zaki@cs.rpi.edu> Rensselaer Polytechnic Institute
00003  *  Written by parimi@cs.rpi.edu
00004  *  Updated by chaojv@cs.rpi.edu, alhasan@cs.rpi.edu, salems@cs.rpi.edu
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License along
00017  *  with this program; if not, write to the Free Software Foundation, Inc.,
00018  *  59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 #ifndef _COUNT_SUPPORT_H_
00021 #define _COUNT_SUPPORT_H_
00022 
00023 #include "pattern.h"
00024 #include "adj_list.h"
00025 #include "mem_storage_manager.h"
00026 #include "generic_classes.h"
00027 
00028 
00033 template<class PP, class JOIN_TYPE, class TRANS, class ST, template<class, typename, typename, template <typename> class > class CC, 
00034 template <typename> class ALLOC, class SM_TYPE >
00035 class count_support<PP, proplist<JOIN_TYPE, proplist<vert_mine, TRANS > >, ST, CC, ALLOC, SM_TYPE >
00036 {
00037   
00038 public:
00039   typedef proplist<JOIN_TYPE, proplist<vert_mine, TRANS > > MINING_PROPS;
00040   typedef ST PAT_ST_TYPE;
00041   typedef PP PATTERN_PROPS;
00042   // typedef SM_TYPE STORAGE_MANAGER_TYPE;
00043   typedef pattern<PATTERN_PROPS, MINING_PROPS, PAT_ST_TYPE, CC, ALLOC > PATTERN;
00044   typedef vat<PATTERN_PROPS, MINING_PROPS, ALLOC, std::vector > VAT;
00045   typedef pattern_support<MINING_PROPS> PAT_SUP;
00046   
00047   count_support(storage_manager<PATTERN, VAT, ALLOC, SM_TYPE > const& sm) : _strg_mgr(sm) {} 
00048   
00049   // function to count support of candidate patterns
00050   // cand_supports is populated, num is # of candidates generated
00051   void count(PATTERN* const& p1, PATTERN* const& p2, PATTERN** const& cand_pats, const int& minsup, const int& num) {
00052     
00053     // invoke storage_mgr's intersect to get VATs and support for candidates
00054     VAT** cand_vats; // pointer to VAT ptrs for candidates
00055     PAT_SUP** cand_sups=new PAT_SUP*[num];
00056     
00057     int i;
00058     for(i=0; i<num; i++)
00059       if(cand_pats[i])
00060         cand_sups[i]=new PAT_SUP;
00061       else
00062         cand_sups[i]=0;
00063     
00064     bool is_l2=(p1->size()==1);
00065     
00066     // intersect() is expected to populate the support member 
00067     // of each cand_pat
00068     cand_vats= _strg_mgr.intersect(p1, p2, cand_sups, cand_pats, is_l2);
00069     
00070     // check which candidates were frequent
00071     // and add their VATs to strg_mgr
00072     for(i=0;i<num;i++) {
00073       if(!cand_pats[i])
00074         continue;
00075       
00076       //if(cand_pats[i]->is_valid(minsup))
00077       if(cand_sups[i]->is_valid(minsup)) {
00078         cand_pats[i]->set_support(cand_sups[i]);
00079         _strg_mgr.add_vat(cand_pats[i], cand_vats[i]);
00080       }
00081       else {
00082         //reclaim memory
00083         delete cand_vats[i];
00084       }
00085       delete cand_sups[i];
00086     }//end for
00087     
00088     delete[] cand_sups;
00089     delete[] cand_vats;
00090     
00091   }//end count()
00092   
00093   void delete_vat(PATTERN* const& p) {
00094     _strg_mgr.delete_vat(p);
00095   }
00096   
00097 private:
00098   storage_manager<PATTERN, VAT, ALLOC, SM_TYPE> _strg_mgr;
00099   
00100 }; //end class count_support()
00101 
00102 #endif

Generated on Wed Jul 26 14:01:08 2006 for DMTL by  doxygen 1.4.7