Last active
May 5, 2020 09:54
-
-
Save Vini2/36be9a156c8c3f9e189b775349a6d611 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Individual { | |
int fitness = 0; | |
int geneLength = 5; | |
int[] genes = new int[5]; | |
public Individual() { | |
Random rn = new Random(); | |
//Set genes randomly for each individual | |
for (int i = 0; i < geneLength; i++) { | |
genes[i] = rn.nextInt() % 2; | |
} | |
fitness = 0; | |
} | |
//Calculate fitness | |
public void calculateFitness() { | |
fitness = 0; | |
for (int i = 0; i < geneLength; i++) { | |
if (genes[i] == 1) { | |
++fitness; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment