/* * Main(): Executes FP Growth algorithm. */ int main(int argc, char **argv) { num_freq_sets = size = colcnt = num_oflines = num_updates = 0; /** Create instance of class FPTree */ fptreePtr fptree; /** Read data to be mined from file */ printf("\nReading Input Data.."); input_dataset(); /** Reorder and prune input data according to frequency of single attr */ printf("\nOrdering Input Data.."); order_input_data(); printf("\nRecasting input Data pruning infrequent items"); recast_data_prune_unsupported(); printf("\nPrinting frequent-1 itemsets"); gen_freq_one_itemsets();/** Prints freq-1 itemsets */ /** Build initial FP-tree */ printf("\nBuilding FP tree"); create_fptree(fptree); /* skip invalid elements(-1) */ printf("\nPrinting FP tree."); out_fptree(fptree); /* need to print the tree */ /** Mine FP-tree */ printf("\nMining FP tree"); start_mining(fptree);/** frequent sets are generated and stored to file here. */ printf("\nReleasing memory consumption of tree."); out_fptree_storage(fptree->root); release_memory(fptree); /** Frees all used memory */ return 0; }
int main(int argc, char * argv[]) { float mTime; clock_t start, end; start = clock(); char *file_name = "1000k"; char *type = "rate"; char *rate = "3"; set_define(file_name, type, rate); int *mItem = malloc(sizeof(int) * TRANSCATION_COUNT * SIZE_OF_ARRAY), *item_counter = malloc(sizeof(int) * (ITEM_COUNT + 1)), *item_index = malloc(sizeof(int) * (ITEM_COUNT + 1)); struct header_table *htable = malloc(sizeof(struct header_table)); struct header_table *head = malloc(sizeof(struct header_table)); get_dataset(mItem, item_counter, item_index); struct node *fptree = malloc(sizeof(struct node)); fptree = create_fptree(); create_header_table(htable, head, item_index); build_fptree(fptree, mItem, item_index, htable, head); while(htable->next != NULL) htable = htable->next; conditional_parrern_base(fptree, htable, item_counter, item_index, ""); end = clock(); mTime = (end-start) / (double) (CLOCKS_PER_SEC); mTime = mTime * 1000; printf("\nneed:%2.f millisecond \n", mTime); return 0; }
void conditional_parrern_base(struct node *fptree, struct header_table *htable, int *item_counter,int *item_index, char *generate_string) { struct frequent_patterns *fp = malloc(sizeof(struct frequent_patterns)); struct frequent_patterns *fp_head = malloc(sizeof(struct frequent_patterns)); struct node *now_node = malloc(sizeof(struct node)); int ptr_index; fp_head = fp; if(generate_string != "") //printf("%s \n", generate_string); while(htable != NULL) { fp = fp_head; fp->next = NULL; fp->index = 0; listStart(htable->cond); while(listNext(htable->cond)) { now_node = listGet(htable->cond); if(fp->index == 0) { fp->ptr = malloc(sizeof(short) * MIN_SUPPORT_INDEX); } else { struct frequent_patterns *new_fp = malloc(sizeof(struct frequent_patterns)); new_fp->ptr = malloc(sizeof(short) * MIN_SUPPORT_INDEX); fp->next = new_fp; fp = new_fp; } fp->counter = now_node->counter; fp->htable_value = htable->no; ptr_index = 0; now_node = now_node->parent; while(now_node != NULL) { if( now_node->no == -1) break; *(fp->ptr + ptr_index) = now_node->no; ptr_index++; now_node = now_node->parent; } fp->index = ptr_index; } struct header_table *sub_htable = malloc(sizeof(struct header_table)); struct node *sub_tree = malloc(sizeof(struct node)); sub_tree = create_fptree(); sub_tree = build_sub_tree(sub_tree, sub_htable, fp_head, item_counter, item_index); //dfs(sub_tree); if(sub_tree->child != NULL) { int len = strlen(generate_string) + 4; char *str_ans = malloc(sizeof(char) * len); myString_cat(str_ans, generate_string, htable->no); while(sub_htable->next != NULL) sub_htable = sub_htable->next; conditional_parrern_base(sub_tree, sub_htable, item_counter, item_index, str_ans); dfs(sub_tree); }else if(htable->prev == NULL || listCount(htable->cond) > 0){ int len = strlen(generate_string) + 4; char *str_ans = malloc(sizeof(char) * len); myString_cat(str_ans, generate_string, htable->no); //printf("%s\n", str_ans); } htable = htable->prev; } while(htable != NULL) { header_head = htable; htable = htable->next; free(header_head); } }