Exemplo n.º 1
0
        private void UpdatePheromenes()
        {
            for (int i = 0; i <= pheromones.Length - 1; i++)
            {
                for (int j = i + 1; j <= pheromones[i].Length - 1; j++)
                {
                    for (int k = 0; k <= ants.Length - 1; k++)
                    {
                        // length of ant k trail
                        double decrease = (1.0 - ACOExample.rho) * pheromones[i][j];
                        double increase = 0.0;
                        if (ACOExample.EdgeInTrail(i, j, ants[k]) == true)
                        {
                            double length = ACOExample.Length(ants[k], dists);
                            increase = (ACOExample.Q / length);
                        }

                        pheromones[i][j] = decrease + increase;

                        if (pheromones[i][j] < 0.0001)
                        {
                            pheromones[i][j] = 0.0001;
                        }
                        else if (pheromones[i][j] > 100000.0)
                        {
                            pheromones[i][j] = 100000.0;
                        }

                        pheromones[j][i] = pheromones[i][j];
                    }
                }
            }
        }
Exemplo n.º 2
0
 private double Length(int[] path)
 {
     return(ACOExample.Length(path, dists));
 }