Example #1
0
        public void DrawATour(string tour, Color color)
        {
            if (this.Points.Count == 0)
            {
                return;
            }
            Color[] colors = { Color.Red, Color.Blue, Color.Green, Color.Black, Color.MediumSlateBlue };

            if (ControlProgram.LastTour != tour)
            {
                ControlProgram.LastTour = tour;

                var tours = ControlProgram.SplitDistances(tour);
                var g     = pictureBox1.CreateGraphics();
                g.Clear(Color.White);
                DrawAllPoints(ControlProgram.Environment.DepoId);
                for (int j = 0; j < tours.Count; j++)
                {
                    var ids = tours[j].Split('-');
                    var pen = new Pen(colors[j % colors.Length]);
                    for (int i = 1; i < ids.Length - 1; i++)
                    {
                        g.DrawLine(pen, Points[int.Parse(ids[i]) - 1], Points[int.Parse(ids[i + 1]) - 1]);
                    }
                    g.DrawLine(pen, Points[int.Parse(ids[ids.Length - 1]) - 1], Points[int.Parse(ids[1]) - 1]);
                }
            }
        }
Example #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            int number;

            if (!int.TryParse(txtTspLibChooseOne.Text, out number))
            {
                return;
            }
            //Get one
            TspLib95 lib     = new TspLib95(tspLibPath);
            var      tspList = lib.LoadAllTSP().ToList();
            var      tsp     = tspList[number]; //-24
            //var tsp = tspList[5]; // 29
            //var tsp = tspList[11];
            //MessageBox.Show(tsp.ToString());
            //MessageBox.Show(File.Exists(Path.Combine(tspLibPath,"TSP",string.Concat(tsp.Problem.Name, ".tsp"))).ToString());

            var filePath = Path.Combine(tspLibPath, "TSP", string.Concat(tsp.Problem.Name, ".tsp"));

            using (var reader = new StreamReader(filePath))
            {
                MessageBox.Show(reader.ReadToEnd());
            }

            ControlProgram.SetTspItem(tsp);
            TransferTspLibItemToPoints();

            /*btnCreateProblem.Enabled = false;
            *  btnRun.Enabled = true;
            *  btnChooseOperator.Enabled = true;*/
        }
Example #3
0
        /// <summary>
        /// Create a problem
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button5_Click(object sender, EventArgs e) // create a problem
        {
            int travelers;

            if (!int.TryParse(txtTravelersAmount.Text, out travelers))
            {
                MessageBox.Show("Please write a number");
                return;
            }

            DistanceOperator dOp;

            if (ControlProgram.tsp != null) // Load From TSPLib95
            {
                TransferTspLibItemToPoints();
                dOp = new DistanceOperator(ControlProgram.tsp.Problem.NodeProvider.CountNodes());
                dOp.CalculateDistance(ControlProgram.tsp.Problem);
            }
            else
            {
                dOp = new DistanceOperator(this.Points.Count, Points);
            }

            TspManager = new TSPManager(dOp, travelers, int.Parse(cmbDepoId.Text), NextGeneration);
            ReportManager pManager = new ReportManager(1, 2, ControlProgram.tsp.Problem.Name);

            TspManager.NextGenerationEvent += pManager.NextGeneration;

            ControlProgram.Start(TspManager.Population, TspManager.dOp, TspManager.Environment);
            btnRun.Enabled            = true;
            btnChooseOperator.Enabled = true;
        }