コード例 #1
0
ファイル: TspForm.cs プロジェクト: michaeloed/mgmgeo
        /// <summary>
        /// A new "best" tour from the TSP algorithm has been received.
        /// Draw the tour on the form, and update a couple of status labels.
        /// </summary>
        /// <param name="sender">Object that generated this event.</param>
        /// <param name="e">Event arguments.</param>
        public void DrawTour(object sender, TspEventArgs e)
        {
            this.lastFitnessValue.Text   = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture);
            this.lastIterationValue.Text = e.Generation.ToString(CultureInfo.CurrentCulture);

            if (cityImage == null)
            {
                cityImage    = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                cityGraphics = Graphics.FromImage(cityImage);
            }

            int lastCity = 0;
            int nextCity = e.BestTour[0].Connection1;

            cityGraphics.FillRectangle(Brushes.White, 0, 0, cityImage.Width, cityImage.Height);
            List <City> newBestTour = new List <City>();

            foreach (City city in e.CityList)
            {
                newBestTour.Add(cityList[lastCity]);
                // Draw a circle for the city.
                cityGraphics.DrawEllipse(Pens.Black, ToX(city.Location.X), ToY(city.Location.Y), 5, 5);

                // Draw the line connecting the city.
                cityGraphics.DrawLine(Pens.Black, ToXY(cityList[lastCity].Location), ToXY(cityList[nextCity].Location));

                // figure out if the next city in the list is [0] or [1]
                if (lastCity != e.BestTour[nextCity].Connection1)
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection1;
                }
                else
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection2;
                }
            }
            newBestTour.Add(cityList[lastCity]);

            this.tourDiagram.Image = cityImage;

            if (e.Complete)
            {
                StartButton.Text      = "Begin";
                StatusLabel.Text      = "Open a City List or click the map to place cities.";
                StatusLabel.ForeColor = Color.Black;

                // DisplayNameAttribute the best tour
                String s = "";
                foreach (City c in newBestTour)
                {
                    s += c.Name + "\r\n";
                }
                MessageBox.Show(s);
            }
        }
コード例 #2
0
ファイル: TspForm.cs プロジェクト: jameskok/TSP
        /// <summary>
        /// A new "best" tour from the TSP algorithm has been received.
        /// Draw the tour on the form, and update a couple of status labels.
        /// </summary>
        /// <param name="sender">Object that generated this event.</param>
        /// <param name="e">Event arguments.</param>
        public void DrawTour(object sender, TspEventArgs e)
        {
            this.lastFitnessValue.Text   = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture);
            this.lastIterationValue.Text = e.Generation.ToString(CultureInfo.CurrentCulture);

            if (cityImage == null)
            {
                cityImage    = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                cityGraphics = Graphics.FromImage(cityImage);
            }

            int lastCity = 0;
            int nextCity = e.BestTour[0].Connection1;

            cityGraphics.FillRectangle(Brushes.White, 0, 0, cityImage.Width, cityImage.Height);
            if (pic_d)
            {
                cityGraphics.DrawImage(pic, ulCorner);
            }

            foreach (City city in e.CityList)
            {
                // Draw a circle for the city.
                cityGraphics.DrawEllipse(Pens.Red, city.Location.X - 2, city.Location.Y - 2, 5, 5);

                // Draw the line connecting the city.
                cityGraphics.DrawLine(Pens.Red, cityList[lastCity].Location, cityList[nextCity].Location);

                // figure out if the next city in the list is [0] or [1]
                if (lastCity != e.BestTour[nextCity].Connection1)
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection1;
                }
                else
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection2;
                }
            }

            this.tourDiagram.Image = cityImage;

            if (e.Complete)
            {
                StartButton.Text      = "Начать";
                StatusLabel.Text      = "Выберете города на карте при помощи мыши или загрузите файл. Количество городов должно быть больше 5.";
                StatusLabel.ForeColor = Color.Black;
            }
        }
コード例 #3
0
        /// <summary>
        /// A new "best" tour from the TSP algorithm has been received.
        /// Draw the tour on the form, and update a couple of status labels.
        /// </summary>
        /// <param name="sender">Object that generated this event.</param>
        /// <param name="e">Event arguments.</param>
        public void DrawTour(object sender, TspEventArgs e)
        {
            this.lastFitnessValue.Text = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture);

            this.lastIterationValue.Text = e.Generation.ToString(CultureInfo.CurrentCulture);

            e.Imprv++;

            this.NumberOfImprv.Text = e.Imprv.ToString();
            if (cityImage == null)
            {
                cityImage    = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                cityGraphics = Graphics.FromImage(cityImage);
            }

            int lastCity = 0;
            int nextCity = e.BestTour[0].Connection1;

            cityGraphics.FillRectangle(Brushes.White, 0, 0, cityImage.Width, cityImage.Height);
            foreach (City city in e.CityList)
            {
                // Draw a circle for the city.
                cityGraphics.DrawEllipse(Pens.Black, city.Location.X - 2, city.Location.Y - 2, 5, 5);

                // Draw the line connecting the city.
                cityGraphics.DrawLine(Pens.Black, cityList[lastCity].Location, cityList[nextCity].Location);

                // figure out if the next city in the list is [0] or [1]
                if (lastCity != e.BestTour[nextCity].Connection1)
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection1;
                }
                else
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection2;
                }
            }

            this.tourDiagram.Image = cityImage;

            if (e.Complete)
            {
                StartButton.Text      = "Начать";
                StatusLabel.Text      = "Откройте XML файл с городами или укажите города мышкой";
                StatusLabel.ForeColor = Color.Black;
            }
        }
コード例 #4
0
        /// TSP algorithm raised an event that a new best tour was found.
        /// We need to do an invoke on the GUI thread before doing any draw code.
        private void tsp_foundNewBestTour(object sender, TspEventArgs e)
        {
            if (this.InvokeRequired)
            {
                try
                {
                    this.Invoke(new DrawEventHandler(DrawTour), new object[] { sender, e });
                    return;
                }
                catch (Exception)
                {
                }
            }

            DrawTour(sender, e);
        }
コード例 #5
0
        /// <summary>
        /// TSP algorithm raised an event that a new best tour was found.
        /// We need to do an invoke on the GUI thread before doing any draw code.
        /// </summary>
        /// <param name="sender">Object that generated this event.</param>
        /// <param name="e">Event arguments.</param>
        private void tsp_foundNewBestTour(object sender, TspEventArgs e)
        {
            if (this.InvokeRequired)
            {
                try
                {
                    this.Invoke(new DrawEventHandler(DrawTour), new object[] { sender, e });
                    return;
                }
                catch (Exception)
                {
                    // This will fail when run as a control in IE due to a security exception.
                }
            }

            DrawTour(sender, e);
        }
コード例 #6
0
ファイル: TspForm.cs プロジェクト: SPQR1608/exp
        /// <summary>
        /// A new "best" tour from the TSP algorithm has been received.
        /// Draw the tour on the form, and update a couple of status labels.
        /// </summary>
        /// <param name="sender">Object that generated this event.</param>
        /// <param name="e">Event arguments.</param>
        public void DrawTour(object sender, TspEventArgs e)
        {
            this.lastFitnessValue.Text   = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture);
            this.lastIterationValue.Text = e.Generation.ToString(CultureInfo.CurrentCulture);

            if (cityImage == null)
            {
                cityImage    = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                cityGraphics = Graphics.FromImage(cityImage);
            }

            int lastCity = 0;
            int nextCity = e.BestTour[0].Connection1;

            cityGraphics.FillRectangle(Brushes.White, 0, 0, cityImage.Width, cityImage.Height);
            foreach (City city in e.CityList)
            {
                // Draw a circle for the city.
                //cityGraphics.DrawEllipse(Pens.Black, city.Location.X - 2, city.Location.Y - 2, 7, 7);

                // Draw the line connecting the city.
                cityGraphics.DrawLine(Pens.Red, cityList[lastCity].Location, cityList[nextCity].Location);

                // figure out if the next city in the list is [0] or [1]
                if (lastCity != e.BestTour[nextCity].Connection1)
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection1;
                }
                else
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection2;
                }
            }

            this.tourDiagram.Image = cityImage;

            if (e.Complete)
            {
                StartButton.Text      = "Begin";
                StatusLabel.Text      = "Нажмите на кнопку Добавить города или правой кнопкой мыши нажмите на пустое поле.";
                StatusLabel.ForeColor = Color.Black;
            }
        }
