// the local pheromone update is done after each step (each ant one city step) private void LocalPheromoneUpdate(int antIndex, int currentCityAmount) { int prevCity = Ants[antIndex].GetCityOfTour(currentCityAmount - 1); int currentCity = Ants[antIndex].GetCityOfTour(currentCityAmount); Pheromones.SetPheromone(prevCity, currentCity, ((1.0f - rho) * Pheromones.GetPheromone(prevCity, currentCity)) + (rho * tau0)); Pheromones.SetPheromone(currentCity, prevCity, Pheromones.GetPheromone(prevCity, currentCity)); choiceInfo.SetChoice(prevCity, currentCity, Math.Pow(Pheromones.GetPheromone(prevCity, currentCity), alpha) * Math.Pow((1.0 / Distances.GetDistance(prevCity, currentCity)), beta)); choiceInfo.SetChoice(currentCity, prevCity, choiceInfo.GetChoice(prevCity, currentCity)); }
// choice update public void UpdateChoiceInfo(Pheromones pheromones, Distances distances, int alpha, int beta) { for (int i = 0; i < size; i++) { for (int j = i + 1; j < size; j++) { choiceInfo[i][j] = Math.Pow(pheromones.GetPheromone(i, j), alpha) * Math.Pow((1.0 / distances.GetDistance(i, j)), beta); choiceInfo[j][i] = choiceInfo[i][j]; /* // To avoid small or high values * if (choiceInfo[i][j] <= 0.000001) * choiceInfo[i][j] = 0.000001; * else if (choiceInfo[i][j] > (double.MaxValue / 100)) * choiceInfo[i][j] = double.MaxValue / 100; */ } } }