Example #1
0
        public static void Main()
        {
            //RandomRegistry.SetRandom(new io.jenetics.prngine.LCG64ShiftRandom.ThreadLocal());
            var engine = Engine.Engine
                         .Builder(
                Length,
                PermutationChromosome.OfInteger(20))
                         .Optimize(Optimize.Minimum)
                         .PopulationSize(1000)
                         .OffspringFraction(0.9)
                         .Alterers(
                new SwapMutator <EnumGene <int>, int>(0.01),
                new PartiallyMatchedCrossover <int, int>(0.3))
                         .Build();


            var statistics = EvolutionStatistics.OfNumber <int>();

            var result = engine.Stream()
                         .TakeWhile(Limits.BySteadyFitness <EnumGene <int>, int>(100))
                         .Take(2500)
                         .Peek(statistics.Accept)
                         .ToBestEvolutionResult();

            Console.WriteLine(statistics);
            Console.WriteLine(result.GetBestPhenotype());
        }
Example #2
0
        public static void Main()
        {
            //SubsetSum problem = Of(500, 15, new LCG64ShiftRandom(101010));
            var problem = Of(500, 15, new Random());

            var engine = Engine.Engine.Builder(problem)
                         .Minimizing()
                         .MaximalPhenotypeAge(5)
                         .Alterers(
                new PartiallyMatchedCrossover <int, int>(0.4),
                new Mutator <EnumGene <int>, int>(0.3))
                         .Build();

            var result = engine.Stream()
                         .TakeWhile(Limits.BySteadyFitness <EnumGene <int>, int>(55))
                         .ToBestPhenotype();

            Console.WriteLine(result);
        }
Example #3
0
        public static void Main()
        {
            var rescue = Engine.Stream()
                         .TakeWhile(Limits.BySteadyFitness <DoubleGene, double>(10))
                         .ToBestEvolutionResult();

            using (var stream = new MemoryStream())
            {
                IFormatter formatter = new BinaryFormatter();
                formatter.Serialize(stream, rescue);
                File.WriteAllBytes("result.bin", stream.ToArray());
            }

            using (var stream = File.OpenRead("result.bin"))
            {
                IFormatter formatter = new BinaryFormatter();
                var        result    = Engine
                                       .Stream((EvolutionResult <DoubleGene, double>)formatter.Deserialize(stream))
                                       .TakeWhile(Limits.BySteadyFitness <DoubleGene, double>(20))
                                       .ToBestEvolutionResult();

                Console.WriteLine(result);
            }
        }