{- Your task is to write a program that can outputs to stdout the answers to the following questions: - Given only yellow customers, what are the average and maximum customer waiting times? - Given only red customers, what are the average and maximum queue lengths in-front of the teller? - Which type of customer(yellow, red or blue) gives the closest value between the average and maximum customer waiting times? -} module Main where import Holmusk import Data.List import Options.Applicative import System.Random data Options = Options { interval :: Double } options :: Parser Options options = Options <$> (option auto ( long "interval" <> short 'i' <> help "interval between checks in queueLengthR" <> showDefault <> value 0.1 <> metavar "DOUBLE" ) ) main :: IO () main = do Options {..} <- execParser $ info (options <**> helper) (fullDesc <> progDesc "Run holmusk simulations") -- Q1 putStrLn "Given only yellow customers, what are the average and maximum customer waiting times?" g1 <- getStdGen g2 <- getStdGen let yAvgPt = avgCustomerProcTime Yellow yMaxPt = maxCustomerProcTime Yellow yAvgQl = queueLengthR yAvgPt interval g1 yMaxQl = queueLengthR yMaxPt interval g2 yAvgW = avgWaitingTime yAvgQl yAvgPt yMaxW = maxWaitingTime yMaxQl yMaxPt putStrLn $ "Avg: " ++ show yAvgW putStrLn $ "Max: " ++ show yMaxW putStrLn "" -- Q2 putStrLn "Given only red customers, what are the average and maximum queue lengths in-front of the teller?" g1 <- getStdGen g2 <- getStdGen let rAvgPt = avgCustomerProcTime Red rMaxPt = maxCustomerProcTime Red rAvgQl = queueLengthR rAvgPt interval g1 rMaxQl = queueLengthR rMaxPt interval g2 rAvgW = avgWaitingTime rAvgQl rAvgPt rMaxW = maxWaitingTime rMaxQl rMaxPt putStrLn $ "Avg: " ++ show rAvgQl putStrLn $ "Max: " ++ show rMaxQl putStrLn "" -- Q3 putStrLn "Which type of customer(yellow, red or blue) gives the closest value between the average and maximum customer waiting times?" g1 <- getStdGen g2 <- getStdGen let bAvgPt = avgCustomerProcTime Blue bMaxPt = maxCustomerProcTime Blue bAvgQl = queueLengthR bAvgPt interval g1 bMaxQl = queueLengthR bMaxPt interval g2 bAvgW = avgWaitingTime bAvgQl bAvgPt bMaxW = maxWaitingTime bMaxQl bMaxPt let dist = [(Yellow, yMaxW - yAvgW), (Red, rMaxW - rAvgW), (Blue, bMaxW - bAvgW)] min = minimumBy (\(_, x) (_, y) -> compare x y) $ dist putStrLn (show min)