Added function to mass-test the heuristic variables.

This commit is contained in:
glax 2023-04-21 13:49:48 +02:00
parent cd3905915b
commit 95c0088b73

View File

@ -26,12 +26,15 @@ public class Server
Coordinates start = new (48.7933798f, 9.8275859f);
Coordinates finish = new (48.795918f, 9.021618f);
TestVariables(workingDir, start, finish);
Console.WriteLine("Preparing BaseRender");
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
/*
Console.WriteLine("Preparing BaseRender");
RegionManager allRegions = new(workingDir);
for (float lat = 48.75f - Region.RegionSize / 2; lat < 48.85f + Region.RegionSize / 2; lat += Region.RegionSize / 2)
for (float lat = 48.78f - Region.RegionSize / 2; lat < 48.87f + Region.RegionSize / 2; lat += Region.RegionSize / 2)
{
for (float lon = 9f - Region.RegionSize / 2; lon < 9.9f + Region.RegionSize / 2; lon += Region.RegionSize / 2)
{
@ -40,36 +43,19 @@ public class Server
}
Console.WriteLine("Regions Loaded. Rendering.");
ValueTuple<Image, Renderer.Bounds> baseRender = Renderer.DrawArea(allRegions);
for (double sameRoadPriority = 0; sameRoadPriority < 0.4; sameRoadPriority += 0.015)
{
for (double roadLevelPriority = 0.4; roadLevelPriority > 0; roadLevelPriority -= 0.015)
{
for (double angleWeightFactor = 45; angleWeightFactor < 65; angleWeightFactor += 1.0)
{
Console.WriteLine($"{angleWeightFactor}/65 {roadLevelPriority}/0,4 {sameRoadPriority}/0,4");
Pathfinder testresult = new Pathfinder(workingDir).AStar(start,
finish, Tag.SpeedType.car, roadLevelPriority, sameRoadPriority,
0, angleWeightFactor);
string fileName = $"angle{angleWeightFactor}_level{roadLevelPriority}_same{sameRoadPriority}.png";
string path = Path.Join(parentFolder, fileName);
Image areaHeur = Renderer.DrawGScores(testresult.gScore, baseRender.Item1, baseRender.Item2).Item1;
Image areaHeurPath = Renderer.DrawPath(testresult.pathResult, areaHeur, baseRender.Item2).Item1;
areaHeurPath.Save(path, ImageFormat.Png);
}
}
}
*/
/*
Pathfinder result = new Pathfinder(workingDir).AStar(start,
finish, Tag.SpeedType.car, 0.03, 0.01,
0, 50);
finish, Tag.SpeedType.car, 0.034, 0.012,
0, 0.18);
Console.WriteLine($"Calc-time {result.pathResult!.calcTime} Path-length: {result.pathResult.pathNodes.Count} Visited-nodes: {result.gScore!.Count}");
string fileName = DateTime.Now.ToFileTime().ToString();
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
string resultFileName = $"{new DirectoryInfo(workingDir).Name}-{fileName}.result";
result.SaveResult(Path.Join(parentFolder, resultFileName));
@ -79,4 +65,53 @@ public class Server
render.Save(Path.Join(parentFolder, renderFileName), ImageFormat.Png);
#pragma warning restore CA1416*/
}
private static void TestVariables(string workingDir, Coordinates start, Coordinates finish)
{
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
Queue<Thread> CalcThreads = new();
for (double sameRoadPriority = 0.002; sameRoadPriority < 0.4; sameRoadPriority += 0.02)
{
for (double roadLevelPriority = 0.4; roadLevelPriority > 0; roadLevelPriority -= 0.02)
{
for (double angleWeightFactor = 0.01; angleWeightFactor < 0.25; angleWeightFactor += 0.01)
{
double priority = roadLevelPriority;
double roadPriority = sameRoadPriority;
double factor = angleWeightFactor;
CalcThreads.Enqueue(new Thread(() =>
{
Pathfinder testresult = new Pathfinder(workingDir).AStar(start,
finish, Tag.SpeedType.car, priority, roadPriority,
0, factor);
string fileName =
$"angle{factor:0.000}_level{priority:0.000}_same{roadPriority:0.000}.result";
testresult.SaveResult(Path.Join(parentFolder, fileName));
}));
}
}
}
int totalTasks = CalcThreads.Count;
int completed = 0;
DateTime startTime = DateTime.Now;
HashSet<Thread> runningThreads = new();
while (CalcThreads.Count > 0)
{
while (runningThreads.Count < 16 && CalcThreads.Count > 0)
{
Thread t = CalcThreads.Dequeue();
runningThreads.Add(t);
t.Start();
}
int newCompleted = runningThreads.RemoveWhere(thread => !thread.IsAlive);
completed += newCompleted;
if(newCompleted > 0)
Console.WriteLine($"To calculate: {CalcThreads.Count}/{totalTasks} Average Time: {(DateTime.Now - startTime)/(completed)} Elapsed: {DateTime.Now - startTime} Remaining: {(DateTime.Now - startTime)/(completed)*CalcThreads.Count}");
}
}
}