Page 1 of 2

stray trains

Posted: Wed Aug 16, 2017 6:17 am
by someone1337
I was playing with friends and we built an unloading stop and several outposts.

Stuff works somehow decent, but sometimes trains stray to my player station instead of taking the intersection right to the unloader stations.
And then the trains that go to my home depot get stuck, as the locomotive wont ever leave unless manually ordered to.

We experimented a with the signals, but cannot figure out, why this rarely happens.

Any ideas?

Re: stray trains

Posted: Wed Aug 16, 2017 6:32 am
by someone1337
Just a few minutes later, we got another stray one.

Its the iron plates train. It was following another train and decided to go to the top instead of following the other train to the right.

Re: stray trains

Posted: Wed Aug 16, 2017 7:08 am
by Optera
You built a nice example showcasing an annoying effect of current train path calculation.
Instead of waiting a few seconds at a signal, trains will take long detours just to keep moving.

In your layout you can try adding more fake stops or a force repath signal so trains are less likely to take that route. However that will only combat symptoms.

Re: stray trains

Posted: Wed Aug 16, 2017 9:03 am
by vanatteveldt
I think Optera's diagnosis is correct.

The reason they like your PAX station so much is that it has a loop so it can be used to turn around, and in most situations it will be empty.

You might be able to tweak the path finder by adding 20 dummy stations on the incoming line, stations supposedly add a pathing penalty.

Re: stray trains

Posted: Wed Aug 16, 2017 9:50 am
by BenSeidel
I don't believe the dummy stops will make much of a difference as each stop gives a 2000 distance penalty to any path that goes through it. The existing stop should be the only one required. Considering that the extra distance of the actual path traveled should have been sufficient (by a long shot) to cause it not to path there in the first place, I doubt additional stops will prevent it in the future. I have seen this issue a few times, but never since the train stop penalty was introduced, so it's good to know that it's still happening with even greater apparent pathing distances.

I have always suspected that the distance penalty for occupied blocks was incorrect in its calculation (It's supposed to be (block length * 2)/distance from current position). I think that the distance from current position is calculated to be zero, pushing the pathing penalty for that block through the roof (infinity, go you floating point ops!!)

As any train path must follow the preceding train in all the rail blocks except the right hand turn then any pathing issues must be with that turn. Somehow during the path calculations that right hand turn is being assigned a value > 2300-ish (2000 for the stop, 300-ish for the physical distance). As infinity > 2300, then the behaviour seems to fit.

I have no proof of this though, only that it explains these apparent bizarre behaviours.

Re: stray trains

Posted: Wed Aug 16, 2017 7:59 pm
by someone1337
What I dont understand: Why was that path chosen as a possibly valid path?

My (nuclear) locomotive was parked there the whole time, its on automatic with a somehow impossible leave condition.

Re: stray trains

Posted: Wed Aug 16, 2017 8:23 pm
by vanatteveldt
someone1337 wrote:What I dont understand: Why was that path chosen as a possibly valid path?

My (nuclear) locomotive was parked there the whole time, its on automatic with a somehow impossible leave condition.
The pathing system presumably does not check leave conditions; it just assigns a penalty for an occupied block or station, so it will prefer a short, empty route but might prefer a route with a stopped train on it over a very long detour.

But apparently some of the penalties can use a bit of tweaking :)

Re: stray trains

Posted: Thu Aug 17, 2017 12:26 am
by BenSeidel
vanatteveldt wrote:The pathing system presumably does not check leave conditions; it just assigns a penalty for an occupied block or station
The pathing system does assign a penalty for stops occupied by a train over and above the 2000 penalty for the stop and the penalty for the occupied block. I am unsure if that penalty is applied for trains pathing through the stop or if it's only applied for trains going to the stop.
a penalty of 6 * "time left before the train leaves" is applied to trains with any form of wait condition (ie, 30 seconds of inactivity, etc).

That has been confirmed by the developers, the following is based upon my observation of pathing behaviours and an extrapolation of the above formula. I have never seen this confirmed anywhere.

There is also a similar penalty for trains with other leave conditions such as "when empty". The penalty applied is 6 * "duration train has been at the stop".
When a train has both a timer condition and another condition, the lesser of the two is selected.

Re: stray trains

Posted: Thu Aug 17, 2017 12:35 am
by impetus maximus
interesting thread. i have this problem on a friends save which the train network it a bit congested.
trains go through a stacker, followed by an unused passenger train stop to bypass traffic.

Re: stray trains

Posted: Thu Aug 17, 2017 2:22 am
by vortex1967
Hi all,

There are no signals at the turn off into your Production Stop and as a consequence until your production
train is fully in position it closes off the actual junction itself into your unloading area.
The other trains also close off the junction until they get past that first signal near the Iron junction.
I think that has the effect of increasing the time that a following train has spent behind and therefore might
be the reason for the unnecessary path finding.

Add signals to the Production Stop turn off and also add signals just after each junction as well so that each junction is freed up sooner for a following train.
To keep trains moving in a timely fashion add a signal between the Production turn off and the Iron turn off just to shorten that distance.
I'd be interested to know if that fixes or reduces the path finding.

Re: stray trains

Posted: Fri Aug 18, 2017 12:40 am
by Frightning
If your personal stop has more than 1 block that is not part of the connected network (the junctions themselves are part of the main network, as any train passing by will enter those blocks, but obviously stay on the main line), then you can have this problem. I was having a similar issue in my old trainworld with my fuel loading stop. I had designed it so that a train wanting to leave could wait not on the block with the stop before entering the 2-way part of the network, but this caused some other trains come over from time to time because they considered it closer than where they would otherwise wait. If I hadn't made it 2-blocks in size, this probably would never have been an issue. So the solution here is to make sure your player stop is a single block.

Re: stray trains

Posted: Sun Aug 20, 2017 6:03 pm
by aaargha
I think this bit from the wiki is relevant here, even if it's a bit old:
Wiki, emphasis mine wrote:When the rail block is occupied by a train -> Add a penalty of 2 * length of the block divided by block distance from the start, so the far away occupied paths don't matter much.
If two trains are both heading to the production area at roughly the same time the second one will see this massive occupied block just after the intersection that is only 0-2 (depending on how they calculate it) blocks away. That penalty is apparently large enough to make the path through the PAX station seem like the better option.

A good way to deal with this is, as others have stated, is to increase the number of blocks in the production area by just adding signals to make the blocks smaller. The smaller blocks reduces the penalty both by decreasing the length of the blocks and by increasing the block distance of each occupied block.

Re: stray trains

Posted: Wed Aug 23, 2017 12:59 am
by Jap2.0
vanatteveldt wrote:I think Optera's diagnosis is correct.

The reason they like your PAX station so much is that it has a loop so it can be used to turn around, and in most situations it will be empty.

You might be able to tweak the path finder by adding 20 dummy stations on the incoming line, stations supposedly add a pathing penalty.
Is the station penalty in the game now or was that for 0.16?

Re: stray trains

Posted: Wed Aug 23, 2017 7:56 am
by Greybeard_LXI
Jap2.0 wrote:
Is the station penalty in the game now or was that for 0.16?

That was introduced in 0.15.

Re: stray trains

Posted: Thu Aug 24, 2017 12:58 am
by Jap2.0
Greybeard_LXI wrote:
Jap2.0 wrote:
Is the station penalty in the game now or was that for 0.16?

That was introduced in 0.15.
Yay, less goofiness :).

Re: stray trains

Posted: Thu Aug 24, 2017 5:24 pm
by SpeedDaemon
I virtually never build "loop" type stations without adding a turn-around before the train stops. No matter how hard you try to prevent it, trains will still try to use stops as a turn-around or bypass, and by giving them a path that avoids getting stuck behind eternally-stopped trains, it avoids most of the problems caused by their path-finding weirdness. With the "wait for empty/full" conditions we have now, not doing this can get trains stuck for hours before they get noticed.

Re: stray trains

Posted: Thu Aug 24, 2017 7:28 pm
by Jap2.0
SpeedDaemon wrote:I virtually never build "loop" type stations without adding a turn-around before the train stops. No matter how hard you try to prevent it, trains will still try to use stops as a turn-around or bypass, and by giving them a path that avoids getting stuck behind eternally-stopped trains, it avoids most of the problems caused by their path-finding weirdness. With the "wait for empty/full" conditions we have now, not doing this can get trains stuck for hours before they get noticed.
:O how did I never think of this.

Re: stray trains

Posted: Thu Aug 24, 2017 11:21 pm
by vanatteveldt
Jap2.0 wrote:
SpeedDaemon wrote:I virtually never build "loop" type stations without adding a turn-around before the train stops. No matter how hard you try to prevent it, trains will still try to use stops as a turn-around or bypass, and by giving them a path that avoids getting stuck behind eternally-stopped trains, it avoids most of the problems caused by their path-finding weirdness. With the "wait for empty/full" conditions we have now, not doing this can get trains stuck for hours before they get noticed.
:O how did I never think of this.
If I work with loop stations I generally have a specific loop only for my PAX station. Since that will always be empty unless I'm there, it can also function as a safe turnaround station.

(but current train routing sucks! The penalty for occupied blocks should be a *lot* lower, and I think the system should refuse routes that are X tiles longer than the shortest route that does not cross other stations...)

Re: stray trains

Posted: Thu Aug 24, 2017 11:51 pm
by impetus maximus
in most cases my trains never have to turn around as they can go either direction from all stops.
the problem for me is if i have a station that is between two main lines that enters on one,
and exits on the other. stray trains start 'cutting through'. :x

Re: stray trains

Posted: Fri Aug 25, 2017 3:20 am
by Tongs
This is why double-headed trains with terminus-style train stops are ideal. There is literally no way for a train to path through a train stop that way. The only trains that end up there, belong there.