コード例 #7
0
        /// <summary>
        /// ����� "�����" ��� �� ��������� TSP ��� �������.
        /// ��������� ��� �� �����, � �������� ���� ����� �������.</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void DrawTour(object sender, TspEventArgs e)
        {
            this.lastFitnessValue.Text = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture);
            this.lastIterationValue.Text = e.Generation.ToString(CultureInfo.CurrentCulture);

            if (cityImage == null)
            {
                cityImage = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                cityGraphics = Graphics.FromImage(cityImage);
            }

            int lastCity = 0;
            int nextCity = e.BestTour[0].Connection1;

            cityGraphics.FillRectangle(Brushes.White, 0, 0, cityImage.Width, cityImage.Height);
            foreach( City city in e.CityList )
            {
                // ������ "�������" �����.
                cityGraphics.DrawEllipse(Pens.Black, city.Location.X - 2, city.Location.Y - 2, 5, 5);

                //������ �����
                cityGraphics.DrawLine(Pens.Black, cityList[lastCity].Location, cityList[nextCity].Location);

                if (lastCity != e.BestTour[nextCity].Connection1)
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection1;
                }
                else
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection2;
                }
            }

            this.tourDiagram.Image = cityImage;

            if (e.Complete)
            {
                StartButton.Text = "������";
                StatusLabel.Text = "�� ������ ��� ����������� ���� ̳��� � ������";
                StatusLabel.ForeColor = Color.Black;
            }
        }
コード例 #8
0
        /// <summary>
        /// A new "best" tour from the TSP algorithm has been received.
        /// Draw the tour on the form, and update a couple of status labels.
        /// </summary>
        /// <param name="sender">Object that generated this event.</param>
        /// <param name="e">Event arguments.</param>
        public void DrawTour(object sender, TspEventArgs e)
        {
            lastFitnessValue.Text   = Math.Round(e.BestTour.Fitness, 2).ToString(CultureInfo.CurrentCulture);
            lastIterationValue.Text = e.Generation.ToString(CultureInfo.CurrentCulture);
            iteration = Convert.ToInt32(lastIterationValue.Text);

            if (cityImage == null)
            {
                cityImage    = new Bitmap(tourDiagram.Width, tourDiagram.Height);
                cityGraphics = Graphics.FromImage(cityImage);
            }

            int lastCity = 0;
            int nextCity = e.BestTour[0].Connection1;
            int city_num = 1;

            integer_cordinates.Clear();

            cityGraphics.FillRectangle(Brushes.Silver, 0, 0, cityImage.Width, cityImage.Height);
            foreach (City city in e.CityList)
            {
                // Draw a circle for the city.
                cityGraphics.DrawString(city_num.ToString(), drawFont, drawBrush, city.Location.X + 3, city.Location.Y + 3);
                cityGraphics.DrawEllipse(Pens.Black, city.Location.X - 2, city.Location.Y - 2, 5, 5);

                // Draw the line connecting the city.
                cityGraphics.DrawLine(Pens.Black, cityList[lastCity].Location, cityList[nextCity].Location);

                // Get Cordinates

                integer_cordinates.Add(new Cordinates()
                {
                    last_city_num = lastCity,
                    x1_y1         = cityList[lastCity].Location.X + ":" + cityList[lastCity].Location.Y,
                    next_city_num = nextCity,
                    x2_y2         = cityList[nextCity].Location.X + ":" + cityList[nextCity].Location.Y
                });

                // figure out if the next city in the list is [0] or [1]
                if (lastCity != e.BestTour[nextCity].Connection1)
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection1;
                }
                else
                {
                    lastCity = nextCity;
                    nextCity = e.BestTour[nextCity].Connection2;
                }
                city_num += 1;
            }

            this.tourDiagram.Image = cityImage;

            if (e.Complete)
            {
                //If we use Kml file for find best way, we can create a kml file (sorry for the tautology)

                if (Path.GetExtension(fileNameTextBox.Text) == ".kml")
                {
                    Create_kml.Enabled = true;
                }

                StartButton.Text      = "Begin";
                StatusLabel.Text      = "Open a City List or click the map to place cities.";
                StatusLabel.ForeColor = Color.Black;
            }
        }
コード例 #9
0
        /// <summary>
        /// ��� �������� ������ �������, ��� ������ ����� ������ ���.
        /// �� ������ ������� ����������� �� GUI ������, ������ ��� ������ �����-���� ����� ����.        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tsp_foundNewBestTour(object sender, TspEventArgs e)
        {
            if ( this.InvokeRequired )
            {
                try
                {
                    this.Invoke(new DrawEventHandler(DrawTour), new object[] { sender, e });
                    return;
                }
                catch (Exception)
                {
                }
            }

            DrawTour(sender, e);
        }