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; }
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); }
public PuzzleSolverStats( IDispatcher dispatcher, CancellationToken cancellationToken, Action <SolutionStats> updateSolutionStatsHandler) { _dispatcher = dispatcher; _cancellationToken = cancellationToken; _updateSolutionStatsHandler = updateSolutionStatsHandler; _solutionStats = new SolutionStats(0, 0, null, null, 0); }
private void OnSolveNoSolutionFound(SolutionStats solutionStats) { _dialogService.CloseSolvingDialog(true); _dialogService.ShowMyMessageBox("Sorry - no solution was found!"); SetStatusMessageFromSolutionStats(solutionStats /*, "no solution found" */); }
private void OnSolveSolutionFound(SolutionStats solutionStats, IEnumerable <MatrixRow> colourPairPaths) { DrawSolution(colourPairPaths); SetStatusMessageFromSolutionStats(solutionStats); _dialogService.CloseSolvingDialog(true); }