Exemplo n.º 1
0
 public void deleteTabuEdge(AntEdge path, int edge)
 {
     if (TabuList.Contains(edge))
     {
         SumOfPathLength -= path.PathLength;
     }
     TabuList.Remove(edge);
 }
Exemplo n.º 2
0
        public Colony(int amountOfVertex, int amountOfAnts)
        {
            SCALE_NUM = 1;
            for (int i = 0; i < SCALE; i++)
            {
                SCALE_NUM *= 10;
            }
            EPS            = (1.0 / SCALE_NUM) * 10;
            isBestChanged  = false;
            amountOfVertex = Math.Min(amountOfVertex, MAX_VERTEXES);
            amountOfAnts   = Math.Min(amountOfAnts, MAX_ANTS);
            MAX_TOURS      = MAX_ANTS * MAX_DISTANCE;
            best           = MAX_TOURS;
            MAX_TIME       = MAX_VERTEXES * MAX_TOURS;
            edges          = new AntEdge[amountOfVertex, amountOfVertex];
            vertexes       = new List <Vertex>();
            Random rand = new Random();

            for (int i = 0; i < amountOfVertex; i++)
            {
                vertexes.Add(new Vertex((int)(rand.NextDouble() * MAX_DISTANCE), (int)(rand.NextDouble() * MAX_DISTANCE), names[i]));
            }
            INIT_PHEROMONE = (1.0 / vertexes.Count);
            for (int from = 0; from < amountOfVertex; from++)
            {
                for (int to = 0; to < amountOfVertex; to++)
                {
                    if (from == to)
                    {
                        edges[from, to] = null;
                    }
                    else
                    if (edges[from, to] == null || edges[from, to].PathLength == 0)
                    {
                        int xd = Math.Abs(vertexes[from].X - vertexes[to].X);
                        int yd = Math.Abs(vertexes[from].Y - vertexes[to].Y);
                        edges[from, to] = new AntEdge(Math.Round(Math.Pow(xd * xd + yd * yd, (1.0 / 2.0)) * SCALE_NUM) / SCALE_NUM, INIT_PHEROMONE);
                        edges[to, from] = new AntEdge(edges[from, to]);
                    }
                }
            }
            ants = new List <Ant>();
            int vertexIndex = 0;

            for (int i = 0; i < amountOfAnts; i++)
            {
                if (vertexIndex >= vertexes.Count)
                {
                    vertexIndex = 0;
                }
                ants.Add(new Ant(vertexIndex++));
            }
            showVertexesMatrix();
        }
Exemplo n.º 3
0
 public void addTabuEdge(AntEdge path, int edge)
 {
     if (!TabuList.Contains(edge))
     {
         TabuList.Add(edge);
         SumOfPathLength += path.PathLength;
         recentPathLength = path.PathLength;
         AllEdgesValues.Add(recentPathLength);
         CurVertex = edge;
     }
 }