Esempio n. 1
0
        private void Save(ComparativeRunReport runReport, Func <ComparativeRunReport, object> selectiveSave = null,
                          bool includeImages = false)
        {
            var images = new List <Image>();

            if (includeImages)
            {
                images.Add(_renderer.RenderGraph(runReport.Graph));
                images.Add(_renderer.RenderGraph(runReport.Graph, runReport.BaseSolverReport.BestWalk));
                images.Add(_renderer.RenderGraph(runReport.Graph, runReport.TestedSolverReport.BestWalk));
            }

            selectiveSave = selectiveSave ?? (x => x);
            _repo.Save(selectiveSave(runReport), images.ToArray());
        }
Esempio n. 2
0
        public ComparativeRunReport CompareWithGraph(Graph graph, ITspSolver baseSolver,
                                                     ITspSolver testedSolver, SaveType saveType        = SaveType.OnFailure,
                                                     Func <ComparativeRunReport, object> selectiveSave = null, bool includeImages = false)
        {
            RunReport baseReport   = null;
            RunReport testedReport = null;
            Exception exception    = null;

            try
            {
                baseReport   = null;
                testedReport = null;
                exception    = null;

                Run(graph, baseSolver, out baseReport);
                Run(graph, testedSolver, out testedReport);
            }
            catch (Exception e)
            {
                exception = e;
            }

            var comparativeReport = ComparativeRunReport.Create(baseReport, testedReport, exception);

            switch (saveType)
            {
            case SaveType.None:
                break;

            case SaveType.OnFailure:
                if (comparativeReport.Outcome != ComparativeRunReport.OutcomeText.Success)
                {
                    Save(comparativeReport, selectiveSave, includeImages);
                }
                break;

            case SaveType.All:
                Save(comparativeReport, selectiveSave, includeImages);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(saveType), saveType, null);
            }

            return(comparativeReport);
        }
Esempio n. 3
0
        public static ComparativeRunReport Create(RunReport baseSolverReport, RunReport testedSolverReport,
                                                  Exception e = null)
        {
            var report = new ComparativeRunReport();

            report.Graph              = baseSolverReport.Graph;
            report.BaseSolverReport   = baseSolverReport;
            report.TestedSolverReport = testedSolverReport;
            if (e == null)
            {
                report.Variance = testedSolverReport.BestDistance.Value - baseSolverReport.BestDistance.Value;
                report.Outcome  = (report.Variance < 0.0001) ? OutcomeText.Success : OutcomeText.Failure;
            }
            else
            {
                report.Outcome = String.Format(OutcomeText.Exception, e.Message);
            }

            return(report);
        }
Esempio n. 4
0
        private void SaveSingleRun(ComparativeRunReport run, string rootPath)
        {
            _fileSystem.EnsureDirectory(FirstFailurePath);
            _fileSystem.ClearDirectory(FirstFailurePath);
            var filePath = rootPath + @"\{0}.bmp";

            var renderer = new GraphRenderer();

            _fileSystem.SaveText(rootPath + @"\Graph.json", _serializer.Serialize(run.Graph));

            _fileSystem.SaveImage(string.Format(filePath, "best"),
                                  renderer.RenderGraph(run.Graph, run.BaseSolverReport.BestWalk));

            var history = (List <Node[]>)run.TestedSolverReport.RunDetails["history"];
            var index   = 1;

            foreach (var walk in history)
            {
                _fileSystem.SaveImage(string.Format(filePath, "step" + index++),
                                      renderer.RenderGraph(run.Graph, walk));
            }
        }