Exemplo n.º 1
0
main(int argc, char *argv[])
{
	int	day, startDay;
	pathStruct	attempt;
	int	i, city;
	FILE	*f;

	traversals = 0;

	f = fopen("tables.tab", "r");
	startDay = initialize(f);
	startDay = -startDay + 1;
	maxTime = days - startDay;
	overall.bestTotal = maxTime;
	fclose(f);
	if (argc == 2 && argv[1][0] == '-' && argv[1][1] == 'v')
		verbose = 1;
	else
		verbose = 0;
	attempt.totalCities = 1;
	for (city = 0; city < cities; city++)
	{
		best.bestTotal = maxTime;
		attempt.startCity = city;
		for (i = 0; i < cities; i++)
		{
			if (i == city)
			{
				attempt.used[i] = 1;
			}
			else
			{
				attempt.used[i] = 0;
			}
		}
		for (day = 70; day > startDay; day--)
		{
			attempt.curTotal = day;
			attempt.startDay = day;
	 		attempt.path[0] = city;
			attempt.numCity = 0;
			printf("%s\n", cityNames[city]);
			traverse(city, attempt);
		}
		printf("\nBEST TOTAL FOR CITY %s:\n", cityNames[city]);
		outputResult(best);
		printf("\n");
		fflush(stdout);
		if (best.bestTotal < overall.bestTotal)
			overall = best;
	}
	printf("\n\nBEST OVERALL TOTAL\n");
	outputResult(overall);
}
Exemplo n.º 2
0
int main(int argc, char **argv) {

    if (argc > 2 || (argc == 2 && strcmp(argv[1], "print"))) {
        printf(
                "I expect no command line argument or \"print\" as unique command line argument.\n");
        return EXIT_FAILURE;
    }
    if (!get_input()) {
        printf("Incorrect input.\n");
        return EXIT_FAILURE;
    }
    convertMaze();
    if (argc == 2) {
        drawMaze();
        return EXIT_SUCCESS;
    }

    countGates();
    countWalls();
    countInAccAreas();
    countAccAreas();
    countCuldesacs();
    countPaths();
    outputResult();

    return EXIT_SUCCESS;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]){
	if(argc != 3){
		usage(argv[0], stderr);
		exit(1);
	}

	FILE *inputFile = fopen(argv[1], "r");

	if(NULL == inputFile){
		fprintf(stderr, "File %s not exist.\n", argv[1]);
		exit(1);
	}

	FILE *outputFile = fopen(argv[2], "w");
	List *list = makeList(inputFile);
	removeInvalidData(list);
	lowPassFilter(list);
	setStatus(list);
	outputResult(list, outputFile);

	fclose(inputFile);
	fclose(outputFile);

	freeList(list);
	return 0;
}
Exemplo n.º 4
0
int main(void){
	int w=100;
	int box[6]={100,20,25,25,20,20};
	sortBox(box,6);
	int result[6]={0};
	loading(box,result,w,6);
	outputResult(result,6);
	return 0;
}
Exemplo n.º 5
0
/**
 * Print results of multiple test.
 * @param transaction_file The file includes associations between TFs and genes.
 *                          Each line indicates a gene.
 *                          If gene is targeted by the TF, then value is 1, otherwise 0.
 * @param flag_file Each line indicates a gene. The column1 is gene name.
 *                   If gene has the feature, the column2 is 1. The other case 0.
 * @param threshold The statistical significance threshold.
 * @param set_method The procedure name for calibration p-value (fisher/u_test/chi).
 * @param alternative hypothesis, 1 -> greater, 0 -> two sided, -1 -> less
 */
