diff options
author | orwell <orwell@bleipb.de> | 2025-05-06 00:43:06 +0200 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2025-05-06 00:43:06 +0200 |
commit | adc01a0bba29b40278e45c50caa954c435374f7b (patch) | |
tree | d6bfb5d0329770b9c62431bbc8fec9b7c7f66fd9 /advtrains_interlocking/ars.lua | |
parent | ed7242c632d63c5d749d3bb9de57c5734b4c5ee1 (diff) | |
download | advtrains-adc01a0bba29b40278e45c50caa954c435374f7b.tar.gz advtrains-adc01a0bba29b40278e45c50caa954c435374f7b.tar.bz2 advtrains-adc01a0bba29b40278e45c50caa954c435374f7b.zip |
Multi-ARS (waiting for multiple routes simultaneously, load-balancing)HEADrelease-2.6.0master
Diffstat (limited to 'advtrains_interlocking/ars.lua')
-rw-r--r-- | advtrains_interlocking/ars.lua | 31 |
1 files changed, 21 insertions, 10 deletions
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<maxv then - maxv = v - maxk = k + -- insertion sort + local order = {} + local oprio = {} + for rteid, prio in pairs(sprio) do + local inspos = 1 + while order[inspos] do + if oprio[inspos] > 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 |