Attempting to Implement Round Robin Schuelder Via LTN

Adds new train stops forming a highly configurable logistic network.

Moderator: Optera

PB4848
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 15, 2024 6:04 pm
Contact:

Attempting to Implement Round Robin Schuelder Via LTN

Post by PB4848 »

I am trying to achieve balance of services to starvation via a CPU scheduler called Round Robin. In the future I might see about implementing others like HRRN, but you will see why I'm starting with Round Robin first.

A simple example: https://youtu.be/aWlQYllBZDs?si=mV_2gr9VaAX088Hg

But I learned the LTN Mod has most of what I need to do already not found in Vanilla:
  • A class of jobs organized in a queue, based on request age.
  • The ability to set a tick (not time) limit for trained parked at request stations (this is the quantum value)
  • LTN Automatically computes delta of resources needed (Resources Requested vs had) and sends out the signal to the network (the equivalent to BT)
From the dispatcher.lua file:

Code: Select all

-- sort requests by priority and age
    sort(global.Dispatcher.Requests, function(a, b)
        if a.priority ~= b.priority then
          return a.priority > b.priority
        else
          return a.age < b.age
        end
      end)
This is a FIFO queue, which is close to RR, but not quite. RR has preemption, I need after let's say ~2500 ticks to preempt the train, and set it to the depot to be rescheduled.

I see there a central issue in LTN, however:
Trains are meant to be used across resource types. For example, a train carrying iron plates, can be used for copper plates. So, a train would have many iron plates leftover. But, given RR will distribute resources within a fraction of a train's cargo. These leftovers I want to be carried to other iron stations. I want trains not bounded to stations, but to types, so trains A,B,C only delivery iron plates, and trains X, Y, Z only deliver green circuits.

This can be solved with LTN I believe, through encoded network IDs.

However, there is a limit in LTN of 32 unique networks, which is just not enough for the setup I aim for. Any help is appreciated.
robot256
Filter Inserter
Filter Inserter
Posts: 994
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Attempting to Implement Round Robin Schuelder Via LTN

Post by robot256 »

To clarify, are you trying to solve a particular factory production problem, or are you trying to specifically make trains drive in a specific way?

LTN is supposed to operate so that consumers only initiate a request when they have space to completely unload the train before it returns to the depot. It is possible to request partial train loads, but it relies on circuits at the provider station to stop the inserters after loading the requested number of items.

If you specifically want one train to visit multiple consumers before returning to a depot or provider, then you should probably look at some other train scheduling mods instead of LTN. Or else just experiment and see if you can trick LTN into doing what you want.
PB4848
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 15, 2024 6:04 pm
Contact:

Re: Attempting to Implement Round Robin Schuelder Via LTN

Post by PB4848 »

Imagine this: resources are finite, and must be rationed across stations, and there must be an algo to decide who gets what first, this is exactly how your CPU works, even for extremely lightweight applications. The answer in Factorio of the typical train logistical issues is "Just always have enough resources bro, then you won't ever have to deal with complex logic" I dislike this answer.

"If you specifically want one train to visit multiple consumers before returning to a depot or provider" that is ideally what I want yes. TSM Mod looks interesting too, but LTN is very powerful and was hoping to use it.
robot256
Filter Inserter
Filter Inserter
Posts: 994
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Attempting to Implement Round Robin Schuelder Via LTN

Post by robot256 »

"Always have enough" isn't the only answer. You can also let the belts back up until materials reach everywhere and the output runs again. But that can take a while and result in cyclic operation.

How about making the LTN station priority dynamically controlled by a timer, so that stations receive higher priority the longer they go without a delivery? You would still need to have each station able to buffer one train's worth and only request when it needs a full train.
PB4848
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 15, 2024 6:04 pm
Contact:

Re: Attempting to Implement Round Robin Schuelder Via LTN

Post by PB4848 »

'How about making the LTN station priority dynamically controlled by a timer, so that stations receive higher priority the longer they go without a delivery?'
LTN already does this.
robot256
Filter Inserter
Filter Inserter
Posts: 994
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Attempting to Implement Round Robin Schuelder Via LTN

Post by robot256 »

Then I guess what's the actual problem? If the built-in timer priority (Fifo) isn't good enough, use the circuit priority to override it however you like. As long as you arrange it so trains empty completely at each requester, you don't need a separate network for each resource.
PB4848
Manual Inserter
Manual Inserter
Posts: 4
Joined: Wed May 15, 2024 6:04 pm
Contact:

Re: Attempting to Implement Round Robin Schuelder Via LTN

Post by PB4848 »

For anyone curious, look into the cybersyn mod, it implements round robin scheduling! It also has other cool features like a train can visit several requester stations without going back to depot first, it's exactly the vision I had here.
Post Reply

Return to “Logistic Train Network”