#include <iostream> #include <ctime> #include <cstdlib> #include <cmath> #include <vector> #include <algorithm> using namespace std; class City { private: int x; int y; public: //constructs a city at chosen x,y location City(int x, int y) { this->x = x; this->y = y; } int getX() { return this->x; } int getY() { return this->y; } double distanceTo(City city) { int xDistance = abs(getX() - city.getX()); int yDistance = abs(getY() - city.getY()); double distance = sqrt((xDistance*xDistance) + (yDistance*yDistance)); return distance; } }; class TourManager { private: //holds the cities vector<City> destinationCities; public: //adds a destination city void addCity(City city) { destinationCities.push_back(city); } //get a city City getCity(int index) { return (City)destinationCities.at(index); } //get the number of destination city int numberOfCities() { return (int)destinationCities.size(); } }; class Tour { private: //holds our tour of cities vector<City> tour; double fitness = 0; int distance = 0; TourManager tourManager; public: //constructs a blank tour Tour() { City *city = new City(0, 0); for (int i = 0; i < tourManager.numberOfCities(); ++i) { tour.push_back(*city); } } Tour(vector<City> tour) { this->tour = tour; } //generates a random individual void generateIndividual() { //loop through all our destinations cities and add them to our tour for (int cityIndex = 0; cityIndex < tourManager.numberOfCities(); ++cityIndex) { setCity(cityIndex, tourManager.getCity(cityIndex)); } //randomly reorder the tour random_shuffle(tour.begin(), tour.end(), tour); } City getCity(int tourPosition) { return (City)tour.at(tourPosition); } void setCity(int tourPosition, City city) { //CAUTION: not sure if the line below will work! tour.insert(tour.begin()+tourPosition, city); //if the tour has been altered we need to reset fitness and distance fitness = 0; distance = 0; } //gets the tours fitness (fitness = cost?) double getFitness() { if (fitness == 0) { fitness = 1/(double)getDistance(); } return fitness; } // Gets the total distance of the tour int getDistance() { if (distance == 0) { int tourDistance = 0; // Loop through our tour's cities for (int cityIndex=0; cityIndex < tourSize(); cityIndex++) { // Get city we're travelling from City fromCity = getCity(cityIndex); // City we're travelling to City *destinationCity = new City(0,0); // Check we're not on our tour's last city, if we are set our // tour's final destination city to our starting city if(cityIndex+1 < tourSize()) { *destinationCity = getCity(cityIndex+1); } else { *destinationCity = getCity(0); } // Get the distance between the two cities tourDistance += fromCity.distanceTo(*destinationCity); } distance = tourDistance; } return distance; } //get the number of cities on our tour int tourSize() { return (int)tour.size(); } // Check if the tour contains a city bool containsCity(City city) { for (int i = 0; i < tourSize(); ++i) { if( (tour[i].getX() == city.getX()) && (tour[i].getY() == city.getY()) ) return true; } return false; } }; class Population { private: //hold population of tours vector<Tour> tours; public: //contructs a population Population(int populationSize, bool initialize) { tours.resize(populationSize); //if we need to initialize a population then do so if (initialize) { for (int i = 0; i < populationSize; ++i) { Tour *newTour = new Tour(); newTour->generateIndividual(); saveTour(i, *newTour); } } } // Saves a tour void saveTour(int index, Tour tour) { tours[index] = tour; } // Gets a tour from population Tour getTour(int index) { return tours[index]; } // Gets the best tour in the population Tour getFittest() { Tour fittest = tours[0]; // Loop through individuals to find fittest for (int i = 1; i < populationSize(); i++) { if (fittest.getFitness() <= getTour(i).getFitness()) { fittest = getTour(i); } } return fittest; } // Gets population size int populationSize() { return (int)tours.size(); } }; class GA { private: /* GA parameters */ double mutationRate = 0.015; int tournamentSize = 5; bool elitism = true; public: //Evolves a population over one generation Population evolvePopulation(Population pop) { Population* newPopulation = new Population(pop.populationSize(), false); //keep our best individual if elitism is enabled int elitismOffset = 0; if (elitism) { newPopulation->saveTour(0, pop.getFittest()); elitismOffset = 1; } // Crossover population // Loop over the new population's size and create individuals from // Current population for (int i = 0; i < newPopulation->populationSize(); ++i) { //select parents Tour parent1 = tournamentSelection(pop); Tour parent2 = tournamentSelection(pop); //crossover parents Tour child = crossover(parent1, parent2); //add child to new population newPopulation->saveTour(i, child); } //mutate the new population a bit to add some new genetic material for (int i = elitismOffset; i < newPopulation->populationSize(); ++i) { mutate(newPopulation->getTour(i)); } return *newPopulation; } //applies crossover to a set of parents and creates offspring Tour crossover(Tour parent1, Tour parent2) { //create the new child Tour* child = new Tour(); City* cityBlank = new City(0, 0); //get start and end sub tour positions for parents1's tour int startPos = (int) (rand() * parent1.tourSize()); int endPos = (int) (rand() * parent1.tourSize()); // Loop and add the sub tour from parent1 to our child for (int i = 0; i < child->tourSize(); i++) { // if our start position is less than the end position if (startPos < endPos && i > startPos && i < endPos) { child->setCity(i, parent1.getCity(i)); } // If our start position is larger else if (startPos > endPos) { if (!(i < startPos && i > endPos)) { child->setCity(i, parent1.getCity(i)); } } } // Loop through parent2's city tour for (int i = 0; i < parent2.tourSize(); i++) { // If child doesn't have the city add it if (!child->containsCity(parent2.getCity(i))) { // Loop to find a spare position in the child's tour for (int ii = 0; ii < child->tourSize(); ii++) { // Spare position found, add city // CHECK HERE! if (child->getCity(ii).getX() == cityBlank->getX() && child->getCity(ii).getY() == cityBlank->getY()) { child->setCity(ii, parent2.getCity(i)); break; } } } } return *child; } // Mutate a tour using swap mutation void mutate(Tour tour) { // Loop through tour cities for(int tourPos1=0; tourPos1 < tour.tourSize(); tourPos1++) { // Apply mutation rate if(rand() < mutationRate) { // Get a second random position in the tour int tourPos2 = (int) (tour.tourSize() * rand()); // Get the cities at target position in tour City city1 = tour.getCity(tourPos1); City city2 = tour.getCity(tourPos2); // Swap them around tour.setCity(tourPos2, city1); tour.setCity(tourPos1, city2); } } } // Selects candidate tour for crossover Tour tournamentSelection(Population pop) { // Create a tournament population Population* tournament = new Population(tournamentSize, false); // For each place in the tournament get a random candidate tour and // add it for (int i = 0; i < tournamentSize; i++) { int randomId = (int) (rand() * pop.populationSize()); tournament->saveTour(i, pop.getTour(randomId)); } // Get the fittest tour Tour fittest = tournament->getFittest(); return fittest; } }; int main() { TourManager tourmanager; GA ga; City *city1 = new City(60, 200); tourmanager.addCity(*city1); City *city2 = new City(180, 200); tourmanager.addCity(*city2); City *city3 = new City(80, 180); tourmanager.addCity(*city3); City *city4 = new City(140, 180); tourmanager.addCity(*city4); City *city5 = new City(20, 160); tourmanager.addCity(*city5); //initialize population Population *pop = new Population(50, true); cout << "Initial distance: " << pop->getFittest().getDistance() << endl; // Evolve population for 50 generations *pop = ga.evolvePopulation(*pop); for (int i = 0; i < 100; i++) { *pop = ga.evolvePopulation(*pop); } // Print final results cout << "Finished" << endl; cout << "Final distance: " << pop->getFittest().getDistance() << endl; cout << "Solution: " << pop->getFittest() << endl; }
Standard input is empty
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)); ^
Standard output is empty