예제 #1
0
파일: TspForm.cs 프로젝트: SPQR1608/exp
        /// <summary>
        /// Starts up the TSP class.
        /// This function executes on a thread pool thread.
        /// </summary>
        /// <param name="stateInfo">Not used</param>
        private void BeginTsp(Object stateInfo)
        {
            int    Col;
            string nCol = string.Empty;
            // Assume the StartButton_Click did all the error checking
            int populationSize      = Convert.ToInt32(populationSizeTextBox.Text, CultureInfo.CurrentCulture);
            int maxGenerations      = Convert.ToInt32(maxGenerationTextBox.Text, CultureInfo.CurrentCulture);;
            int mutation            = Convert.ToInt32(mutationTextBox.Text, CultureInfo.CurrentCulture);
            int groupSize           = Convert.ToInt32(groupSizeTextBox.Text, CultureInfo.CurrentCulture);
            int seed                = 0; //Convert.ToInt32(randomSeedTextBox.Text, CultureInfo.CurrentCulture);
            int numberOfCloseCities = Convert.ToInt32(NumberCloseCitiesTextBox.Text, CultureInfo.CurrentCulture);
            int chanceUseCloseCity  = Convert.ToInt32(CloseCityOddsTextBox.Text, CultureInfo.CurrentCulture);

            Col = cityList.CalculateCityDistances(numberOfCloseCities);

            nCol = Convert.ToString(Col);

            if (label1.InvokeRequired)
            {
                label1.Invoke(new Action <string>((s) => label1.Text = s), nCol);
            }
            else
            {
                label1.Text = nCol;
            }

            tsp = new Tsp();
            tsp.foundNewBestTour += new Tsp.NewBestTourEventHandler(tsp_foundNewBestTour);
            tsp.Begin(populationSize, maxGenerations, groupSize, mutation, seed, chanceUseCloseCity, cityList, Col);
            tsp.foundNewBestTour -= new Tsp.NewBestTourEventHandler(tsp_foundNewBestTour);
            tsp = null;
        }
예제 #2
0
        /// Starts up the TSP class.
        /// This function executes on a thread pool thread.
        /// stateInfo - Not used
        private void BeginTsp(Object stateInfo)
        {
            // Assume the StartButton_Click did all the error checking
            int populationSize      = Convert.ToInt32(populationSizeTextBox.Text, CultureInfo.CurrentCulture);
            int maxGenerations      = Convert.ToInt32(maxGenerationTextBox.Text, CultureInfo.CurrentCulture);;
            int mutation            = Convert.ToInt32(mutationTextBox.Text, CultureInfo.CurrentCulture);
            int groupSize           = Convert.ToInt32(groupSizeTextBox.Text, CultureInfo.CurrentCulture);
            int seed                = Convert.ToInt32(randomSeedTextBox.Text, CultureInfo.CurrentCulture);
            int numberOfCloseCities = Convert.ToInt32(NumberCloseCitiesTextBox.Text, CultureInfo.CurrentCulture);
            int chanceUseCloseCity  = Convert.ToInt32(CloseCityOddsTextBox.Text, CultureInfo.CurrentCulture);

            cityList.CalculateCityDistances(numberOfCloseCities);

            tsp = new Tsp();
            tsp.foundNewBestTour += new Tsp.NewBestTourEventHandler(tsp_foundNewBestTour);
            tsp.Begin(populationSize, maxGenerations, groupSize, mutation, seed, chanceUseCloseCity, cityList);
            tsp.foundNewBestTour -= new Tsp.NewBestTourEventHandler(tsp_foundNewBestTour);
            tsp = null;
        }
예제 #3
0
파일: frmBoard.cs 프로젝트: rborsini/tsp
        private void AddPoint(Tsp.Point point)
        {
            if (this.points.Count == 0)
            {
                point.Type = Tsp.PointType.Start;
            }
            else
            {
                point.Type = Tsp.PointType.End;

                if (this.points.Count > 1)
                {
                    this.points.Last().Type = Tsp.PointType.Waypoiny;
                    DrawPoint(this.points.Last());
                }
            }

            this.points.Add(point);
            DrawPoint(point);
        }
예제 #4
0
파일: frmBoard.cs 프로젝트: rborsini/tsp
        private void DrawPoint(Tsp.Point point)
        {
            System.Drawing.Pen myPen;
            Color color = System.Drawing.Color.Red;
            switch(point.Type)
            {
                case Tsp.PointType.Start:
                    color = System.Drawing.Color.Cyan;
                    break;
                case Tsp.PointType.Waypoiny:
                    color = System.Drawing.Color.Gray;
                    break;
                case Tsp.PointType.End:
                    color = System.Drawing.Color.Red;
                    break;
            }

            myPen = new System.Drawing.Pen(color);

            int x1 = ((int)point.X-2);
            int y1 = ((int)point.Y - 2);

            formGraphics.DrawRectangle(myPen, x1, y1, 7, 7);
            formGraphics.DrawRectangle(myPen, x1, y1, 6, 6);
            formGraphics.DrawRectangle(myPen, x1, y1, 5, 5);
            formGraphics.DrawRectangle(myPen, x1, y1, 4, 4);
            formGraphics.DrawRectangle(myPen, x1, y1, 3, 3);
            formGraphics.DrawRectangle(myPen, x1, y1, 2, 2);
        }
예제 #5
0
파일: frmBoard.cs 프로젝트: rborsini/tsp
        private void DrawLine(Tsp.Point origin, Tsp.Point destination)
        {
            System.Drawing.Pen myPen;
            myPen = new System.Drawing.Pen(System.Drawing.Color.Black);

            int x1 = ((int)origin.X);
            int y1 = ((int)origin.Y);
            int x2 = ((int)destination.X);
            int y2 = ((int)destination.Y);

            formGraphics.DrawLine(myPen, x1, y1, x2, y2);
        }
예제 #6
0
        /// <summary>
        /// ��������� ����� TSP.
        /// ��� ������� ��������� �� ���� ���� �������.  </summary>
        /// <param name="stateInfo">Not used</param>
        private void BeginTsp(Object stateInfo)
        {
            int populationSize = Convert.ToInt32(populationSizeTextBox.Text, CultureInfo.CurrentCulture);
            int maxGenerations = Convert.ToInt32(maxGenerationTextBox.Text, CultureInfo.CurrentCulture); ;
            int mutation = Convert.ToInt32(mutationTextBox.Text, CultureInfo.CurrentCulture);
            int groupSize = Convert.ToInt32(groupSizeTextBox.Text, CultureInfo.CurrentCulture);
            int seed = Convert.ToInt32(randomSeedTextBox.Text, CultureInfo.CurrentCulture);
            int numberOfCloseCities = Convert.ToInt32(NumberCloseCitiesTextBox.Text, CultureInfo.CurrentCulture);
            int chanceUseCloseCity = Convert.ToInt32(CloseCityOddsTextBox.Text, CultureInfo.CurrentCulture);

            cityList.CalculateCityDistances(numberOfCloseCities);

            tsp = new Tsp();
            tsp.foundNewBestTour += new Tsp.NewBestTourEventHandler(tsp_foundNewBestTour);
            tsp.Begin(populationSize, maxGenerations, groupSize, mutation, seed, chanceUseCloseCity, cityList);
            tsp.foundNewBestTour -= new Tsp.NewBestTourEventHandler(tsp_foundNewBestTour);
            tsp = null;
        }