Does LTN select a train from the nearest Depot?

Adds new train stops forming a highly configurable logistic network.

Moderator: Optera

Post Reply
Achilleshiel
Burner Inserter
Burner Inserter
Posts: 15
Joined: Fri Oct 31, 2014 8:57 pm
Contact:

Does LTN select a train from the nearest Depot?

Post by Achilleshiel »

Does LTN select a train from the nearest Depot?
Or will it pick a train at random from any depot?
Ignoring the train composition here, because i'm only running one type of train.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by mrvn »

The nearest from the list of suitable / optimal trains.

Achilleshiel
Burner Inserter
Burner Inserter
Posts: 15
Joined: Fri Oct 31, 2014 8:57 pm
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by Achilleshiel »

Is nearest defined as path length or as the crow flies?

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by mrvn »

Afaik the later as the LUA script has no access to path lengths.

Dune
Fast Inserter
Fast Inserter
Posts: 201
Joined: Tue Dec 12, 2017 4:27 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by Dune »

mrvn wrote:
Tue Sep 25, 2018 2:59 pm
Afaik the later as the LUA script has no access to path lengths.
Now that the devs have added train paths in schedules, is this now available?
Image

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by eduran »

Not really. The path only exists when a train is actually moving to a station. You would have to pick a train at the starting station, add the destination to its schedule, set it to automatic, read the path and quickly restore the original settings before it moves out of the station.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by mrvn »

You could read out the value on every train-leaves event and update the internal as-crow-flies estimate. Over time the distances calculations would improve then.

I think this would help a lot in certain cases. I sometimes have depots near stations that aren't really connected to the depot. But since they are right next to each other LTN always picks trains there and sends them a long long way around to reach the stop.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by Optera »

mrvn wrote:
Thu Apr 11, 2019 3:08 pm
You could read out the value on every train-leaves event and update the internal as-crow-flies estimate. Over time the distances calculations would improve then.

I think this would help a lot in certain cases. I sometimes have depots near stations that aren't really connected to the depot. But since they are right next to each other LTN always picks trains there and sends them a long long way around to reach the stop.
And how would you update the lookup table to changes in rail network?
At most the table can be wiped entirely whenever a rail is placed or removed, BUT the removal events are not always raised, e.g. when rails are implicitly removed by chunk/surface removal or when other scripts remove them.

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by mrvn »

Optera wrote:
Thu Apr 11, 2019 4:01 pm
mrvn wrote:
Thu Apr 11, 2019 3:08 pm
You could read out the value on every train-leaves event and update the internal as-crow-flies estimate. Over time the distances calculations would improve then.

I think this would help a lot in certain cases. I sometimes have depots near stations that aren't really connected to the depot. But since they are right next to each other LTN always picks trains there and sends them a long long way around to reach the stop.
And how would you update the lookup table to changes in rail network?
At most the table can be wiped entirely whenever a rail is placed or removed, BUT the removal events are not always raised, e.g. when rails are implicitly removed by chunk/surface removal or when other scripts remove them.
You could reset distance to as-crow-flies if they aren't taken for a long time. A decaying average should work. So every now and then you pick a bad one and the distance goes up again.

User avatar
Optera
Smart Inserter
Smart Inserter
Posts: 2915
Joined: Sat Jun 11, 2016 6:41 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by Optera »

mrvn wrote:
Thu Apr 11, 2019 7:49 pm
You could reset distance to as-crow-flies if they aren't taken for a long time. A decaying average should work. So every now and then you pick a bad one and the distance goes up again.
A terrible solution, producing unexpected results whenever players redesign their network.

I would have to check if LuaTrainPath.valid was invalidated when parts of it where removed.
Then at least no longer existing paths would be handled. However newer shorter routes would only be discovered by chance which still is far from ideal.

Overall it's too much hassle for what it's worth. LTN will use only linear distances until this is implemented:
viewtopic.php?f=28&t=67199

mrvn
Smart Inserter
Smart Inserter
Posts: 5696
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Does LTN select a train from the nearest Depot?

Post by mrvn »

Optera wrote:
Fri Apr 12, 2019 5:32 am
mrvn wrote:
Thu Apr 11, 2019 7:49 pm
You could reset distance to as-crow-flies if they aren't taken for a long time. A decaying average should work. So every now and then you pick a bad one and the distance goes up again.
A terrible solution, producing unexpected results whenever players redesign their network.

I would have to check if LuaTrainPath.valid was invalidated when parts of it where removed.
Then at least no longer existing paths would be handled. However newer shorter routes would only be discovered by chance which still is far from ideal.

Overall it's too much hassle for what it's worth. LTN will use only linear distances until this is implemented:
viewtopic.php?f=28&t=67199
I disagree with the "by chance" part. All distances would decay to as-the-crow-flies distance over time and the route can never be shorter than that. So newer shorter routes would be discovered in the time it takes for a cached distance to decay enough to be less than the new route.

I agree though that it is far from ideal. I'm not sure how your other topic helps that much though. Even if you can ask for the path between 2 stations you still have no way of knowing if that path still exists later of if the distance has changed. You would have to constantly check the path between every pair of stations and that's O(n^2). With 1000 stations checking one per tick would need 4.6 hours to verify all distances. That probably needs something that uses as-crow-flies as approximation and only computes the real distance for pairs that are real candidates in a delivery and caching the result for a while.

Post Reply

Return to “Logistic Train Network”