Examples of Chromosome


Examples of jcgp.backend.population.Chromosome

   *
   */
  @Test
  public void compareTest() {
    // create a clone of the chromosome, compare - should return true
    Chromosome c = new Chromosome(chromosome);
    assertTrue("Chromosomes did not match.", chromosome.compareGenesTo(c));
    assertTrue("Symmetry not obeyed.", c.compareGenesTo(chromosome));

    // create a new random chromosome, this time they should not match
    c = new Chromosome(resources);
    assertTrue("Chromosomes did match.", !chromosome.compareGenesTo(c));
  }
View Full Code Here

Examples of jcgp.backend.population.Chromosome

    resources.setRows(3);
    resources.setInputs(3);
    resources.setOutputs(2);
    resources.setLevelsBack(3);

    Chromosome c = new Chromosome(resources);

    c.getNode(0, 0).initialise(resources.getFunction(0), c.getInput(0), c.getInput(1));
    c.getNode(1, 1).initialise(resources.getFunction(0), c.getNode(0, 0), c.getInput(1));
    c.getNode(1, 2).initialise(resources.getFunction(0), c.getNode(1, 1), c.getInput(2));

    c.getOutput(0).setSource(c.getNode(0, 0));
    c.getOutput(1).setSource(c.getNode(1, 2));
   
    return c;
  }
View Full Code Here

Examples of megamek.client.bot.ga.Chromosome

        }
    }

    // now they have a hard-coded hoard metality
    protected double getFitness(int iChromIndex) {
        Chromosome chrom = this.chromosomes[iChromIndex];
        ArrayList<MoveOption> possible = new ArrayList<MoveOption>();
        for (int iGene = 0; iGene < chromosomeDim; iGene++) {
            possible.add(new MoveOption(
                    this.moves.get(iGene)[chrom.genes[iGene]]));
        }
View Full Code Here

Examples of megamek.client.bot.ga.Chromosome

        }
        return -result + (max - distance_mod);
    }

    public MoveOption getResult() {
        Chromosome r = this.chromosomes[best];
        ArrayList<MoveOption> possible = new ArrayList<MoveOption>();
        for (int iGene = 0; iGene < chromosomeDim; iGene++) {
            possible.add(new MoveOption(this.moves.get(iGene)[r.genes[iGene]]));
        }
        Object[] move_array = possible.toArray();
View Full Code Here

Examples of megamek.client.bot.ga.Chromosome

        }
        return result;
    }

    protected void doRandomMutation(int iChromIndex) {
        Chromosome c1 = this.chromosomes[iChromIndex];
        // I don't think we need to mutate an empty chromosome
        if (c1.genes.length < 1) {
            return;
        }
        int r1 = (c1.genes.length > 2) ? Compute.randomInt(c1.genes.length - 1)
View Full Code Here

Examples of megamek.client.bot.ga.Chromosome

    public double[] getDamageUtilities() {
        int iChromIndex = populationDim - 1;
        targets.clear(); // could use ArrayList and not hashtable
        double[] result = new double[target_array.size()];
        Chromosome chromArrayList = chromosomes[iChromIndex];
        // TODO should account for high heat?
        int heat_total = 0;
        if (chromArrayList.genes[chromosomeDim - 1] >= target_array.size()) {
            chromArrayList.genes[chromosomeDim - 1] = valid_target_indexes.get(
                    0).intValue();
View Full Code Here

Examples of megamek.client.bot.ga.Chromosome

     * but the highest chance of mutation, this is where we use the primary
     * target heuristic to drive convergence
     */
    @Override
    protected void doRandomMutation(int iChromIndex) {
        Chromosome c1 = chromosomes[iChromIndex];
        // skip if it's an empty chromosome
        if (c1.genes.length < 1) {
            return;
        }
        int r1 = (c1.genes.length > 2) ? Compute.randomInt(c1.genes.length - 1)
View Full Code Here

Examples of megamek.client.bot.ga.Chromosome

        // use first weapon target as primary, not smart but good enough...
        AttackOption a = attack.get(0).get(0);
        (chromosomes[0]).genes[chromosomeDim - 1] = a.target.enemy_num;

        for (int i = 1; i < populationDim; i++) {
            Chromosome cv = chromosomes[i];
            for (int iGene = 0; iGene < chromosomeDim - 1; iGene++) {
                cv.genes[iGene] = Compute.randomInt(attack.get(iGene).size());
                if (i <= attack.size()) {
                    if (iGene + 1 == i) {
                        cv.genes[iGene] = 0; // fire
View Full Code Here

Examples of no.uib.jsparklines.data.Chromosome

        int possibleCpt = 0, retainedCpt = 0;

        for (String protein : possibleProteins) {

            String description, geneName, proteinEvidenceLevel;
            Chromosome chromosome;

            try {
                description = sequenceFactory.getHeader(protein).getSimpleProteinDescription();

                // if description is not set, return the accession instead - fix for home made fasta headers
                if (description == null || description.trim().isEmpty()) {
                    description = protein;
                }

                geneName = sequenceFactory.getHeader(protein).getGeneName();
                proteinEvidenceLevel = sequenceFactory.getHeader(protein).getProteinEvidence();

                if (proteinEvidenceLevel != null) {
                    try {
                        Integer level = new Integer(proteinEvidenceLevel);
                        proteinEvidenceLevel = GenePreferences.getProteinEvidencAsString(level);
                    } catch (NumberFormatException e) {
                        // ignore
                    }
                }

                String chromosomeNumber = geneFactory.getChromosomeForGeneName(geneName);
                chromosome = new Chromosome(chromosomeNumber);

            } catch (Exception e) {
                peptideShakerGUI.catchException(e);
                description = "Error";
                geneName = "Error";
View Full Code Here

Examples of org.apache.commons.math3.genetics.Chromosome

           
            int generation = 0;
           
            @Override
            public boolean isSatisfied(Population population) {
                Chromosome fittestChromosome = population.getFittestChromosome();
               
                if (generation == 1 || generation % 10 == 0) {
                    System.out.println("Generation " + generation + ": " + fittestChromosome.toString());
                }
                generation++;

                double fitness = fittestChromosome.fitness();
                if (Precision.equals(fitness, 0.0, 1e-6)) {
                    return true;
                } else {
                    return false;
                }
            }
        };

        System.out.println("Starting evolution ...");
       
        // run the algorithm
        Population finalPopulation = ga.evolve(initial, stoppingCondition);

        // Get the end time for the simulation.
        long endTime = System.currentTimeMillis();

        // best chromosome from the final population
        Chromosome best = finalPopulation.getFittestChromosome();
        System.out.println("Generation " + ga.getGenerationsEvolved() + ": " + best.toString());
        System.out.println("Total execution time: " + (endTime - startTime) + "ms");
  }
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.