Skip to content
Snippets Groups Projects
Commit f8bdb290 authored by a.croix's avatar a.croix
Browse files

Some fix thanks to SpotBugs

parent d2330d1f
No related branches found
No related tags found
No related merge requests found
Pipeline #1389 failed
...@@ -95,9 +95,11 @@ public abstract class AbstractSolution ...@@ -95,9 +95,11 @@ public abstract class AbstractSolution
*/ */
@Override @Override
public final int compareTo(final AbstractSolution solution) { public final int compareTo(final AbstractSolution solution) {
if (this.getFitnessScore() > solution.getFitnessScore()) { if (Double.compare(this.getFitnessScore(),
solution.getFitnessScore()) > 0) {
return 1; return 1;
} else if (this.getFitnessScore() < solution.getFitnessScore()) { } else if (Double.compare(this.getFitnessScore(),
solution.getFitnessScore()) < 0) {
return -1; return -1;
} else { } else {
return 0; return 0;
......
...@@ -57,18 +57,4 @@ public class SolutionDistance extends AbstractSolution { ...@@ -57,18 +57,4 @@ public class SolutionDistance extends AbstractSolution {
} }
/**
* @param solution
* @return int
*/
public final int compareTo(final SolutionDistance solution) {
if (this.fitness_score > solution.getFitnessScore()) {
return 1;
} else if (this.fitness_score < solution.getFitnessScore()) {
return -1;
} else {
return 0;
}
}
} }
...@@ -117,7 +117,7 @@ public class Trainer { ...@@ -117,7 +117,7 @@ public class Trainer {
final int number_of_weight, final int number_of_weight,
final int population_size) { final int population_size) {
int number_of_random_element = population_size / 2; int number_of_random_element = population_size / 2;
if (Math.pow(number_of_weight, 2) < population_size / 2) { if (Math.pow(number_of_weight, 2) < population_size / (double) 2) {
number_of_random_element = number_of_random_element =
(int) (population_size - Math.pow(number_of_weight, 2)); (int) (population_size - Math.pow(number_of_weight, 2));
} }
......
...@@ -31,7 +31,6 @@ public class TrainerParameters { ...@@ -31,7 +31,6 @@ public class TrainerParameters {
private Logger logger; private Logger logger;
private int population_size; private int population_size;
//private int crossover_rate;
private int mutation_rate; private int mutation_rate;
private int selection_method; private int selection_method;
private int number_of_parents; private int number_of_parents;
...@@ -130,10 +129,9 @@ public class TrainerParameters { ...@@ -130,10 +129,9 @@ public class TrainerParameters {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Crossover rate must be between 1 and 99"); "Crossover rate must be between 1 and 99");
} }
//this.crossover_rate = crossover_rate;
int nbr_parents = Math.round(this.population_size int nbr_parents = Math.round(this.population_size
* (1 - (float) crossover_rate / 100)); * (1 - (float) crossover_rate / 100));
if (nbr_parents % 2 == 1) { if (nbr_parents % 2 != 0) {
nbr_parents++; nbr_parents++;
} }
this.number_of_parents = nbr_parents; this.number_of_parents = nbr_parents;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment