fork(1) download
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <vector>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. class City
  11. {
  12. private:
  13. int x;
  14. int y;
  15.  
  16. public:
  17. //constructs a city at chosen x,y location
  18. City(int x, int y)
  19. {
  20. this->x = x;
  21. this->y = y;
  22. }
  23.  
  24. int getX()
  25. {
  26. return this->x;
  27. }
  28.  
  29. int getY()
  30. {
  31. return this->y;
  32. }
  33.  
  34. double distanceTo(City city)
  35. {
  36. int xDistance = abs(getX() - city.getX());
  37. int yDistance = abs(getY() - city.getY());
  38. double distance = sqrt((xDistance*xDistance) + (yDistance*yDistance));
  39.  
  40. return distance;
  41. }
  42. };
  43.  
  44. class TourManager
  45. {
  46. private:
  47. //holds the cities
  48. vector<City> destinationCities;
  49.  
  50. public:
  51. //adds a destination city
  52. void addCity(City city)
  53. {
  54. destinationCities.push_back(city);
  55. }
  56.  
  57. //get a city
  58. City getCity(int index)
  59. {
  60. return (City)destinationCities.at(index);
  61. }
  62.  
  63. //get the number of destination city
  64. int numberOfCities()
  65. {
  66. return (int)destinationCities.size();
  67. }
  68. };
  69.  
  70. class Tour
  71. {
  72. private:
  73. //holds our tour of cities
  74. vector<City> tour;
  75. double fitness = 0;
  76. int distance = 0;
  77. TourManager tourManager;
  78.  
  79. public:
  80. //constructs a blank tour
  81. Tour()
  82. {
  83. City *city = new City(0, 0);
  84. for (int i = 0; i < tourManager.numberOfCities(); ++i)
  85. {
  86. tour.push_back(*city);
  87. }
  88. }
  89.  
  90. Tour(vector<City> tour)
  91. {
  92. this->tour = tour;
  93. }
  94.  
  95. //generates a random individual
  96. void generateIndividual()
  97. {
  98. //loop through all our destinations cities and add them to our tour
  99. for (int cityIndex = 0; cityIndex < tourManager.numberOfCities(); ++cityIndex)
  100. {
  101. setCity(cityIndex, tourManager.getCity(cityIndex));
  102. }
  103. //randomly reorder the tour
  104. random_shuffle(tour.begin(), tour.end(), tour);
  105. }
  106.  
  107. City getCity(int tourPosition)
  108. {
  109. return (City)tour.at(tourPosition);
  110. }
  111.  
  112. void setCity(int tourPosition, City city)
  113. {
  114. //CAUTION: not sure if the line below will work!
  115. tour.insert(tour.begin()+tourPosition, city);
  116.  
  117. //if the tour has been altered we need to reset fitness and distance
  118. fitness = 0;
  119. distance = 0;
  120. }
  121.  
  122. //gets the tours fitness (fitness = cost?)
  123. double getFitness()
  124. {
  125. if (fitness == 0)
  126. {
  127. fitness = 1/(double)getDistance();
  128. }
  129.  
  130. return fitness;
  131. }
  132.  
  133. // Gets the total distance of the tour
  134. int getDistance()
  135. {
  136. if (distance == 0)
  137. {
  138. int tourDistance = 0;
  139.  
  140. // Loop through our tour's cities
  141. for (int cityIndex=0; cityIndex < tourSize(); cityIndex++)
  142. {
  143. // Get city we're travelling from
  144. City fromCity = getCity(cityIndex);
  145.  
  146. // City we're travelling to
  147. City *destinationCity = new City(0,0);
  148.  
  149. // Check we're not on our tour's last city, if we are set our
  150. // tour's final destination city to our starting city
  151. if(cityIndex+1 < tourSize())
  152. {
  153. *destinationCity = getCity(cityIndex+1);
  154. }
  155. else
  156. {
  157. *destinationCity = getCity(0);
  158. }
  159.  
  160. // Get the distance between the two cities
  161. tourDistance += fromCity.distanceTo(*destinationCity);
  162. }
  163. distance = tourDistance;
  164. }
  165. return distance;
  166. }
  167.  
  168. //get the number of cities on our tour
  169. int tourSize()
  170. {
  171. return (int)tour.size();
  172. }
  173.  
  174. // Check if the tour contains a city
  175. bool containsCity(City city)
  176. {
  177. for (int i = 0; i < tourSize(); ++i)
  178. {
  179. if( (tour[i].getX() == city.getX()) && (tour[i].getY() == city.getY()) )
  180. return true;
  181. }
  182.  
  183. return false;
  184. }
  185. };
  186.  
  187. class Population
  188. {
  189. private:
  190. //hold population of tours
  191. vector<Tour> tours;
  192.  
  193. public:
  194. //contructs a population
  195. Population(int populationSize, bool initialize)
  196. {
  197. tours.resize(populationSize);
  198.  
  199. //if we need to initialize a population then do so
  200. if (initialize)
  201. {
  202. for (int i = 0; i < populationSize; ++i)
  203. {
  204. Tour *newTour = new Tour();
  205. newTour->generateIndividual();
  206. saveTour(i, *newTour);
  207. }
  208. }
  209. }
  210.  
  211. // Saves a tour
  212. void saveTour(int index, Tour tour)
  213. {
  214. tours[index] = tour;
  215. }
  216.  
  217. // Gets a tour from population
  218. Tour getTour(int index)
  219. {
  220. return tours[index];
  221. }
  222.  
  223. // Gets the best tour in the population
  224. Tour getFittest()
  225. {
  226. Tour fittest = tours[0];
  227.  
  228. // Loop through individuals to find fittest
  229. for (int i = 1; i < populationSize(); i++)
  230. {
  231. if (fittest.getFitness() <= getTour(i).getFitness())
  232. {
  233. fittest = getTour(i);
  234. }
  235. }
  236. return fittest;
  237. }
  238.  
  239. // Gets population size
  240. int populationSize()
  241. {
  242. return (int)tours.size();
  243. }
  244. };
  245.  
  246. class GA
  247. {
  248. private:
  249.  
  250. /* GA parameters */
  251. double mutationRate = 0.015;
  252. int tournamentSize = 5;
  253. bool elitism = true;
  254.  
  255. public:
  256.  
  257. //Evolves a population over one generation
  258. Population evolvePopulation(Population pop)
  259. {
  260. Population* newPopulation = new Population(pop.populationSize(), false);
  261.  
  262. //keep our best individual if elitism is enabled
  263. int elitismOffset = 0;
  264. if (elitism)
  265. {
  266. newPopulation->saveTour(0, pop.getFittest());
  267. elitismOffset = 1;
  268. }
  269.  
  270. // Crossover population
  271. // Loop over the new population's size and create individuals from
  272. // Current population
  273. for (int i = 0; i < newPopulation->populationSize(); ++i)
  274. {
  275. //select parents
  276. Tour parent1 = tournamentSelection(pop);
  277. Tour parent2 = tournamentSelection(pop);
  278.  
  279. //crossover parents
  280. Tour child = crossover(parent1, parent2);
  281.  
  282. //add child to new population
  283. newPopulation->saveTour(i, child);
  284. }
  285.  
  286. //mutate the new population a bit to add some new genetic material
  287. for (int i = elitismOffset; i < newPopulation->populationSize(); ++i)
  288. {
  289. mutate(newPopulation->getTour(i));
  290. }
  291.  
  292. return *newPopulation;
  293. }
  294.  
  295. //applies crossover to a set of parents and creates offspring
  296.  
  297. Tour crossover(Tour parent1, Tour parent2)
  298. {
  299. //create the new child
  300. Tour* child = new Tour();
  301. City* cityBlank = new City(0, 0);
  302.  
  303. //get start and end sub tour positions for parents1's tour
  304. int startPos = (int) (rand() * parent1.tourSize());
  305. int endPos = (int) (rand() * parent1.tourSize());
  306.  
  307. // Loop and add the sub tour from parent1 to our child
  308. for (int i = 0; i < child->tourSize(); i++)
  309. {
  310. // if our start position is less than the end position
  311. if (startPos < endPos && i > startPos && i < endPos)
  312. {
  313. child->setCity(i, parent1.getCity(i));
  314. } // If our start position is larger
  315. else if (startPos > endPos)
  316. {
  317. if (!(i < startPos && i > endPos))
  318. {
  319. child->setCity(i, parent1.getCity(i));
  320. }
  321. }
  322. }
  323.  
  324. // Loop through parent2's city tour
  325. for (int i = 0; i < parent2.tourSize(); i++)
  326. {
  327. // If child doesn't have the city add it
  328. if (!child->containsCity(parent2.getCity(i)))
  329. {
  330. // Loop to find a spare position in the child's tour
  331. for (int ii = 0; ii < child->tourSize(); ii++)
  332. {
  333. // Spare position found, add city
  334. // CHECK HERE!
  335. if (child->getCity(ii).getX() == cityBlank->getX() && child->getCity(ii).getY() == cityBlank->getY())
  336. {
  337. child->setCity(ii, parent2.getCity(i));
  338. break;
  339. }
  340. }
  341. }
  342. }
  343. return *child;
  344. }
  345.  
  346. // Mutate a tour using swap mutation
  347. void mutate(Tour tour)
  348. {
  349. // Loop through tour cities
  350. for(int tourPos1=0; tourPos1 < tour.tourSize(); tourPos1++)
  351. {
  352. // Apply mutation rate
  353. if(rand() < mutationRate)
  354. {
  355. // Get a second random position in the tour
  356. int tourPos2 = (int) (tour.tourSize() * rand());
  357.  
  358. // Get the cities at target position in tour
  359. City city1 = tour.getCity(tourPos1);
  360. City city2 = tour.getCity(tourPos2);
  361.  
  362. // Swap them around
  363. tour.setCity(tourPos2, city1);
  364. tour.setCity(tourPos1, city2);
  365. }
  366. }
  367. }
  368.  
  369. // Selects candidate tour for crossover
  370. Tour tournamentSelection(Population pop)
  371. {
  372. // Create a tournament population
  373. Population* tournament = new Population(tournamentSize, false);
  374.  
  375. // For each place in the tournament get a random candidate tour and
  376. // add it
  377. for (int i = 0; i < tournamentSize; i++)
  378. {
  379. int randomId = (int) (rand() * pop.populationSize());
  380. tournament->saveTour(i, pop.getTour(randomId));
  381. }
  382.  
  383. // Get the fittest tour
  384. Tour fittest = tournament->getFittest();
  385.  
  386. return fittest;
  387. }
  388. };
  389.  
  390. int main()
  391. {
  392. TourManager tourmanager;
  393. GA ga;
  394.  
  395. City *city1 = new City(60, 200);
  396. tourmanager.addCity(*city1);
  397.  
  398. City *city2 = new City(180, 200);
  399. tourmanager.addCity(*city2);
  400.  
  401. City *city3 = new City(80, 180);
  402. tourmanager.addCity(*city3);
  403.  
  404. City *city4 = new City(140, 180);
  405. tourmanager.addCity(*city4);
  406.  
  407. City *city5 = new City(20, 160);
  408. tourmanager.addCity(*city5);
  409.  
  410. //initialize population
  411. Population *pop = new Population(50, true);
  412. cout << "Initial distance: " << pop->getFittest().getDistance() << endl;
  413.  
  414. // Evolve population for 50 generations
  415. *pop = ga.evolvePopulation(*pop);
  416. for (int i = 0; i < 100; i++)
  417. {
  418. *pop = ga.evolvePopulation(*pop);
  419. }
  420.  
  421. // Print final results
  422. cout << "Finished" << endl;
  423. cout << "Final distance: " << pop->getFittest().getDistance() << endl;
  424. cout << "Solution: " << pop->getFittest() << endl;
  425.  
  426. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:75:22: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     double fitness = 0;
                      ^
prog.cpp:76:20: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     int distance = 0;
                    ^
prog.cpp:251:27: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     double mutationRate = 0.015;
                           ^
prog.cpp:252:26: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     int tournamentSize = 5;
                          ^
prog.cpp:253:20: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 [enabled by default]
     bool elitism = true;
                    ^
prog.cpp: In function ‘int main()’:
prog.cpp:424:26: error: no match for ‘operator<<’ (operand types are ‘std::basic_ostream<char>’ and ‘Tour’)
     cout << "Solution: " << pop->getFittest() << endl;
                          ^
prog.cpp:424:26: note: candidates are:
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:108:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(__ostream_type& (*__pf)(__ostream_type&))
       ^
/usr/include/c++/4.8/ostream:108:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘std::basic_ostream<char>::__ostream_type& (*)(std::basic_ostream<char>::__ostream_type&) {aka std::basic_ostream<char>& (*)(std::basic_ostream<char>&)}’
/usr/include/c++/4.8/ostream:117:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ios_type& (*)(std::basic_ostream<_CharT, _Traits>::__ios_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>; std::basic_ostream<_CharT, _Traits>::__ios_type = std::basic_ios<char>]
       operator<<(__ios_type& (*__pf)(__ios_type&))
       ^
/usr/include/c++/4.8/ostream:117:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘std::basic_ostream<char>::__ios_type& (*)(std::basic_ostream<char>::__ios_type&) {aka std::basic_ios<char>& (*)(std::basic_ios<char>&)}’
/usr/include/c++/4.8/ostream:127:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(ios_base& (*__pf) (ios_base&))
       ^
/usr/include/c++/4.8/ostream:127:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘std::ios_base& (*)(std::ios_base&)’
/usr/include/c++/4.8/ostream:166:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(long __n)
       ^
/usr/include/c++/4.8/ostream:166:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘long int’
/usr/include/c++/4.8/ostream:170:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned long __n)
       ^
