1 from xml.dom.minidom import *
2 from teamwork.policy.LookupPolicy import *
3 from teamwork.policy.LookaheadPolicy import *
4
6 lookupClass = LookupPolicy
7 lookaheadClass = LookaheadPolicy
8
9 - def __init__(self,entity,actions,size,depth=1):
10 self.lookaheadClass.__init__(self,entity,actions,depth)
11 self.lookupClass.__init__(self,entity=entity,actions=actions,
12 span=size)
13
15 self.lookaheadClass.setDepth(self,depth)
16
17 - def tryLookup(self,state,choices,debug,explain):
18 if len(choices) > 0:
19 newChoices = choices + [self.entity.actionClass({'type':'lookahead'})]
20 else:
21 newChoices = choices
22 act,exp = self.lookupClass.execute(self,state,newChoices,debug)
23 return act,exp
24
26 act,exp = self.tryLookup(state,choices,debug,explain)
27 if not act:
28 act,exp = self.lookaheadClass.execute(self,state,choices,debug,
29 explain=explain)
30 elif act[0]['type'] == 'lookahead':
31 depth = -1
32 for value in act.values():
33 if value != 'lookahead' and value:
34 depth = value
35 break
36 act,exp = self.lookaheadClass.execute(self,state,choices,debug,
37 depth,explain=explain)
38 return act,exp
39
41 newPolicy = self.__class__(self.entity,self.choices,
42 self.span,self.horizon)
43 newPolicy.entries = self.entries[:]
44 return newPolicy
45
47 newPolicy = self.__class__(self.entity,self.choices,
48 self.span,self.horizon)
49 newPolicy.entries = copy.deepcopy(self.entries,memo)
50 return newPolicy
51
59
63
68
70 LookaheadPolicy.parse(self,element)
71 try:
72 self.span = int(element.getAttribute('span'))
73 except ValueError:
74 self.span = 1
75