Dynamic Train Routes a Little Too Dynamic
I've loaded the new Dynamic Train Routes mod on my 1.0 save with 150+ trains, and I'm running into weirdness. For example, I have a train on a dual track veer off through a loop on a station on the side, then return to the dual track only to continue in the same direction. No other trains in the way, just an inexplicable detour.
The same train then does another detour through another station it was not scheduled to stop at, blows through the station, then again returns to the same route it was originally on. Again, no other trains in the way to make this detour look like a shortcut.
I'm also seeing trains stopping at a path signal before an intersection and waiting for a train to go through that did not interfere with its intended path.
I'm going to start capturing this using OBS for the mod author. Love the idea, but the latest 1.0.5 is doing this.
59 Replies
CC @Ryan
Hmm interesting, yea some videos of it would be useful. If you'd be willing to upload your save file + mod profile I'd be willing to look into it as well
When the trains blow through the station, are the paths shorter in distance compared to the normal path? or longer? I'd imagine longer. I did edit a line of code related to the station penalties so hopefully I didn't accidentally mess it up
This one's interesting. It shouldn't do that but I have a few ideas on maybe why it could be happening that'd require some testing to drill down
If you had the mod previous to 1.0.5, was it doing this before?
Lots of questions at you lol but rest assured we'll get to the bottom of it. Appreciate you bringing it up
Hi Ryan, The station is definitely a longer path. For example, I have a dual mainline and the train will take a T intersection to a station well off the trail, not stop at the station (it's not scheduled to), then come back to the same T intersection and continue on the dual mainline in the direction it was heading before the detour.
I've discovered this happening on even longer side-excursions. I recorded a lengthy video but will cut out some of the boring middle stuff where no odd behavior is occurring and provide some commentary with video time references. Happy to also send the save, but I have 66 mods running that, until now, how had no impact on the train pathing. There are two others involving trains - the 1st person train view mod and the modular stations.
In one example, I caught the train making a left out of a station it had been scheduled to visit, and take a very long detour almost the entire length of the Gold Coast, loop through a station it had no business being at, then go all the way back through the T intersection where it could (and usually did) make a right instead. There are no track issues (e.g. tracks looking like they connect but don't).
I recorded a lengthy video but will cut out some of the boring middle stuff where no odd behavior is occurring. Happy to also send the save. Will post on Google Drive and send you a DM with link. I have 66 mods running. There are two others involving trains - the 1st person train view mod.
My train schedules often span the map. How far down the overall path to the next destination does each train "look" for blockages?
BTW, I'm west-coast US, but am having a trouble sleeping. I will do all this tomorrow sometimes.
I may have a fix actually. I realized in a previous update I added penalties to track reserved by a path signal, so other trains could go around it, but it was a bidirectional reserve, and this would cause trains just to avoid that segment entirely. I've switched it so the penalty is directional against the train's direction
same here I just hate sleep lol
Lol. Hello, fellow insomniac.
1.0.5 introduces a configurable setting you can modify. I'm lowering it down in this next update
I was actually about to push 1.0.6 and then head to sleep
in my last minute testing however, I still get weird cases where the train will make an unnecessary loop, most likely similar to what you're seeing
If you're pushing 1.0.6 I can give it a test in the morning and see if I can capture any of the same behavior on OBS before sending you vids. Also, what params in the configuration do you suggest I tweak if I still see unexpected behavior?
Just saw your last comment. So you're seeing the detourrs as well?
Still happy to help, but if you plan more work and are already aware, maybe I can test again once you have another look (1.0.7?)
Yea but it's random. I have a giant train network someone sent me previously and that's when I noticed some weird detours. I resolved the obvious detours, but I'm still perplexed on these random loops that offer no benefit
the default params are fine, in 1.0.6 I'm lowering the train penalty to 2000m
This is why I asked how far down the route the train looked.
If it's seeing some problem in the distant future, it seems like these detours may look more beneficial to the route than all the blockages on the way to the final destination.
but the train looks all the way to the station, just penalties are applied to where the trains are on the tracks
the penalties are directional, so trains headed in the same direction incur 0 penalty to the train you're looking at
On the one hand, it has to know the whole route, but only consider near future blockages. Then again, if it's not looking ahead far enough, it will just behave like vanilla if a train is in the way 4-5 (10) blocks away and it gets there without having any more turn options.
It's like the penalties can only apply to near-future encounters.
or they would accumulate to make a lot of other options viable in terms of "shorter" routes.
Yea I did have that thought earlier today as I was thinking about it, but then if you really need to go a completely other way then that's the hard part
the penalty value works in a similar fashion, if it's 0 then it's vanilla trains
too high of a value, trains take crazy alternates, too low, not dynamic enough
I have been working similar algorithms with FICSIT Networks and trains, so when I saw your mod, I jumped at it.
oo that's cool
How does the algorithm tell the difference between a problem 5km away to know it must take a turn now, versus a situation where it has 9 other possible turns later?
pathfinding algorithm, I use A*
it uses a hueristic function based on linear distance to get an idea of which way to start looking, that's where A* excels at, and then it figures out the true costs as it searches nodes
I'm going to think about this so deeply, I may be up the rest of the night.
But for any pathfinding, the answer right now about obstructing trains how is not the same answer when the train actually gets there.
So, the challenge seems to be how do you limit as late as possible when the train starts using alternatives?
It is an aspect, but it's not a huge problem. Like it should still get there optimally
right now, my trains just seem to be doing weird things occasionally, taking non-optimal paths
a collision just happened in this save, which, should not happen
I've not had collisions.
and I have some pretty dense train traffic.
I do see one other new thing, though: I get flashing orange triangles indicating a stuck train from time to time with the mod. They go away after a few seconds, though. Never ever happened before the mod.
(on the compass, I mean)
Hm I thought that was normal lol, I'll have to look into it. I thought it was just because of the way I was testing without actually loading or unloading cargo
Anyways, I'll wait to push, I gotta look into this more first as the primary issue hasn't been resolved yet
Trains should never show as an orange triangle unless they're stuck from a deadlock. I haven't had one of those since early access. The track topography on my save has been around since around U6/U7 so that's how long I've not seen a orange triangle.
Gotcha, I’ll take a look at it then. I’ve noticed it only happens when leaving a station. It can also happen if a train has been idle for too long
I promised myself I'd go back to bed at 2am. Didn't mean to get your brain all active at this hour.
If you could share your save file too at some point that’d be great. I got work in the morning so I wouldn’t be able to take a look at it until after
and you’re good, I was already up working on it
Do you want the save now, all 66 other mods?
I was going to strip it down for you.
On the other hand, if you have work in the morning...
yea that’s fine with me, I’ll slap the mod profile in and it’ll be fine. I got fast internet and a good desktop
Let me put it up on GDrive now.
sweet, I’ll take a look at it tomorrow. Anyways for now, I must sleep lol. We’ll get this figured out at some point so it works flawlessly
I'm sure you will. This was no small feat.
I'll DM the link.
You should have the link now.
Have a good night.
I was able to resolve the orange triangles on the trains
I think I resolved the weird looping, have to test it more
either way I'm working on a new approach to handling the train penalties that should work more efficiently overall
instead of placing a huge penalty when a train is stopped on a track, I'm going to penalize time spent stalled there
so as a train just sits there not moving, the penalty will rise which will slowly being to deter other trains pathing to it
there will still be a small base penalty for the train stopping, so things like track stackers and bypass lanes work immediately
but for your large train networks, an extremely idle train is something we should try to route around if possible
Makes sense. Let me know if you want me to test it.
Where along the route will the penalization for a stopped train accumulate? I ask because if a train is stalled within the next 500-1000m then the penalty to go around it would be very small by the time the trailing train reaches it. If it's far away, and it takes longer for the traiing train to get there, the accumulation will increase as time passes and it gets nearer. It almost seems like the penalty should be based on stall time / distance. In this way, a nearby train stalled for a given time will carry a higher penalty than a far train blocking the way.
Good point, but there's tradeoffs to each. It depends how aggressively you want to reroute. For recently stopped trains, the effect won't be much, a little more than a station penalty, but it's enough to go around it given a bypass lane, but not severely enough that it immediately considers going around the entire map. That could be the case if we take distance into account.
Now if we do have a far away train, the initial small penalty won't be enough to have it drastically change routes, maybe it takes a bypass lane near the block. If it's been blocked for over 60 seconds though, and it turns out we can get to our destination faster using a different way, should we take that route instead? Perhaps.
It's a tricky situation because either side has valid points. I'm going to try this implementation first, and if it's still giving weird cases for when trains are far out, I'll explore diminishing penalties for tracks far away.
Maybe I misunderstand the data structure in which the penalties accumulate. Are those measured from the perspective of the stalled/blocking train where the blocking train may have been standing there 5 minutes before the trailing train assesses a route, or is that penalty accumulated in a data structure associated with the trailing train where the penalty accumulates according to each trailing train's world view?
Penalties are assigned to each track in each direction, so each track technically has two penalties associated with it. The underlying data structure and adjacency list is a bit more technical and complex than that, but it's an easy way to simplify it. I keep track of which tracks have trains on them and update their penalties. The penalty is added to the length of the track, so by increasing the penalty, the "length" of the track gets artificially longer. Each of these penalties update on-demand as a train enters/leaves a track as well as every second if a train is on it. When pathing, a train will simply find the shortest "distance", which includes the artificial penalties.
I think I will add a thing that checks to see how far out that track is, and taper off the penalty after a certain distance
@wivaca I just released a new version, let me know if train behavior is improved. I did notice in your save that sometimes a train would go through a station, since even with the 100m penalty it's a shorter route. If you want to be more strict, station penalties are a configurable setting and you can bump it up to a much higher value to prevent trains from going through stations.
@Ryan I've just downloaded and will ride a few trains today to see how it goes.
Thanks for your incredible work. Routing algorithms and penalties aren't trivial programming challenges.
I just had a UI oddity. Have you ever seen a train make a stop, then proceed to the next station on its timetable, but the timetable continues to show the prior station it stopped at as "next station"? The pic is showing the train pulling into Cliffside station after visiting Framington, yet Framington continues to show as Next Station. It updated directly to Dune Circuits. I may have had the timetable menu open during the entire visit to Framington. Doing more testing and didn't have recording on.

This is another of those map-spanning routes that takes me from Dune Desert (DDCC, Dune Circuits, and Framington) to Grass Fields (cliffside).
This behavior just repeated on a second cycle. I'm going to let it run some more on another train and later I'll uninstall Dynamic Train Routes to see if I can catch it doing this without the mod.
Just caught a second train doing this (showing last station as next)
I did notice that actually, but I wasn’t sure if it was my mod or not. Were you able to verify if it was my mod?
Appreciate it! It’s a good thing I like networks and their algorithms lol
Aside from the UI, did the trains do a better job with their routing?
Just got back to my desk after breakfast and starting to record video. So far, I've seen trains do a better job, but I still had one right before I went afk that took an excursion. More analysis needed.
I have to find a way to load my save in SCIM so I can get a track diagram. You may have noticed it won't load. I think I need to send the save to Anthor again so he can see what is not parsing. It's often something in FICSIT Networks for me,
I tested with your save with dynamic train routes uninstalled and it happened, so it seems to be beyond the scope of my mod. I noticed it updates when it reaches the next station though.
Some excursions can be expected from time to time, especially if it finds that route is faster, or if there's a large backup on the other route. Perhaps the two choices are really close in distance so any additional penalty to the normal route could send it the other way
Been recording for about 45 minutes now, and so far no hiccups across 5-6 trains
Picking ones that go many stops, across the whole map.
Ample opportunity to take excusions. Behaves essentially like vanilla for me, again, but my tracks were designed wihtout any stacking.
I've removed almost all mods
Have yet to check on that one that keeps the prior station as next station.
I'm sprinkling some stalled trains (not on auto-drive) in places to force alternative routes
I am seeing other trains waiting on me on consecutive blocks which is a sign they've come directly for their destination instead of wondering around. They should do that when the shortest path is where I'm at and no other alternatives remain for routes around me.
So are you running into the case where they're not going around? Or is there no alternate path?
If the alternate path is a huge way around, it may take a little for it to register
Like I said, I don't have any stackers so my entire track system was designed without stackers.
If you wanted to hop in a voice channel and share your screen I'd be down for that as well
If not that's perfectly okay
RIght now it's pretty boring. I'm just riding trains and there's nothing really to see, TBH.
Also, I have no mic setup.
Gotcha no worries
If I run into something odd I'll setup a mic and run you through it.
As a pro developer and former QA a long time ago, my assessment after 60 minutes of watching this is you've got it dialed in - at least so it isn't doing anything worse than vanilla. I will put some more trains in the way and see what happens. I'm also eyeballing where I might put in some stackers or bypasses to take advantage of the dynamic routing, but where I'd put them so far would be a legit shortcut even for vanilla.
Perfect that's great to hear! Glad we got it dialed in
Yea with the current setup, dynamic trains aren't necessary, the method we've used for vanilla does work just fine. But it does provide opportunities to do some more complex things, such as train strackers, bypass lanes, and especially a lot more with single rails
Just as I say this, I put a train in the way with an expected train having to end run, and it's entirely AWOL. It's hard to find trains on the map when you have all these places it can go.
Not an easily controlled test.
Have you ever seen my Train Bootcamp save? Maybe I should be testing it on that.
Just proved taking the long way works if a train is in the way.
Oh no way you're the one who created that! I didn't even realize that was you lol
I've tested it on that in the early versions of the mod, didn't make much a difference I've noticed
Yeah, that bootcamp is designed without any dynamic pathing in mind, of course.
Yea it's a very informative bootcamp, was interesting to read all the different configurations.
I'm working on a 5.0 version that uses 1.1 improvements.
If you look at the dynamic train routes mod page, I added an example of a single track configuration doing wild things, might be able to add it in this chat? lemme see
Yes, I read every word of your post and looked at the pictures in detail. Nice doc.
what improvements to 1.1 are there to trains? All I could see was being able to rotate the end pience and being able to do n:m track switches right?
and thanks!
Left-side track signals, but I just mention those and show an example. Of course the end-of-track bumpers. You can put signals anywhere now, not just seams (it makes them). Probably the biggest deal is you can now build switches back-to-back and directly off of train stations. Wonder if that will impact your mod.
There are a few others, but I'm wondering if CSS doesn't have more in store for us than that.
To me, the biggest problem facing trains is the train stops can't control which car is loaded/unloaded.
You can build signals where there are no seams in 1.0, but the side they're on seems to depend on the direction you created the track. For example, if you build left-to-right in a curve around you, getting signals on an outside of the curve is impossible, but if you build right-to-left, you can't put them on the inside of the curve. (edited)
Hey, I just went back to that train that was showing the prior station as next on the time table. It's still doing it with just your Mod, PAK Utility, and Flex Splines loaded. I'm going to unload DTR now, and see if that keeps happening.
Whatever is causing those trains to show the last stop as the next stop, it persists after your mod is unloaded. In fact, I have so few mods installed now (just PAK and Flex Splines) that I think this is probably a edge case bug in vanilla.
Should be okay I believe. I'll have to double check things such as left-side track signals, but I'd expect the code to be similar. Since you can already put signals where there are no seams that use-case should be covered, but I didn't know it was still limited like that in 1.0, interesting. Should be fine still. And connecting directly to train stations shouldn't make a difference since it still uses the rails.
So hopefully when 1.1 releases it won't make much of a difference
Seems like it, thanks for investigating