Examples of IChromosome


Examples of forestry.api.genetics.IChromosome

          throw new RuntimeException("Found Chromosome with invalid Alleles. See config option \"genetics.clear.invalid.chromosomes\".");
      }
    }

    // handle old saves that have missing chromosomes
    IChromosome speciesChromosome = chromosomes[EnumTreeChromosome.SPECIES.ordinal()];
    if (speciesChromosome != null) {
      IAlleleSpecies species = (IAlleleSpecies)speciesChromosome.getActiveAllele();
      IAllele[] template = getSpeciesRoot().getTemplate(species.getUID());
      for (int i = 0; i < chromosomes.length; i++) {
        if ((chromosomes[i] == null) && (template[i] != null))
          chromosomes[i] = new Chromosome(template[i]);
      }
View Full Code Here

Examples of forestry.api.genetics.IChromosome

    IChromosome[] genetics = other.getChromosomes();
    if (chromosomes.length != genetics.length)
      return false;

    for (int i = 0; i < chromosomes.length; i++) {
      IChromosome chromosome = chromosomes[i];
      if (chromosome == null && genetics[i] != null)
        return false;
      if (chromosome != null && genetics[i] == null)
        return false;
      if (chromosome == null && genetics[i] == null)
        continue;

      if (!chromosome.getPrimaryAllele().getUID().equals(genetics[i].getPrimaryAllele().getUID()))
        return false;
      if (!chromosome.getSecondaryAllele().getUID().equals(genetics[i].getSecondaryAllele().getUID()))
        return false;
    }

    return true;
  }
View Full Code Here

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

Examples of org.jgap.IChromosome

      @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

Examples of org.jgap.IChromosome

      @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

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();
          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

Examples of org.jgap.IChromosome

      {
        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

Examples of org.jgap.IChromosome

      {
        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

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();
          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

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();
          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
TOP
Copyright © 2018 www.massapi.com. 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.