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

📄 tree__vat_8h-source.html

📁 这是一个用于数据挖掘的常用算法的模板库(数据挖掘的C++模板库for UNIX)
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<a name="l00137"></a>00137         output.write(reinterpret_cast&lt;const char *&gt;(&amp;ml_sz), ITSZ);<a name="l00138"></a>00138         <span class="keywordflow">for</span> (it_store=it_inst-&gt;get_ml_begin();it_store!=it_inst-&gt;get_ml_end();++it_store){<a name="l00139"></a>00139           output.write(reinterpret_cast&lt;const char *&gt;(&amp;(*it_store)), ITSZ);<a name="l00140"></a>00140         }          <a name="l00141"></a>00141         _lb=it_inst-&gt;get_lb();  <a name="l00142"></a>00142         output.write(reinterpret_cast&lt;const char *&gt;(&amp;_lb), ITSZ);<a name="l00143"></a>00143         _ub=it_inst-&gt;get_ub();  <a name="l00144"></a>00144         output.write(reinterpret_cast&lt;const char *&gt;(&amp;_ub), ITSZ);<a name="l00145"></a>00145         _depth=it_inst-&gt;get_depth();  <a name="l00146"></a>00146         output.write(reinterpret_cast&lt;const char *&gt;(&amp;_depth), ITSZ);<a name="l00147"></a>00147         _type=(int)it_inst-&gt;induced();  <a name="l00148"></a>00148         output.write(reinterpret_cast&lt;const char *&gt;(&amp;_type), ITSZ);<a name="l00149"></a>00149       } <span class="comment">//for it_inst</span><a name="l00150"></a>00150     }<span class="comment">//it</span><a name="l00151"></a>00151      output_file.write(output.str().c_str(), output.str().size());<a name="l00152"></a>00152   }<a name="l00153"></a>00153     <a name="l00154"></a>00154   <span class="keywordtype">void</span> read_file (istream &amp; input, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <span class="keywordtype">int</span> size) {<a name="l00155"></a>00155     <span class="comment">//cout&lt;&lt;"reading from the the file"&lt;&lt;endl;</span><a name="l00156"></a>00156     <span class="keywordtype">int</span> ITSZ=<span class="keyword">sizeof</span>(int);<a name="l00157"></a>00157     <span class="keywordtype">int</span> buf_size=size/ITSZ;   <a name="l00158"></a>00158     <span class="comment">// cout&lt;&lt;buf_size;</span><a name="l00159"></a>00159     <span class="keywordtype">int</span> *buf = <span class="keyword">new</span> <span class="keywordtype">int</span>[buf_size];<a name="l00160"></a>00160     input.read((<span class="keywordtype">char</span> *)buf, (size));<a name="l00161"></a>00161     <span class="keywordtype">int</span> current=0;<a name="l00162"></a>00162     <span class="keywordflow">while</span>(current&lt;buf_size){<a name="l00163"></a>00163       <span class="keywordtype">int</span> tid=buf[current++];<a name="l00164"></a>00164       <span class="keywordtype">int</span> inst_sz=buf[current++];<a name="l00165"></a>00165       INSTANCES _new_instlist;<a name="l00166"></a>00166       <span class="keywordflow">while</span> (inst_sz--&gt;0){<a name="l00167"></a>00167         <span class="keywordtype">int</span> ml_sz=buf[current++];<a name="l00168"></a>00168         std::vector&lt;int&gt; ml;<a name="l00169"></a>00169         <span class="keywordflow">while</span>(ml_sz--&gt;0)<a name="l00170"></a>00170           ml.push_back(buf[current++]);<a name="l00171"></a>00171         _new_instlist.push_back(INSTANCE(ml, buf[current],buf[current+1],buf[current+2],buf[current+3]));<a name="l00172"></a>00172         current=current+4;<a name="l00173"></a>00173       }<a name="l00174"></a>00174       _idlist.push_back(make_pair(tid,_new_instlist));<a name="l00175"></a>00175     } <a name="l00176"></a>00176     input.clear();<a name="l00177"></a>00177     <span class="keyword">delete</span> [] buf;<a name="l00178"></a>00178   } <a name="l00179"></a>00179 <a name="l00180"></a>00180   <a name="l00184"></a>00184   <span class="keyword">template</span>&lt;<span class="keyword">class</span> PAT&gt;<a name="l00185"></a><a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#2da019bf93196eae2a21f2a84fe23216">00185</a>   <span class="keyword">static</span> <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>** intersection(<span class="keyword">const</span> <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>*<span class="keyword">const</span>&amp; v1, <span class="keyword">const</span> <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>*<span class="keyword">const</span>&amp; v2, <a class="code" href="classpattern__support.html">PAT_SUP</a>** cand_sups, PAT**, <span class="keywordtype">bool</span>) {<a name="l00186"></a>00186     <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>** cand_vats=<span class="keyword">new</span> <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>*[2]; <span class="comment">// max of 2 candidates possible</span><a name="l00187"></a>00187     <span class="keywordtype">bool</span> do_child, do_cousin;<a name="l00188"></a>00188     do_cousin=(cand_sups[0]? 1:0);<a name="l00189"></a>00189     do_child=(cand_sups[1]? 1:0);<a name="l00190"></a>00190     <a name="l00191"></a>00191     <span class="keywordflow">if</span>(!do_child &amp;&amp; !do_cousin) {<a name="l00192"></a>00192       cerr&lt;&lt;<span class="stringliteral">"tree_vat: neither child nor cousin intersection is valid"</span>&lt;&lt;endl;<a name="l00193"></a>00193       exit(0);<a name="l00194"></a>00194     }<a name="l00195"></a>00195     <a name="l00196"></a>00196     <span class="keywordflow">if</span>(do_cousin)<a name="l00197"></a>00197       cand_vats[0]=<span class="keyword">new</span> <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>;<a name="l00198"></a>00198     <a name="l00199"></a>00199     <span class="keywordflow">if</span>(do_child)<a name="l00200"></a>00200       cand_vats[1]=<span class="keyword">new</span> <a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html">VAT</a>;<a name="l00201"></a>00201     <a name="l00202"></a>00202     CONST_IT it_v1=v1-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#37f4ec5abad0ab6c3d31577c690d897f">begin</a>(), it_v2=v2-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#37f4ec5abad0ab6c3d31577c690d897f">begin</a>();<a name="l00203"></a>00203     <a name="l00204"></a>00204     <span class="keywordflow">while</span>(it_v1!=v1-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#e8540e78ff18379ee78deb129f8a5fb3">end</a>() &amp;&amp; it_v2!=v2-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#e8540e78ff18379ee78deb129f8a5fb3">end</a>()) {<a name="l00205"></a>00205       <span class="keywordflow">if</span>(it_v1-&gt;first &lt; it_v2-&gt;first) {<a name="l00206"></a>00206         it_v1++;<a name="l00207"></a>00207         <span class="keywordflow">continue</span>;<a name="l00208"></a>00208       }<a name="l00209"></a>00209       <a name="l00210"></a>00210       <span class="keywordflow">if</span>(it_v1-&gt;first &gt; it_v2-&gt;first) {<a name="l00211"></a>00211         it_v2++;<a name="l00212"></a>00212         <span class="keywordflow">continue</span>;<a name="l00213"></a>00213       }<a name="l00214"></a>00214       <a name="l00215"></a>00215       <span class="comment">// execution reaches here only if both TIDs are equal</span><a name="l00216"></a>00216       CONST_INST_IT inst_it_v1;<a name="l00217"></a>00217       CONST_INST_IT inst_it_v2;<a name="l00218"></a>00218       <a name="l00219"></a>00219       <span class="keywordflow">for</span>(inst_it_v1=it_v1-&gt;second.begin(); inst_it_v1!=it_v1-&gt;second.end(); inst_it_v1++) {<a name="l00220"></a>00220         <span class="keywordflow">for</span>(inst_it_v2=it_v2-&gt;second.begin(); inst_it_v2!=it_v2-&gt;second.end(); inst_it_v2++) {<a name="l00221"></a>00221           <span class="comment">// check if same tree's same inst are being compared</span><a name="l00222"></a>00222           <span class="keywordflow">if</span>(v1==v2 &amp;&amp; it_v1==it_v2 &amp;&amp; inst_it_v1==inst_it_v2)<a name="l00223"></a>00223             <span class="keywordflow">continue</span>;<a name="l00224"></a>00224           <a name="l00225"></a>00225           <span class="comment">// cousin test</span><a name="l00226"></a>00226           <span class="keywordflow">if</span>(do_cousin &amp;&amp; cousin_test(*inst_it_v1, *inst_it_v2)) {<a name="l00227"></a>00227             <a class="code" href="classtree__instance.html">INSTANCE</a> new_inst(*inst_it_v2, inst_it_v1-&gt;lower());<a name="l00228"></a>00228             <a name="l00229"></a>00229             <span class="comment">// append new pair if this tid did not exist in vat</span><a name="l00230"></a>00230             <span class="keywordflow">if</span>(cand_vats[0]-&gt;empty() || cand_vats[0]-&gt;back().first != it_v1-&gt;first) {<a name="l00231"></a>00231               VAT_ST&lt;INSTANCE, ALLOC&lt;INSTANCE&gt; &gt; new_st;<a name="l00232"></a>00232               new_st.push_back(new_inst);<a name="l00233"></a>00233               cand_vats[0]-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#8b2a704967f4a1a09cb096b2d68d0436">push_back</a>(make_pair(it_v1-&gt;first, new_st));<a name="l00234"></a>00234             }<a name="l00235"></a>00235             <span class="keywordflow">else</span><a name="l00236"></a>00236               cand_vats[0]-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#4168cd3e9eb772fa3978bec2eb2f3dab">back</a>().second.push_back(new_inst);<a name="l00237"></a>00237           }<span class="comment">//end if cousin_test</span><a name="l00238"></a>00238           <a name="l00239"></a>00239           <span class="comment">// child test</span><a name="l00240"></a>00240           <span class="keywordflow">if</span>(do_child &amp;&amp; inst_it_v1-&gt;child_test(*inst_it_v2)) {<a name="l00241"></a>00241             <a class="code" href="classtree__instance.html">INSTANCE</a> new_inst(*inst_it_v2, inst_it_v1-&gt;lower());<a name="l00242"></a>00242             <a name="l00243"></a>00243             <span class="comment">// append new pair if this tid did not exist in vat</span><a name="l00244"></a>00244             <span class="keywordflow">if</span>(cand_vats[1]-&gt;empty() || cand_vats[1]-&gt;back().first != it_v1-&gt;first) {<a name="l00245"></a>00245               VAT_ST&lt;INSTANCE, ALLOC&lt;INSTANCE&gt; &gt; new_st;<a name="l00246"></a>00246               new_st.push_back(new_inst);<a name="l00247"></a>00247               cand_vats[1]-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#8b2a704967f4a1a09cb096b2d68d0436">push_back</a>(make_pair(it_v1-&gt;first, new_st));<a name="l00248"></a>00248             }<a name="l00249"></a>00249             <span class="keywordflow">else</span><a name="l00250"></a>00250               cand_vats[1]-&gt;<a class="code" href="classvat_3_01TREE__PROP_00_01V__Fkk__EMB__MINE__PROP_00_01ALLOC_00_01VAT__ST_01_4.html#4168cd3e9eb772fa3978bec2eb2f3dab">back</a>().second.push_back(new_inst);<a name="l00251"></a>00251             <a name="l00252"></a>00252           }<span class="comment">//end if child_test</span><a name="l00253"></a>00253           <a name="l00254"></a>00254         }<span class="comment">//end for inst_it_v2</span><a name="l00255"></a>00255         <a name="l00256"></a>00256       } <span class="comment">//end for inst_it_v1  </span><a name="l00257"></a>00257       <a name="l00258"></a>00258       <span class="comment">// advance to next tid</span><a name="l00259"></a>00259       it_v1++;<a name="l00260"></a>00260       it_v2++;<a name="l00261"></a>00261       <a name="l00262"></a>00262     } <span class="comment">//end while </span><a name="l00263"></a>00263     <a name="l00264"></a>00264     <span class="comment">// copy the support into cand_sups</span><a name="l00265"></a>00265     <span class="keywordflow">if</span>(do_cousin)<a name="l00266"></a>00266       cand_sups[0]-&gt;<a class="code" href="classpattern__support.html#ceb8296801b8f94ae5ec5e00f0867b9d">set_sup</a>(make_pair(cand_vats[0]-&gt;size(), 0));<a name="l00267"></a>00267     <a name="l00268"></a>00268     <span class="keywordflow">if</span>(do_child)<a name="l00269"></a>00269       cand_sups[1]-&gt;<a class="code" href="classpattern__support.html#ceb8296801b8f94ae5ec5e00f0867b9d">set_sup</a>(make_pair(cand_vats[1]-&gt;size(), 0));<a name="l00270"></a>00270     <a name="l00271"></a>00271     <span class="keywordflow">return</span> cand_vats;<a name="l00272"></a>00272     <a name="l00273"></a>00273   }<span class="comment">//end intersect()</span><a name="l00274"></a>00274   <a name="l00275"></a>00275   <span class="keyword">friend</span> ostream&amp; operator&lt;&lt; &lt;&gt;(ostream&amp;, <span class="keyword">const</span> VAT*);<a name="l00276"></a>00276   <a name="l00277"></a>00277  <span class="keyword">private</span>:<a name="l00278"></a>00278   IDLIST_T _idlist;<a name="l00279"></a>00279   <a name="l00281"></a>00281   pair&lt;int, VAT_ST&lt;INSTANCE, ALLOC&lt;INSTANCE&gt; &gt; &gt;&amp; back() {<a name="l00282"></a>00282     <span class="keywordflow">if</span>(empty()) {

⌨️ 快捷键说明

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