Пример #1
0
void Agent::random_restart_hill_climb() {

	//TODO
	//HINT:
	//		std::srand ( unsigned ( std::time(0) ) );

	int counter = 0;
	vector<City> journeyPath;
	while (counter != 200) {
		random_shuffle(cities.begin(), cities.end());

		journeyPath = hillClimb(cities);

		counter += 1;
	}

	for (std::vector<City>::iterator it = journeyPath.begin();
			it != journeyPath.end(); ++it) {
		cout << (*it).get_name() << endl;
	}
	cout << journeyPath.size() << endl;
	cout << "total distance " << shortestDistance << endl;
	cout << "-------------------------------------------" << endl;
	print_cities(journeyPath);
}
Пример #2
0
int main(int argc, char* argv[]) {
	if(argc > 1) {
		FILE* fptr = fopen(argv[1], "r");
		assert(fptr != NULL);
		
		int city_c = count_cities(fptr);
		printf("City count: %d\n", city_c);
		
		city* cities[city_c];
		
		read_cities(fptr, cities, city_c);
		print_cities(cities, city_c);
		printf("Distance between Helsinki and Espoo: %f km\n", distance(cities[1], cities[4]));
		printf("Path distance: %f km\n", path_distance(cities, city_c));
		
		free_cities(cities, city_c);
		fclose(fptr);
	}
	return EXIT_SUCCESS;
}