Skip to content

Commit

Permalink
Register done tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaimaruseac committed May 20, 2012
1 parent b5ae3d5 commit f25b20c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions MAS/AF.hs
Expand Up @@ -53,16 +53,24 @@ doLoop af@(AF { taskList = tl }) t'

agentLoopPhase2 :: AF -> Time -> IO ()
agentLoopPhase2 af@(AF { agentList=ags, taskList=tl, profit=p }) t = do
-- TODO: read tasks done
receiveTasksDone af
allTasks <- receiveTasksDone af
putStrLn ""
putStrLn $ "Cycle " ++ show t ++ ", phase 2:"
printAllTasks allTasks
let pNow = 42 -- TODO
let p' = p + pNow -- TODO
putStrLn $ "Total profit: " ++ show p' ++ " (now: " ++ show pNow ++ ")"
let af' = af { profit = p' }
unless (tl == [] && all finished ags) $ agentLoopAF af' (t + 1)

printAllTasks :: [(ID, [Task], [Task])] -> IO ()
printAllTasks = mapM_ printTasksOneAgent

printTasksOneAgent :: (ID, [Task], [Task]) -> IO ()
printTasksOneAgent (aid, todo, leftOver) = do
when (todo /= []) $ putStrLn $ "AP" ++ show aid ++ " executes: " ++ pprintTasks todo
when (leftOver /= []) $ putStrLn $ "AP" ++ show aid ++ " postpones " ++ pprintTasks leftOver

agentLoopSendingTasks :: AF -> Time -> IO ()
agentLoopSendingTasks af@(AF { taskList = (t, _):_ }) t'
| t == t' + 1 = doSendTasks af t'
Expand Down

0 comments on commit f25b20c

Please sign in to comment.