Permalink
Browse files

Proper sending of tasks (send nothing to unblock).

  • Loading branch information...
1 parent e14e616 commit 27c13f28fe431473b88d2bfcef64470ba741c9ae @mihaimaruseac committed May 20, 2012
Showing with 13 additions and 3 deletions.
  1. +10 −3 MAS/AF.hs
  2. +3 −0 MAS/AP.hs
View
@@ -74,10 +74,17 @@ agentLoopNoTasksToSend af t = do
agentLoopPhase2 af t
doSendTasks :: AF -> Time -> IO ()
-doSendTasks af@(AF { taskList = (_, ts):tss }) t = do
- distributeTasks $ computeOptimumTaskDistribution af ts
+doSendTasks af@(AF { agentList=ag, taskList=(_, ts):tss }) t = do
+ let otd = computeOptimumTaskDistribution af ts
+ distributeTasks $ fillIn otd ag
let af' = af { taskList = tss }
agentLoopNoTasksToSend af' t
+ where
+ fillIn l [] = l
+ fillIn l (x:xs)
+ | x `elem` map fst l = fillIn l xs
+ | otherwise = (x, []) : fillIn l xs
+
receiveTasksDone :: AF -> IO ()
receiveTasksDone a@(AF {numAgents=n, incoming=c}) = doRTD n c
where
@@ -94,7 +101,7 @@ distributeTasks = mapM_ distributeTasksToOneAgent
distributeTasksToOneAgent :: (AP, [Task]) -> IO ()
distributeTasksToOneAgent (a@AP { idAP = aid, incomingAP = c }, t) = do
- putStrLn $ "AF -> AP" ++ show aid ++ ": " ++ pprintTasks t
+ when (t /= []) $ putStrLn $ "AF -> AP" ++ show aid ++ ": " ++ pprintTasks t
writeChan c $ Tasks t
launchSystem :: AF -> IO ()
View
@@ -61,3 +61,6 @@ pprintAP a = "AP" ++ id ++ ": budget: " ++ bdg ++ " caps: " ++ capss
instance Show AP where
show = pprintAP
+
+instance Eq AP where
+ AP {idAP=id1} == AP {idAP=id2} = id1 == id2

0 comments on commit 27c13f2

Please sign in to comment.