|
|
|
module Main where
|
|
|
|
|
|
|
|
import Algo.MaxRate as MaxRate
|
|
|
|
import Algo.MaxMinRate as MaxMinRate
|
|
|
|
import Algo.PF as PF
|
|
|
|
import Algo.Common
|
|
|
|
import Types
|
|
|
|
import Heap
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
--s <- getLine
|
|
|
|
--let speeds = map read $ words s :: [Double]
|
|
|
|
let speeds = [72, 54 ,36]
|
|
|
|
let ts = map (ceiling . (* 1000) . (Types.packet_size/)) speeds -- ms
|
|
|
|
|
|
|
|
putStr "======\nMaxRate\n"
|
|
|
|
let h = runUntilCycle MaxRate.createHeap MaxRate.updateHeap packet_t ts
|
|
|
|
print $ getAverageSpeed h
|
|
|
|
print $ getShare h
|
|
|
|
|
|
|
|
putStr "======\nMaxMinRate\n"
|
|
|
|
let h = runUntilCycle MaxMinRate.createHeap MaxMinRate.updateHeap packet_t ts
|
|
|
|
print $ getAverageSpeed h
|
|
|
|
print $ getShare h
|
|
|
|
|
|
|
|
putStr "======\nPF\n"
|
|
|
|
let h = runUntilCycle PF.createHeap PF.updateHeap packet_t ts
|
|
|
|
print $ getAverageSpeed h
|
|
|
|
print $ getShare 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
|
|
|
|
|