Ejemplo n.º 1
0
        private Tour findReplacement(Tour Next, Tour Prev)
        {
            Tour B = new Tour();
            int  k, p;

            for (int i = 0; i < Prev.Count; i++)
            {
                k = Next.IndexOf(Prev[i]);
                p = k;
                if (k == numberOfCities - 1)
                {
                    p = 0;
                }
                else
                {
                    p += 1;
                }
                if (i != Next.Count - 1)
                {
                    if (Next[p] != Prev[i + 1])
                    {
                        B.Add(Next[p]);
                    }
                }
                else
                {
                    if (Next[p] != Prev[0])
                    {
                        B.Add(Next[p]);
                    }
                }
            }
            return(B);
        }
Ejemplo n.º 2
0
        private void DrawTour(Tour whatsNew)
        {
            Image    cityImage = new Bitmap(tourDiagram.Width, tourDiagram.Height);
            Graphics graphics  = Graphics.FromImage(cityImage);

            for (int i = 0; i < numberOfCities; i++)
            {
                graphics.DrawEllipse(Pens.Black, citiesPositions[i, 0] / citiesPositionsToGuiRatio - 2, citiesPositions[i, 1] / citiesPositionsToGuiRatio - 2, 4, 4);
            }
            Pen Color = Pens.Black;

            for (int i = 0; i < globalTour.Count - 1; i++)
            {
                if (whatsNew.Count > 0)
                {
                    if (whatsNew.IndexOf(globalTour[i + 1]) != -1)
                    {
                        Color = Pens.Red;
                    }
                    else
                    {
                        Color = Pens.Black;
                    }
                }
                graphics.DrawLine(Color, citiesPositions[globalTour[i], 0] / citiesPositionsToGuiRatio, citiesPositions[globalTour[i], 1] / citiesPositionsToGuiRatio,
                                  citiesPositions[globalTour[i + 1], 0] / citiesPositionsToGuiRatio, citiesPositions[globalTour[i + 1], 1] / citiesPositionsToGuiRatio);
            }
            if (whatsNew.Count > 0)
            {
                if (whatsNew.IndexOf(globalTour[0]) != -1)
                {
                    Color = Pens.Red;
                }
                else
                {
                    Color = Pens.Black;
                }
            }
            graphics.DrawLine(Color, citiesPositions[globalTour[0], 0] / citiesPositionsToGuiRatio,
                              citiesPositions[globalTour[0], 1] / citiesPositionsToGuiRatio,
                              citiesPositions[globalTour[globalTour.Count - 1], 0] / citiesPositionsToGuiRatio,
                              citiesPositions[globalTour[globalTour.Count - 1], 1] / citiesPositionsToGuiRatio);
            tourDiagram.BeginInvoke(new MethodInvoker(() =>
            {
                tourDiagram.Image = cityImage;
            }));
        }
Ejemplo n.º 3
0
        private Tour WhatChanged(Tour B)
        {
            Tour C = new Tour();

            for (int i = 0; i < globalTour.Count; i++)
            {
                int next;
                if (i < globalTour.Count - 1)
                {
                    next = globalTour[i + 1];
                }
                else
                {
                    next = globalTour[0];
                }
                int where = B.IndexOf(globalTour[i]);
            }

            return(C);
        }