-
-
Save szymonzo/941c94bb1e2f93d0d18b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args){ | |
ArrayList<City> tour = new ArrayList<City>(); | |
for(int i1 = 0; i1 < 100; i1++){ | |
int c; | |
int b; | |
Random randomno = new Random(); | |
c= randomno.nextInt(300); | |
b= randomno.nextInt(260); | |
City city = new City(b, c); | |
tour.add(city); | |
} | |
// Initialize population | |
Population pop = new Population(50, true); | |
System.out.println("Initial distance: " + pop.getFittest().getDistance()); | |
// Evolve population for 100 generations | |
pop = GA.evolvePopulation(pop); | |
for (int i = 0; i < 100; i++) { | |
pop = GA.evolvePopulation(pop); | |
} | |
// Print final results | |
System.out.println("Finished"); | |
System.out.println("Final distance: " + pop.getFittest().getDistance()); | |
System.out.println("Solution:"); | |
System.out.println(pop.getFittest()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment