Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void run(I ind) {
- /*
- for (int i = 0; i <ind.getNumGenes() ; i++) {
- if(GeneticAlgorithm.random.nextDouble()<probability){
- ind.swapGenes(ind,i);
- }
- }*/
- /** Swap Mutation
- In swap mutation, we select two positions on the genome at random,
- and interchange the values.
- **/
- if(GeneticAlgorithm.random.nextDouble()<=probability) {
- int p1 = GeneticAlgorithm.random.nextInt(ind.getGenome().length);
- int p2;
- do{
- p2= GeneticAlgorithm.random.nextInt(ind.getGenome().length);
- }while(p2==p1);
- System.out.println(p1+" "+p2);
- ind.swapGenesMutation(ind, p1, p2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement