UBCSailbot / raye-global-pathfinding

UBC Sailbot's Global Pathfinding Repository: A* pathfinding that creates sailing paths with minimized length and desirable wind speeds throughout.
MIT License
5 stars 1 forks source link

Modify wind cost function #66

Closed tylerlum closed 1 year ago

tylerlum commented 2 years ago

Right now, we have 2 cost components.

  1. Distance: Length of the path. Sum of the distance between nodes in the path.
  2. Wind: Wind cost value that is a function of wind speed between nodes. Sum of wind cost per node-node segment.
Total Cost = Distance Cost + (wind_factor) * Wind Cost
wind_factor is a parameter to scale.

Let p0, p1, p2, ..., pn be the waypoints of the global path.

The distance cost is approximately invariant with respect to pathfinding resolution (how far apart each node is). If we double the resolution, the total distance is still the same.

Distance Cost = sum[ dist(pi, pi+1) ] for i = 0:n-1

The wind cost is not invariant with respect to pathfinding resolution. If we double the resolution, there will be about double as many node-node segments. Thus the wind cost will be approximately doubled. Ideally, this should be invariant.

Wind Cost = sum[ Wind_Cost_Function( (Wind_Speed(pi) + Wind_Speed(pi+1)) / 2) ] for i = 0:n-1
Wind_Cost_Function = https://www.desmos.com/calculator/md1byjfsl2

image

One possible solution is to scale each wind cost segment by the distance of the node-node segment. This way, doubling the resolution results in the wind cost being about the same.

Wind Cost = sum[ dist(pi, pi+1) * Wind_Cost_Function( (Wind_Speed(pi) + Wind_Speed(pi+1)) / 2) ] for i = 0:n-1
Wind_Cost_Function = https://www.desmos.com/calculator/md1byjfsl2

ALSO: Average wind might not be the best thing to do here. What if one is 0 and one is 40 (both bad). Average is 20, which appears good... Could replace Wind_Cost_Function( (Wind_Speed(pi) + Wind_Speed(pi+1)) / 2) with (Wind_Cost_Function(Wind_Speed(pi)) + Wind_Cost_Function(Wind_Speed(pi+1))) / 2