Collapsing Rail Segments in Path Finder

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
cfo82
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jun 28, 2020 10:05 am
Contact:

Collapsing Rail Segments in Path Finder

Post by cfo82 »

Hi All,

I have a quick question. I have quite a large factory and sometimes the train pathfinder took up to 50ms according to the debug overlay. Therefore I was thinking about what I was doing wrong and especially I was thinking about removing signals to have less train segments. At the moment I have one signal every 4 train tracks so that trains are able to drive very close to each other.

Before I do that however I started to think about how factorio might be able to optimize that network. My thinking was that it would probably be possible to collapse rail segments that divided by simple signals without crossroads into a single segment in the search graph of the pathfinder. If factorio does an optimization like that removing signals by hand would not impact the performance at all.

Does anyone know if Factorio does an optimization like that on the search graph? Or is there anything that I overlooked that makes that impossible?

If text is not understandable enough I could start and try to create a picture of what I think.

Cheers,
Christian

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3146
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by DaveMcW »

cfo82 wrote:
Sun Jun 28, 2020 10:17 am
I have one signal every 4 train tracks so that trains are able to drive very close to each other.
It is impossible to collapse straight segments together, because that would break the ability for trains to drive very close.

Also, "very close" is not that close. Trains reserve all segments up to their braking distance for themselves, so there is always a large gap. You don't lose much more by using large segments, say 30 tracks instead of 4.

cfo82
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jun 28, 2020 10:05 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by cfo82 »

Thanks for the answer. In that case I will have to change my rail layout to make it more performant.
It is impossible to collapse straight segments together, because that would break the ability for trains to drive very close.
Wouldn't it be possible to separate this issue from the main path finder? I mean in my case it is very rare that trains drive closely (yes I know this means I don't suffer from having less signals...). But I would guess 80% of the time the pathfinder doesn't have to care about proximity and could use the collapsed graph and then get into more detail once the train drives into one of the collapsed segments.

Zavian
Smart Inserter
Smart Inserter
Posts: 1500
Joined: Thu Mar 02, 2017 2:57 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by Zavian »

Is this a city block style rail network?

Those tend to have a higher cpu impact than simpler layouts due to the large number of alternate paths that the pathfinder must examine.

cfo82
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jun 28, 2020 10:05 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by cfo82 »

Is this a city block style rail network?
True. I have quadrants. Between quadrants I have two rails going parallel into one direction so that two trains can drive besides each other. Inside the quadrant I have a ring-rail that standardises the inside (so that I can copy/paste factory parts into it) which are separated from the main rail mesh using dummy train stations that should prevent trains from going into the inner ring that don't deliver stuff into the quadrant. At the moment I have 169 quadrants which are not all filled. Maybe about half are.

I think train pathfinding is not my most urgent issue and next time I would stay with one line in between quadrants. However the inner ring proved to be very useful. It served the purpose of copy/paste and it made the whole network extremely fault tolerant.

Its just a lot of manual labor to fix the issue. I don't know of an automatic way that works like find/replace to improve my rail network.

Zavian
Smart Inserter
Smart Inserter
Posts: 1500
Joined: Thu Mar 02, 2017 2:57 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by Zavian »

Assuming that all the rails use exactly the same blueprints, then create a set of blueprints with new signals, then use a filtered deconstruction planner to remove the old signals, and then place new signals using the new blueprints. (Be careful when removing the old signals that you don't have too many collisions. You might want to set all of your trains to manual before replacing the signals).

cfo82
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jun 28, 2020 10:05 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by cfo82 »

Thanks for the tips with the blueprints. Yes its actually all copy/paste. But it will still be a lot of fun. I can't deactive all trains because I need power to defend against the biters. So I'll have to do it very carefully in a smart way.

Just so that you have a feeling about what I am talking:

One Quadrant:
Image

The station called _To_Rename is the place where fuel will be dropped.

Factory:
Image

Zavian
Smart Inserter
Smart Inserter
Posts: 1500
Joined: Thu Mar 02, 2017 2:57 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by Zavian »

Just remove one peice of rail from the entrance to each section of track before removing the old signals. Once there there is only one train currently in that section to track, it should now be safe to remove and replace the signals. The new blueprint can replace the track at the same time as the new signals.

I think that just using a deconstruction planner to order the deconstruction of a piece of track is enough to cause any trains that intend to enter that section of track to repath and avoid it, so you can probably do everything from map view, and only need to wait if there are multiple trains in that section of tracks.

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 871
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by boskid »

cfo82 wrote:
Sun Jun 28, 2020 10:17 am
My thinking was that it would probably be possible to collapse rail segments that divided by simple signals without crossroads into a single segment in the search graph of the pathfinder. If factorio does an optimization like that removing signals by hand would not impact the performance at all.
There is no such thing implemented. If only source of penalty would be a rail lengths, it could be implemented, but since penalties also depend on trains distributed by rail segments in such long section, state of signals and even for which train pathfinding is being performed, it is not worth implementing that idea.

When i was doing trains pathfinder optimisation for 0.18.0 i was looking into different approach: "fast forward" - when processing a node that has only 1 exit, immediately go forward one rail segment. This was to reduce amount of priority queue operations but in the end it was slower because it was defeating gain made by heuristic since pathfinder was often overexpanding into a direction that was not important.

cfo82
Burner Inserter
Burner Inserter
Posts: 5
Joined: Sun Jun 28, 2020 10:05 am
Contact:

Re: Collapsing Rail Segments in Path Finder

Post by cfo82 »

@Zavian: Thanks for all the tips! I will try as you suggest.

@boskid: I really appreciate your technical explanation of how it works! Thank you very much!

Post Reply

Return to “Gameplay Help”

Who is online

Users browsing this forum: No registered users