int readGraph(){ int startVertex = 0 ; int n = 0 ; scanf("%d",&startVertex); scanf("%d",&n); int ** matrix = readIn(n); printMatrix(matrix,n); struct queue* q = (struct queue*)malloc(sizeof(struct queue)); init(q); struct stack stk; initialize(&stk); int * visited = (int *) malloc(sizeof(int)*n); int i = 0 ; for ( i = 0 ; i < n ; i++ ) visited[i] = 0 ; printf("\nBreadth First: "); breadthFirst(matrix,startVertex,n,q); printf("\nDepth First: "); depthFirst(matrix,startVertex,n,stk); printf("\nDepth First: "); depthCaller(matrix,n); printf("\n"); free(q); free(visited); free(matrix); return 0 ; }
/* bool operator<(const food & lhs, const food & rhs) { return std::get<0>(lhs) < std::get<0>(rhs) || (std::get<0>(lhs) == std::get<0>(rhs) && (std::get<1>(lhs) < std::get<1>(rhs) || (std::get<1>(lhs) == std::get<1>(rhs) && std::get<2>(lhs) < std::get<2>(rhs)))); } */ bool depthFirst(const food & totalFood, const food & accum, const std::vector<food> & foods) { if (accum >= totalFood) { // if (accum == totalFood) { // std::cout << foods; // } return accum == totalFood; } for (std::size_t i = 0; i < foods.size(); ++i) { auto newFood = foods; const auto newAccum = accum + foods[i]; newFood.erase(std::begin(newFood) + i); if (depthFirst(totalFood, newAccum, newFood)) { return true; } } return false; }
/** * Run multiple test. * @param transaction_list List of itemset and expression value. * @param trans4lcm File name for argument of LCM program. This file is made in this method. * @param threshold The statistical significance threshold. * @param set_method The procedure name for calibration p-value (fisher/u_test). * @param max_comb The maximum arity limit. * @param outlog File name for logging. * @param alternative hypothesis, 1 -> greater, 0 -> two sided, -1 -> less * @param max_lambda Return value of maximum lambda. * @return */ int LampCore::runMultTest(const std::vector<Transaction*>& transaction_list, std::string& trans4lcm, double threshold, std::string& set_method, int max_comb, std::ostream& outlog, int alternative, double max_lambda) { int lam_star = 1; double k = -1; try { if (set_method.compare("fisher") == 0) { func_f = new Functions4fisher(transaction_list, std::abs(alternative)); } else if (set_method.compare("u_test") == 0) { func_f = new Functions4u_test(transaction_list, alternative); } else if (set_method.compare("chi") == 0) { func_f = new Functions4chi(transaction_list, std::abs( alternative)); } else { throw std::string("Error: choose \"fisher\", \"chi\" or \"u_test\" by using -p option."); } double lam = max_lambda; // check a MASL of max_lambda double n1 = 0.0; if (std::find(BINARY_METHODS.begin(), BINARY_METHODS.end(), set_method) != BINARY_METHODS.end()) { n1 = func_f->sumValue(); if (n1 < max_lambda) { max_lambda = int( n1 ); lam = int( n1 ); } } fre_pattern->makeFile4Lem(transaction_list, trans4lcm); // make itemset file for lcm // If Fisher's exact test or chi-square test is used for computing P-value, // LCM-LAMP is run to find optimal lambda. if (set_method == "fisher") { int neg_size = func_f->getAllSize() - func_f->getN1(); n1 = std::min( n1, (double)neg_size ); // # of positives == # of negatives, and two.sided hypothesis test. if (( func_f->getN1() == neg_size ) && (alternative == 0)) { lam_star = depthFirst( trans4lcm, max_comb, n1, 0.5*threshold, 1 ); } else { lam_star = depthFirst( trans4lcm, max_comb, n1, threshold, 1 ); } } else if (set_method == "chi") { int neg_size = func_f->getAllSize() - func_f->getN1(); n1 = std::min( n1, (double)neg_size ); // two-sided hypothesis test if (alternative == 0) { lam_star = depthFirst( trans4lcm, max_comb, n1, 0.5*threshold, 2 ); } // one-sided else { lam_star = depthFirst( trans4lcm, max_comb, n1, threshold, 2 ); } } // If Mann-Whitney U test of Chi-square test is used, // LAMP ver 1. is run for computing the optimal lambda. else { // two-sided hypothesis test if (alternative == 0) { lam_star = breadthFirst( trans4lcm, max_comb, 0.5*threshold, lam, outlog ); } // one-sided hypothesis test else { lam_star = breadthFirst( trans4lcm, max_comb, threshold, lam, outlog ); } } fre_pattern->frequentPatterns( trans4lcm, lam_star, max_comb ); // P_lambda* at line 13 k = fre_pattern->getTotal( lam_star ); } catch (std::string &msg) { throw msg; } catch (...) { throw std::string("Error: An unexpected error occurred while trying multiple test."); } // multiple test by using k and lambda_star outlog << "finish calculation of K: " << k << std::endl; // If lam_star > max_lambda, m_lambda set to max_lambda. // This case cause when optimal solution is found at first step. outlog << lam_star << std::endl; if (max_lambda < lam_star) lam_star = max_lambda; return lam_star; }