Пример #1
0
 private void radioButton1_CheckedChanged(object sender, EventArgs e)
 {
     ChromosomeOperator.ChangeOperator(new CrossoverOperatorAEX());
 }
Пример #2
0
 private void rbCrossoverTwoPoint_CheckedChanged(object sender, EventArgs e)
 {
     ChromosomeOperator.ChangeOperator(new CrossoverOperatorOX());
 }
Пример #3
0
 private void rbMutationInsertion_CheckedChanged(object sender, EventArgs e)
 {
     ChromosomeOperator.ChangeOperator(new MutationOperatorInsertions());
 }
Пример #4
0
 private void rbMutationRSM_CheckedChanged(object sender, EventArgs e)
 {
     ChromosomeOperator.ChangeOperator(new MutationOperatorRSM());
 }
Пример #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);
                        }
                    }
                }
            }
        }