Пример #1
0
        static void Main(string[] args)
        {
            DataCase example;

            example = new DataCase(12, 21, 2100);
            example.PrintData();

            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
            stopwatch.Start();
            example.DynamicProg();
            //System.Threading.Thread.Sleep(10000);
            stopwatch.Stop();
            TimeSpan ts = stopwatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               ts.Hours, ts.Minutes, ts.Seconds,
                                               ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);
            example.GeneticAlg();
            //Test
            //Individ test = new Individ(5,11);



            //Тест
            //Random rnd = new Random();
            //test.FullRand(rnd);
            //test.Print();
            //test.Mutation(rnd);
            //test.Mutation(rnd);
            //Тест
            //test.Print();
        }
Пример #2
0
        static void Main(string[] args)
        {
            DataCase example;

            example = new DataCase(250, 5001, 500000);
            //example.PrintData();

            Console.WriteLine("Прямой жадный алгоритм: ");
            System.Diagnostics.Stopwatch stopwatchGreed = new System.Diagnostics.Stopwatch();
            stopwatchGreed.Start();
            example.GreedyAlg();
            stopwatchGreed.Stop();
            TimeSpan tsGreed          = stopwatchGreed.Elapsed;
            string   elapsedTimeGreed = String.Format("{0:00}:{1:00}:{2:00}.{3:00}\n", tsGreed.Hours, tsGreed.Minutes, tsGreed.Seconds, tsGreed.Milliseconds / 10);

            Console.WriteLine("RunTime: " + elapsedTimeGreed);

            Console.WriteLine("Пропорциональный жадный алгоритм: ");
            System.Diagnostics.Stopwatch stopwatchProportionalGreed = new System.Diagnostics.Stopwatch();
            stopwatchProportionalGreed.Start();
            example.GreedProportional();
            stopwatchProportionalGreed.Stop();
            TimeSpan tsProportionalGreed          = stopwatchProportionalGreed.Elapsed;
            string   elapsedTimeProportionalGreed = String.Format("{0:00}:{1:00}:{2:00}.{3:00}\n", tsProportionalGreed.Hours, tsProportionalGreed.Minutes, tsProportionalGreed.Seconds, tsProportionalGreed.Milliseconds / 10);

            Console.WriteLine("RunTime: " + elapsedTimeProportionalGreed);

            Console.WriteLine("Динамическое программирование:");
            System.Diagnostics.Stopwatch stopwatchDyn = new System.Diagnostics.Stopwatch();
            stopwatchDyn.Start();
            example.DynamicProg();
            stopwatchDyn.Stop();
            TimeSpan tsDyn          = stopwatchDyn.Elapsed;
            string   elapsedTimeDyn = String.Format("{0:00}:{1:00}:{2:00}.{3:00}\n", tsDyn.Hours, tsDyn.Minutes, tsDyn.Seconds, tsDyn.Milliseconds / 10);

            Console.WriteLine("RunTime: " + elapsedTimeDyn);

            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine("Генетический алгоритм: ");
                System.Diagnostics.Stopwatch stopwatchGen = new System.Diagnostics.Stopwatch();
                stopwatchGen.Start();
                example.GeneticAlg(stopwatchDyn);
                stopwatchGen.Stop();
                TimeSpan tsGen          = stopwatchGen.Elapsed;
                string   elapsedTimeGen = String.Format("{0:00}:{1:00}:{2:00}.{3:00}\n", tsGen.Hours, tsGen.Minutes, tsGen.Seconds, tsGen.Milliseconds / 10);
                Console.WriteLine("RunTime: " + elapsedTimeGen);
            }

            //Console.WriteLine("Полный допустимый перебор: ");
            //System.Diagnostics.Stopwatch stopwatchBrute = new System.Diagnostics.Stopwatch();
            //stopwatchBrute.Start();
            //example.BruteForce();
            //stopwatchBrute.Stop();
            //TimeSpan tsBrute = stopwatchBrute.Elapsed;
            //string elapsedTimeBrute = String.Format("{0:00}:{1:00}:{2:00}.{3:00}\n", tsBrute.Hours, tsBrute.Minutes, tsBrute.Seconds, tsBrute.Milliseconds / 10);
            //Console.WriteLine("Brute RunTime " + elapsedTimeBrute);
        }