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.

41 lines
1.3 KiB
Haskell

module Main where
import Algo.MaxRate as MaxRate
import Algo.MaxMinRate as MaxMinRate
import Algo.PF as PF
import Types
import Heap
main :: IO ()
main = do
s <- getLine
let speeds = map read $ words s :: [Double]
let ts = map (ceiling . (* 1000) . (Types.packet_size/)) speeds -- ms
putStr "======\nMaxRate\n"
let max_rate_h = MaxRate.runUntilCycle packet_t ts
print $ getAverageSpeed max_rate_h
print $ getShare max_rate_h
putStr "======\nMaxMinRate\n"
let max_min_rate_h = MaxMinRate.runUntilCycle packet_t ts
print $ getAverageSpeed max_min_rate_h
print $ getShare max_min_rate_h
putStr "======\nPF\n"
let pf_h = PF.runUntilCycle packet_t ts
print pf_h
print $ getAverageSpeed pf_h
print $ getShare pf_h
getAverageSpeed :: Heap Unit -> Double
getAverageSpeed h = summary_bytes / ((fromIntegral . getSummaryTime) h) where
summary_bytes = (foldr (\x result -> fromIntegral (1000 * (sent_p x)) + result) 0 h)
getSummaryTime :: Heap Unit -> Time
getSummaryTime = foldr (\x result-> result + (sent_p x) * (period x)) 0
getShare :: Heap Unit -> [(Double, Double)]
getShare h = foldr (\x lst -> (1000 / (fromIntegral $ period x), (fromIntegral $ (sent_p x) * (period x)) / sum_t) : lst) [] h where
sum_t = fromIntegral $ getSummaryTime h