مرحبا..
عندي ملف نصي يحتوي:
9 1 2 3 4 5 6 7 8 9 7 3 5 6 7 8 9 2 9 1 2 4 3 5 6 9 8 7 6 1 2 4 5 6 7 5 2 4 5 6 7 9 2 3 4 5 9 6 7 1 8 6 2 3 1 5 9 7
بحيث أن الرقم الأول من اليسار عبارة عن عدد العناصر في كل سطر
قمت بتعديل برنامج وجدته على النت لحساب عدد مرات تكرار كل عنصر:
int threshold; /* User input threshold */int numItem; /* Number of items in the database */int numRows; /* Number of rows in the database */char dataFile[100]; /* File name of the database */int *numLarge; /* numLarge[k-1] = no. of large k-itemsets found. */int *support1; /* stores # of occurrence of each itemes*/int *largeItem1; /* large items >= threshold*/typedef struct Itemsetnode *LargeItemPtr; // A list to store large items in descending order of their supports.struct Itemsetnode{ int support; int *itemset; LargeItemPtr next;};LargeItemPtr *largeItemset; /* largeItemset[k-1] = array of large k-items */void pass2(){int RowSize; int item; FILE *fp; int i, j; /* Initialize the itemes list and support list */ support1 = (int *)malloc(sizeof(int)* numItem ); largeItem1 = (int *)malloc(sizeof(int)* numItem ); if ((support1 == NULL) || (largeItem1 == NULL)) { cout << "out of memory\n"; exit(1); } for (i = 0; i < numItem; i++) { support1 = 0; // Support = support of the large stored in largeItem largeItem1 = i; // largeItem1[] -> Array to store 1-items } /* scan DB to count the frequency of each item */ if ((fp = fopen(dataFile, "r")) == NULL) // Database file { cout << "Can't open data file " << dataFile << "\n"; exit(1); } /* Scan each row of the DB */ for (i = 0; i < numRows; i++) { /* Read the row size */ fscanf(fp, "%d", &RowSize); /* Read the items in the row */ for (j = 0; j < RowSize; j++) { fscanf(fp, "%d", &item); support1[item]++; } } fclose(fp); for (i = 0; i < Rowsize; i++) { largeItemset = NULL; numLarge = 0; } /* Sort the supports of 1-itemsets in descending order */ q_sortD(&(support1[0]), largeItem1, 0, numItem - 1, numItem); numLarge[0] = 0; while ((numLarge[0] < numItem) && (support1[numLarge[0]] >= threshold)) (numLarge[0])++; cout << "\n No. of large 1-itemsets (numLarge[0]) = " << numLarge[0] << "\n"; for (i = 0; i < numItem; i++) { if (support1 >= threshold) { printf("%d [%d] ", largeItem1, support1); cout << "\n"; } } cout << "\n"; return;}وحصلت على هده النتيجة:
7 [7]
5 [7]
2 [7]
6 [6]
3 [5]
4 [5]
1 [5]
9 [5]
8 [4]
أريد الآن.. تعديل البرنامج ليقوم بحساب جميع الأزواج من النتيجة السابقة لتكون النتيجة:
7 5 [7]
7 2 [7]
5 2 [7]
6 5 [6]
6 2 [6]
6 7 [6]
7 3 [5]
5 3 [5]
2 3 [5]
9 3 [5]
4 5 [5]
4 7 [5]
4 2 [5]
4 6 [5]
5 1 [5]
2 1 [5]
7 1 [5]
9 5 [5]
9 2 [5]
9 7 [5]
8 7 [4]
8 6 [4]
8 5 [4]
8 2 [4]
8 3 [4]
8 9 [4]
1 3 [4]
6 3 [4]
4 1 [4]
9 1 [4]
6 1 [4]
9 6 [4]
8 4 [3]
8 1 [3]
4 3 [3]
4 9 [3]
قمت بالتعديل التالي:
/* Scan each row of the DB */
for (i = 0; i < numRows; i++) {
/* Read the row size */
fscanf(fp, "%d", &RowSize);
/* Read the items1 in the row*/
for (j = 0; j < transSize; j++) {
fscanf(fp, "%d", &item1);
/* Read the items2 in the row*/
for (k = j + 1; k < transSize; k++) {
fscanf(fp, "%d", &item2);
support2[item1][item2]+=1;
}
}
}
fclose(fp);ولم احصل على النتيجة المطلوبة
الرجاء المساعدة
وشكرا