Compare commits
No commits in common. "6b5dddb1e3452ac2581f8d1b62d66a083ba59bbd" and "ec6725a5c513a9b52c881c8077a1a07a59a7eb3a" have entirely different histories.
6b5dddb1e3
...
ec6725a5c5
@ -135,13 +135,9 @@ public class Pathfinder
|
|||||||
double priority = regionManager.GetPriorityForVehicle(_speedType, edge, currentNode);
|
double priority = regionManager.GetPriorityForVehicle(_speedType, edge, currentNode);
|
||||||
if (priority == 0)
|
if (priority == 0)
|
||||||
return double.MaxValue;
|
return double.MaxValue;
|
||||||
|
|
||||||
double distance = Utils.DistanceBetween(neighborNode, goalNode);
|
|
||||||
|
|
||||||
double speed = regionManager.GetSpeedForEdge(currentNode, edge.wayId, _speedType);
|
double speed = regionManager.GetSpeedForEdge(currentNode, edge.wayId, _speedType);
|
||||||
|
|
||||||
double roadPriority = priority * roadPriorityFactor;
|
|
||||||
|
|
||||||
double angle = 0;
|
double angle = 0;
|
||||||
if (_cameFromDict!.ContainsKey(currentNode))
|
if (_cameFromDict!.ContainsKey(currentNode))
|
||||||
{
|
{
|
||||||
@ -155,13 +151,12 @@ public class Pathfinder
|
|||||||
angle = nodeAngle / 180;
|
angle = nodeAngle / 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
return distance / (speed * angle + roadPriority + 1);
|
double roadPriority = priority * roadPriorityFactor;
|
||||||
|
return Utils.DistanceBetween(neighborNode, goalNode) / (speed * angle + roadPriority + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveResult(string path)
|
public void SaveResult(string path)
|
||||||
{
|
{
|
||||||
if(File.Exists(path))
|
|
||||||
File.Delete(path);
|
|
||||||
FileStream fs = new (path, FileMode.CreateNew);
|
FileStream fs = new (path, FileMode.CreateNew);
|
||||||
JsonSerializer.Serialize(fs, pathResult, JsonSerializerOptions.Default);
|
JsonSerializer.Serialize(fs, pathResult, JsonSerializerOptions.Default);
|
||||||
fs.Dispose();
|
fs.Dispose();
|
||||||
|
@ -30,7 +30,7 @@ public class Server
|
|||||||
GetShortestRoute("D:");
|
GetShortestRoute("D:");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
ValueTuple<Image, Renderer.Bounds> area = Renderer.DrawArea(LoadRegions(workingDir, start, finish));
|
ValueTuple<Image, Renderer.Bounds> area = RenderAreaBaseImage(workingDir, start, finish);
|
||||||
area.Item1.Save(@"D:\Base.png", ImageFormat.Png);
|
area.Item1.Save(@"D:\Base.png", ImageFormat.Png);
|
||||||
|
|
||||||
ValueTuple<Image, Renderer.Bounds> areaDistance = Renderer.DrawPath(
|
ValueTuple<Image, Renderer.Bounds> areaDistance = Renderer.DrawPath(
|
||||||
@ -87,12 +87,10 @@ public class Server
|
|||||||
if (calcTime.Key.calcTime > result.calcTime)
|
if (calcTime.Key.calcTime > result.calcTime)
|
||||||
calcTime = new KeyValuePair<PathResult, string>(result, filePath);
|
calcTime = new KeyValuePair<PathResult, string>(result, filePath);
|
||||||
}
|
}
|
||||||
Console.WriteLine($"\nShortest:\t{shortest.Key.distance:0.0} {shortest.Key.weight:0.00} {shortest.Key.calcTime} {shortest.Value}\n" +
|
Console.WriteLine($"Shortest: {shortest.Key.distance} {shortest.Value}\nFastest: {shortest.Key.weight} {fastest.Value}\nCalcTime: {calcTime.Key.calcTime} {calcTime.Value}");
|
||||||
$"Fastest:\t{fastest.Key.distance:0.0} {fastest.Key.weight:0.00} {fastest.Key.calcTime} {fastest.Value}\n" +
|
|
||||||
$"CalcTime:\t{calcTime.Key.distance:0.0} {calcTime.Key.weight:0.00} {calcTime.Key.calcTime} {calcTime.Value}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RegionManager LoadRegions(string workingDir, Coordinates c1, Coordinates c2)
|
private static ValueTuple<Image, Renderer.Bounds> RenderAreaBaseImage(string workingDir, Coordinates c1, Coordinates c2)
|
||||||
{
|
{
|
||||||
float minLat = c1.latitude < c2.latitude ? c1.latitude : c2.latitude;
|
float minLat = c1.latitude < c2.latitude ? c1.latitude : c2.latitude;
|
||||||
float minLon = c1.longitude < c2.longitude ? c1.longitude : c2.longitude;
|
float minLon = c1.longitude < c2.longitude ? c1.longitude : c2.longitude;
|
||||||
@ -107,21 +105,22 @@ public class Server
|
|||||||
allRegions.GetRegion(new Coordinates(lat, lon));
|
allRegions.GetRegion(new Coordinates(lat, lon));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("Loaded needed Regions");
|
Console.WriteLine("Regions Loaded. Rendering.");
|
||||||
return allRegions;
|
ValueTuple<Image, Renderer.Bounds> baseRender = Renderer.DrawArea(allRegions);
|
||||||
|
return baseRender;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void TestVariables(string workingDir, Coordinates start, Coordinates finish, int threads)
|
private static void TestVariables(string workingDir, Coordinates start, Coordinates finish, int threads)
|
||||||
{
|
{
|
||||||
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
|
string parentFolder = new DirectoryInfo(workingDir).Parent!.FullName;
|
||||||
|
|
||||||
RegionManager rm = LoadRegions(workingDir, start, finish);
|
RegionManager rm = new (workingDir);
|
||||||
|
|
||||||
Queue<Thread> calcThreads = new();
|
Queue<Thread> calcThreads = new();
|
||||||
|
|
||||||
for (double roadLevelPriority = 0.016; roadLevelPriority < 0.02; roadLevelPriority += 0.0002)
|
for (double roadLevelPriority = 0.02; roadLevelPriority > 0; roadLevelPriority -= 0.001)
|
||||||
{
|
{
|
||||||
for (double maxAngle = 25; maxAngle < 35; maxAngle += 1)
|
for (double maxAngle = 5; maxAngle < 45; maxAngle += 5)
|
||||||
{
|
{
|
||||||
double priority = roadLevelPriority;
|
double priority = roadLevelPriority;
|
||||||
double angle = maxAngle;
|
double angle = maxAngle;
|
||||||
@ -129,7 +128,7 @@ public class Server
|
|||||||
{
|
{
|
||||||
Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start,
|
Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start,
|
||||||
finish, Tag.SpeedType.car);
|
finish, Tag.SpeedType.car);
|
||||||
string fileName = $"angle{angle:00}_level{priority:0.0000}.result";
|
string fileName = $"angle{angle:0.000}_level{priority:0.000}.result";
|
||||||
testresult.SaveResult(Path.Join(parentFolder, fileName));
|
testresult.SaveResult(Path.Join(parentFolder, fileName));
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -140,7 +139,7 @@ public class Server
|
|||||||
DateTime startTime = DateTime.Now;
|
DateTime startTime = DateTime.Now;
|
||||||
|
|
||||||
HashSet<Thread> runningThreads = new();
|
HashSet<Thread> runningThreads = new();
|
||||||
while (calcThreads.Count > 0 || runningThreads.Count > 0)
|
while (calcThreads.Count > 0)
|
||||||
{
|
{
|
||||||
while (runningThreads.Count < threads && calcThreads.Count > 0)
|
while (runningThreads.Count < threads && calcThreads.Count > 0)
|
||||||
{
|
{
|
||||||
@ -154,7 +153,7 @@ public class Server
|
|||||||
if (newCompletedTasks > 0)
|
if (newCompletedTasks > 0)
|
||||||
{
|
{
|
||||||
TimeSpan elapsedTime = DateTime.Now - startTime;
|
TimeSpan elapsedTime = DateTime.Now - startTime;
|
||||||
Console.WriteLine($"To calculate: {calcThreads.Count}(+{runningThreads.Count})/{totalTasks} Time Average: {(elapsedTime)/(completedTasks)} Elapsed: {elapsedTime} Remaining: {(elapsedTime)/(completedTasks)*calcThreads.Count}");
|
Console.WriteLine($"To calculate: {calcThreads.Count}/{totalTasks} Time Average: {(elapsedTime)/(completedTasks)} Elapsed: {elapsedTime} Remaining: {(elapsedTime)/(completedTasks)*calcThreads.Count}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user