Permalink
Browse files

完成!

  • Loading branch information...
1 parent caa7416 commit 6c0da0227015b8fbe1db2a78156f20a87decbb47 @wvogel00 committed May 18, 2012
Showing with 14 additions and 8 deletions.
  1. +13 −7 Friday/SimulatorT.hs
  2. +1 −1 Friday/SimulatorT_Interface.hs
View
@@ -11,18 +11,24 @@ simulate ft info@(s,p,wwt,b,n) (r1:r2:randoms) = if now s >= ft
--イベント種類によってsystemを更新
update rs (sy,p,wwt,b,n) nowState = case nowState of
CallOfLoss -> (systemC, newPacket (now sy) sy rs,wwt,b+1,n+1) where
- systemC = (capacity sy,parameter sy,queue sy,
- nextTime sy $ newPacket (now sy) sy rs)
+ systemC = (capacity sy,parameter sy,queue',
+ nextTime queue' $ newPacket (now sy) sy rs)
+ queue' = queue sy
EnQueue -> (systemE, newPacket (now sy) sy rs, wwt,b,n+1) where
- systemE = (capacity sy,parameter sy,queue sy++[p],
- nextTime sy $ newPacket (now sy) sy rs)
+ systemE = (capacity sy,parameter sy,queue',
+ nextTime queue' $ newPacket (now sy) sy rs)
+ queue' = queue sy ++ [p]
Process -> (systemP, p, wwt+stayTime, b, n) where
- systemP = (capacity sy,parameter sy,tail$queue sy,nextTime sy p)
+ systemP = (capacity sy,parameter sy,queue',nextTime queue' p)
stayTime = now sy - arrive (head $ queue sy)
+ queue' = updateQueue (now sy) $ tail $ queue sy
--パケットを生成する
newPacket time sy (r1,r2) = mkPacket time (parameter sy) r1 r2
--次回イベント時刻を求める
-nextTime sy = min (escapeTime sy).arrive
-escapeTime sy = if queue sy/=[] then escape.head $queue sy else 10^10
+nextTime q = min escapeTime.arrive where
+ escapeTime = if q /=[] then escape $ head q else 10^10
+--Queueの先頭パケットの離脱時間を更新
+updateQueue _ [] = []
+updateQueue time ((at,st,et,bool):ps) = (at,st,time+st,bool):ps
@@ -49,7 +49,7 @@ input = do
= ((read l,read m),read capa,read st, read ft)
output measuredTime (system,p,wwt,b,n) = do
- print $ system
+ putStrLn $ "(" ++ show b ++ "::" ++ show n ++ ")"
putStrLn $ "call of loss == " ++ show callofloss
putStrLn $ "average of packets = " ++ show (wwt/measuredTime)
putStrLn $ "average of waiting time = " ++ show avgWaiting where

0 comments on commit 6c0da02

Please sign in to comment.