1 from teamwork.agent.DefaultBased import *
2 from teamwork.agent.Entities import *
3 from teamwork.multiagent.sequential import *
4 from teamwork.multiagent.GenericSociety import *
5 from teamwork.action.PsychActions import *
6 from ThespianActions import ThespianAction
7 from ThespianMessage import *
8 from ThespianGeneric import *
9
10 from teamwork.dynamics.pwlDynamics import *
11
13
14 sceneID = 6
15
17 """Creates a new order vector. Orders the agents according to the comparison method on the member agents
18 @return: the turn state vector suitable for the initial state of the simulation
19 @rtype: L{KeyedVector}
20 """
21 if entities is None:
22 entities = self.activeMembers()
23
24
25 if self.sceneID == '-1':
26 entities = ['student','Kamela','Xaled','Abasin','Hamed']
27 elif self.sceneID == '6':
28 newEntities = list(range(len(entities)))
29 for index in range(len(entities)):
30 agent = entities[index]
31 if agent.name == 'usr':
32 newEntities[0] = agent
33 elif agent.name == 'streetrat':
34 newEntities[1] = agent
35 elif agent.name == 'labrat1':
36 newEntities[2] = agent
37 elif agent.name == 'labrat2':
38 newEntities[3] = agent
39 elif agent.name == 'otherTeam':
40 newEntities[4] = agent
41 elif agent.name == 'timer':
42 newEntities[5] = agent
43 else:
44 entities.sort()
45
46 return SequentialAgents.generateOrder(self,entities)
47
48
49
51 """Computes the change in turn due to the specified actions
52 @param actions: the actions being performed, indexed by actor name
53 @type actions: C{dict:strS{->}L{teamwork.action.PsychActions.Action}[]}
54 @return: a decision tree representing the changes to the standing turn order vector based on the specified actions
55 @rtype: L{KeyedTree}
56 """
57
58 assert(len(actions) == 1)
59
60
61
62
63
64
65
66
67
68
69
70
71
72 actor,action = actions.items()[0]
73 need_to_update_turn = 1
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 actor = actions.keys()[0]
90 if not actor in self.activeMembers():
91 need_to_update_turn = 0
92
93 unchangedMatrix = KeyedMatrix()
94 for agent in self.activeMembers():
95 key = StateKey({'entity':agent.name,
96 'feature':self.turnFeature})
97 row = KeyedVector()
98 row[key] = 1.
99 unchangedMatrix[key] = row
100 row = KeyedVector()
101 row[keyConstant] = 1.
102 unchangedMatrix[keyConstant] = row
103
104
105 if len(self) == 0 or need_to_update_turn == 0:
106 tree = KeyedTree()
107 tree.makeLeaf(unchangedMatrix)
108 return tree
109 actor = actions.keys()[0]
110
111 resetWeights = KeyedVector()
112 for agent in self.activeMembers():
113 if not actions.has_key(agent.name):
114 resetWeights[StateKey({'entity':agent.name,
115 'feature':self.turnFeature})] = 1.
116 resetPlane = KeyedPlane(resetWeights,0.0001)
117
118 updateMatrix = KeyedMatrix()
119 for agent in self.activeMembers():
120 key = StateKey({'entity':agent.name,
121 'feature':self.turnFeature})
122 row = KeyedVector()
123 if actions.has_key(agent.name):
124
125 pass
126 elif self.positions[agent.name] < self.positions[actor]:
127
128 row[key] = 2.
129 else:
130
131 row[key] = 1.
132 updateMatrix[key] = row
133 row = KeyedVector()
134 row[keyConstant] = 1.
135 updateMatrix[keyConstant] = row
136
137 alreadyActed = ThresholdRow(keys=[{'entity':actor,
138 'feature':self.turnFeature}])
139 updateTree = KeyedTree()
140 updateTree.branch(KeyedPlane(alreadyActed,0.),
141 unchangedMatrix,updateMatrix)
142
143 resetMatrix = KeyedMatrix()
144 for agent in self.activeMembers():
145 key = StateKey({'entity':agent.name,
146 'feature':self.turnFeature})
147 row = KeyedVector()
148 row[keyConstant] = self.positions[agent.name]
149 resetMatrix[key] = row
150 row = KeyedVector()
151 row[keyConstant] = 1.
152 resetMatrix[keyConstant] = row
153
154 tree = KeyedTree()
155 tree.branch(resetPlane,resetMatrix,updateTree)
156 return tree
157