Question: I am writing a Genetic Algorithm in Java using Unifrom order Crossover with BITMASK for solving TSP Problem. My issue is my initial pop is

I am writing a Genetic Algorithm in Java using Unifrom order Crossover with BITMASK for solving TSP Problem. My issue is my initial pop is of size popsize with each having a path of 1,2,3--numofcities, and if i do a uniform order crossover with 1,2,3 / 1,2,3, and whatever the bitmask is I get the same path 1,2,3,4...

here is my code:

public static SetOfChromosomes crossoverPopulationn(SetOfChromosomes poptocross){ int helper=0; SetOfChromosomes newPop= new SetOfChromosomes(poptocross.population.length, 0, 0); int[] bitmask22= createBitmaskArray(poptocross.population[0].chromosomerepersentation.length); //creates array to repersent bitmask for 22 cities (1010101010101010101010) for 51 cities (101010101010101010101010101010101010101010101010101) int[] bitmask51= createBitmaskArray(poptocross.population[0].chromosomerepersentation.length); SingleChromosome parent1 = TournamentSelection(poptocross,103434);//parent 1 //picks the best individual in the population subset of (tournament size) int[] parent1rep= parent1.chromosomerepersentation; while(helper Math.random()&& helper >= 2){ SingleChromosome parent2=poptocross.population[helper]; Random somer= new Random(); int[] parent2rep=parent2.chromosomerepersentation; parent2rep=swapArrayVals(parent2rep, 5, 10, 15); int[] offspring1=new int[parent2rep.length]; // int[] offspring2=new int[parent2rep.length]; //if there is 1 in bitmask gene comes from parent1 if 0 gene comes from parent 2 for(int i=0;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!