コード例 #1
0
def _substring(agent, term, intention):
    needle = asl_str(agentspeak.grounded(term.args[0], intention.scope))
    haystack = asl_str(agentspeak.grounded(term.args[1], intention.scope))

    choicepoint = object()

    pos = haystack.find(needle)
    while pos != -1:
        intention.stack.append(choicepoint)

        if agentspeak.unify(term.args[2], pos, intention.scope,
                            intention.stack):
            yield

        agentspeak.reroll(intention.scope, intention.stack, choicepoint)
        pos = haystack.find(needle, pos + 1)
コード例 #2
0
ファイル: runtime.py プロジェクト: fahidRM/python-agentspeak
def dump_variables(variables, scope):
    not_in_scope = []

    for name, variable in sorted(variables.items()):
        if variable in scope:
            print("%s = %s" %
                  (name, asl_str(agentspeak.deref(variable, scope))))
        else:
            not_in_scope.append("%s = %s" % (name, variable))

    if not_in_scope:
        print("%d unbound: %s" % (len(not_in_scope), ", ".join(not_in_scope)))
コード例 #3
0
ファイル: bdi.py プロジェクト: ccarstens/spade_bdi
 def _send(agent, term, intention):
     receivers = asp.grounded(term.args[0], intention.scope)
     if isinstance(receivers, str) or isinstance(receivers, asp.Literal):
         receivers = (receivers,)
     ilf = asp.grounded(term.args[1], intention.scope)
     if not asp.is_atom(ilf):
         return
     ilf_type = ilf.functor
     mdata = {"performative": "BDI", "ilf_type": ilf_type, }
     for receiver in receivers:
         body = asp.asl_str(asp.freeze(term.args[2], intention.scope, {}))
         msg = Message(to=str(receiver), body=body, metadata=mdata)
         self.agent.submit(self.send(msg))
     yield
コード例 #4
0
def _csv(agent, term, intention, _files={}):
    if agent in _files:
        f = _files[agent]
    else:
        f = open("%s.csv" % agent.name, "w")
        _files[agent] = f

    memo = {}
    txt = ",".join(
        asl_str(agentspeak.freeze(t, intention.scope, memo))
        for t in term.args)

    f.write(txt)
    f.write("\n")
    f.flush()

    yield
コード例 #5
0
def _print(agent, term, intention, _color_map={}, _current_color=[0]):
    if agent in _color_map:
        color = _color_map[agent]
    else:
        color = COLORS[_current_color[0]]
        _current_color[0] = (_current_color[0] + 1) % len(COLORS)
        _color_map[agent] = color

    memo = {}
    text = " ".join(
        asl_str(agentspeak.freeze(t, intention.scope, memo))
        for t in term.args)

    with colorama.colorama_text():
        print(color[0],
              color[1],
              agent.name,
              colorama.Fore.RESET,
              colorama.Back.RESET,
              " ",
              text,
              sep="")

    yield