From adc01a0bba29b40278e45c50caa954c435374f7b Mon Sep 17 00:00:00 2001 From: orwell Date: Tue, 6 May 2025 00:43:06 +0200 Subject: Multi-ARS (waiting for multiple routes simultaneously, load-balancing) --- advtrains_interlocking/ars.lua | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'advtrains_interlocking/ars.lua') diff --git a/advtrains_interlocking/ars.lua b/advtrains_interlocking/ars.lua index fc9f2a3..5182cd3 100644 --- a/advtrains_interlocking/ars.lua +++ b/advtrains_interlocking/ars.lua @@ -245,16 +245,29 @@ function il.ars_check_rule_match(ars, train) end local function sort_priority(sprio) - -- TODO implement and return the correct sorted table - -- for now just minimum - local maxk,maxv = nil,10000 - for k,v in pairs(sprio) do - if v prio then + -- next item has higher priority number (= less urgent), insert before it + break + elseif oprio[inspos] == prio and order[inspos] > rteid then + -- next item has same priority as current and a higher routeid, insert before it + break + end + inspos = inspos + 1 end + table.insert(order, inspos, rteid) + table.insert(oprio, inspos, prio) + end + --atdebug("sort_priority",sprio,"result",order,oprio) + if #order == 1 then + return order[1] -- only one route, table doesnt make sense end - return maxk + return order end local function find_rtematch(routes, train) @@ -278,12 +291,10 @@ local function find_rtematch(routes, train) end end if next(sprio) then - atdebug("Ars: SMultiArs", sprio, "is not implemented yet!") return sort_priority(sprio) elseif default then return default elseif next(dprio) then - atdebug("Ars: DMultiArs", dprio, "is not implemented yet!") return sort_priority(dprio) else return nil -- cgit v1.2.3