Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Population createIntegerCombinatorics(int populationSize, int genomeSize, int seed, int n) {
- Population randomPopulation = new Population();
- Random random = new Random(seed);
- int numPermutations = factorial(genomeSize);
- for (int i = 0; i < populationSize / numPermutations; i++) {
- Set<Genome> batch = new TreeSet<>();
- while (batch.size() < numPermutations) {
- batch.add(GenomeFactoru.createRandomPermutation(genomeSize, n, random));
- }
- for (Genome g : batch) {
- Individual ind = new Individual(g);
- if(!ind.isPermutation()) {
- throw new RuntimeException("Yo dawg! You generated an invalid individual!");
- }
- randomPopulation.addIndividual(ind);
- }
- }
- for (int i = randomPopulation.size(); i < populationSize; i++) {
- Genome randomGenome = GenomeFactory.createRandomPermutation(genomeSize, n, random);
- Individual ind = new Individual(randomGenome);
- if(!ind.isPermutation()) {
- throw new RuntimeException("Yo dawg! You generated an invalid individual!");
- }
- randomPopulation.addIndividual(ind);
- }
- return randomPopulation;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement