Skip to content

Commit

Permalink
fix chromosome ranking based on dominated count in fast non-dominated…
Browse files Browse the repository at this point in the history
… sort (based on issue #12)
  • Loading branch information
onclave committed Mar 22, 2021
1 parent 1cc9a28 commit 3c1be75
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.5.1</version>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/debacharya/nsgaii/NSGA2.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,20 @@ public void fastNonDominatedSort(Population population) {
if(population.getLast().getDominatedCount() == 0)
population.getLast().setRank(1);

for(Chromosome chromosome : populace)
for(Chromosome dominatedChromosome : chromosome.getDominatedChromosomes()) {

dominatedChromosome.incrementDominatedCount(-1);

if(dominatedChromosome.getDominatedCount() == 0)
dominatedChromosome.setRank(chromosome.getRank() + 1);
}
while(Service.populaceHasUnsetRank(populace)) {
populace.forEach(chromosome -> {
if(chromosome.getRank() != -1)
chromosome.getDominatedChromosomes().forEach(dominatedChromosome -> {
if(dominatedChromosome.getDominatedCount() > 0) {

dominatedChromosome.incrementDominatedCount(-1);

if(dominatedChromosome.getDominatedCount() == 0)
dominatedChromosome.setRank(chromosome.getRank() + 1);
}
});
});
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/debacharya/nsgaii/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ public static boolean isInGeneticCode(List<IntegerAllele> geneticCode, int value
return false;
}

public static boolean populaceHasUnsetRank(List<Chromosome> populace) {
for(Chromosome chromosome : populace)
if(chromosome.getRank() == -1)
return true;
return false;
}

/**
* an implementation of min-max normalization
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Chromosome getCopy() {

public void reset() {
this.dominatedCount = 0;
this.rank = Integer.MAX_VALUE;
this.rank = -1;
this.dominatedChromosomes = new ArrayList<>();
}

Expand Down

0 comments on commit 3c1be75

Please sign in to comment.