Ejemplo n.º 1
0
void runLocalSearch(FILE *fileResults, HistoricalData *fileReader, int populationSize, int numberOfSteps, int cycle)
{	
	printf ("LS Bugs %d - Cycle %d      \r", fileReader->openBugList.size(), cycle);
	int maxEvaluations = (int) (numberOfSteps * populationSize * (1 - TOPMOST_PERCENTIL));

	time_t start = time (NULL);
	LocalSearch *method = new LocalSearch(fileReader, maxEvaluations);
	Chromosome *bestSolution = method->run();

	time_t finish = time (NULL);
	int diff = (int) (finish - start);

	printSchedule(bestSolution, "LS", cycle, populationSize, numberOfSteps, fileReader->openBugList.size());
	fprintf(fileResults, "Cycle %d; Time = %d; Cost = %.0f; Makespan = %d\n", cycle, diff, bestSolution->getCost(), bestSolution->getSchedule()->calculateMakespan());
	fflush(fileResults);
}
Ejemplo n.º 2
0
void runGeneticAlgorithm(FILE *fileResults, HistoricalData *fileReader, int populationSize, int numberOfSteps, int cycle)
{
	time_t start = time (NULL);
	RandomKeyMethod *method = new RandomKeyMethod (fileReader, populationSize);

	for (int i=0; i < numberOfSteps; i++)
	{
		printf ("GA Bugs %d - Cycle %d - Step %d       \r", fileReader->openBugList.size(), cycle, i);
		method->reproduct ();
	}

	Chromosome *bestSolution = method->getBestSolution();
	time_t finish = time (NULL);
	int diff = (int) (finish - start);

	printSchedule(bestSolution, "GA", cycle, populationSize, numberOfSteps, fileReader->openBugList.size());
	fprintf(fileResults, "Cycle %d; Time = %d; Cost = %.0f; Makespan = %d\n", cycle, diff, bestSolution->getCost(), bestSolution->getSchedule()->calculateMakespan());
	fflush(fileResults);
}