Пример #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>();
        }
        public EvolutionaryAlgorithmController()
        {
            randomRouteGenerator = new RandomRouteGenerator();
            routeEvaluator       = new RouteEvaluator();
            parentSelection      = new ParentSelection();
            parentSelection      = new ParentSelection();
            mutation             = new Mutation();
            random = new Random();

            parentPopulation      = new List <Route>();
            offspringPopulation   = new List <Route>();
            BestRouteInGeneration = new Dictionary <int, Route>();
        }
Пример #4
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);
        }
Пример #5
0
        public void ConstructGreedyRoute(Graph graph, RouteEvaluator routeEvaluator)
        {
            int startEndCity = InitialiseFirstCity(graph);

            while (CurrentRoute.Count <= graph.GraphOfNodes.Count)
            {
                CurrentRoute.Add(graph.GetClosestCity(CurrentRoute.Count - 1, VisitedCities));
            }

            CurrentRoute.Add(startEndCity);
            int[] CurrentRouteArray = CurrentRoute.ToArray();

            double routeCost = routeEvaluator.CalculateCostOfSingleRoute(CurrentRouteArray, graph);

            AntRoute = new Route(CurrentRouteArray, routeCost);
        }
Пример #6
0
 public TimeBasedEvaluator()
 {
     this.randomRouteGenerator = new RandomRouteGenerator();
     this.routeEvaluator       = new RouteEvaluator();
 }
Пример #7
0
 public LocalSearch()
 {
     routeEvaluator = new RouteEvaluator();
     tourFormatter  = new TourFormatter();
 }