Skip to content
Browse files

Compute profits.

  • Loading branch information...
1 parent f25b20c commit 8c93bcbe70047b7a641ca9a2f545d9dbd7d192d2 @mihaimaruseac committed May 20, 2012
Showing with 16 additions and 10 deletions.
  1. +16 −10 MAS/AF.hs
View
26 MAS/AF.hs
@@ -52,16 +52,22 @@ doLoop af@(AF { taskList = tl }) t'
| otherwise = agentLoopSendingTasks af t'
agentLoopPhase2 :: AF -> Time -> IO ()
-agentLoopPhase2 af@(AF { agentList=ags, taskList=tl, profit=p }) t = do
- 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)
+agentLoopPhase2 af@(AF { agentList=ags, taskList=tl, profit=p,
+ leftOverPenalty=lop }) t = do
+ allTasks <- receiveTasksDone af
+ putStrLn ""
+ putStrLn $ "Cycle " ++ show t ++ ", phase 2:"
+ printAllTasks allTasks
+ let pNow = -lop * fromIntegral (getLeftOverCount allTasks)
+ let p' = p + pNow
+ putStrLn $ "Total profit: " ++ show p' ++ " (now: " ++ show pNow ++ ")"
+ let af' = af { profit = p' }
+ unless (tl == [] && all finished ags) $ agentLoopAF af' (t + 1)
+
+getLeftOverCount :: [(ID, [Task], [Task])] -> Int
+getLeftOverCount = length . concat . map thrd
+ where
+ thrd (_, _, x) = x
printAllTasks :: [(ID, [Task], [Task])] -> IO ()
printAllTasks = mapM_ printTasksOneAgent

0 comments on commit 8c93bcb

Please sign in to comment.
Something went wrong with that request. Please try again.