@ -3,30 +3,31 @@ module Main where
import Algo.MaxRate as MaxRate
import Algo.MaxRate as MaxRate
import Algo.MaxMinRate as MaxMinRate
import Algo.MaxMinRate as MaxMinRate
import Algo.PF as PF
import Algo.PF as PF
import Algo.Common
import Types
import Types
import Heap
import Heap
main :: IO ()
main :: IO ()
main = do
main = do
s <- getLine
--s <- getLine
let speeds = map read $ words s :: [ Double ]
--let speeds = map read $ words s :: [Double]
let speeds = [ 72 , 54 , 36 ]
let ts = map ( ceiling . ( * 1000 ) . ( Types . packet_size / ) ) speeds -- ms
let ts = map ( ceiling . ( * 1000 ) . ( Types . packet_size / ) ) speeds -- ms
putStr " ====== \ n MaxRate \ n "
putStr " ====== \ n MaxRate \ n "
let max_rate_h = MaxRate . runUntilCycle packet_t ts
let h = runUntilCycle MaxRate . createHeap MaxRate . updateHeap packet_t ts
print $ getAverageSpeed max_rate_ h
print $ getAverageSpeed h
print $ getShare max_rate_ h
print $ getShare h
putStr " ====== \ n MaxMinRate \ n "
putStr " ====== \ n MaxMinRate \ n "
let max_min_rate_h = MaxMinRate . runUntilCycle packet_t ts
let h = runUntilCycle MaxMinRate . createHeap MaxMinRate . updateHeap packet_t ts
print $ getAverageSpeed max_min_rate_ h
print $ getAverageSpeed h
print $ getShare max_min_rate_ h
print $ getShare h
putStr " ====== \ n PF \ n "
putStr " ====== \ n PF \ n "
let pf_h = PF . runUntilCycle packet_t ts
let h = runUntilCycle PF . createHeap PF . updateHeap packet_t ts
print pf_h
print $ getAverageSpeed h
print $ getAverageSpeed pf_h
print $ getShare h
print $ getShare pf_h
getAverageSpeed :: Heap Unit -> Double
getAverageSpeed :: Heap Unit -> Double
getAverageSpeed h = summary_bytes / ( ( fromIntegral . getSummaryTime ) h ) where
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 :: Heap Unit -> [ ( Double , Double ) ]
getShare h = foldr ( \ x lst -> ( 1000 / ( fromIntegral $ period x ) , ( fromIntegral $ ( sent_p x ) * ( period x ) ) / sum_t ) : lst ) [] h where
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
sum_t = fromIntegral $ getSummaryTime h