|
@@ -454,7 +454,7 @@ public class GaAlgorithm implements Algorithm {
|
|
best.fitness = evaluatePosition(best.position, false);
|
|
best.fitness = evaluatePosition(best.position, false);
|
|
println("Start with Fitness: " + best.fitness);
|
|
println("Start with Fitness: " + best.fitness);
|
|
int problemSize = best.position.size();
|
|
int problemSize = best.position.size();
|
|
- List<Individual> population = initPopuluationRandom(problemSize);
|
|
|
|
|
|
+ List<Individual> population = initPopuluationRandom(problemSize, best);
|
|
println("Size To Test:" + population.size());
|
|
println("Size To Test:" + population.size());
|
|
for(int generation = 0; generation< maxGenerations; generation++) {
|
|
for(int generation = 0; generation< maxGenerations; generation++) {
|
|
println("Generation" + generation + " start with Fitness: " + best.fitness);
|
|
println("Generation" + generation + " start with Fitness: " + best.fitness);
|
|
@@ -534,11 +534,13 @@ public class GaAlgorithm implements Algorithm {
|
|
/**
|
|
/**
|
|
* Initialize the Population with Individuals that have a random Position.
|
|
* Initialize the Population with Individuals that have a random Position.
|
|
*/
|
|
*/
|
|
- private List<Individual> initPopuluationRandom(int problemSize){
|
|
|
|
|
|
+ private List<Individual> initPopuluationRandom(int problemSize, Individual startIndidual){
|
|
List<Individual> population = new ArrayList<Individual>();
|
|
List<Individual> population = new ArrayList<Individual>();
|
|
- for(int i = 0; i < popsize; i++) {
|
|
|
|
|
|
+ for(int i = 0; i < popsize -1; i++) {
|
|
population.add(createRandomIndividualWithoutFitness(problemSize));
|
|
population.add(createRandomIndividualWithoutFitness(problemSize));
|
|
}
|
|
}
|
|
|
|
+ //Add Start Position
|
|
|
|
+ population.add(new Individual(startIndidual));
|
|
return population;
|
|
return population;
|
|
}
|
|
}
|
|
|
|
|