/usr/include/c++/4.8/ostream:170:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘long unsigned int’
/usr/include/c++/4.8/ostream:174:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(bool __n)
       ^
/usr/include/c++/4.8/ostream:174:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘bool’
In file included from /usr/include/c++/4.8/ostream:609:0,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:91:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char; _Traits = std::char_traits<char>]
     basic_ostream<_CharT, _Traits>::
     ^
/usr/include/c++/4.8/bits/ostream.tcc:91:5: note:   no known conversion for argument 1 from ‘Tour’ to ‘short int’
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:181:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned short __n)
       ^
/usr/include/c++/4.8/ostream:181:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘short unsigned int’
In file included from /usr/include/c++/4.8/ostream:609:0,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:105:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char; _Traits = std::char_traits<char>]
     basic_ostream<_CharT, _Traits>::
     ^
/usr/include/c++/4.8/bits/ostream.tcc:105:5: note:   no known conversion for argument 1 from ‘Tour’ to ‘int’
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:192:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned int __n)
       ^
/usr/include/c++/4.8/ostream:192:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘unsigned int’
/usr/include/c++/4.8/ostream:201:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(long long __n)
       ^
/usr/include/c++/4.8/ostream:201:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘long long int’
/usr/include/c++/4.8/ostream:205:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(unsigned long long __n)
       ^
