Beispiel #1
0
        public void Dump(BatchModes batchMode)
        {
            switch (batchMode)
            {
            case BatchModes.All:
                FileWriter.WriteStatisticsToFile(batchMode.ToString(), "All Statistics", FormatAllStatistics());
                FileWriter.WriteStatisticsToFile(BatchModes.Wrong.ToString(), "Wrong Statistics", FormatStatistics(item => !item.Correct));
                FileWriter.WriteStatisticsToFile(BatchModes.Correct.ToString(), "Correct Statistics", FormatStatistics(item => item.Correct));
                FileWriter.WriteStatisticsToFile(BatchModes.Slow.ToString(), "Slow Statistics", FormatOrderedStatistics(false, item => item.SolutionTime, 10));
                FileWriter.WriteStatisticsToFile(BatchModes.Fast.ToString(), "Fast Statistics", FormatOrderedStatistics(true, item => item.SolutionTime, 10));
                break;

            case BatchModes.Wrong:
                FileWriter.WriteStatisticsToFile(batchMode.ToString(), "Wrong Statistics", FormatStatistics(item => !item.Correct));
                break;

            case BatchModes.Correct:
                FileWriter.WriteStatisticsToFile(batchMode.ToString(), "Correct Statistics", FormatStatistics(item => item.Correct));
                break;

            case BatchModes.Slow:
                FileWriter.WriteStatisticsToFile(batchMode.ToString(), "Slow Statistics", FormatOrderedStatistics(false, item => item.SolutionTime, 10));
                break;

            case BatchModes.Fast:
                FileWriter.WriteStatisticsToFile(batchMode.ToString(), "Fast Statistics", FormatOrderedStatistics(true, item => item.SolutionTime, 10));
                break;
            }
        }
 public void Run(BatchModes batchMode = BatchModes.All)
 {
     var tempBatchMode = (batchMode == BatchModes.Correct || batchMode == BatchModes.Fast || batchMode == BatchModes.None) ? BatchModes.All : batchMode;
     foreach (Problem problem in ProblemsToSolve[tempBatchMode]) {
         Run(problem, RunModes.Solution, batchMode);
         ClearCache.Clear();
         Console.WriteLine();
     }
     StatisticsWriter.Dump(batchMode);
 }
Beispiel #3
0
        public void Run(BatchModes batchMode = BatchModes.All)
        {
            var tempBatchMode = (batchMode == BatchModes.Correct || batchMode == BatchModes.Fast || batchMode == BatchModes.None) ? BatchModes.All : batchMode;

            foreach (Problem problem in ProblemsToSolve[tempBatchMode])
            {
                Run(problem, RunModes.Solution, batchMode);
                ClearCache.Clear();
                Console.WriteLine();
            }
            StatisticsWriter.Dump(batchMode);
        }
Beispiel #4
0
        public void Run(Problem problemToSolve, RunModes runMode, BatchModes batchMode = BatchModes.None)
        {
            problemToSolve.RunMode = runMode;
            problemToSolve.Logging = Logging;

            Thread problemThread = new Thread(problemToSolve.Run);

            DateTime start = DateTime.Now;

            problemThread.Start();

            bool  useTimer   = batchMode != BatchModes.None;
            bool  tooSlow    = false;
            Timer EulerTimer = new Timer(
                (obj) => {
                if (useTimer)
                {
                    if (problemThread.ThreadState == ThreadState.Running)
                    {
                        useTimer = false;
                        tooSlow  = true;
                        Console.WriteLine(String.Format("{0} - {1}", problemToSolve.GetType(), SlowString));
                        var stat = new Statistics(problemToSolve.GetType(), SlowString, new TimeSpan(0, 1, 0), false);
                        StatisticsWriter.Add(stat);
                        problemThread.Abort();
                    }
                }
            }, null, Minute, Minute);

            problemThread.Join();

            if (!tooSlow)
            {
                useTimer = false;
                RunResponse response = problemToSolve.RunResponse;
                var         elapsed  = DateTime.Now - start;
                var         correct  = response.Response != null && response.Solution != null &&
                                       response.Response.Equals(response.Solution);
                var stat = new Statistics(problemToSolve.GetType(), response.Response, elapsed, correct);
                StatisticsWriter.Add(stat);
                //if (!batchMode) {
                Console.WriteLine(stat);
                //}
            }
        }
        public void Run(Problem problemToSolve, RunModes runMode, BatchModes batchMode = BatchModes.None)
        {
            problemToSolve.RunMode = runMode;
            problemToSolve.Logging = Logging;

            Thread problemThread = new Thread(problemToSolve.Run);

            DateTime start = DateTime.Now;
            problemThread.Start();

            bool useTimer = batchMode != BatchModes.None;
            bool tooSlow = false;
            Timer EulerTimer = new Timer(
                (obj) => {
                    if (useTimer) {
                        if (problemThread.ThreadState == ThreadState.Running) {
                            useTimer = false;
                            tooSlow = true;
                            Console.WriteLine(String.Format("{0} - {1}", problemToSolve.GetType(), SlowString));
                            var stat = new Statistics(problemToSolve.GetType(), SlowString, new TimeSpan(0, 1, 0), false);
                            StatisticsWriter.Add(stat);
                            problemThread.Abort();
                        }
                    }
                }, null, Minute, Minute);
            problemThread.Join();

            if (!tooSlow) {
                useTimer = false;
                RunResponse response = problemToSolve.RunResponse;
                var elapsed = DateTime.Now - start;
                var correct = response.Response != null && response.Solution != null &&
                                            response.Response.Equals(response.Solution);
                var stat = new Statistics(problemToSolve.GetType(), response.Response, elapsed, correct);
                StatisticsWriter.Add(stat);
                //if (!batchMode) {
                Console.WriteLine(stat);
                //}
            }
        }