Skip to content

Instantly share code, notes, and snippets.

@szymonzo
Created January 13, 2015 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save szymonzo/941c94bb1e2f93d0d18b to your computer and use it in GitHub Desktop.
Save szymonzo/941c94bb1e2f93d0d18b to your computer and use it in GitHub Desktop.
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