Trains and Signals?...

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
PanTobi
Fast Inserter
Fast Inserter
Posts: 202
Joined: Fri Feb 05, 2016 12:34 am
Contact:

Trains and Signals?...

Post by PanTobi »

How trains find best path?...

I mean... if Train in about to enter crossroad how he calculate which exit to use?
- is is amount of chain signals to exit? so if for example Train have 2 ways one with 5 signals and other one with 7 signals train will pick that one with 5 signals?... is that correct?...

its important for me because im trying to force my trains to pick middle way ( speed way )
when they want to go forward and ignore loop ( because loop is only for trains that want to go back... )

What i want to do:
- Trains should use Middle way if they want to go forward
- Trains should use Round if they wand to go Left or turn back
- Trains should use Side way if they want to go Right
- Trains should stick to Middle way so they don't block other trains that want to go right...

here is example behavior and signals count:

Can any1 explain me why sometimes trains pick right way and sometimes they pick wrong way????
s1.png
s1.png (1 MiB) Viewed 258 times

netmand
Filter Inserter
Filter Inserter
Posts: 283
Joined: Wed Feb 22, 2017 1:20 am
Contact:

Re: Trains and Signals?...

Post by netmand »


User avatar
disentius
Filter Inserter
Filter Inserter
Posts: 573
Joined: Fri May 12, 2017 3:17 pm
Contact:

Re: Trains and Signals?...

Post by disentius »

Because trains calculate their paths to their destination once, when leaving the station. They repath or revalidate their path under the following conditions:
(see https://wiki.factorio.com/Railway/Train_path_finding)

Path Revalidation

A rail path will be revalidated if any event happens that could make this trains path invalid. If the path is found to be invalid then the game will repath the train. Path revalidation just confirms that the current path is still valid and does not confirm that it is still the best. The follow events cause path revalidation

A rail is destroyed (all trains are revalidated).
A rail is created and invalidates a signal (all trains are revalidated) .
A signal (chain or regular) is created or destroyed (all trains are revalidated).
A rail block changes and invalidates a signal (chain or regular) (all trains are revalidated).
LuaTrain::recalculate_path() is called on the train by a script.
The train's schedule is changed.
The train's braking force gets changed and the train is currently driving normally, arriving at a signal (chain or regular) or arriving at a station.
The train has waited at a chain signal for a multiple of 5 seconds.

Repath events

There are a number of events that can cause a train to repath listed below. When one of these conditions is met the game considers possible paths from the trains current location to its destination train stop and will chose the path with the lowest score according to the penalties listed above.
User / script generated events

A locomotive that is part of the train is rotated.
LuaTrain::recalculate_path(true) is called on the train by a script.
The train is switched to automatic control when it was previously manually controlled.
The train is set to go to a station using the "Go to stop" button in the train's GUI.
A waypoint (train stop without wait condition) is removed from the train's schedule.

Repaths that happen as part of normal train operation

A train fails a revalidation.
The train stop a train is heading to is renamed or destroyed.
The train is preparing to stop at a signal (chain or regular) that changes so that the train can now continue.
The train is braking for a signal (chain or regular) it cant reserve.
The train enters a new rail block and can't reserve the next needed signal (chain or regular).
The train has waited at a chain signal for a multiple of 5 seconds and there are multiple train stops with the same name as the destination.
The train has waited at a chain signal for a multiple of 30 seconds and there is only a single train stop with the same name as the destination.
The train wants to depart from a signal (chain or regular) that it stopped at.
The train wants to depart from a train stop.
The train is pathing to a train stop that gets disabled.

Destination full / No path trains

A rail gets created.
A train stop that is part of the train's schedule gets enabled, renamed or created.
The train limit of a train stop that is part of the train's schedule becomes not full.
The train stop that it currently cannot reach gets disabled or destroyed.

Others

The train collides with something that is not a train (like a player).

SoShootMe
Fast Inserter
Fast Inserter
Posts: 189
Joined: Mon Aug 03, 2020 4:16 pm
Contact:

Re: Trains and Signals?...

Post by SoShootMe »

PanTobi wrote:
Wed Jul 07, 2021 6:31 pm
here is example behavior and signals count:

Can any1 explain me why sometimes trains pick right way and sometimes they pick wrong way????
s1.png
Most likely an occupied block west of the junction at the time of the most recent repath caused changing lanes to have a lower cost.

Post Reply

Return to “Gameplay Help”