Skip to content

Commit

Permalink
Reenabled new pathcaluclation after one year. To be tested!
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan-S committed May 21, 2021
1 parent b2a3bb9 commit 25b4980
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
12 changes: 6 additions & 6 deletions FS19_AutoDrive/scripts/Manager/GraphManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ function ADGraphManager:pathFromTo(startWaypointId, targetWaypointId)
if startWaypointId == targetWaypointId then
table.insert(wp, self.wayPoints[targetWaypointId])
else
-- wp = ADPathCalculator:GetPath(startWaypointId, targetWaypointId)
wp = AutoDrive:dijkstraLiveShortestPath(startWaypointId, targetWaypointId)
wp = ADPathCalculator:GetPath(startWaypointId, targetWaypointId)
--wp = AutoDrive:dijkstraLiveShortestPath(startWaypointId, targetWaypointId)
end
end
return wp
Expand All @@ -168,8 +168,8 @@ function ADGraphManager:pathFromToMarker(startWaypointId, markerId)
table.insert(wp, 1, self.wayPoints[targetId])
return wp
else
-- wp = ADPathCalculator:GetPath(startWaypointId, targetId)
wp = AutoDrive:dijkstraLiveShortestPath(startWaypointId, targetId)
wp = ADPathCalculator:GetPath(startWaypointId, targetId)
--wp = AutoDrive:dijkstraLiveShortestPath(startWaypointId, targetId)
end
end
return wp
Expand Down Expand Up @@ -200,8 +200,8 @@ function ADGraphManager:FastShortestPath(start, markerName, markerId)
return wp
end

-- wp = ADPathCalculator:GetPath(start_id, target_id)
wp = AutoDrive:dijkstraLiveShortestPath(start_id, target_id)
wp = ADPathCalculator:GetPath(start_id, target_id)
--wp = AutoDrive:dijkstraLiveShortestPath(start_id, target_id)
return wp
end

Expand Down
12 changes: 8 additions & 4 deletions FS19_AutoDrive/scripts/PathCalculation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ function ADPathCalculator:GetPath(startID, targetID)
local count = 0

if not ADGraphManager:areWayPointsPrepared() then
print("ADPathCalculator - preparing waypoints - 1")
AutoDrive.checkWaypointsLinkedtothemselve(true) -- find WP linked to themselve, with parameter true issues will be fixed
print("ADPathCalculator - preparing waypoints - 2")
AutoDrive.checkWaypointsMultipleSameOut(true) -- find WP with multiple same out ID, with parameter true issues will be fixed
print("ADPathCalculator - preparing waypoints - 3")
ADGraphManager:prepareWayPoints()
print("ADPathCalculator - preparing waypoints - 4")
end

local network = ADGraphManager:getWayPoints()
Expand Down Expand Up @@ -54,8 +58,8 @@ function ADPathCalculator:GetPath(startID, targetID)
for _, outId in pairs(outMap) do
local outPoint = network[outId]

-- axel TODO implement automatic network check for such issue: waypoint linked to itself -> DONE with AutoDrive.checkWaypointsLinkedtothemselve(true)
if point.id ~= outPoint.id then
-- axel TODO implement automatic network check for such issue: waypoint linked to itself -> DONE with AutoDrive.checkWaypointsLinkedtothemselve(true)
--if point.id ~= outPoint.id then
-- First check if this point needs to be added to the candidate list or if it has already been tested
local toBeAdded = true
if results[outId] ~= nil then
Expand All @@ -69,7 +73,7 @@ function ADPathCalculator:GetPath(startID, targetID)
toBeAdded = false
end
end
if toBeAdded or (#point.incoming > 1) then
if toBeAdded then --or (#point.incoming > 1)
candidates:enqueue({p=outPoint, distance=(distance + distanceFunc(outPoint.x - point.x, outPoint.z - point.z) + (addedWeights[outPoint.id] or 0)), pre=point.id})
end

Expand All @@ -80,7 +84,7 @@ function ADPathCalculator:GetPath(startID, targetID)
results[point.id][outId] = {distance=distance, pre=previousPoint}
end
end
end
--end
end
point = nil
else
Expand Down

5 comments on commit 25b4980

@jala15
Copy link
Contributor

@jala15 jala15 commented on 25b4980 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Stephan-S Not a long time ago I tried to use this path calculation method because I liked its behaviour with blue lines, but I found that in big routes (ex. 4x map, 6 different routes inside each bunker silo to distribute discharge) it triggered the limit of >500000 calculations. Increasing this limit made calculations too laggy.


Calculations were multiplied by 2 at every path bifurcation, and exponential calculations become too big. That's what made me try to improve DijkstraLive to calculate blue lines forward and backward instead.
Anyway, at least for me, it worked fine with smaller routes.
I hope this info can be useful for your testing ;)

@Stephan-S
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jala15 ,
thanks for the quick feedback.
Do you have a network with a problematic size for me to test this?
I can't seem to reproduce any errors with it. There is exactly one small lag the first time you start a driver because it prepares some tables. But I could just as well put that into the init code during map loading.
Otherwise the performance is better than the old Dijkstra implementation or at least the same.

It could have to do with that line:
25b4980#diff-5335b753e3c250d60b8a51be252cf70c981829f6fa4c032f3fbd71bef82a21b8L72

I honestly don't yet know why Axel put it in there and I haven't heard back yet, so I removed it for now.

@jala15
Copy link
Contributor

@jala15 jala15 commented on 25b4980 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this config for the map Southwind Fields
AutoDrive_config.xml.txt
I remember my truck couldn't drive from "Sellpoint 150" to "F6 sw", but I guess it could drive from "Sellpoint 150" to "Fuel station" and from there to "F6 sw". I'm not sure of the last statement, but I guess the limit of driving/not driving was around "Fuel station".

@Stephan-S
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I checked it out and there was zero lag for me and 'Sellpoint 150" to "F6 sw" was no problem at all.

@jala15
Copy link
Contributor

@jala15 jala15 commented on 25b4980 May 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow I feel quite stupid now. So much time spent with dijkstraBlue instead of removing one line. I will give it a try in a few days, very busy at the time.
Thank you very much

Please sign in to comment.