void LampCore::print(std::string& transaction_file, std::string& flag_file, double threshold,
        std::string& set_method, int alternative) {
	try {
		// output result
		outputResult( transaction_file, flag_file, threshold, set_method,
				readFile.getColumnid2name(), readFile.getTransaction_list(), alternative );

		// output time cost
		long long ccf = std::chrono::duration_cast<std::chrono::microseconds>(correction_term_time - starttime).count();
		long long esc = std::chrono::duration_cast<std::chrono::microseconds>(finish_test_time - correction_term_time).count();
		long long tt  = std::chrono::duration_cast<std::chrono::microseconds>(finish_test_time - starttime).count();
		std::cout << "Time (sec.): Computing correction factor "
				<< boost::format("%.3f") % ((double)ccf / 1000000)
				<< ", Enumerating significant combinations "
				<< boost::format("%.3f") % ((double)esc / 1000000)
				<< ", Total "
				<< boost::format("%.3f") % ((double)tt / 1000000)
				<< std::endl;
	} catch (std::string &msg) {
		throw msg;
	} catch (...) {
		throw std::string("Error: An unexpected error occurred while trying to print.");
	}
}
Exemplo n.º 6
0
void traverse(int from, pathStruct attempt)
{
	int	i;

	traversals++;

	if (traversals == 0)
	{
		printf("traversals variable wrapped!\n");
		fflush(stdout);
	}
	else if (traversals % 10000000 == 0)
	{
		printf("traversals = %d.\n", traversals);
		fflush(stdout);
	}

	if (attempt.totalCities == cities)
	{
		attempt.curTotal += distance[from][attempt.startCity];
		if ((attempt.curTotal - attempt.startDay) < best.bestTotal)
			printf("NEW BEST PATH\n");
		else if (verbose)
			printf("PATH NOT BEST\n");
	 	if ((attempt.curTotal - attempt.startDay) < best.bestTotal)
		{
			best = attempt;
			best.bestTotal = attempt.curTotal - attempt.startDay;
			outputResult(best);
			printf("Traversal #%d\n", traversals);
			fflush(stdout);
	 	}
	}
	else
	{
		int	startTotal, numCities = sort(from, &attempt);
		
		startTotal = attempt.curTotal;
		attempt.totalCities++;
		for (i = 0; i < numCities; i++)
		{
			int	city = attempt.sortedList[i], j;
			if (verbose)
			{
				for (j = 0; j < attempt.totalCities - 1; j++)
					printf(" ");
				printf("%s\n", cityNames[city]);
			}
			attempt.curTotal = startTotal;
			if (attempt.used[city] == 0)
			{
				attempt.curTotal += distance[from][city];
	 			if (attempt.curTotal < 0)
				{
					if (verbose) printf("Before season starts. %d cities\n", attempt.totalCities);
					continue;
				}
				if (wait[city][attempt.curTotal] == 999)
				{
					if (verbose) printf("Team not coming home again. %d cities\n", attempt.totalCities);
					continue;
				}
	 			attempt.curTotal += wait[city][attempt.curTotal];
				if (attempt.curTotal - attempt.startDay >= best.bestTotal)
				{
					if (verbose) printf("Worse than best total already. %d cities\n", attempt.totalCities);
					continue;
				}
				if (attempt.curTotal >= days)
				{
					if (verbose) printf("After end of season. %d cities\n", attempt.totalCities);
					continue;
				}
				attempt.used[city]++;
				attempt.numCity++;
				attempt.path[attempt.numCity] = city;
	 			traverse(city, attempt);
				attempt.used[city] = 0;
				attempt.numCity--;
	 		}
			else if (verbose)
				printf("City already seen.\n");
		}
	} 
}
int main(int argc, char* argv[]) {

	clock_t start, end;
	start = clock();

	// pattern part
	char *patternFilename = new char[100];
	strcpy(patternFilename, "../datafolder/onlydata.txt");
	int totalCheckNumberLine = CountLines(patternFilename);
	int patternLength;


	// text part
	char *textFilename = new char[100];
	strcpy(textFilename, "../datafolder/longest.txt");
	string Text = ReturnString(patternFilename,0);

	// alphabet part
	string alphabet = "GTAC ";
	int alphabetSize = alphabet.length();

	//alphabet matrix S
	Matrix S;
	std::map<char,Vector> sMap;

	//result Matrix
	std::vector<Matrix> SinglePatternResult;

    for (int j = 0; j <= totalCheckNumberLine ;j++)
    {
    	if(j == 57054) continue;

		string Pattern = ReturnString(patternFilename,j).substr(0,32);
		patternLength = Pattern.length();

		S.setsize(patternLength, alphabetSize);
		S.set(initWithSpecificChar(0.0, patternLength*alphabetSize));
		initWithInputString(Pattern,alphabet,S);
		S=S.transpose();

		sMap.clear();
		sMap = sMapInit(S,alphabet);

		SinglePatternResult.clear();
		SinglePatternResult.push_back(getExactMatchMatrix(Pattern,Text,sMap));

		for (int i = 0;i < errorLimit ;i ++)
		{
			SinglePatternResult.push_back(getNextMatrix(Pattern,Text,sMap,SinglePatternResult[i],i));
		}

	  	Vector outputResult(SinglePatternResult[errorLimit][Pattern.length()-1]);
	  	int posnum = 0;
	  	int *pos = new int[Text.length()];

		for (int i = 0;i < outputResult.getn() ;i ++)
		{
			if (outputResult[i] == 1)
			{
				cout<<"find it @ position " <<' '<< i+1 << " in "<<j<<" sequence!!!"<<endl;
				pos[posnum] = i;
				++ posnum;
			}
		}
		if(posnum == 0 )
			cout<<j<<" sequence!!!"<<endl;
		delete []pos;
	}
  	delete []textFilename;
  	delete []patternFilename;
  	
  	end = clock();

  	// show the clock elipse time
 	std::cout<<"Run time: "<<(double)(end - start) / CLOCKS_PER_SEC<<" s"<<std::endl;
	return 0;
}