コード例 #1
0
ファイル: runtime.py プロジェクト: fahidRM/python-agentspeak
    def execute(self, agent, intention):
        for _ in self.impl(agent, self.term, intention):
            #fahid: log action

            Logger.log_action(agent=agent.name.localpart,
                              payload={
                                  "IDENTIFIER": self._get_readable_name(),
                                  "CODE_LINE": self.loc.lineno,
                                  "CODE_FILE": self.loc.filename
                              },
                              bb_payload=agent.get_belief_base())
            yield
コード例 #2
0
ファイル: TraceableBehaviour.py プロジェクト: fahidRM/spade
    def _on_run(self):
        Logger.log_action(
            agent=self.agent.name,
            payload={
                    "META": "Running Behaviour",
                    "IDENTIFIER": self.name,
                    "CODE_LINE": "",
                    "CODE_FILE": ""
            },
            bb_payload=[]

        )
コード例 #3
0
ファイル: runtime.py プロジェクト: fahidRM/python-agentspeak
    def call(self, trigger, goal_type, term, calling_intention, delayed=False):
        # Modify beliefs.
        if goal_type == agentspeak.GoalType.belief:
            if trigger == agentspeak.Trigger.addition:
                self.add_belief(term, calling_intention.scope)
            else:
                found = self.remove_belief(term, calling_intention)
                if not found:
                    return True

        # Freeze with caller scope.
        frozen = agentspeak.freeze(term, calling_intention.scope, {})

        if not isinstance(frozen, agentspeak.Literal):
            raise AslError("expected literal")

        # Wake up waiting intentions.
        for intention_stack in self.intentions:
            if not intention_stack:
                continue
            intention = intention_stack[-1]

            if not intention.waiter or not intention.waiter.event:
                continue
            event = intention.waiter.event

            if event.trigger != trigger or event.goal_type != goal_type:
                continue

            if agentspeak.unifies_annotated(event.head, frozen):
                intention.waiter = None
        # fahid..... log plan trace here.....
        self.get_belief_base()
        applicable_plans = self.plans[(trigger, goal_type, frozen.functor,
                                       len(frozen.args))]
        applicable_plans_trace = []
        for plan in applicable_plans:
            """
            if type(plan.context) is list:
                print (">>>> list")
            else:
                print (">>>>> ", type(plan.context))
                if type(plan.context) is AndQuery:
                    print(".....")
                    print(plan.context.left)
                    print(plan.context.right)
                elif type(plan.context) is OrQuery:
                    print("////")
                    print(plan.context.left)

                    print(plan.context.right)
            """
            applicable_plans_trace.append({
                "IDENTIFIER":
                str(plan.head),
                "CONTEXT":
                flatten_context(
                    plan.context
                ),  #str(plan.context) if type(plan.context) is not type (NotQuery("")) else "not " + str(plan.context.query),
                "CODE_LINE":
                "",
                "CODE_FILE":
                ""
            })
        if len(applicable_plans_trace) > 0:
            Logger.log_plan_trace(agent=self.name,
                                  payload=applicable_plans_trace,
                                  bb_payload=self.get_belief_base())

        choicepoint = object()
        intention = Intention()
        # Find matching plan.
        counter = -1
        for plan in applicable_plans:
            counter += 1
            for _ in agentspeak.unify_annotated(plan.head, frozen,
                                                intention.scope,
                                                intention.stack):
                for _ in plan.context.execute(self, intention):
                    intention.head_term = frozen
                    intention.instr = plan.body
                    intention.calling_term = term

                    if not delayed and self.intentions:
                        for intention_stack in self.intentions:
                            if intention_stack[-1] == calling_intention:
                                intention_stack.append(intention)
                                # Fahid: log selected plan....
                                Logger.log_plan_selection(
                                    agent=self.name,
                                    payload=applicable_plans_trace[counter],
                                    bb_payload=self.get_belief_base())
                                return True

                    new_intention_stack = collections.deque()
                    new_intention_stack.append(intention)
                    self.intentions.append(new_intention_stack)
                    # Fahid: Log selected plan.....
                    Logger.log_plan_selection(
                        agent=self.name,
                        payload=applicable_plans_trace[counter],
                        bb_payload=self.get_belief_base())
                    return True

        #fahid: log not found...
        if goal_type == agentspeak.GoalType.achievement:
            raise AslError("no applicable plan for %s%s%s/%d" %
                           (trigger.value, goal_type.value, frozen.functor,
                            len(frozen.args)))
        elif goal_type == agentspeak.GoalType.test:
            return self.test_belief(term, calling_intention)

        return True
コード例 #4
0
 def add_behaviour(self, behaviour, template=None):
     super().add_behaviour(behaviour, template)
     Logger.add_persistent_data(self.name, {"source": "self", "type": "Behaviour", "value": behaviour.get_name()} )
コード例 #5
0
 def remove_behaviour(self, behaviour):
     super().remove_behaviour(behaviour)
     Logger.remove_persistent_data(self.name, {"source": "self", "type": "Behaviour", "value": behaviour.get_name()})
コード例 #6
0
ファイル: TraceableBehaviour.py プロジェクト: fahidRM/spade
 def on_resume(self, owner):
     Logger.add_persistent_data(self.agent.name, {"source": "self", "type": "Behaviour", "value": self.name} )
コード例 #7
0
ファイル: TraceableBehaviour.py プロジェクト: fahidRM/spade
 def on_pause(self, owner):
     Logger.remove_persistent_data(owner, {"source": "self", "type": "Behaviour", "value": self.name} )
コード例 #8
0
ファイル: TraceableBehaviour.py プロジェクト: fahidRM/spade
 def _on_end(self):
     Logger.remove_persistent_data(self.agent.name, {"source": "self", "type": "Behaviour", "value": self.name} )
コード例 #9
0
ファイル: TraceableBehaviour.py プロジェクト: fahidRM/spade
 def _on_start(self):
     Logger.add_persistent_data(self.agent.name, {"source": "self", "type": "Behaviour", "value": self.name} )