コード例 #1
0
ファイル: planning.py プロジェクト: bitcraft/lpc1
class PlanningNode(object):
    """
    each node has a copy of a bb (self.bb) in order to simulate a plan.
    """

    def __init__(self, parent, action, bb=None):
        self.parent = parent
        self.action = action
        self.bb = Blackboard()
        self.delta = Blackboard()
        #self.cost = action.calc_cost()
        self.cost = 1
        self.g = calcG(self)
        self.h = 1

        if not parent == None:
            self.bb.update(parent.bb)

        elif not bb == None:
            self.bb.update(bb)

        action.touch(self.delta)
        self.bb.update(self.delta)

    def __eq__(self, other):
        if isinstance(other, PlanningNode):
            #if DEBUG: print "[cmp] {} {}".format(self.delta.memory, other.delta.memory)
            return self.delta == other.delta
        else:
            return False

    def __repr__(self):
        try:
            return "<PlanNode: '%s', cost: %s, p: %s>" % \
            (self.action.__name__,
                self.cost,
                self.parent.action.__class__.__name__)

        except AttributeError:
            return "<PlanNode: '%s', cost: %s, p: None>" % \
            (self.action.__class__.__name__,
                self.cost)
コード例 #2
0
class PlanningNode(object):
    """
    each node has a copy of a bb (self.bb) in order to simulate a plan.
    """
    def __init__(self, parent, action, bb=None):
        self.parent = parent
        self.action = action
        self.bb = Blackboard()
        self.delta = Blackboard()
        #self.cost = action.calc_cost()
        self.cost = 1
        self.g = calcG(self)
        self.h = 1

        if not parent == None:
            self.bb.update(parent.bb)

        elif not bb == None:
            self.bb.update(bb)

        action.touch(self.delta)
        self.bb.update(self.delta)

    def __eq__(self, other):
        if isinstance(other, PlanningNode):
            #if DEBUG: print "[cmp] {} {}".format(self.delta.memory, other.delta.memory)
            return self.delta == other.delta
        else:
            return False

    def __repr__(self):
        try:
            return "<PlanNode: '%s', cost: %s, p: %s>" % \
            (self.action.__name__,
                self.cost,
                self.parent.action.__class__.__name__)

        except AttributeError:
            return "<PlanNode: '%s', cost: %s, p: None>" % \
            (self.action.__class__.__name__,
                self.cost)