コード例 #1
0
        public void ResearchByTimePerSize(StreamWriter fileWriter)
        {
            List <Average> time = new List <Average>();

            ResearchGraph researchGraph = new ResearchGraph();
            var           startX        = researchGraph.GetStableX;
            var           startYD       = 0;
            var           startYF       = 0;
            var           counter       = 0;

            string result;

            bool file = false;

            if (fileWriter != null)
            {
                file = true;
            }

            Console.WriteLine("Enter start size:");
            var startSize = Convert.ToInt32(Console.ReadLine());

            if (startSize <= 0)
            {
                throw new Exception("Not positive value");
            }
            Console.WriteLine("Enter finish size:");
            var finishSize = Convert.ToInt32(Console.ReadLine());

            if (startSize <= 0 || startSize > finishSize)
            {
                throw new Exception("Invalid value");
            }
            Console.WriteLine("Enter step:");
            var step = Convert.ToInt32(Console.ReadLine());

            if (step <= 0)
            {
                throw new Exception("Invalid value");
            }
            Console.WriteLine("A max value of flow: ");
            bound = Convert.ToInt32(Console.ReadLine());
            if (bound <= 0)
            {
                throw new Exception("Not positive value");
            }
            Console.WriteLine("Enter research size:");
            var researchSize = Convert.ToInt32(Console.ReadLine());

            if (researchSize <= 0)
            {
                throw new Exception("Not positive value");
            }


            for (int i = startSize; i <= finishSize; i += step)
            {
                _console.ResearchInput(i, 1, i);
                CounterReset();
                Console.WriteLine($"\t\t___MATRIX SIZE: {i}___\n");
                if (fileWriter != null)
                {
                    fileWriter.WriteLine($"\t\t___MATRIX SIZE: {i}___\n");
                }
                ResearchForSize(fileWriter, researchSize, false);
                time.Add(new Average(i, Compare(null)));

                researchGraph.DrawGraphLine(true, startX, startYF, ((finishSize - startSize) / step) + 1, time[(i - startSize) / step].Time[0] / 10);
                startYF = Convert.ToInt32(time[(i - startSize) / step].Time[0] * 10);

                researchGraph.DrawGraphLine(false, startX, startYD, ((finishSize - startSize) / step) + 1, time[(i - startSize) / step].Time[1] / 10);
                startYD = Convert.ToInt32(time[(i - startSize) / step].Time[1] * 10);

                var divider  = ((finishSize - startSize) / step) >= 5 ? 5 : ((finishSize - startSize) / step);
                var partsize = ((finishSize - startSize) / step) / divider;
                if (i == (startSize + (counter * partsize * step)) || i == finishSize && counter < 6)
                {
                    researchGraph.DrawXNumbers(i, startX + ((researchGraph.GetX - 420) / (((finishSize - startSize) / step) + 1)));
                    counter++;
                }

                startX += ((researchGraph.GetX - 420) / (((finishSize - startSize) / step) + 1));
            }
            researchGraph.DrawYNumbers(time);
            researchGraph.DrawAxes("size", "msec");
            researchGraph.DrawLegend(startSize, finishSize, step, researchSize);

            researchGraph.SaveJPG(2);

            result = "RESULTS FOR TIME PER SIZE:\n";
            for (int i = 0; i < time.Count; i++)
            {
                result += $"Size: {time[i].Size}\n";
                result += $"    Ford-Falkerson time: \t{time[i].Time[0]}\n";
                result += $"    Dinics time: \t\t{time[i].Time[1]}\n";
                result += $"    Greedy time: \t\t{time[i].Time[2]}\n";
                result += $"    DFS time: \t\t\t{time[i].Time[3]}\n";
            }
            Console.WriteLine(result);
            if (file)
            {
                fileWriter.WriteLine(result);
                _console.WriteResearch(time);
            }
        }