/usr/include/c++/4.8/ostream:205:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘long long unsigned int’
/usr/include/c++/4.8/ostream:220:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(double __f)
       ^
/usr/include/c++/4.8/ostream:220:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘double’
/usr/include/c++/4.8/ostream:224:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(float __f)
       ^
/usr/include/c++/4.8/ostream:224:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘float’
/usr/include/c++/4.8/ostream:232:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(long double __f)
       ^
/usr/include/c++/4.8/ostream:232:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘long double’
/usr/include/c++/4.8/ostream:245:7: note: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__ostream_type = std::basic_ostream<char>]
       operator<<(const void* __p)
       ^
/usr/include/c++/4.8/ostream:245:7: note:   no known conversion for argument 1 from ‘Tour’ to ‘const void*’
In file included from /usr/include/c++/4.8/ostream:609:0,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:119:5: note: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__streambuf_type*) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_CharT, _Traits>::__streambuf_type = std::basic_streambuf<char>]
     basic_ostream<_CharT, _Traits>::
     ^
/usr/include/c++/4.8/bits/ostream.tcc:119:5: note:   no known conversion for argument 1 from ‘Tour’ to ‘std::basic_ostream<char>::__streambuf_type* {aka std::basic_streambuf<char>*}’
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
     operator<<(basic_ostream<_CharT, _Traits>& __os,
     ^
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   ‘Tour’ is not derived from ‘const std::basic_string<_CharT, _Traits, _Alloc>’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:471:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
     ^
/usr/include/c++/4.8/ostream:471:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   deduced conflicting types for parameter ‘_CharT’ (‘char’ and ‘Tour’)
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:476:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
     ^
/usr/include/c++/4.8/ostream:476:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘char’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:482:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
     operator<<(basic_ostream<char, _Traits>& __out, char __c)
     ^
/usr/include/c++/4.8/ostream:482:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘char’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:488:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
     ^
/usr/include/c++/4.8/ostream:488:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘signed char’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:493:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
     ^
/usr/include/c++/4.8/ostream:493:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘unsigned char’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:513:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
     ^
/usr/include/c++/4.8/ostream:513:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   mismatched types ‘const _CharT*’ and ‘Tour’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/ostream:609:0,
                 from /usr/include/c++/4.8/iostream:39,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
     ^
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘const char*’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:530:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
     ^
/usr/include/c++/4.8/ostream:530:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘const char*’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
     ^
/usr/include/c++/4.8/ostream:543:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘const signed char*’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
     ^
/usr/include/c++/4.8/ostream:548:5: note:   template argument deduction/substitution failed:
prog.cpp:424:45: note:   cannot convert ‘Population::getFittest()()’ (type ‘Tour’) to type ‘const unsigned char*’
     cout << "Solution: " << pop->getFittest() << endl;
                                             ^
In file included from /usr/include/c++/4.8/algorithm:62:0,
                 from prog.cpp:6:
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘void std::random_shuffle(_RAIter, _RAIter, _Generator&) [with _RAIter = __gnu_cxx::__normal_iterator<City*, std::vector<City> >; _Generator = std::vector<City>]’:
prog.cpp:104:54:   required from here
/usr/include/c++/4.8/bits/stl_algo.h:5253:58: error: no match for call to ‘(std::vector<City>) (__gnu_cxx::__normal_iterator<City*, std::vector<City> >::difference_type)’
  std::iter_swap(__i, __first + __rand((__i - __first) + 1));
                                                          ^
stdout
Standard output is empty