Exemple #1
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;*/
        }
Exemple #2
0
        private void DisplayTspLib95Data()
        {
            TspLib95            lib;
            List <TspLib95Item> tspList;

            try
            {
                lib     = new TspLib95(tspLibPath);
                tspList = lib.LoadAllTSP().ToList();
            }
            catch (Exception) {
                MessageBox.Show("Please choose TspLib95 path");
                return;
            }

            var info = "";

            for (var i = 0; i < tspList.Count; i++)
            {
                info += string.Format(@"{0}:  {1}

", i, tspList[i].ToString());
            }

            textBox1.Text = info;
        }
Exemple #3
0
        public void LoadAllTSP()
        {
            var tspLib = new TspLib95(RootDir);

            tspLib.LoadAllTSP();
            var items = tspLib.TSPItems();

            Assert.AreEqual(Enumerable.Count(items), 112);
        }
Exemple #4
0
        public void GetItemByInvalidName()
        {
            var tspLib = new TspLib95(RootDir);

            tspLib.LoadAllTSP();
            Assert.IsNull(tspLib.GetItemByName("bob", ProblemType.TSP));
            Assert.IsNull(tspLib.GetItemByName("", ProblemType.TSP));
            Assert.IsNull(tspLib.GetItemByName(" ", ProblemType.TSP));
        }
Exemple #5
0
        static void Main(string[] args)
        {
            //timerInterval = new List<double>
            //{
            //    100
            //};

            //duration = new List<double>
            //{
            //    600
            //};

            TspLib95 lib     = new TspLib95(tspLibPath);
            var      tspList = lib.LoadAllTSP().ToList();

            var tspItemNumbers = new List <int> {
                39 // - 21 city
                ,
                2  //- 49
                ,
                27 //- 70+
                ,
                25 //- 101
                ,
                44 //- 666
            };

            var tspItems = new Dictionary <int, TspLib95Item>();

            foreach (var id in tspItemNumbers)
            {
                tspItems.Add(id, tspList[id]);
            }

            List <ICrossoverOperator> crossovers = new List <ICrossoverOperator>()
            {
                new CrossoverOperatorOX(),
                new CrossoverOperatorPMX(),
                new CrossoverOperatorAEX(),
                //new CrossoverOperatorAEXWithShortestDistance()
            };

            List <IMutationOperator> mutations = new List <IMutationOperator>()
            {
                new MutationOperatorRSM(),
                new MutationOperatorInsertions(),
                new MutationOperatorPSM(),
                //new MutationOperatorHalfRSMHalfPSM(),
            };

            var number = 100;


            //int city = 0, cI = 0, mI = 0, nI = 0;
            //var dOp = new DistanceOperator(tspItems[tspItemNumbers[city]].Problem.NodeProvider.CountNodes());
            //dOp.CalculateDistance(tspItems[tspItemNumbers[city]].Problem);
            //ChromosomeOperator.ChangeOperator(crossovers[cI]);
            //ChromosomeOperator.ChangeOperator(mutations[mI]);
            //var reportManager = new ReportManager(number[nI], tspItemNumbers[city],
            //                    tspItems[tspItemNumbers[city]].Problem.Name);
            //var tspManager = new TSPManager(dOp, 1, 1, reportManager.NextGeneration);
            //tspManager.Start();
            //reportManager.EndOfAlgorithm(tspManager.Population);

            var indx = 0;


            var total = tspItemNumbers.Count * crossovers.Count * mutations.Count * number;

            for (int city = 0; city < tspItemNumbers.Count; city++)
            {
                var dOp = new DistanceOperator(tspItems[tspItemNumbers[city]].Problem.NodeProvider.CountNodes());
                dOp.CalculateDistance(tspItems[tspItemNumbers[city]].Problem);
                for (int cI = 0; cI < crossovers.Count; cI++)
                {
                    ChromosomeOperator.ChangeOperator(crossovers[cI]);
                    for (int mI = 0; mI < mutations.Count; mI++)
                    {
                        ChromosomeOperator.ChangeOperator(mutations[mI]);
                        for (int nI = 2; nI <= number; nI++)
                        {
                            Console.WriteLine("{0}%", (double)indx / total * 100);
                            Console.WriteLine("start {0} :  {1} {2} {3} {4}", indx++,
                                              tspItemNumbers[city],
                                              crossovers[cI].GetType().Name,
                                              mutations[mI].GetType().Name,
                                              nI
                                              );

                            var reportManager = new ReportManager(nI, tspItemNumbers[city],
                                                                  tspItems[tspItemNumbers[city]].Problem.Name);
                            //var tspManager = new TSPManager(dOp, 1, 1, reportManager.NextGeneration);
                            var tspManager = new TSPManager(dOp, 1, 1, reportManager.NextGeneration);

                            var timer = new Timer(timerInterval[city]);
                            currentCity    = city;
                            timer.Elapsed += NextTick;

                            SetUpNewTest(tspManager.Population, reportManager);
                            timer.Start();
                            tspManager.Start(StopFunc);
                            timer.Stop();
                            reportManager.EndOfAlgorithm(tspManager.Population);
                        }
                    }
                }
            }
        }