Êý¾ÝÍÚ¾òʵÑéÈýÓ¦Óà Apriori Ëã·¨ÍÚ¾òƵ·±Ï ÏÂÔر¾ÎÄ

while(!infile.eof()) {

infile >> sal[sal_size].serial >> sal[sal_size].market >> sal[sal_size].date>> sal[sal_size].sn>> sal[sal_size].id>> sal[sal_size].num>> sal[sal_size].price;

sal_size++; }

///////////////ȡͳһÁ÷Ë®µÄÉÌÆ·IDÇ°Èýλ°´ÉýÐòÎÞÖظ´µÄ±£´æÆðÀ´/////////////////////////

new1[0][0]=sal[0].id/10000; for (int i =1;i

new1[m][n]=sal[i].id/10000; //////Á÷Ë®ºÅÏàͬ n++; //outfile<

if(new1[m][j] > new1[m][j+1]) {

int t = new1[m][j];

new1[m][j] = new1[m][j+1]; new1[m][j+1] = t; } } } for(int l= 0;l< n;l++) { if(new1[m][l-1]!=new1[m][l]) outfile<

} }

infile.close();//¹Ø±ÕÎļþ outfile.close();//¹Ø±ÕÎļþ system( \}

2¡¢//AprioriËã·¨ÍÚ¾òƵ·±Ïsupport = 2£¨¼Ó×¢ÊÍ£©

#include #include #include #include #include #include #include #include #include using namespace std;

const int minsup=2; //ÉèÖÃ×îС֧³Ö¶È

map items_count; //ͳ¼Æ¸÷¸öÏµÄÊýÄ¿

vector mergeItem(vector vect1,vector vect2,int round); //ºÏ²¢Éú³ÉеĺòÑ¡Ï

int isExist(vector item,vector >items); //ÅжÏÏitemÊÇ·ñÒѾ­´æÔÚºòÑ¡Ï¼¯ºÏitemsÖÐ,´æÔÚÔò·µ»Ø

vector mergeItem(vector vect1,vector vect2,int round) //ÅжÏÁ½¸öÏÊÇ·ñ¿ÉÒԺϲ¢(ÒªÇóÖ»ÓÐÒ»Ïͬ)³ÉÒ»¸öеÄÏ£¨×öΪºòÑ¡¼¯£©

{

////////////////////////////////////////////¼ôÖ¦¹¤×÷//// int count=0; //ͳ¼ÆÁ½¸övectorÖÐÏàͬµÄÏîµÄÊýÄ¿ vector vect;

map tempMap; //¸¨ÖúÅжÏÁ½¸övectorÖÐÖظ´µÄÏî for(vector::size_type st=0;st

tempMap[vect1[st]]++; vect.push_back(vect1[st]); }

for(int st=0;st

tempMap[vect2[st]]++;

if(tempMap[vect2[st]]==2) //±íʾÕâÁ½ÏîÏàͬ {

count++; } else {

vect.push_back(vect2[st]); } }

if((count+1)!=round) //ÒªÇóÁ½¸öÏîÄ¿¼¯Ö»ÓÐÒ»¸öÏîÄ¿²»Ïàͬ£¬ÆäËû¶¼Ïàͬ { vect.clear(); }

return vect; }

int isExist(vector item,vector >items) //ÅжÏÏitemÊÇ·ñÒѾ­´æÔÚºòÑ¡Ï¼¯ºÏitemsÖÐ,´æÔÚÔò·µ»Ø

{

int count; //ͳ¼ÆÏàͬµÄÏîµÄÊýÄ¿ if(!items.empty()) {

for(vector >::size_type ix=0;ix!=items.size();ix++) {

count=0;

for(vector::size_type iy=0;iy!=items[ix].size();iy++) {

for(vector::size_type iz=0;iz!=item.size();iz++) {

if(item[iz]==items[ix].at(iy)) {

count++; } } }

if(count==item.size()) //±íʾ´æÔÚ {

return 1; } } }

return 0; }

int main() {

vector > datavec; //ԭʼÊý¾ÝÏ vector > candidatevec; //ºòÑ¡Ï vector > frequentvec; //Ƶ·±Ï

vector > bitmap; //ÅжÏij¸öÏîÄ¿ÔÚijһ¸öÊÂÎñÖÐÊÇ·ñ´æÔÚ£¬´æÔÚÔòֵΪ1£¬·´Ö®Îª0

long trancount=0; //ԭʼÊÂÎñ×ÜÊý char name1[50];

ifstream file;

cout<<\Ñ¡ÔñÒª´ò¿ªµÄÎļþ£ºnew1.txt new2.txt new3.txt\ cin>>name1;

file.open(name1,ios::in); //´ò¿ªÊý¾ÝÎļþ if(!file) //¼ì²éÎļþÊÇ·ñ´ò¿ª³É¹¦ {

cout<<\ return 1; } else {

string temp;

vector item; //ÏµÄÁÙʱvector int begin,end;

while(getline(file,temp)) //Ò»ÐÐÒ»ÐжÁÈëÊý¾Ý {

trancount++; begin=0; temp.erase(0,temp.find_first_not_of(\È¥³ý×Ö·û´®Êײ¿µÄ¿Õ¸ñ temp.erase(temp.find_last_not_of(\

while((end=temp.find('\\t',begin))!=string::npos) //ÿһ¸öÊÂÎñÖеÄÏîÊÇÒÔ'\\t'Ϊ·Ö¸ô·ûµÄ

{

item.push_back(temp.substr(begin,end-begin)); //½«Ã¿Ò»¸öÏî²åÈëitemÖÐ begin=end+1; }

item.push_back(temp.substr(begin)); //Ò»¸öÊÂÎñÖеÄ×îºóÒ»Ïî

datavec.push_back(item); //½«Ò»¸öÊÂÎñÖеÄËùÓÐÏîµ±³ÉÒ»¸öÕûÌå²åÈëÁíÒ»¸ö´óµÄvectorÖÐ

item.clear(); //Çå¿Õitem }

cout<<\ getchar();

map item_map;

for(vector >::size_type ix=0;ix!=datavec.size();++ix) {

for(vector::size_type iy=0;iy!=datavec[ix].size();++iy) {

items_count[datavec[ix].at(iy)]++; //¸ÃÏµÄ¼ÆÊý¼Ó

item_map[datavec[ix].at(iy)]=1; //±íʾ¸ÃÏîÄ¿ÔÚ¸ÃÊÂÎñÖдæÔÚ£¬ÖµÎª1£¬·ñÔòĬÈÏΪ0

}

bitmap.push_back(item_map);

item_map.clear(); //ÕâÀïÒ»¶¨ÒªÇå¿ÕÒ»ÏÂ