Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. public static Population createIntegerCombinatorics(int populationSize, int genomeSize, int seed, int n) {
  2.         Population randomPopulation = new Population();
  3.         Random random = new Random(seed);
  4.         int numPermutations = factorial(genomeSize);
  5.         for (int i = 0; i < populationSize / numPermutations; i++) {
  6.             Set<Genome> batch = new TreeSet<>();
  7.             while (batch.size() < numPermutations) {
  8.                 batch.add(GenomeFactoru.createRandomPermutation(genomeSize, n, random));               
  9.             }
  10.             for (Genome g : batch) {
  11.                  Individual ind = new Individual(g);
  12.                 if(!ind.isPermutation()) {
  13.                     throw new RuntimeException("Yo dawg! You generated an invalid individual!");
  14.                 }
  15.                 randomPopulation.addIndividual(ind);
  16.             }
  17.         }
  18.         for (int i = randomPopulation.size(); i < populationSize; i++) {
  19.              Genome randomGenome = GenomeFactory.createRandomPermutation(genomeSize, n, random);
  20.              Individual ind = new Individual(randomGenome);
  21.              if(!ind.isPermutation()) {
  22.                 throw new RuntimeException("Yo dawg! You generated an invalid individual!");
  23.              }
  24.              randomPopulation.addIndividual(ind);
  25.         }
  26.         return randomPopulation;
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement