Esempio n. 1
0
        public void OXTest1()
        {
            int populationSize = 120;

            file = root + "\\bays29.xml";
            XDocument           tspFile    = XDocument.Load(file);
            AdjacencyMatrix     testMatrix = new AdjacencyMatrix(tspFile);
            OXCrossover         crossover  = new OXCrossover((float)(1));
            TournamentSelection selector   = new TournamentSelection(5);
            InversionMutation   inv        = new InversionMutation((float)0.05);

            GeneticSolver    solver   = new GeneticSolver(testMatrix, inv, crossover, selector, populationSize, 10);
            List <Candidate> listCand = solver.randomPopulation();
            Candidate        parentX  = listCand[0];
            Candidate        parentY  = listCand[1];

            parentX.chromoson = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9
            };
            parentY.chromoson = new List <int>()
            {
                5, 3, 6, 7, 8, 1, 2, 9, 4,
            };



            crossover.Crossover(parentX, parentY);
        }
Esempio n. 2
0
        public void Should_Perform_Crossover()
        {
            var algorithm = new OXCrossover(1);
            var a         = new Element(new double[] { 0D, 1D, 2D, 3D, 4D, 5D, 6D, 7D, 8D, 9D });
            var b         = new Element(new double[] { 8D, 3D, 2D, 9D, 1D, 0D, 7D, 6D, 5D, 4D });

            algorithm.Crossover(ref a, ref b, 2, 6);

            Assert.Equal(new double[] { 2D, 3D, 4D, 9D, 1D, 0D, 7D, 5D, 6D, 8D }, a.Data);
            Assert.Equal(new double[] { 8D, 2D, 9D, 3D, 4D, 5D, 6D, 1D, 0D, 7D }, b.Data);
        }