/// <summary>
        /// reads from a file then finds a path between every point in the file
        /// k points in file = k(k-1)/2 paths
        /// Creates output file for each implementation with the average time for each path
        /// </summary>
        /// <param name="pf"></param>
        private static AlgorithmTestResults TestPathFinder(PathFinder pf)
        {
            AlgorithmTestResults        resultsList = new AlgorithmTestResults(pf.GetAbbreivatedName());
            List <StartDestinationPair> testPoints  = ReadPointFile(pf.Graph.TestPointsPath);
            string outputPath = System.IO.Path.Combine("output", DateTime.Now.ToString(pf.Graph.Name + "yyyyMMdd_hhmmss") + pf.GetType().Name + ".txt");

            if (!System.IO.Directory.Exists("output"))
            {
                System.IO.Directory.CreateDirectory("output");
            }
            using (System.IO.TextWriter tw = new System.IO.StreamWriter(outputPath, false))
            {
                double totalRunTime          = 0;
                int    successfullPathsFound = 0;

                foreach (var startDestinationPair in testPoints)
                {
                    float pathLength = 0;
                    var   sw         = new Stopwatch();

                    Vertex startVertex       = pf.FindClosestVertex(startDestinationPair.Start);
                    Vertex destinationVertex = pf.FindClosestVertex(startDestinationPair.Destination);

                    sw.Start();
                    var path = pf.FindShortestPath(startVertex, destinationVertex, ref pathLength);
                    sw.Stop();
                    pf.ResetGraph();
                    string msg         = null;
                    double elapsedTime = sw.Elapsed.TotalSeconds;
                    if (path != null && path.Count > 0)
                    {
                        totalRunTime += elapsedTime;
                        successfullPathsFound++;
                        msg = startDestinationPair.ToString() + "Completed in " + elapsedTime.ToString() + " seconds." + " with path length = " + pathLength + " vertex count = " + path.Count;
                    }
                    else
                    {
                        msg = startDestinationPair.ToString() + "Failed to find path in " + elapsedTime.ToString() + " seconds.";
                    }
                    tw.WriteLine(pf.GetType().Name + " " + msg);
                    if (path != null)
                    {
                        resultsList.AddTestResult(new TestResults(elapsedTime, path.Count));
                    }
                    else
                    {
                        resultsList.AddTestResult(new TestResults(elapsedTime, -1));
                    }
                }
                tw.WriteLine("Average Runtime(sec) = " + totalRunTime / successfullPathsFound + " Failed Paths = " + (testPoints.Count - successfullPathsFound));
            }
            return(resultsList);
        }
Beispiel #2
0
 public void AddAlgorithmTestResult(AlgorithmTestResults atr)
 {
     atr.CalculateIntervalRuntimes();
     this.AlgorithmTestResults.Add(atr);
 }