/** * Return a new, random genotype by creating new, random chromosomes (calling * the {@link Chromosome#newInstance()} method) from the chromosomes of this * genotype. */ @Override public Genotype<G> newInstance() { return new Genotype<>(_chromosomes.map(Factory::newInstance)); }
/** * Create a new {@code Genotype} from a given array of {@code chromosomes}. * * @since 3.0 * * @param <G> the gene type * @param chromosomes the {@code Chromosome}s the returned genotype consists * of * @return a new {@code Genotype} from the given chromosomes * @throws NullPointerException if {@code chromosomes} is {@code null} or * one of its element. * @throws IllegalArgumentException if {@code chromosome.length() < 1}. */ public static <G extends Gene<?, G>> Genotype<G> of(final Iterable<? extends Chromosome<G>> chromosomes) { return new Genotype<>(ISeq.of(chromosomes)); }
/** * Create a new {@code Genotype} which consists of {@code n} chromosomes, * which are created by the given {@code factory}. This method can be used * for easily creating a <i>gene matrix</i>. The following example will * create a 10x5 {@code DoubleGene} <i>matrix</i>. * * <pre>{@code * final Genotype<DoubleGene> gt = Genotype * .of(DoubleChromosome.of(0.0, 1.0, 10), 5); * }</pre> * * @since 3.0 * * @param <G> the gene type * @param factory the factory which creates the chromosomes this genotype * consists of * @param n the number of chromosomes this genotype consists of * @return new {@code Genotype} containing {@code n} chromosomes * @throws IllegalArgumentException if {@code n < 1}. * @throws NullPointerException if the {@code factory} is {@code null}. */ public static <G extends Gene<?, G>> Genotype<G> of(final Factory<? extends Chromosome<G>> factory, final int n) { final ISeq<Chromosome<G>> ch = ISeq.of(factory::newInstance, n); return new Genotype<>(ch); }
public static Genotype<DoubleGene> nextGenotypeDoubleGene() { return new Genotype<>(ISeq.of(PersistentObject::nextDoubleChromosome, 5)); }
public static Genotype<EnumGene<Short>> nextGenotypeEnumGeneShort() { return new Genotype<>(ISeq.of(PersistentObject::nextShortPermutationChromosome, 5)); }
public static Genotype<EnumGene<String>> nextGenotypeEnumGeneString() { return new Genotype<>(ISeq.of(PersistentObject::nextStringPermutationChromosome, 5)); }
public static Genotype<LongGene> nextGenotypeLongGene() { return new Genotype<>(ISeq.of(PersistentObject::nextLongChromosome, 5)); }
public static Genotype<EnumGene<Byte>> nextGenotypeEnumGeneByte() { return new Genotype<>(ISeq.of(PersistentObject::nextBytePermutationChromosome, 5)); }
public static Genotype<BitGene> nextGenotypeBitGene() { return new Genotype<>(ISeq.of(PersistentObject::nextBitChromosome, 5)); }
public static Genotype<CharacterGene> nextGenotypeCharacterGene() { return new Genotype<>(ISeq.of(PersistentObject::nextCharacterChromosome, 5)); }
public static Genotype<EnumGene<Long>> nextGenotypeEnumGeneLong() { return new Genotype<>(ISeq.of(PersistentObject::nextLongPermutationChromosome, 5)); }
public static Genotype<EnumGene<Float>> nextGenotypeEnumGeneFloat() { return new Genotype<>(ISeq.of(PersistentObject::nextFloatPermutationChromosome, 5)); }
public static Genotype<IntegerGene> nextGenotypeIntegerGene() { return new Genotype<>(ISeq.of(PersistentObject::nextIntegerChromosome, 5)); }
public static Genotype<EnumGene<Character>> nextGenotypeEnumGeneCharacter() { return new Genotype<>(ISeq.of(PersistentObject::nextCharacterPermutationChromosome, 5)); }
public static Genotype<EnumGene<Integer>> nextGenotypeEnumGeneInteger() { return new Genotype<>(ISeq.of(PersistentObject::nextIntegerPermutationChromosome, 5)); }
public static Genotype<EnumGene<Double>> nextGenotypeEnumGeneDouble() { return new Genotype<>(ISeq.of(PersistentObject::nextDoublePermutationChromosome, 5)); }
/** * Create a new {@code Genotype} from a given array of {@code Chromosomes}. * * @since 3.0 * * @param <G> the gene type * @param first the first {@code Chromosome} of the {@code Genotype} * @param rest the rest of the genotypes chromosomes. * @return a new {@code Genotype} from the given chromosomes * @throws NullPointerException if {@code chromosomes} is {@code null} or * one of its element. */ @SafeVarargs public static <G extends Gene<?, G>> Genotype<G> of( final Chromosome<G> first, final Chromosome<G>... rest ) { final MSeq<Chromosome<G>> seq = MSeq.ofLength(1 + rest.length); seq.set(0, first); for (int i = 0; i < rest.length; ++i) { seq.set(i + 1, rest[i]); } return new Genotype<>(seq.toISeq()); }
public static ISeq<Phenotype<EnumGene<Double>, Double>> newPermutationDoubleGenePopulation( final int ngenes, final int nchromosomes, final int npopulation ) { final Random random = new Random(122343); final MSeq<Double> alleles = MSeq.ofLength(ngenes); for (int i = 0; i < ngenes; ++i) { alleles.set(i, random.nextDouble()*10); } final ISeq<Double> ialleles = alleles.toISeq(); final MSeq<PermutationChromosome<Double>> chromosomes = MSeq.ofLength(nchromosomes); for (int i = 0; i < nchromosomes; ++i) { chromosomes.set(i, PermutationChromosome.of(ialleles)); } final Genotype<EnumGene<Double>> genotype = new Genotype<>(chromosomes.toISeq()); final MSeq<Phenotype<EnumGene<Double>, Double>> population = MSeq.ofLength(npopulation); for (int i = 0; i < npopulation; ++i) { population.set(i, Phenotype.of(genotype.newInstance(), 0, PFF)); } return population.toISeq(); }
public static ISeq<Phenotype<DoubleGene, Double>> population( final int ngenes, final int nchromosomes, final int npopulation ) { final MSeq<DoubleChromosome> chromosomes = MSeq.ofLength(nchromosomes); for (int i = 0; i < nchromosomes; ++i) { chromosomes.set(i, DoubleChromosome.of(0, 10, ngenes)); } final Genotype<DoubleGene> genotype = new Genotype<>(chromosomes.toISeq()); final MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(npopulation); for (int i = 0; i < npopulation; ++i) { population.set(i, Phenotype.of(genotype.newInstance(), 0, TestUtils.FF)); } return population.toISeq(); }
/** * Create a population of DoubleGenes */ public static ISeq<Phenotype<DoubleGene, Double>> newDoubleGenePopulation( final int ngenes, final int nchromosomes, final int npopulation ) { final MSeq<DoubleChromosome> chromosomes = MSeq.ofLength(nchromosomes); for (int i = 0; i < nchromosomes; ++i) { chromosomes.set(i, DoubleChromosome.of(0, 10, ngenes)); } final Genotype<DoubleGene> genotype = new Genotype<>(chromosomes.toISeq()); final MSeq<Phenotype<DoubleGene, Double>> population = MSeq.ofLength(npopulation); for (int i = 0; i < npopulation; ++i) { population.set(i, Phenotype.of(genotype.newInstance(), 0, FF).evaluate()); } return population.toISeq(); }