Example #1
0
        private void Start(int numberOfAnts, int numberOfIterations)
        {
            List <Ant> antColony = AntColonyManager.CreateAntColony(numberOfAnts, MatrixSize, RandomGenerator);

            for (int iterationCounter = 0; iterationCounter < numberOfIterations; iterationCounter++)
            {
                for (int visitedCityCounter = 0; visitedCityCounter < MatrixSize; visitedCityCounter++)
                {
                    for (int antCounter = 0; antCounter < numberOfAnts; antCounter++)
                    {
                        int nextCityIDForCurrentAnt;
                        if (visitedCityCounter == (MatrixSize - 1))
                        {
                            nextCityIDForCurrentAnt = antColony[antCounter].visitedCitiesIdList.First();
                        }
                        else
                        {
                            var probabilityList = CalculateNextCitiesProbability(antColony[antCounter]);
                            nextCityIDForCurrentAnt = ChooseNextCityForAnt(antColony[antCounter], probabilityList);
                        }
                        MoveAntToNextCity(antColony[antCounter], nextCityIDForCurrentAnt);
                    }
                    PheromoneMatrixManager.UpdatePhermoneMatrixByEvaporation(PheromoneMatrix, EvaporationValue);
                }
                CheckIfBetterSolutionWasFound(antColony, iterationCounter);
                AntColonyManager.ResetAntColonyMemory(antColony, MatrixSize, RandomGenerator);
            }
        }
Example #2
0
        private void GeneratePrerequisite(string fileName)
        {
            var fileReader = new FileReader(fileName);

            DistanceMatrix  = fileReader.CreateDistanceMatrix();
            MatrixSize      = fileReader.GetMatrixSize();
            PheromoneMatrix = PheromoneMatrixManager.CreatePhermoneMatrix(MatrixSize, StartingPheromoneValue);
            BestFoundRoute  = new List <int>();
        }