Skip to content

Commit

Permalink
fixed speed issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bitcraft committed Jun 8, 2011
1 parent c948180 commit cd7afe1
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pygoap.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@
import random
import sys
import traceback
import copy


ACTIONSTATE_NOT_STARTED = 0
ACTIONSTATE_FINISHED = 1
Expand Down Expand Up @@ -283,8 +281,7 @@ def make_dict(self, bb=None):

if bb != None:
# copy the dictionaries
for tag in bb.tags():
safe_dict[tag] = bb.read(tag)
safe_dict.update(bb)

return safe_dict

Expand Down Expand Up @@ -329,7 +326,7 @@ def do_exec(self, expr, bb):
# the bb was modified
for key, value in d.items():
if key[:2] != "__":
bb.post(key, value)
bb[key] = value

return True

Expand Down Expand Up @@ -453,10 +450,12 @@ def __init__(self, parent, obj, cost, h, bb=None, touch=True):
self.g = calcG(self)
self.h = h

self.bb_delta = {}

if parent != None:
self.bb_delta = copy.deepcopy(parent.bb_delta)
self.bb_delta.update(parent.bb_delta)
elif bb != None:
self.bb_delta = copy.deepcopy(bb)
self.bb_delta.update(bb)

if touch: self.obj.touch(self.bb_delta)

Expand Down Expand Up @@ -484,7 +483,7 @@ def valid(self, bb):

if (self.prereq == None) or (self.prereq == ""):
return 1.0
elif self.prereq in bb.tags():
elif self.prereq in bb.keys():
return 1.0
else:
return 0.0
Expand All @@ -505,7 +504,8 @@ def valid(self, bb):
#return e.do_eval(self.prereq, bb)

e = PyEval()
d = copy.deepcopy(bb.tagDB)
d = {}
d.update(bb)
return e.cmp_bb(d, self.prereq)

def __repr__(self):
Expand All @@ -520,7 +520,7 @@ def __init__(self, effect):
self.effect = effect

def touch(self, bb):
bb.post(self.effect, True)
bb[self.effect] = True

def __repr__(self):
return "<BasicActionEffect=\"%s\">" % self.effect
Expand Down Expand Up @@ -595,7 +595,7 @@ def get_relevancy(self, bb):

def satisfied(self, bb):
try:
bb.read(self.satisfies)
bb[self.satisfies]
except KeyError:
return 0.0
else:
Expand All @@ -621,7 +621,8 @@ def get_relevancy(self, bb):

def satisfied(self, bb):
e = PyEval()
d = copy.deepcopy(bb.tagDB)
d = {}
d.update(bb)
return e.cmp_bb(d, self.expr)

class SimpleActionNode(object):
Expand Down Expand Up @@ -710,13 +711,13 @@ def touch(self):
mark the parent's blackboard to reflect changes
of a successful execution
"""
self.validator.touch(self.caller.blackboard)
self.validator.touch(self.caller.blackboard.tagDB)

def valid(self, do=False):
"""
make sure the action is able to be started
"""
return self.validator.valid(self.caller.blackboard)
return self.validator.valid(self.caller.blackboard.tagDB)

def start(self):
"""
Expand Down Expand Up @@ -1016,7 +1017,7 @@ def search_actions(self, actions, start_action, start_blackboard, goal):
pushback = None # the pushback is used to limit node access in the heap
success = False

keyNode = PlanningNode(None, start_action, 0, 0, start_blackboard, False)
keyNode = PlanningNode(None, start_action, 0, 0, start_blackboard.tagDB, False)

heap = [(0, keyNode)]

Expand Down

0 comments on commit cd7afe1

Please sign in to comment.