public void CrossingoverTest()
 {
     CyclicalCrossingover target = new CyclicalCrossingover();
     target.Crossingover(_parent1, _parent2, _child1, _child2);
     Assert.IsTrue(TwoIntArrayEquals(_child1.Genotype, _equalChild1));
     Assert.IsTrue(TwoIntArrayEquals(_child2.Genotype, _equalChild2));
     Assert.IsFalse(TwoIntArrayEquals(_child1.Genotype, _child2.Genotype));
     Assert.IsTrue(IsItemsUnique(_child1.Genotype));
     Assert.IsTrue(IsItemsUnique(_child2.Genotype));
 }
示例#2
0
        public Configuration()
        {
            AliasCrossingover = new List<string>();
            AliasMutations = new List<string>();
            AliasSelection = new List<string>();

            ConfigName = "Новая конфигурация";
            AlgMode = AlgorithmMode.Singl;
            CountOfReplays = 1;
            ProbOfCrossingover = 100;
            ProbOfMutation = 100;
            FitnessParam = 10;
            Mutation = new NotRandomMutation();
            AliasMutations.Add(Mutation.GetName());
            Crossingover = new CyclicalCrossingover();
            AliasCrossingover.Add(Crossingover.GetName());
            Selection = new TournamentSelection();
            AliasSelection.Add(Selection.GetName());
            Graph = new UndirectedConnectedGraph(10);
            FitnessFunction = new BestReps((int)FitnessParam);
            Tracks = new AbstractTrack[10];
            Random r = new Random();
            for (int i = 0; i < Tracks.Length; i++)
            {
                int[] points = new int[10];
                for (int j = 0; j < points.Length; j++)
                {
                    points[j] = -1;
                }
                int newRandomChromosome = r.Next(points.Length - 1);
                for (int j = 0; j < points.Length; j++)
                {
                    while (points.Contains(newRandomChromosome))
                    {
                        newRandomChromosome = r.Next(points.Length);
                    }
                    points[j] = newRandomChromosome;
                }
                Tracks[i] = new ClosedTrack(points, Graph);
            }
        }