public IChromosome Clone() { BitChromosome cpy = new BitChromosome(); cpy.length = this.length; cpy.bits = new Genes.BitGene[cpy.length]; for (int i = 0; i < cpy.length; ++i) cpy.bits[i] = (Genes.BitGene)this.bits[i].Clone(); return (IChromosome)cpy; }
public static ICodec <IImmutableSeq <T>, BitGene> OfSubSet <T>(IImmutableSeq <T> basicSet) { Positive(basicSet.Length); return(Codec.Of( () => Genotype.Of(BitChromosome.Of(basicSet.Length)), gt => ((BitChromosome)gt.GetChromosome()).Ones().Select(i => basicSet[i]).ToImmutableSeq() )); }
public static void Main() { // 1.) Define the genotype (factory) suitable // for the problem. Factory <Genotype <BitGene> > F = delegate() { return(Genotype.Of(BitChromosome.Of(10, 0.5))); }; // 3.) Create the execution environment. var engine = Engine.Engine.Builder(Eval, F).Build(); // 4.) Start the execution (evolution) and // collect the result. var result = engine.Stream().Take(100).ToBestGenotype(); Console.WriteLine("Hello World:\n" + result); }
public static void Main() { var engine = Engine.Engine .Builder( Count, BitChromosome.Of(20, 0.15)) .PopulationSize(500) .Selector(new RouletteWheelSelector <BitGene, int>()) .Alterers( new Mutator <BitGene, int>(0.55), new SinglePointCrossover <BitGene, int>(0.06)) .Build(); var statistics = EvolutionStatistics.OfNumber <int>(); var best = engine.Stream() .TakeWhile(BySteadyFitness <BitGene, int>(7)) .Take(100) .Peek(statistics.Accept) .ToBestPhenotype(); Console.WriteLine(statistics); Console.WriteLine(best); }
public IChromosome GetNewChromosome() { IChromosome ret = new BitChromosome(this.length, new Genes.BitGeneFactory()); return ret; }