Stephan-S / AutoDrive

This is a script for the Farming Simulator 17 which lets your tractor drive to destinations autonomously
16 stars 9 forks source link

AutoDrive:dijkstra() optimization #14

Open DeckerMMIV opened 7 years ago

DeckerMMIV commented 7 years ago

I've reduced the number of array-lookups and did some tweaks in the function/method, which for me resulted in a speed-boost when recalculating the graph.

Using locals are quicker in LUA (link), than searching through a multi-dimensional-array, so that is why I replaced self.ad.<member> with a newPaths.<member>, and reworked usage of self.ad.Q[start][setToUse] so there is no need to do multiple lookups.

Also discovered that there is no need to make a deep-copy of the Graph into Q. An array of the 'unvisited' nodes will suffice, so that is why I've made a shallow-copy of graphinto local workGraph (previously Q), which directly references the elements in graph, as these elements are not modified when this function is doing its task.

Another trick with LUA, is that the indices of an array/table can have gaps - so it is actually not an 'array' as such. With this knowledge, I could see an optimization of the for i2 in pairs(self.ad.Q) do ... if inQ == true then, and changed it to do a direct-lookup if a wanted waypoint-id was still in the workGraph table (array).

Dzi4d3k commented 7 years ago

I can confirm that optimization works very well. On quad core Intel i7 CPU @2.90 GHz recalculation on GCV is reduced from 1:46 minutes to 19 seconds.

streubeheubar commented 6 years ago

Hallo an Dzi4d3K.

Besteht die Möglichkeit die geänderte Vesion von dir zu bekommen ?

mfg Martin

Anonymous-any commented 7 months ago

Hallo an Dzi4d3K.

Besteht die Möglichkeit die geänderte Vesion von dir zu bekommen ?

mfg Martin

Late but income, click the link below then https://raw.githubusercontent.com/Stephan-S/AutoDrive/a0e22f793c5bf8def3be87c4f5b3bae61ecdb6c1/Mod/AutoDrive.lua

register file into browser, go to file register under and u got your "AutoDrive.lua" to replace into the .zip file mod. Br