Пример #1
0
        private int ChooseNextCityToVisit(PheromoneLookup pheromoneLookup, RouteEvaluator routeEvaluator, Graph graph)
        {
            int           currentCity       = CurrentRoute.Last();
            List <double> componentProducts = new List <double>();
            List <int>    citiesBeingConsideredToTravelTo = new List <int>();

            for (int cityToConsiderTravellingTo = 1; cityToConsiderTravellingTo <= graph.GraphOfNodes.Count; cityToConsiderTravellingTo++)
            {
                if (VisitedCities.Contains(cityToConsiderTravellingTo))
                {
                    continue;
                }
                citiesBeingConsideredToTravelTo.Add(cityToConsiderTravellingTo);

                double pheremoneOnEdge    = pheromoneLookup.GetPheromoneLevelForEdge(new int[] { currentCity, cityToConsiderTravellingTo });
                double pheremoneComponent = Math.Pow(pheromoneLookup.GetPheromoneLevelForEdge(new int[] { currentCity, cityToConsiderTravellingTo }), ACOConstants.ALPHA_PHEROMONE_IMPORTANCE);
                double edgeComponent      = Math.Pow(routeEvaluator.CalculateCostOfEdge(new int[] { currentCity, cityToConsiderTravellingTo }, graph), ACOConstants.BETA_EDGE_IMPORTANCE);

                componentProducts.Add(pheremoneComponent * edgeComponent);
            }

            componentProducts = SumComponentProductsCumulatively(componentProducts);

            int cityToMoveTo = PickCityBasedOnComponents(componentProducts, citiesBeingConsideredToTravelTo);

            return(cityToMoveTo);
        }
Пример #2
0
        public ACOController()
        {
            BestRouteInGeneration = new Dictionary <int, Route>();

            pheromoneLookup = new PheromoneLookup();
            routeEvaluator  = new RouteEvaluator();
            antPopulation   = new List <Ant>();
        }
Пример #3
0
        public Route WalkRoute(PheromoneLookup pheromoneLookup, RouteEvaluator routeEvaluator, Graph graph)
        {
            int startEndCity = InitialiseFirstCity(graph);

            while (CurrentRoute.Count <= graph.GraphOfNodes.Count - 1)
            {
                int city = ChooseNextCityToVisit(pheromoneLookup, routeEvaluator, graph);
                CurrentRoute.Add(city);
                VisitedCities.Add(city);
            }

            CurrentRoute.Add(startEndCity);

            AntRoute = new Route(CurrentRoute.ToArray(), double.MaxValue);
            return(AntRoute);
        }