Pathfinding: reject unconnected buildings / construction sites in specific scenarios#1889
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
|
Thanks for the attempt anyway. |
I'm not giving up on the probem just yet. 😉 But the current solution still seems a bit too easy for my taste, let me know if I missed something substantial here. At least the large map from the issue seems to run fine now, only very minor stuttering upon posting a new flag. |
|
2 issues I see:
An idea: I guess "unconnected" buildings/construction sites usually have simply no road from the building flag to anywhere. We could check for that (only required at the target) before running the full pathfinding. In any case this will break replays so it is hard to measure how much benefit this provides. Only empirically by running many longer replays on a large map ignoring the async, which provides at least an indicator. |
Yes, this goes in the direction of my first attempt visible in the first two commits. It resolved the issue with the map in the ticket, but I found it too specific as it fails to work as soon as some roads are attached to the construction sites. But it could be a last resort. So you would say that even with that solution of checking just the target flag, the replay compatibility is endangered? Could you point me to an example in the code where randomness is factored into the pathfinding in these scenarios? |
Looks like i misremembered that. Only place I found is unrelated to road pathfinding: s25client/libs/s25main/pathfinding/FreePathFinder.cpp Lines 103 to 105 in e6489dc Given that I guess that checking the flag connections should not impact the replays.
What situation would that be? Usually either the building is fully connected or not connected at all, isn't it? |
I think I know what you mean now, it is related to the If that is the case, I guess the current solution is then out of question. There would be an intermediate solution by additionally calculating if a path exists from the goal to nearby warehouses (see the third and forth commit) before, which also resolves the problem with isolated buildings aswell (at least in my tests) but adds additional pathfinding overall, which is not really great.
Yes, I thought it could be somehow integrated into the pathfinding itself without additional checks and have the benefit of covering also "non-connected networks", but given the restrictions it might really be best to just check the building flag itself, as it would still cover most user scenarios. I will update the PR.
|
Right: That is for making sure wares can go around a flag that has currently so many wares in the same direction that the other way is faster even if longer.
We could only do that for the
When there is no path from A to B then there is also no path from B to A. So I don't really see a benefit of always swapping the direction. It only helps if the network of B has less nodes than that of A but you don't know that before, do you? So swapping might even make it worse.
My intention is that unconnected buildings are usually e.g. military buildings where no gold or soldiers should go in/out and hence have no connection at all. And this is common enough to do additional checks before running the full pathfinding. |
Flamefire
left a comment
There was a problem hiding this comment.
See inline comments.
Major point: Why not put the reachable check at the lowest level close to where the pathfinding is done? That explains the check better (closer to where it matters) and avoids having to catch all call sites.
Flamefire
left a comment
There was a problem hiding this comment.
Final round: One is about avoiding reads then not using the result the rest is just style/wording.
If I haven't missed anything (please check) you can apply them all via the PR UI (IIRC in the "Changes" tab add each to queue and accept in one go.
If you are happy with that mark the PR as ready so we can merge it.
Have you checked how much this change gains?
Thanks a lot!
Yes, I did check it against the large example map posted in the issue ticket to see if it resolves the seconds long freezes in the following scenarios:
For 1) and 2) it resolved the freezes completely. For 3) it was decreased down to a fraction of a second, due to the still large road network. |
Flamefire
left a comment
There was a problem hiding this comment.
Ok LGTM!
Mark as ready if this can be merged
.. in FindWarehouseForAllJobs and FindMaterialForBuildingSites.
.. also considering FindClientForWare.
Co-authored-by: Alexander Grund <Flamefire@users.noreply.github.com>
Co-authored-by: Alexander Grund <Flamefire@users.noreply.github.com>
c9f7c45 to
d7cf2c5
Compare
Related Issue:
Closes #1785
Changes Summary
This will not implement the algorithm mentioned in #164, but is an attempt to fix the immediate issues in #1785 by rejecting buildings that are not connected to anything / are isolated. This is implemented for the following cases: