Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab1;
- import java.util.List;
- import java.util.Random;
- import org.jgap.Gene;
- import org.jgap.GeneticOperator;
- import org.jgap.IChromosome;
- import org.jgap.InvalidConfigurationException;
- import org.jgap.Population;
- public class SudokuSegmentMutationOperator implements GeneticOperator{
- private static final long serialVersionUID = 1L;
- private int brSegmenta;
- public SudokuSegmentMutationOperator(int brSegm){
- this.brSegmenta = brSegm;
- }
- public SudokuSegmentMutationOperator(){
- }
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override
- public void operate(Population a_population, List a_candidateChromosomes) {
- Random rand = new Random();
- int x = rand.nextInt(9);
- int y = rand.nextInt(9);
- IChromosome tempChrom = a_population.getChromosome(brSegmenta);
- Gene[] genes = tempChrom.getGenes();
- Gene tmpGene = genes[x];
- genes[x] = genes[y];
- genes[y] = tmpGene;
- try {
- tempChrom.setGenes(genes);
- } catch (InvalidConfigurationException e) {
- e.printStackTrace();
- }
- a_candidateChromosomes.add(tempChrom);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment