The simplest and least intrusive change would also be totally fix the problem and would not cost any more time in the long run, just move some calculations to earlier:Jap2.0 wrote:The point is that no matter how hard you try, you (probably) won't be able to find a solution less computationally intensive than creating a straight line and occasionally checking "if charge < x then charging logic". Changing it would also require a lot of work and could create a lot of bugs. There is also the problem of regenerating tables if you use that method, with lag spikes or wacky behavior, and possibly bugs. Bot pathing during that time could also be an issue.mrvn wrote:First of this is not traveling salesman. You are not trying to find a path that visits all roboports in the shortest total distance. It's a simple graph problem. Given a network where each roboport has a shortest route to every other adding a roboport is simple. You take the table from each roboport in reach (usually no more than 4), add the distance to that roboport and then build your own table taking the shortest entry from the tables. Now I reaslize that removing a roboport is expensive though and needs a full table rebuild. The network may even split in two.pleegwat wrote:That's just space. Computationally, it's travelling salesman, which is NP.featherwinglove wrote:I do agree with you that mrvn's table of waypoints idea sounds a lot like a n^2 problem.
I'd hazard it's probably cheaper computationally and more effective to route within the coverage area instead of between explicit roboports. Then only if the bot determines it does not have enough charge for its intended path, it can schedule to detour via a convenient roboport near its path.
Really though, though NP problems are not solved as such, there is certainly plenty of reading material.
As for having 1000 roboports and therefor the table needing a million entries. So what? That would be 4Mib of memory where each cell holds a 32bit ID of the next roboport. Compared to the GiB of memory already used that is negible. But I totally agree that a lot of the time just picking the roboport thats in the general direction of the destination will be the right thing. So the table could be made sparse to save space.
Or just do an A* search every time you plan a path. It's 1000 roboports for a big base and most of that will cover the whole area on the inside. Unless you have a very long U shaped base A* will include nearly no wrong roboports.
- Plan your straight line just like now.
- Compute point where you run out of charge (cheaper than checking every tick for sure)
- If destination is too far away find recharging station from where you would run out of juice. (this part is just done earlier)
- Fly there directly. (this will actually save time since the distance will generally shorter)
- If already there send a signal that the bot is stuck. (better than constantly flying back and forth)