private void RegisterAttempt(RunReport report, Node[] attempt) { _validator.Validate(report.Graph.Nodes, attempt); var distance = _calculator.Distance(attempt); if (report.BestDistance == null || distance < report.BestDistance) { report.BestWalk = attempt; report.BestDistance = distance; } }
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); }
public void Run(Graph graph, ITspSolver solver, out RunReport report) { report = new RunReport { SolverName = solver.GetType().Name, Graph = graph }; var timer = new Stopwatch(); timer.Start(); var runReport = report; solver.TrySolve(graph, attempt => RegisterAttempt(runReport, attempt.ToArray()), runReport.RunDetails); timer.Stop(); report.Duration = timer.Elapsed; }
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); }