void SocketIMEngineGlobal::init () { SCIM_DEBUG_IMENGINE(1) << "Init SocketIMEngine Global.\n"; String address = scim_get_default_socket_imengine_address (); m_socket_timeout = scim_get_default_socket_timeout (); m_socket_address.set_address (address); if (!m_socket_address.valid ()) return; // Connect to SocketFrontEnd. if (!create_connection ()) { SCIM_DEBUG_IMENGINE(2) << " Cannot connect to SocketFrontEnd (" << address << ").\n"; return; } SCIM_DEBUG_IMENGINE(2) << " Connected to SocketFrontEnd (" << address << ") MagicKey (" << m_socket_magic_key << ").\n"; // Init the connection, and get IMEngineFactory list. Transaction trans; // Get IMEngineFactory list. init_transaction (trans); trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_LIST); trans.put_data (String ("")); if (!send_transaction (trans)) return; int cmd; if (trans.read_from_socket (m_socket_client, m_socket_timeout) && trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY && trans.get_data (m_peer_factories) && trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) { SCIM_DEBUG_IMENGINE(2) << " Found " << m_peer_factories.size () << " IMEngine Factories.\n"; } }
int main(int argc, char *argv[]){ struct timeval start_time, end_time; /* structs for timer */ struct timezone zone; long int sec = 0, usec = 0; /* sec & microsec for the timer */ long int time_total_sec = 0; double time_total_msec = 0; long int time_total_usec = 0; int numTrans, pid, numItems, item, count, i , j; FILE *f_input, *f_utility, *f_output; int sizeDB; double minshare; int MV = 0; int ML = 0; int tempML = 0; if(argc != 7){ fprintf(stderr, "Usage: %s transactionDB utilityTable outputFile min_util MAXITEMS MAXCANDIDATES\n", argv[0]); exit(0); } f_input = fopen(argv[1], "r"); f_utility = fopen(argv[2], "r"); f_output = fopen(argv[3], "w"); minshare = atof(argv[4]); MAXITEMS = atoi(argv[5]); MAXITEMSETS = atoi(argv[6]); if((f_input == NULL) || (f_utility == NULL) || (f_output == NULL)){ fprintf( stdout, "ERROR[%s]: Can't open %s or %s or %s\n", argv[0], argv[1], argv[2], argv[3] ); fprintf( stderr, "ERROR[%s]: Can't open %s or %s or %s\n", argv[0], argv[1], argv[2], argv[3] ); fprintf( stderr, "ERROR[%s]: Can't open %s or %s or %s\n", argv[0], argv[1], argv[2], argv[3] ); exit( 0 ); } TreeNode *rootCk; rootCk = create_new_node(ROOT); TreeNode *rootRc; rootRc = create_new_node(ROOT); TreeNode *rootF; //the tree for frequent itemsets rootF = create_new_node(ROOT); TreeNode *setRc[MAXITEMSETS + 1]; TreeNode *setCk[MAXITEMSETS + 1]; TreeNode *setF[MAXITEMSETS + 1]; int sizeRc = 0; int sizeCk = 0; int sizeF = 0; double utility[MAXITEMS + 1]; double TutilItem[MAXITEMS + 1]; int items[MAXITEMS + 1]; double lmv[MAXITEMS + 1]; double TutilDB = 0; float cost; for(i = 1; i <= MAXITEMS; i ++){ utility[i] = 0; TutilItem[i] = 0; items[i] = 0; lmv[i] = 0; } printf("===== %s %s %s %f =====\n\n", argv[0], argv[1], argv[2], minshare); //record the time for the first db scan if(gettimeofday(&start_time, &zone) == -1){ fprintf(stderr, "gettimeofday error\n"); } fscanf(f_utility, "%d ", &numItems); for(i = 1; i <= numItems; i ++){ fscanf(f_utility, "%d %f ", &item, &cost); utility[item] = cost; } fscanf(f_input, "%d ", &numTrans); double transUtil = 0; //read the whole db once to get candidate 1-itemsets for(i = 1; i <= numTrans; i ++){ fscanf(f_input, "%d ", &pid); fscanf(f_input, "%d ", &numItems); //printf("\n%d %d ", pid, numItems); for(j = 1; j <= numItems; j ++){ fscanf(f_input, "%d %d ", &item, &count); //printf("item %d count %d ", item, count); transUtil += count * utility[item]; items[item] = 1; if(count > MV){ MV = count; } tempML ++; //printf("\nitem: %d count: %d", item, count); lmv[item] += count; } for(j = 1; j <= MAXITEMS; j ++){ if(items[j] == 1){ TutilItem[j] += transUtil; items[j] = 0; } } if(tempML > ML){ ML = tempML; } TutilDB += transUtil; transUtil = 0; tempML = 0; } sizeDB = numTrans; if(gettimeofday(&end_time, &zone) == 0){ if(end_time.tv_usec >= start_time.tv_usec){ sec = end_time.tv_sec - start_time.tv_sec; usec = end_time.tv_usec - start_time.tv_usec; }else{ sec = end_time.tv_sec - start_time.tv_sec - 1; usec = end_time.tv_usec - start_time.tv_usec + 1000000; } time_total_sec += sec; time_total_usec += usec; fprintf(stdout, "\n[FUM] Total runtime for first db scan is %ld sec. %.3f msec\n", sec, usec/1000.0); f_output = fopen( argv[3], "a" ); fprintf(f_output, "\n[FUM] Total runtime for first db scan is %ld sec. %.3f msec\n", sec, usec/1000.0); fclose( f_output ); } if(DEBUG){ for(i = 1; i <= MAXITEMS; i ++){ printf("\nutil item (%d): %f", i, utility[i]); } printf("\n"); for(i = 1; i <= MAXITEMS; i ++){ printf("\nitem (%d) has Tutil: %f", i, TutilItem[i]); } printf("\n\nTutilDB: %f Min_Lutil: %f\n", TutilDB, MIN_LUTIL(TutilDB, minshare)); printf("\nMV: %d ML: %d", MV, ML); } int isolated_itemsets[MAXITEMS + 1]; int size = 0; //get candidate 1-itemsets for(i = 1; i <= MAXITEMS; i ++){ if(utility[i] > 0){ if(TutilItem[i] >= MIN_LUTIL(TutilDB, minshare)){ Itemset I; init_itemset(&I); I.itemset[i] = 1; double lutil = (lmv[i] * utility[i]); insert(I.itemset, rootRc, 1, &sizeRc, i, setRc, lutil); free_itemset(&I); } else{ isolated_itemsets[size] = i; size ++; } } } //int k_prime = 1; //needed for other version of critical function int c; for(c = 0; c < sizeRc; c ++){ TreeNode *X = setRc[c]; if(X->lutil >= MIN_LUTIL(TutilDB, minshare)){ Itemset I; to_itemset(&I, X); insert(I.itemset, rootF, 1, &sizeF, 1, setF, X->lutil); free_itemset(&I); } //printf("\nCF: %f", CF(X->lutil, 1, MV, ML, k_prime)); //if(CF(X->lutil, 1, MV, ML, k_prime) < MIN_LUTIL(TutilDB, minshare)){ if(TutilItem[X->item] < MIN_LUTIL(TutilDB, minshare)){ remove_itemset(X, setRc, c); } } adjust_set(setRc, &sizeRc); if(PRT_CNT){ printf("\n\nIteration (%d)", 0); printf("\n|Ck| = %d", sizeCk); printf("\n|Rc| = %d", sizeRc); printf("\n|Fk| = %d", sizeF); } int k; int counterF = 0; boolean stop = false; int num_false_positives[MAXITEMSETS + 1]; int sizeFP = 0; //record the time for mining if(gettimeofday(&start_time, &zone) == -1){ fprintf(stderr, "gettimeofday error\n"); } for(k = 1; sizeRc > 0 && stop == false; k ++){ //apriori join + apriori prune generate(rootRc, setRc, sizeRc, setCk, &sizeCk, rootCk, k); if(PRT_MEM){ printf("\n\nIteration (%d)", k); int mem_counterCk = 0; count_nodes(rootCk, &mem_counterCk); printf("\nNode Count = [%d]", mem_counterCk); printf("\nNode Size = [%ld bytes]", sizeof(TreeNode)); printf("\nMemory space required for candidate tree = %ld bytes", mem_counterCk * sizeof(TreeNode)); } if(sizeCk > 0){ double TransUtil; rewind(f_input); fscanf(f_input, "%d ", &numTrans); for(i = 1; i <= numTrans; i ++){ fscanf(f_input, "%d ", &pid); fscanf(f_input, "%d ", &numItems); Transaction T; init_transaction(&T); for(j = 1; j <= numItems; j ++){ fscanf(f_input, "%d %d ", &item, &count); if(is_isolated_item(item, isolated_itemsets, size) == false){ T.itemset[item] += count; T.total_count += (count * utility[item]); } } TransUtil = T.total_count; for(j = 0; j < sizeCk; j ++){ TreeNode *X = setCk[j]; boolean in_transaction = true; double Lutil = 0; while(is_root(X) == false && in_transaction == true){ //first check if itemset in transaction if(T.itemset[X->item] == 0){ in_transaction = false; } Lutil += (T.itemset[X->item] * utility[X->item]); X = X->parent; } if(in_transaction){ TreeNode *last_node = setCk[j]; last_node->lutil += Lutil; last_node->CF += TransUtil; } } free_transaction(&T); } if(PRT_CNT){ printf("\n\nIteration (%d)", k); printf("\n|Ck| = %d", sizeCk); } if(PRT_FALSE_POS){ num_false_positives[k] = sizeCk; sizeFP ++; } for(c = 0; c < sizeCk; c ++){ TreeNode *X = setCk[c]; //print_itemset(X); //printf(" lutil: %f minlutil: %f\n", X->lutil, MIN_LUTIL(TutilDB, minshare)); if(X->lutil >= MIN_LUTIL(TutilDB, minshare)){ counterF ++; Itemset I; to_itemset(&I, X); insert(I.itemset, rootF, 1, &sizeF, 1, setF, X->lutil); free_itemset(&I); } if(X->CF < MIN_LUTIL(TutilDB, minshare)){ //if(CF(X->lutil, 1, MV, ML, k_prime) < MIN_LUTIL(TutilDB, minshare)){ remove_itemset(X, setCk, c); } } adjust_set(setCk, &sizeCk); copy_tree(rootCk, setCk, &sizeCk, rootRc, setRc, &sizeRc); if(PRT_CNT){ printf("\n|Rc| = %d", sizeRc); printf("\n|Fk| = %d", counterF); } if(PRT_FALSE_POS){ num_false_positives[k] -= counterF; printf("\nFalse Positives Iteration (%d): %d", k, num_false_positives[k]); } } else{ stop = true; } counterF = 0; } if(gettimeofday(&end_time, &zone) == 0){ if(end_time.tv_usec >= start_time.tv_usec){ sec = end_time.tv_sec - start_time.tv_sec; usec = end_time.tv_usec - start_time.tv_usec; }else{ sec = end_time.tv_sec - start_time.tv_sec - 1; usec = end_time.tv_usec - start_time.tv_usec + 1000000; } time_total_sec += sec; time_total_usec += usec; fprintf(stdout, "\n[FUM] Total runtime for mining is %ld sec. %.3f msec\n", sec, usec/1000.0); f_output = fopen( argv[3], "a" ); fprintf(f_output, "\n[FUM] Total runtime for mining is %ld sec. %.3f msec\n", sec, usec/1000.0); fclose( f_output ); } f_output = fopen(argv[3], "a"); if(PRT_FALSE_POS){ int total_FP = 0; for(k = 1; k <= sizeFP; k ++){ total_FP += num_false_positives[k]; } printf("\nTotal False Positives: %d", total_FP); } if(PRT_FP){ printf("\n\nFound (%d) ShFrequent Itemsets:", sizeF); fprintf(f_output, "\n\nFound (%d) ShFrequent Itemsets:", sizeF); print_frequent_itemset(setF, sizeF, f_output); } if(PRT_MEM){ int mem_counterF = 0; count_nodes(rootF, &mem_counterF); printf("\n\nNode Count = [%d]", mem_counterF); printf("\nNode Size = [%ld bytes]", sizeof(TreeNode)); printf("\nMemory space required for frequent itemset tree = %ld bytes", mem_counterF * sizeof(TreeNode)); } time_total_msec = time_total_usec / 1000.0; if(time_total_msec >= 1000){ time_total_sec += floor(time_total_msec/1000); time_total_msec = time_total_usec % 1000; } //printf("\ntime sec: %ld time msec: %.3lf time usec: %ld", time_total_sec, time_total_msec, time_total_usec); fprintf(stdout, "\n\n[FUM] Total (aggregate) runtime is %ld sec. %.3lf msec\n", time_total_sec, time_total_msec); fprintf(f_output, "\n\n[FUM] Total (aggregate) runtime is %ld sec. %.3lf msec\n", time_total_sec, time_total_msec); free_tree(setRc, &sizeRc); free_tree(setCk, &sizeCk); free_tree(setF, &sizeF); fclose(f_input); fclose(f_output); fclose(f_utility); printf("\n\nProcessing Complete\n"); return 0; }
String SocketIMEngineGlobal::load_icon (const String &icon) { String local_icon = icon; IconRepository::const_iterator it = m_icon_repository.find (icon); // The icon has been loaded, just return the local copy filename. if (it != m_icon_repository.end ()) local_icon = it->second; // This icon is already available in local system, just return. if (scim_load_file (local_icon, 0) != 0) return local_icon; Transaction trans; int cmd; char *bufptr = 0; size_t filesize = 0; local_icon = String (""); init_transaction (trans); trans.put_command (SCIM_TRANS_CMD_LOAD_FILE); trans.put_data (icon); // Load icon file from remote SocketFrontEnd. if (send_transaction (trans) && receive_transaction (trans) && trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY && trans.get_data (&bufptr, filesize) && trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) { String tempfile; String::size_type pos = icon.rfind (SCIM_PATH_DELIM); if (pos != String::npos) { tempfile = icon.substr (pos + 1, String::npos); } else { tempfile = icon; } char tmp [80]; snprintf (tmp, 80, "%lu", (unsigned long) m_socket_magic_key); tempfile = String (SCIM_TEMPDIR) + String (SCIM_PATH_DELIM_STRING) + String ("scim-") + String (tmp) + String ("-") + tempfile; SCIM_DEBUG_IMENGINE(1) << "Creating temporary icon file: " << tempfile << "\n"; std::ofstream os (tempfile.c_str ()); if (os) { os.write (bufptr, filesize); os.close (); // Check if the file is written correctly. if (scim_load_file (tempfile, 0) == filesize) { m_icon_repository [icon] = tempfile; local_icon = tempfile; } else { unlink (tempfile.c_str ()); } } } delete [] bufptr; return local_icon; }