Removed unnecessary factors
This commit is contained in:
parent
886ccaa8dc
commit
ec6725a5c5
@ -13,10 +13,9 @@ builder.Services.AddSwaggerGen();
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double stayOnSameRoadPriority, double useHigherLevelRoadsPriority, double useRoadsWithLessJunctionsPriority, double angleFactor) =>
|
app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle, double useHigherLevelRoadsPriority, double maxTurnAngle) =>
|
||||||
{
|
{
|
||||||
Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", useHigherLevelRoadsPriority, stayOnSameRoadPriority,
|
Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", useHigherLevelRoadsPriority, maxTurnAngle).AStar(new Coordinates(latStart, lonStart),
|
||||||
useRoadsWithLessJunctionsPriority, 30).AStar(new Coordinates(latStart, lonStart),
|
|
||||||
new Coordinates(latEnd, lonEnd), vehicle);
|
new Coordinates(latEnd, lonEnd), vehicle);
|
||||||
return result.pathResult;
|
return result.pathResult;
|
||||||
}
|
}
|
||||||
@ -24,8 +23,7 @@ app.MapGet("/getRoute", (float latStart, float lonStart, float latEnd, float lon
|
|||||||
|
|
||||||
app.MapGet("/getShortestRoute", (float latStart, float lonStart, float latEnd, float lonEnd) =>
|
app.MapGet("/getShortestRoute", (float latStart, float lonStart, float latEnd, float lonEnd) =>
|
||||||
{
|
{
|
||||||
Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", 0, 0,
|
Pathfinder result = new Pathfinder("D:/stuttgart-regbez-latest", 0, 30).AStar(new Coordinates(latStart, lonStart),
|
||||||
0, 30).AStar(new Coordinates(latStart, lonStart),
|
|
||||||
new Coordinates(latEnd, lonEnd), Tag.SpeedType.any);
|
new Coordinates(latEnd, lonEnd), Tag.SpeedType.any);
|
||||||
return result.pathResult;
|
return result.pathResult;
|
||||||
}
|
}
|
||||||
|
@ -13,25 +13,21 @@ public class Pathfinder
|
|||||||
public Dictionary<OsmNode, double>? gScore;
|
public Dictionary<OsmNode, double>? gScore;
|
||||||
private Dictionary<OsmNode, OsmNode>? _cameFromDict;
|
private Dictionary<OsmNode, OsmNode>? _cameFromDict;
|
||||||
private SpeedType _speedType;
|
private SpeedType _speedType;
|
||||||
private double roadPriorityFactor, junctionFactor, sameRoadFactor, turnAngle;
|
private double roadPriorityFactor, turnAngle;
|
||||||
|
|
||||||
public Pathfinder(string workingDirectory, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double turnAngle)
|
public Pathfinder(string workingDirectory, double roadPriorityFactor, double turnAngle)
|
||||||
{
|
{
|
||||||
if (!Path.Exists(workingDirectory))
|
if (!Path.Exists(workingDirectory))
|
||||||
throw new DirectoryNotFoundException(workingDirectory);
|
throw new DirectoryNotFoundException(workingDirectory);
|
||||||
regionManager = new(workingDirectory);
|
regionManager = new(workingDirectory);
|
||||||
this.roadPriorityFactor = roadPriorityFactor;
|
this.roadPriorityFactor = roadPriorityFactor;
|
||||||
this.junctionFactor = junctionFactor;
|
|
||||||
this.sameRoadFactor = sameRoadFactor;
|
|
||||||
this.turnAngle = turnAngle;
|
this.turnAngle = turnAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Pathfinder(RegionManager regionManager, double roadPriorityFactor, double junctionFactor, double sameRoadFactor, double turnAngle)
|
public Pathfinder(RegionManager regionManager, double roadPriorityFactor, double turnAngle)
|
||||||
{
|
{
|
||||||
this.regionManager = regionManager;
|
this.regionManager = regionManager;
|
||||||
this.roadPriorityFactor = roadPriorityFactor;
|
this.roadPriorityFactor = roadPriorityFactor;
|
||||||
this.junctionFactor = junctionFactor;
|
|
||||||
this.sameRoadFactor = sameRoadFactor;
|
|
||||||
this.turnAngle = turnAngle;
|
this.turnAngle = turnAngle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,27 +150,9 @@ public class Pathfinder
|
|||||||
else
|
else
|
||||||
angle = nodeAngle / 180;
|
angle = nodeAngle / 180;
|
||||||
}
|
}
|
||||||
|
|
||||||
TagManager curTags = regionManager.GetRegion(currentNode.coordinates)!.tagManager;
|
|
||||||
TagManager nextTags = regionManager.GetRegion(neighborNode.coordinates)!.tagManager;
|
|
||||||
|
|
||||||
bool sameName = false;
|
|
||||||
string? curName = (string?)curTags.GetTag(edge.wayId, TagType.name);
|
|
||||||
bool sameRef = false;
|
|
||||||
string? curRef = (string?)curTags.GetTag(edge.wayId, TagType.tagref);
|
|
||||||
if(curName is not null)
|
|
||||||
foreach (OsmEdge pEdge in neighborNode.edges)
|
|
||||||
{
|
|
||||||
if ((string?)nextTags.GetTag(pEdge.wayId, TagType.name) == curName)
|
|
||||||
sameName = true;
|
|
||||||
if ((string?)nextTags.GetTag(pEdge.wayId, TagType.tagref) == curRef)
|
|
||||||
sameRef = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
double junctionCount = (neighborNode.edges.Count > 2 ? 0 : 1) * junctionFactor;
|
|
||||||
double roadPriority = priority * roadPriorityFactor;
|
double roadPriority = priority * roadPriorityFactor;
|
||||||
double sameRoadName = (sameRef || sameName ? 1 : 0) * sameRoadFactor;
|
return Utils.DistanceBetween(neighborNode, goalNode) / (speed * angle + roadPriority + 1);
|
||||||
return Utils.DistanceBetween(neighborNode, goalNode) / (speed * angle + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SaveResult(string path)
|
public void SaveResult(string path)
|
||||||
|
@ -118,25 +118,19 @@ public class Server
|
|||||||
|
|
||||||
Queue<Thread> calcThreads = new();
|
Queue<Thread> calcThreads = new();
|
||||||
|
|
||||||
for (double sameRoadPriority = 0; sameRoadPriority < 0.02; sameRoadPriority += 0.001)
|
for (double roadLevelPriority = 0.02; roadLevelPriority > 0; roadLevelPriority -= 0.001)
|
||||||
{
|
{
|
||||||
for (double roadLevelPriority = 0.02; roadLevelPriority > 0; roadLevelPriority -= 0.001)
|
for (double maxAngle = 5; maxAngle < 45; maxAngle += 5)
|
||||||
{
|
{
|
||||||
for (double maxAngle = 5; maxAngle < 45; maxAngle += 5)
|
double priority = roadLevelPriority;
|
||||||
|
double angle = maxAngle;
|
||||||
|
calcThreads.Enqueue(new Thread(() =>
|
||||||
{
|
{
|
||||||
double priority = roadLevelPriority;
|
Pathfinder testresult = new Pathfinder(rm, priority, angle).AStar(start,
|
||||||
double roadPriority = sameRoadPriority;
|
finish, Tag.SpeedType.car);
|
||||||
double angle = maxAngle;
|
string fileName = $"angle{angle:0.000}_level{priority:0.000}.result";
|
||||||
calcThreads.Enqueue(new Thread(() =>
|
testresult.SaveResult(Path.Join(parentFolder, fileName));
|
||||||
{
|
}));
|
||||||
Pathfinder testresult = new Pathfinder(rm, priority, roadPriority,
|
|
||||||
0, angle).AStar(start,
|
|
||||||
finish, Tag.SpeedType.car);
|
|
||||||
string fileName =
|
|
||||||
$"angle{angle:0.000}_level{priority:0.000}_same{roadPriority:0.000}.result";
|
|
||||||
testresult.SaveResult(Path.Join(parentFolder, fileName));
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user