Esempio n. 1
0
 public Ant(int initialCity, Graph graph, PheromonMatrix pheromonMatrix, AcoProcessor.AcoParameters parameters)
 {
     _currentCity    = initialCity;
     _graph          = graph;
     _pheromonMatrix = pheromonMatrix;
     _parameters     = parameters;
 }
Esempio n. 2
0
        public double GetShortestPath(AcoParameters parameters, out int[] path)
        {
            _acoParameters = parameters;

            PheromonMatrix pheromonMatrix = new PheromonMatrix(_graph.Size, parameters.pheromonInitial);

            double shortest = Double.PositiveInfinity;

            int[] shortestPath = null;

            for (int i = 0; i < parameters.tMax; i++)
            {
                Ant ant = new Ant(0, _graph, pheromonMatrix, parameters);
                while (ant.CanMove())
                {
                    ant.Move();
                }
                ant.DoPheromon();

                double antPathLen = ant.GetLength();
                if (antPathLen < shortest)
                {
                    shortest     = antPathLen;
                    shortestPath = ant.Path;
                }
            }

            path = shortestPath;

            return(shortest);
        }