|
@@ -51,7 +51,7 @@ public class GaAlgorithm implements Algorithm {
|
|
*/
|
|
*/
|
|
private int popsize = 20;
|
|
private int popsize = 20;
|
|
private int maxGenerations = 100;
|
|
private int maxGenerations = 100;
|
|
- private int tournamentSize = 2;
|
|
|
|
|
|
+ private double tournamentSize = 2.1;
|
|
private double fixedSwapProbability = 0.02;
|
|
private double fixedSwapProbability = 0.02;
|
|
private boolean useFixedSpawProbability = false;
|
|
private boolean useFixedSpawProbability = false;
|
|
private double fixedMutateProbability = 0.02;
|
|
private double fixedMutateProbability = 0.02;
|
|
@@ -150,6 +150,10 @@ public class GaAlgorithm implements Algorithm {
|
|
swapLabel.setEnabled(this.useFixedSpawProbability);
|
|
swapLabel.setEnabled(this.useFixedSpawProbability);
|
|
parameterPanel.add(swapLabel);
|
|
parameterPanel.add(swapLabel);
|
|
|
|
|
|
|
|
+ JLabel tournamentLabel = new JLabel("TournamentSize:");
|
|
|
|
+ tournamentLabel.setBounds(20, 185, 150, 20);
|
|
|
|
+ parameterPanel.add(tournamentLabel);
|
|
|
|
+
|
|
|
|
|
|
JLabel progressLabel = new JLabel("Progress:");
|
|
JLabel progressLabel = new JLabel("Progress:");
|
|
progressLabel.setBounds(350, 135, 170, 20);
|
|
progressLabel.setBounds(350, 135, 170, 20);
|
|
@@ -269,6 +273,18 @@ public class GaAlgorithm implements Algorithm {
|
|
parameterPanel.add(useFixSwapCheckBox);
|
|
parameterPanel.add(useFixSwapCheckBox);
|
|
|
|
|
|
|
|
|
|
|
|
+ NumberFormatter tournamentFormatter = new NumberFormatter(doubleFormat);
|
|
|
|
+ tournamentFormatter.setMinimum(1.0);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JFormattedTextField tournamentSizeTextField = new JFormattedTextField(tournamentFormatter);
|
|
|
|
+ tournamentSizeTextField.setValue(this.tournamentSize);
|
|
|
|
+ tournamentSizeTextField.setToolTipText("Only Double bigger or equal then 1.");
|
|
|
|
+ tournamentSizeTextField.addPropertyChangeListener(propertyChange -> this.tournamentSize = Double.parseDouble(tournamentSizeTextField.getValue().toString()));
|
|
|
|
+ tournamentSizeTextField.setBounds(160, 185, 50, 20);
|
|
|
|
+ parameterPanel.add(tournamentSizeTextField);
|
|
|
|
+
|
|
|
|
+
|
|
return parameterPanel;
|
|
return parameterPanel;
|
|
}
|
|
}
|
|
public JPanel createButtonPanel() {
|
|
public JPanel createButtonPanel() {
|
|
@@ -533,10 +549,20 @@ public class GaAlgorithm implements Algorithm {
|
|
*/
|
|
*/
|
|
private Individual selectAParent(List<Individual> population,int popsize) {
|
|
private Individual selectAParent(List<Individual> population,int popsize) {
|
|
Individual tournamentBest = population.get(Random.nextIntegerInRange(0, popsize));
|
|
Individual tournamentBest = population.get(Random.nextIntegerInRange(0, popsize));
|
|
- for(int i = 2 ; i <= tournamentSize; i++) {
|
|
|
|
|
|
+ double participants;
|
|
|
|
+ for(participants = tournamentSize ; participants >= 2; participants -= 1.0) {
|
|
Individual next = population.get(Random.nextIntegerInRange(0, popsize));
|
|
Individual next = population.get(Random.nextIntegerInRange(0, popsize));
|
|
if(next.fitness < tournamentBest.fitness) tournamentBest = next;
|
|
if(next.fitness < tournamentBest.fitness) tournamentBest = next;
|
|
}
|
|
}
|
|
|
|
+ //if tournament size is not a whole number like 2.5 or 3.6
|
|
|
|
+ //the remaining part is the chance to fight another time; 2.7 -> 70% chance to fight a second time
|
|
|
|
+ if( participants > 1) {
|
|
|
|
+ if(Random.nextDouble() < participants - 1.0) {
|
|
|
|
+ println("Chance to find a match");
|
|
|
|
+ Individual next = population.get(Random.nextIntegerInRange(0, popsize));
|
|
|
|
+ if(next.fitness < tournamentBest.fitness) tournamentBest = next;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
return tournamentBest;
|
|
return tournamentBest;
|
|
}
|
|
}
|
|
/**
|
|
/**
|