public List <Route> RunRecombination(Route parentOne, Route parentTwo)
        {
            if (random.NextDouble() < EvolutionaryAlgorithmConstants.RECOMBINATION_PROBABILITY)
            {
                return(new List <Route>()
                {
                    parentOne, parentTwo
                });
            }

            List <Route> offspring = new List <Route>
            {
                OrderOneCrossover(
                    tourFormatter.RemoveStartAndEndNodeToRoute(parentOne.RouteIds),
                    tourFormatter.RemoveStartAndEndNodeToRoute(parentTwo.RouteIds),
                    parentOne.RouteIds.First()),

                OrderOneCrossover(
                    tourFormatter.RemoveStartAndEndNodeToRoute(parentTwo.RouteIds),
                    tourFormatter.RemoveStartAndEndNodeToRoute(parentOne.RouteIds),
                    parentOne.RouteIds.First())
            };

            return(offspring);
        }
Пример #2
0
        private List <int[]> GetAllTwoOptNeighbourhoods(int[] initialRoute)
        {
            List <int[]> listOfNeighbourhoods = new List <int[]>();

            int[] formatedRoute = tourFormatter.RemoveStartAndEndNodeToRoute(initialRoute);

            for (int index = 0; index <= formatedRoute.Length - 2; index++)
            {
                for (int secondIndex = index + 1; secondIndex <= formatedRoute.Length - 1; secondIndex++)
                {
                    int[] swappedRoute = TwoOptSwap(formatedRoute, index, secondIndex);
                    listOfNeighbourhoods.Add(tourFormatter.AddStartAndEndNodeToRoute(initialRoute[0], swappedRoute));
                }
            }
            return(listOfNeighbourhoods);
        }