Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: mihaimaruseac/cdte
base: 6d5a111416
...
head fork: mihaimaruseac/cdte
compare: 27c13f28fe
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 36 additions and 15 deletions.
  1. +19 −4 MAS/AF.hs
  2. +17 −11 MAS/AP.hs
View
23 MAS/AF.hs
@@ -53,9 +53,10 @@ 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
putStrLn ""
putStrLn $ "Cycle " ++ show t ++ ", phase 2:"
- -- TODO: read tasks done
let pNow = 42 -- TODO
let p' = p + pNow -- TODO
putStrLn $ "Total profit: " ++ show p' ++ " (now: " ++ show pNow ++ ")"
@@ -73,10 +74,24 @@ 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
+ doRTD 0 _ = return () -- TODO
+ doRTD n inc = do
+ m <- readChan c
+ if isEnd m then doRTD (n - 1) inc else doRTD n inc
computeOptimumTaskDistribution :: AF -> [Task] -> [(AP, [Task])]
computeOptimumTaskDistribution af t = [(head $ agentList af, t)]
@@ -86,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
28 MAS/AP.hs
@@ -18,24 +18,22 @@ data AP = AP
, caps :: [Cap]
, afap :: Chan Message -- to AF (incoming for AF)
, incomingAP :: Chan Message -- incoming to me
- , tasksToDo :: [Task] -- received now from AF
, leftOvers :: [Task] -- task not done previously
- , tasksFromOthers :: [Task] -- from other agents
}
--- received from AF, received from other APs and leftovers
-tasksToConsider :: AP -> [Task]
-tasksToConsider a@(AP { tasksToDo=tdd, leftOvers=lo, tasksFromOthers=tfo})
- = tdd ++ lo ++ tfo
-
-- Return True if I have no task to do (at all).
finished :: AP -> Bool
finished a@(AP { leftOvers=lo }) = lo == []
agentLoopAP :: AP -> IO ()
-agentLoopAP ap = do
- t <- receiveTasks ap []
- print $ "AP:" ++ show (ap, t)
+agentLoopAP a@(AP { 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"
receiveTasks :: AP -> [Message] -> IO [Task]
receiveTasks a@(AP { incomingAP=inc }) ms = do
@@ -46,8 +44,13 @@ 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)
+
buildAP :: ID -> Cost -> [Cap] -> Chan Message -> Chan Message -> AP
-buildAP i bdg caps afap incoming = AP i bdg caps afap incoming [] [] []
+buildAP i bdg caps afap incoming = AP i bdg caps afap incoming []
pprintAP :: AP -> String
pprintAP a = "AP" ++ id ++ ": budget: " ++ bdg ++ " caps: " ++ capss
@@ -58,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

No commit comments for this range

Something went wrong with that request. Please try again.