Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Dummy send back

  • Loading branch information...
commit b5ae3d5dd4ea267d902db1a0a64b4ecbf6cbfbd4 1 parent 5d3dbca
@mihaimaruseac authored
Showing with 21 additions and 16 deletions.
  1. +10 −5 MAS/AF.hs
  2. +9 −11 MAS/AP.hs
  3. +2 −0  MAS/Messages.hs
View
15 MAS/AF.hs
@@ -85,13 +85,18 @@ doSendTasks af@(AF { agentList=ag, taskList=(_, ts):tss }) t = do
| 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
+receiveTasksDone :: AF -> IO [(ID, [Task], [Task])]
+receiveTasksDone a@(AF {numAgents=n, incoming=c}) = doRTD n c []
where
- doRTD 0 _ = return () -- TODO
- doRTD n inc = do
+ doRTD 0 _ _ = return []
+ doRTD n inc ms = do
m <- readChan c
- if isEnd m then doRTD (n - 1) inc else doRTD n inc
+ case m of
+ WillDo aid todo lo -> do
+ putBackAll ms inc
+ ret <- doRTD (n - 1) inc ms
+ return $ (aid, todo, lo) : ret
+ _ -> doRTD n inc (m:ms)
computeOptimumTaskDistribution :: AF -> [Task] -> [(AP, [Task])]
computeOptimumTaskDistribution af t = [(head $ agentList af, t)]
View
20 MAS/AP.hs
@@ -26,14 +26,10 @@ finished :: AP -> Bool
finished a@(AP { leftOvers=lo }) = lo == []
agentLoopAP :: AP -> IO ()
-agentLoopAP a@(AP { afap=afap }) = do
+agentLoopAP a@(AP {idAP=aid, afap=afap}) = do
t <- receiveTasks a []
- (td, lo) <- planifyTasks a t
- print $ "X" ++ show (td, lo)
- print "ap"
- print a
- writeChan afap $End 42
- print "Done"
+ (td, lo) <- planifyTasks a t []
+ writeChan afap $ WillDo aid td lo
receiveTasks :: AP -> [Message] -> IO [Task]
receiveTasks a@(AP { incomingAP=inc }) ms = do
@@ -44,10 +40,12 @@ receiveTasks a@(AP { incomingAP=inc }) ms = do
return t
_ -> receiveTasks a (m:ms)
-planifyTasks :: AP -> [Task] -> IO ([Task], [Task])
-planifyTasks a@(AP {budget=b, caps=c, leftOvers=lo, afap=afap, incomingAP=inc}) t = do
- print (t, lo)
- return (t, lo)
+planifyTasks :: AP -> [Task] -> [Task] -> IO ([Task], [Task])
+planifyTasks a@(AP {budget=b, caps=c, leftOvers=lo, afap=afap,
+ incomingAP=inc}) t r = do
+ let all_tasks = lo ++ t ++ r
+ -- TODO distribute tasks to other agents
+ return ([], all_tasks)
buildAP :: ID -> Cost -> [Cap] -> Chan Message -> Chan Message -> AP
buildAP i bdg caps afap incoming = AP i bdg caps afap incoming []
View
2  MAS/Messages.hs
@@ -12,6 +12,8 @@ type Comm = (Chan Message, Chan Message)
data Message
= None Int
| Tasks [Task] -- list of tasks to do this step (only af->ap)
+ | WillDo ID [Task] [Task] -- list of tasks that AP ID will do and list of
+ -- leftovers (AP->AF)
| End ID
deriving (Show)
Please sign in to comment.
Something went wrong with that request. Please try again.