This repository was archived by the owner on Feb 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneticAlg.java
More file actions
45 lines (39 loc) · 1.52 KB
/
GeneticAlg.java
File metadata and controls
45 lines (39 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Genetic;
import Principal.Main;
import Principal.Population;
import Principal.Solution;
import SimulatedAnnealing.SimulatedAnnealing;
/**
*
* @author yo
*/
public class GeneticAlg {
public void run() {
Population pop = new Population();
pop.initializePopulationRandomly(Main.POPULATION_SIZE);
for (int i = 0; i < Main.NUM_EVOLUTION_ITERATIONS; i++) {
pop = pop.evolve();
if (i % 3 == 0 && Main.PRINT_ITERATION) {
System.out.println("Finished Iteration: " + i + ". Best Solution: " + pop.getBestIndividualInPop().getCost());
}
if (i % 3 == 0 && Main.PRINT_BEST_POPULATION) {
for (int j = 0; j < pop.solutions.size(); j++) {
System.out.println("Sol cost: " + j + "\t" + pop.solutions.get(j).getCost());
System.out.println(pop.solutions.get(j).toString());
}
}
}
Solution best = pop.getBestIndividualInPop();
System.out.println("\nGenetic Algorithm:\nFinal solution: " + best.getCost()
+ "\nCoste medicos: " + best.getDinero() + " €\tDistancia "
+ "total: " + best.getDistancia() + " km");
if (Main.PRINT_BEST) {
System.out.println("Mejor solucion: " + best.toString());
}
}
}