@ -3,30 +3,31 @@ 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 ]
--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 " ====== \ n MaxRate \ n "
let max_rate_h = MaxRate . runUntilCycle packet_t ts
print $ getAverageSpeed max_rate_ h
print $ getShare max_rate_ h
let h = runUntilCycle MaxRate . createHeap MaxRate . updateHeap packet_t ts
print $ getAverageSpeed h
print $ getShare h
putStr " ====== \ n MaxMinRate \ n "
let max_min_rate_h = MaxMinRate . runUntilCycle packet_t ts
print $ getAverageSpeed max_min_rate_ h
print $ getShare max_min_rate_ h
let h = runUntilCycle MaxMinRate . createHeap MaxMinRate . updateHeap packet_t ts
print $ getAverageSpeed h
print $ getShare h
putStr " ====== \ n PF \ n "
let pf_h = PF . runUntilCycle packet_t ts
print pf_h
print $ getAverageSpeed pf_h
print $ getShare pf_h
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
@ -38,3 +39,4 @@ 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