You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

21 lines
915 B
Haskell

module Algo.PF where
import Types
import Heap
import qualified Algo.Common
createHeap :: [Time] -> Heap Unit
createHeap [] = Nil
createHeap (t:ts) = insert (Unit (1 / (fromIntegral t) / 0.01) t 1 0) $ createHeap ts -- we use r/R as metric, where r is speed, R - transmitted size
updateHeap :: Time -> Time -> (Heap Unit, Heap Unit) -> (Heap Unit, Heap Unit)
updateHeap start_t fin_t (h, nh) = if (div start_t Types.packet_t /= div fin_t Types.packet_t) then
let inc_rem x = x {rem_p = rem_p x + 1}
restore x h = insert (x {rem_p = 1}) h in
(updateMetrics $ foldr restore (fmap inc_rem h) nh, emptyHeap) -- "bring back" clients without available packets every 20ms
else fmap updateMetrics (h, nh)
-- Rebuild tree to update metrics
updateMetrics :: Heap Unit -> Heap Unit
updateMetrics = foldr (\x h -> insert (x {metric = 1 / (fromIntegral $ (period x) * (sent_p x))}) h) emptyHeap