Package org.jgap

Examples of org.jgap.IChromosome


      {
        for (int i = 0; i < arg0.size(); i++)
        {
          if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
            continue;
          IChromosome chromosome = (IChromosome) ((ICloneable) arg0.getChromosome(i)).clone();
          Gene[] beforeArray = chromosome.getGenes();
          for (int j = (int) (Math.random() * beforeArray.length); j < beforeArray.length - 1; j++)
            beforeArray[j] = beforeArray[j + 1];
          try
          {
            chromosome.setGenes(beforeArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
View Full Code Here


      @Override
      public void operate(Population arg0, List arg1)
      {
        if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
          return;
        IChromosome best = arg0.determineFittestChromosome();
        for (int i = 0; i < best.getGenes().length; i++)
        {
          IChromosome chromosome = (IChromosome) ((ICloneable) best).clone();
          Gene[] beforeArray = chromosome.getGenes();
          for (int j = (int) i; j < beforeArray.length - 1; j++)
            beforeArray[j].setAllele(beforeArray[j + 1].getAllele());
          try
          {
            chromosome.setGenes(beforeArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      @Override
      public void operate(Population arg0, List arg1)
      {
        if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
          return;
        IChromosome best = arg0.determineFittestChromosome();
       
        // TODO expects that there is ALWAYS an overlord action which won't work for other races. But then, this is the Overlording action.
        int overlord = actions.indexOf(EcActionBuildOverlord.class);     
       
        for (int i = 0; i < best.getGenes().length; i++)
        {
          IChromosome chromosome = (IChromosome) ((ICloneable) best).clone();
          Gene[] beforeArray = chromosome.getGenes();
          beforeArray[i].setAllele(overlord);
          try
          {
            chromosome.setGenes(beforeArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      {
        for (int i = 0; i < arg0.size(); i++)
        {
          if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
            continue;
          IChromosome chromosome = (IChromosome) ((ICloneable) arg0.getChromosome(i)).clone();
          Gene[] beforeArray = chromosome.getGenes();
          int randomPoint = (int) (Math.random() * beforeArray.length);
          for (int j = randomPoint; j < beforeArray.length - 1; j++)
            beforeArray[j + 1] = beforeArray[j];
          beforeArray[randomPoint].setAllele((int) (Math.random() * ((IntegerGene) chromosome
              .getGene(randomPoint)).getUpperBounds()));
          try
          {
            chromosome.setGenes(beforeArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      {
        for (int i = 0; i < arg0.size(); i++)
        {
        if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
          continue;
          IChromosome chromosome = arg0.getChromosome(i);
          Gene[] beforeArray = chromosome.getGenes();
          Gene[] afterArray = new Gene[beforeArray.length + 1];
          for (int j = 0; j < beforeArray.length; j++)
            afterArray[j] = beforeArray[j];
          afterArray[afterArray.length - 1] = afterArray[0].newGene();
          try
          {
            chromosome.setGenes(afterArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            logger.severe(sw.toString());
          }
        }
        IChromosome chromosome = arg0.getConfiguration().getSampleChromosome();
        Gene[] beforeArray = chromosome.getGenes();
        Gene[] afterArray = new Gene[beforeArray.length + 1];
        for (int j = 0; j < beforeArray.length; j++)
          afterArray[j] = beforeArray[j];
        afterArray[afterArray.length - 1] = afterArray[0].newGene();
        try
        {
          chromosome.setGenes(afterArray);
        }
        catch (InvalidConfigurationException e)
        {
          StringWriter sw = new StringWriter();
          e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      {
        if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
          return;
        for (int i = 0; i < arg0.size(); i++)
        {
          IChromosome chromosome = arg0.getChromosome(i);
          Gene[] beforeArray = chromosome.getGenes();
          Gene[] afterArray = new Gene[beforeArray.length - 1];
          for (int j = 0; j < afterArray.length; j++)
            afterArray[j] = beforeArray[j];
          try
          {
            chromosome.setGenes(afterArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            logger.severe(sw.toString());
          }
        }
        IChromosome chromosome = arg0.getConfiguration().getSampleChromosome();
        Gene[] beforeArray = chromosome.getGenes();
        Gene[] afterArray = new Gene[beforeArray.length - 1];
        for (int j = 0; j < afterArray.length; j++)
          afterArray[j] = beforeArray[j];
        try
        {
          chromosome.setGenes(afterArray);
        }
        catch (InvalidConfigurationException e)
        {
          StringWriter sw = new StringWriter();
          e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      {
        for (int i = 0; i < arg0.size(); i++)
        {
          if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
            continue;
          IChromosome chromosome = (IChromosome) ((ICloneable) arg0.getChromosome(i)).clone();
          Gene[] beforeArray = chromosome.getGenes();
          int randomPoint = (int) (Math.random() * beforeArray.length);
          int randomPoint2 = (int) (Math.random() * beforeArray.length);
          Gene swap = beforeArray[randomPoint];
          beforeArray[randomPoint] = beforeArray[randomPoint2];
          beforeArray[randomPoint2] = swap;
          try
          {
            chromosome.setGenes(beforeArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      {
        for (int i = 0; i < arg0.size(); i++)
        {
          if (Math.random() > c.getBaseMutationRate()/c.getChromosomeLength())
            continue;
          IChromosome chromosome = (IChromosome) ((ICloneable) arg0.getChromosome(i)).clone();
          Gene[] beforeArray = chromosome.getGenes();
          int randomPoint = (int) (Math.random() * beforeArray.length);
          if (randomPoint < beforeArray.length - 1)
          {
            Gene swap = beforeArray[randomPoint];
            beforeArray[randomPoint] = beforeArray[randomPoint + 1];
            beforeArray[randomPoint + 1] = swap;
          }
          try
          {
            chromosome.setGenes(beforeArray);
          }
          catch (InvalidConfigurationException e)
          {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
View Full Code Here

      {
        Collections.shuffle(conf.getGeneticOperators());
        BASE_MUTATION_RATE += .001;
        if (BASE_MUTATION_RATE >= (double) CHROMOSOME_LENGTH / 2.0 )
          BASE_MUTATION_RATE = 1;
        IChromosome fittestChromosome = population.getFittestChromosome();
        if (killThreads)
        {
          threads.remove(thread);
          thread.interrupt();
        }
        double fitnessValue = fittestChromosome.getFitnessValue();
        if (fitnessValue > bestScores[threadIndex])
        {
          bestScores[threadIndex] = fitnessValue;
          evolutionsSinceDiscovery[threadIndex] = 0;
          BASE_MUTATION_RATE = 1;
View Full Code Here

    gaConf.setPreservFittestIndividual(true);

               
    GeneFactory gf = new GeneFactory(geneType, in.getSize());
   
    IChromosome sampleChromosome = new Chromosome(gaConf, gf.getInstance(gaConf),
          chromesize);
   
               
    gaConf.setSampleChromosome(sampleChromosome);
    gaConf.setPopulationSize(popsize);
View Full Code Here

TOP

Related Classes of org.jgap.IChromosome

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.