00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _PATTERN_H
00021 #define _PATTERN_H
00022
00023
00024
00025
00026 #include <vector>
00027 #include <sstream>
00028 #include "properties.h"
00029
00030 using namespace std;
00031
00032
00033 template<class PP, class MP, class ST, template<class, typename, typename, template <typename> class > class CC,
00034 template <typename> class ALLOC, class SM_TYPE>
00035 class count_support;
00036
00037 template<class PP, class MP, class ST, template<class, typename, typename, template <typename> class > class CC, template <typename> class ALLOC >
00038 class pattern;
00039
00040 template<class PP, class MP, class ST, template<class, typename, typename, template <typename> class > class CC, template <typename> class ALLOC >
00041 void update_rmost_path(pattern<PP, MP, ST, CC, ALLOC>*const&);
00042
00043 template<class PP, class MP, class ST, template<class, typename, typename, template <typename> class > class CC, template <typename> class ALLOC >
00044 ostream& operator<<(ostream&, const pattern<PP, MP, ST, CC, ALLOC>*);
00045
00046 template<class PP, class MP, class ST, template<class, typename, typename, template <typename> class > class CC, template <typename> class ALLOC >
00047 bool check_isomorphism(pattern<PP, MP, ST, CC, ALLOC>* const&);
00048
00049 #include "adj_list.h"
00050 #include "pat_support.h"
00051
00052
00060 template<class PATTERN_PROPS, class MINING_PROPS, class ST, template<class, typename, typename, template <typename> class> class CC,
00061 template <typename> class ALLOC=std::allocator >
00062 class pattern
00063 {
00064
00065 public:
00066 typedef typename ST::VERTEX_T VERTEX_T;
00067 typedef PATTERN_PROPS PAT_PROPS;
00068 typedef MINING_PROPS MINE_PROPS;
00069 typedef typename ST::EDGE_T EDGE_T;
00070 typedef pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC > PATTERN;
00071 typedef typename ST::IT IT;
00072 typedef typename ST::CONST_IT CONST_IT;
00073 typedef typename ST::EIT EIT;
00074 typedef typename ST::CONST_EIT CONST_EIT;
00075 typedef typename ST::EIT_PAIR EIT_PAIR;
00076 typedef typename ST::CONST_EIT_PAIR CONST_EIT_PAIR;
00077 typedef CC<PATTERN_PROPS, VERTEX_T, EDGE_T, ALLOC > CAN_CODE;
00078 typedef std::vector<int, ALLOC<int> > RMP_T;
00079 typedef typename CAN_CODE::STORAGE_TYPE CC_STORAGE_TYPE;
00080 typedef typename CAN_CODE::INIT_TYPE CC_INIT_TYPE;
00081 typedef typename CAN_CODE::COMPARISON_FUNC CC_COMPARISON_FUNC;
00082
00083
00084 void* operator new(size_t size) {
00085 ALLOC<PATTERN> pa;
00086 return pa.allocate(size);
00087 }
00088
00089 void operator delete(void *p, size_t size) {
00090 if (p) {
00091 ALLOC<PATTERN> pa;
00092 pa.deallocate(static_cast<PATTERN*> (p), size);
00093 }
00094 }
00095
00096 pattern(): _rmost_vid(-1), _is_canonical(false) {}
00097
00098 IT begin() {return _graph.begin();}
00099 CONST_IT begin() const {return _graph.begin();}
00100 IT end() {return _graph.end();}
00101 CONST_IT end() const {return _graph.end();}
00102
00103 int size() const {
00104 return _graph.size();
00105 }
00106
00107 int rmp_size() const { return _rmost_path.size();}
00108
00110 pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC>* clone() const {
00111
00112 pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC>* clone=new pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC>();
00113
00114 CONST_IT it;
00115 for(it=this->begin(); it!=this->end(); it++)
00116 clone->_graph.push_back(*it);
00117
00118 clone->_rmost_vid=_rmost_vid;
00119 clone->_rmost_path=_rmost_path;
00120
00121 clone->_canonical_code = _canonical_code;
00122 clone->_canonical_code.update_code();
00123
00124 return clone;
00125 }
00126
00127 int rmost_vid() const {return _rmost_vid;};
00128 void set_rmost_vid(const int& rvid) {_rmost_vid=rvid;}
00129
00130 bool is_canonical() const {return _is_canonical;}
00131
00132 const VERTEX_T& rmost_vertex() const {
00133 int rvid=rmost_vid();
00134 CONST_IT it=_graph.vertex_vals(rvid);
00135 return it->v;
00136 }
00137
00139 const VERTEX_T& label(const int& vid) const {
00140 CONST_IT it=_graph.vertex_vals(vid);
00141 return it->v;
00142 }
00143
00145 int add_vertex(const VERTEX_T& v) {
00146 set_rmost_vid(_graph.add_vertex(v));
00147
00148 return rmost_vid();
00149 }
00150
00151
00154 void add_out_edge(const int& src, const int& dest, const EDGE_T& e) {
00155 _graph.add_out_edge(src, dest, e);
00156 }
00157
00161 void add_in_edge(const int& dest, const int& src, const EDGE_T& e) {
00162 _graph.add_in_edge(dest, src, e);
00163 }
00164
00167 EIT_PAIR out_edges(const int& idval) {
00168 return _graph.out_edges(idval);
00169
00170 }
00171
00172 CONST_EIT_PAIR out_edges(const int& idval) const {
00173
00174 return _graph.out_edges(idval);
00175 }
00176
00177
00180 EIT_PAIR in_edges(const int& idval) {
00181 return _graph.in_edges(idval);
00182 }
00183
00184 CONST_EIT_PAIR in_edges(const int& idval) const {
00185 return _graph.in_edges(idval);
00186 }
00187
00188 bool get_out_edge(const int& src, const int& dest, EDGE_T& e) const {
00189 return _graph.get_out_edge(src, dest, e);
00190 }
00191
00192 bool get_in_edge(const int& src, const int& dest, const EDGE_T& e) const {
00193 return _graph.get_in_edge(src, dest, e);
00194 }
00195
00196
00197 CC_STORAGE_TYPE
00198 pat_id() const { return _canonical_code.getCode(); }
00199
00200 bool operator< (const pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC> rhs) const;
00201
00202 friend ostream& operator<< <>(ostream&, const pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC>*);
00203
00204 friend bool check_isomorphism <>(PATTERN* const& pat);
00205
00206
00207 friend void update_rmost_path <>(pattern<PATTERN_PROPS, MINING_PROPS, ST, CC, ALLOC>*const&);
00208
00209 void set_support(const pattern_support<MINING_PROPS>* const& pat_sup) {
00210 _pat_sup.set_vals(pat_sup);
00211 }
00212
00217 void set_sup(const pair<int, int>& s) {
00218 _pat_sup.set_sup(s);
00219 _is_canonical=true;
00220 }
00221
00222 bool is_freq(int min_sup) {
00223 return _pat_sup.is_freq(min_sup);
00224 }
00225
00226 bool is_valid(const int& ms) const {
00227 return (_pat_sup.is_valid(ms));
00228 }
00229
00233 void init_canonical_code(const CC_INIT_TYPE& cc) {
00234 _canonical_code.init(cc, this);
00235 }
00236
00237 const RMP_T& rmost_path() const { return _rmost_path;}
00238
00239 void update_rmpath(int val) {
00240 _rmost_path.push_back(val);
00241 }
00242
00243 const CAN_CODE& canonical_code() const { return _canonical_code;}
00244 pattern_support<MINING_PROPS> _pat_sup;
00245
00246 private:
00247
00248 ST _graph;
00249 CAN_CODE _canonical_code;
00250 int _rmost_vid;
00251 bool _is_canonical;
00252 RMP_T _rmost_path;
00253
00254 };
00255
00256 #endif