Пример #1
0
        private void SetStatusMessageFromSolutionStats(SolutionStats solutionStats /*, string extraMessage = null */)
        {
            var statusMessage = string.Format(
                "Matrix size: {0} rows x {1} cols",
                solutionStats.NumMatrixRows,
                solutionStats.NumMatrixCols);

            const string timeSpanFormat = @"hh\:mm\:ss\.fff";

            if (solutionStats.MatrixBuildingDuration.HasValue)
            {
                statusMessage += string.Format("; Matrix build time: {0}", solutionStats.MatrixBuildingDuration.Value.ToString(timeSpanFormat));
            }

            if (solutionStats.MatrixSolvingDuration.HasValue)
            {
                statusMessage += string.Format("; Matrix solve time: {0}", solutionStats.MatrixSolvingDuration.Value.ToString(timeSpanFormat));
            }

            //if (!string.IsNullOrEmpty(extraMessage))
            //{
            //    statusMessage += string.Format(" ({0})", extraMessage);
            //}

            statusMessage += string.Format("; Direction changes: {0}", solutionStats.MaxDirectionChanges);

            StatusMessage = statusMessage;
        }
Пример #2
0
        private TResult MeasureExecutionTime <TResult>(Func <TResult> func, int maxDirectionChanges, ICollection <MatrixRow> matrix, ref TimeSpan?duration)
        {
            _cancellationToken.ThrowIfCancellationRequested();

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();
            var result = func();

            stopwatch.Stop();

            if (duration.HasValue)
            {
                duration += stopwatch.Elapsed;
            }
            else
            {
                duration = stopwatch.Elapsed;
            }

            _solutionStats = new SolutionStats(
                matrix.Count,
                matrix.Any() ? matrix.First().DlxRowEnumerable.Count() : 0,
                MatrixBuildingDuration,
                MatrixSolvingDuration,
                maxDirectionChanges);

            _dispatcher.Invoke(_updateSolutionStatsHandler, _solutionStats);

            return(result);
        }
Пример #3
0
 public PuzzleSolverStats(
     IDispatcher dispatcher,
     CancellationToken cancellationToken,
     Action <SolutionStats> updateSolutionStatsHandler)
 {
     _dispatcher                 = dispatcher;
     _cancellationToken          = cancellationToken;
     _updateSolutionStatsHandler = updateSolutionStatsHandler;
     _solutionStats              = new SolutionStats(0, 0, null, null, 0);
 }
Пример #4
0
 private void OnSolveNoSolutionFound(SolutionStats solutionStats)
 {
     _dialogService.CloseSolvingDialog(true);
     _dialogService.ShowMyMessageBox("Sorry - no solution was found!");
     SetStatusMessageFromSolutionStats(solutionStats /*, "no solution found" */);
 }
Пример #5
0
 private void OnSolveSolutionFound(SolutionStats solutionStats, IEnumerable <MatrixRow> colourPairPaths)
 {
     DrawSolution(colourPairPaths);
     SetStatusMessageFromSolutionStats(solutionStats);
     _dialogService.CloseSolvingDialog(true);
 }