/// <summary> /// Outputs the given results to a text file. /// </summary> private void OutputResults(TestResultCollection results, TestConfig config) { StreamWriter sw; IEnumerable <string> dirs = Directory.EnumerateDirectories(Directory.GetCurrentDirectory()); if (!dirs.Contains <string>("Test Results")) { Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Test Results/"); } try { sw = new StreamWriter(Directory.GetCurrentDirectory() + "/Test Results/" + config.OutputFile + ".txt"); } catch (Exception e) { Console.Write("Failed to open stream for test output file.\nException: " + e.Message + "\n"); return; } sw.Write("Test Run On: " + config.StartTime.ToLongDateString() + " at " + config.EndTime.ToLongTimeString() + sw.NewLine + sw.NewLine); sw.Write("----- Configuration -----" + sw.NewLine); sw.Write("Algorithm: " + config.Algorithm.ToString() + sw.NewLine); sw.Write("Map: " + config.MapName + sw.NewLine); sw.Write("Number of Obstacles on Map: " + config.NumberOfObstacles + sw.NewLine); sw.Write("Manhattan distance between start and target: " + config.PathDistance + sw.NewLine); sw.Write("Number of tests: " + config.NumberOfTestRuns + sw.NewLine + sw.NewLine); sw.Write("----- Results ----" + sw.NewLine); sw.Write("Average path length: \t\t" + results.AverageLength + " (STDEV: " + results.STDEVLength + ")" + sw.NewLine); sw.Write("Average nodes searched: \t" + results.AveragedNodesSearched + " (STDEV: " + results.STDEVNodesSearched + ")" + sw.NewLine); sw.Write("Average ms taken: \t\t" + ((double)results.AverageTicksForPath * TestResult.MS_PER_TICK) + " (STDEV: " + results.STDEVMillisecondsTaken + ")" + sw.NewLine); sw.Flush(); sw.Close(); }
/// <summary> /// Outputs the given results to a text file. /// </summary> private void OutputResults(TestResultCollection results, TestConfig config) { StreamWriter sw; IEnumerable<string> dirs = Directory.EnumerateDirectories(Directory.GetCurrentDirectory()); if(!dirs.Contains<string>("Test Results")) Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Test Results/"); try { sw = new StreamWriter(Directory.GetCurrentDirectory() + "/Test Results/" + config.OutputFile + ".txt"); } catch(Exception e) { Console.Write("Failed to open stream for test output file.\nException: " + e.Message + "\n"); return; } sw.Write("Test Run On: " + config.StartTime.ToLongDateString() + " at " + config.EndTime.ToLongTimeString() + sw.NewLine); sw.Write("Map: " + config.MapName + sw.NewLine); sw.Write("Number of Obstacles on Map: " + config.NumberOfObstacles + sw.NewLine); sw.Write("Average path length: " + results.AverageLength + sw.NewLine); sw.Write("Average ticks taken: " + results.AverageTicksForPath + sw.NewLine); sw.Write("Test Finished On: " + config.EndTime.ToLongDateString() + " at " + config.StartTime.ToLongTimeString() + sw.NewLine); sw.Flush(); sw.Close(); }
/// <summary> /// Outputs the given results to a text file. /// </summary> private void OutputResults(TestResultCollection results, TestConfig config) { StreamWriter sw; IEnumerable <string> dirs = Directory.EnumerateDirectories(Directory.GetCurrentDirectory()); if (!dirs.Contains <string>("Test Results")) { Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Test Results/"); } try { sw = new StreamWriter(Directory.GetCurrentDirectory() + "/Test Results/" + config.OutputFile + ".txt"); } catch (Exception e) { Console.Write("Failed to open stream for test output file.\nException: " + e.Message + "\n"); return; } sw.Write("Test Run On: " + config.StartTime.ToLongDateString() + " at " + config.EndTime.ToLongTimeString() + sw.NewLine); sw.Write("Map: " + config.MapName + sw.NewLine); sw.Write("Number of Obstacles on Map: " + config.NumberOfObstacles + sw.NewLine); sw.Write("Average path length: " + results.AverageLength + sw.NewLine); sw.Write("Average ticks taken: " + results.AverageTicksForPath + sw.NewLine); sw.Write("Test Finished On: " + config.EndTime.ToLongDateString() + " at " + config.StartTime.ToLongTimeString() + sw.NewLine); sw.Flush(); sw.Close(); }
public TestWorker(TestConfig config) { this.config = config; cancel = false; rand = new Random(DateTime.Now.Millisecond); results = new TestResultCollection(); WorkerReportsProgress = true; }
TestResultCollection results; // The list of results #endregion Fields #region Constructors public TestWorker(TestConfig config) { this.config = config; cancel = false; rand = new Random(DateTime.Now.Millisecond); results = new TestResultCollection(); WorkerReportsProgress = true; }
/// <summary> /// Runs a test and returns the result. /// </summary> /// <param name="algorithm">The pathfinding algorithm to use.</param> /// <param name="startPos">The starting position to use for the test.</param> /// <param name="pathLength">The length in manhattan distance that the target position should be from the starting position.</param> /// <param name="rand">A seeded random number generator to used to calculate a target position.</param> /// <returns></returns> public static TestResult RunTest(PathfinderAlgorithm algorithm, Coord2 startPos, List <Coord2> possibleTargets) { // Initialize result collection TestResultCollection results = new TestResultCollection(); // Set the pathfinding algorithm Level.SetPathfindingAlgorithm(algorithm); // Create time take variable TimeSpan timeTaken; // The target position Coord2 targetPos; do { // Find random target do { targetPos = possibleTargets[rand.Next(0, possibleTargets.Count)]; } while (!level.Map.ValidPosition(targetPos)); // Get Start Time DateTime startTime = DateTime.Now; // Find Path Level.Map.pathfinder.Build(startPos, targetPos, true); // Calculate time taken DateTime finishTime = DateTime.Now; timeTaken = finishTime - startTime; } while (Level.Map.pathfinder.GetPath().Count() == 0); // If no path was found, try again // Return result return(new TestResult(timeTaken.Ticks, Level.Map.pathfinder.GetPath().Count(), Level.Map.pathfinder.NodesSearched())); }
public TestCompletedArgs(TestResultCollection results, bool cancelled) { this.cancelled = cancelled; this.results = results; }
/// <summary> /// Outputs the given results to a text file. /// </summary> private void OutputResults(TestResultCollection results, TestConfig config) { StreamWriter sw; IEnumerable<string> dirs = Directory.EnumerateDirectories(Directory.GetCurrentDirectory()); if(!dirs.Contains<string>("Test Results")) Directory.CreateDirectory(Directory.GetCurrentDirectory() + "/Test Results/"); try { sw = new StreamWriter(Directory.GetCurrentDirectory() + "/Test Results/" + config.OutputFile + ".txt"); } catch(Exception e) { Console.Write("Failed to open stream for test output file.\nException: " + e.Message + "\n"); return; } sw.Write("Test Run On: " + config.StartTime.ToLongDateString() + " at " + config.EndTime.ToLongTimeString() + sw.NewLine + sw.NewLine); sw.Write("----- Configuration -----" + sw.NewLine); sw.Write("Algorithm: " + config.Algorithm.ToString() + sw.NewLine); sw.Write("Map: " + config.MapName + sw.NewLine); sw.Write("Number of Obstacles on Map: " + config.NumberOfObstacles + sw.NewLine); sw.Write("Manhattan distance between start and target: " + config.PathDistance + sw.NewLine); sw.Write("Number of tests: " + config.NumberOfTestRuns + sw.NewLine + sw.NewLine); sw.Write("----- Results ----" + sw.NewLine); sw.Write("Average path length: \t\t" + results.AverageLength + " (STDEV: " + results.STDEVLength + ")" + sw.NewLine); sw.Write("Average nodes searched: \t" + results.AveragedNodesSearched + " (STDEV: " + results.STDEVNodesSearched + ")" + sw.NewLine); sw.Write("Average ms taken: \t\t" + ((double)results.AverageTicksForPath * TestResult.MS_PER_TICK) + " (STDEV: " + results.STDEVMillisecondsTaken + ")" + sw.NewLine); sw.Flush(); sw.Close(); }
public TestCompletedArgs(TestResultCollection results, TestConfig config, bool cancelled) { this.cancelled = cancelled; this.results = results; this.config = config; }
/// <summary> /// Runs a test and returns the result. /// </summary> /// <param name="algorithm">The pathfinding algorithm to use.</param> /// <param name="startPos">The starting position to use for the test.</param> /// <param name="pathLength">The length in manhattan distance that the target position should be from the starting position.</param> /// <param name="rand">A seeded random number generator to used to calculate a target position.</param> /// <returns></returns> public static TestResult RunTest(PathfinderAlgorithm algorithm, Coord2 startPos, List<Coord2> possibleTargets) { // Initialize result collection TestResultCollection results = new TestResultCollection(); // Set the pathfinding algorithm Level.SetPathfindingAlgorithm(algorithm); // Create time take variable TimeSpan timeTaken; // The target position Coord2 targetPos; do { // Find random target do { targetPos = possibleTargets[rand.Next(0, possibleTargets.Count)]; } while (!level.Map.ValidPosition(targetPos)); // Get Start Time DateTime startTime = DateTime.Now; // Find Path Level.Map.pathfinder.Build(startPos, targetPos, true); // Calculate time taken DateTime finishTime = DateTime.Now; timeTaken = finishTime - startTime; } while (Level.Map.pathfinder.GetPath().Count() == 0); // If no path was found, try again // Return result return new TestResult(timeTaken.Ticks, Level.Map.pathfinder.GetPath().Count(), Level.Map.pathfinder.NodesSearched()); }