Package teamwork :: Package multiagent :: Module Team
[hide private]
[frames] | no frames]

Source Code for Module teamwork.multiagent.Team

 1  import copy 
 2  import sys 
 3  from teamwork.multiagent.Multiagent import * 
 4   
5 -class Team(MultiagentSystem):
6 """Base class for representing a team of entities""" 7
8 - def generateAllActions(self,seedAction={}):
9 """Generates all possible combined team actions consistent 10 with the specified seed action (generates all possible 11 combined team actions if seed action is left unspecified)""" 12 agentList = [] 13 for agent in self.members(): 14 if not seedAction.has_key(agent.name): 15 agentList.append(agent) 16 return self.__generateAllActions([seedAction],agentList)
17
18 - def __generateAllActions(self,actList,agents):
19 if len(agents) > 0: 20 newList = [] 21 for act in agents[0].actions: 22 for combinedAct in actList: 23 newAct = copy.copy(combinedAct) 24 newAct[agents[0].name] = act 25 newList.append(newAct) 26 return self.__generateAllActions(newList,agents[1:]) 27 else: 28 return actList
29
30 - def composeActions(self,actions):
31 """Translates a dictionary of agent:action pairs into a single 32 string""" 33 agentList = self.keys() 34 actionString = actions[agentList[0]] 35 for agent in agentList[1:]: 36 actionString = actionString + ' ' + actions[agent] 37 return actionString
38
39 - def decomposeActions(self,actionString):
40 """Translates a string into a dictionary of agent:action 41 pairs""" 42 actionList = string.split(actionString) 43 actions = {} 44 for agent in range(len(self.keys())): 45 actions[self.keys()[agent]] = actionList[agent] 46 return actions
47 48 # This method should probably be in ComMTDP
49 - def individualObs(self,state,actions,observation,agent):
50 """Default method for returning the probability distribution 51 over observations for an individual agent. Returns a uniform 52 distribution. Should be overwritten.""" 53 raise NotImplementedError
54 55 # This method should probably be in ComMTDP
56 - def observableProb(self,state,actions,observation,agent):
57 """Handles the observation function for features that are 58 completely observable. If the observation does not match the 59 true state on the completely observable features, then this 60 function returns 0.0; otherwise, it returns 1.0""" 61 for key in observation.keys(): 62 if key[0] != '_' and \ 63 self[agent].observations[key] == 'observable': 64 if state[key] != observation[key]: 65 return 0.0 66 else: 67 return 1.0
68