BeltRouter


This mod allows you to route belts and pipes automatically: 1. Put the starting belt and ending belt on ground first, 2. then select the starting belt with ctrl+right-click and 3. select a ending belt with ctrl+left-click. 4. Boom, belt ghosts are created!

Utilities
3 years ago
1.0 - 1.1
28.3K

b Wrong path if source entity is splitter

4 years ago
(updated 4 years ago)

This is an awesome mod, really useful. One small issue I've found:

Greediness setting is set to 1.

If the source entity is a splitter, and the output side closer to the target is free, then everything looks normal: https://imgur.com/TfHLi0z

But if the output side closer to the target is used/blocked, then the route takes unnecessary turns, and doesn't use undergrounds: https://imgur.com/SklH1I8
it also takes visibly longer to calculate the second case, considering how short the distance is.

4 years ago

Thanks a lot! :D Will look into this issue.

BTW setting 1 as greediness will slowdown the process a lot, since path finder will explore every possible path around.

4 years ago

Do you want to try again for the version 1.1.3? I think the problem is now solved

4 years ago

Wow, that was fast.

It uses undergrounds now, but it's still doing the extra turns, which doesn't happen normally: https://imgur.com/ivlcQQp
It also does these weird very small undergrund jumps, just 1 tile wide, because of the extra turns.

What does the greediness setting influence exactly? A* with manhattan distance as the heuristic function should be both fast and accurate, shouldn't it? I haven't dug too deep into the code, maybe I'll take a look later this weekend.

4 years ago

Hmmm interestingly it works on my side: https://imgur.com/a/MZ9dS6C
FYI, I have greedy setting as 1.05

What does the greediness setting influence exactly? A* with manhattan distance as the heuristic function should be both fast and accurate, shouldn't it? I haven't dug too deep into the code, maybe I'll take a look later this weekend.

You are correct, but A has a huge issue with equal-distance path. say you have to find path from (0,0) to (3,3). You can take either >>>^^^ or ^>^>^> . A will consider them both as equal distance and will try to find all path, which degrade the performance to BFS algorithms like Dijkstra. So I'm currently trying to solve this problem with Jump Point Search (JPS) algorithm, but the JPS's paper doesn't consider factorio's underground path situation. So I'm still trying to figure out a way of integrating it into the mod.

4 years ago

Hmm, one possible way to improve on the equal-distance issue is to make fewer of the paths exactly equal. For example, you could add a cost penalty for turning (and this could be really small too, like 0.001), with that the above example would only have 2 equal best paths (>>>^^^ and ^^^>>>), or maybe only 1 because the source and target belts have fixed direction too.

You could also add the turn penalty to the heuristic function, based on the minimum number of turns required. This could be based only on the direction of the target belt, and the current belt (and their coordinates)
- Same direction, and they are in the same "lane" (column or row), and target is in front of the current belt: min 0 turns >>>
- Same direction, not the same lane, in front: min 2 turns (have to do a lane change) >>>^>>>
- Same direction, target is behind: min 4 turns (need to do a 360 turn) >^<<<<v>>
- Right-angle, in front in both directions: min 1 turn >>>^^^
- Right-angle, behind (could be behind either or both directions) : min 3 turns >^<<<^^^ or >vvv>>>^
- Opposite direction: min 4 turns

If you do something like this, could you expose the turn penalty as a setting, so we can tweak it? And also the cost penalty for underground belts in case of "prefer overground" mode. Right now I think it is pretty high, but I'd prefer this to be also something like 0.01, so it'd go overground in long straight stretches, but it'd use undergrounds if it can save any travel distance.

4 years ago

Sounds good. I already have turning penalty and underground penalty in the mod, I can add those settings in the next mod version. Thanks :D

New response