Пример #1
0
class Creator(Developer, pyson.runtime.Agent):

    actions = pyson.Actions(actions)

    def __init__(self, beliefs, rules, plans, name):
        Developer.__init__(self, name)
        pyson.runtime.Agent.__init__(self, beliefs, rules, plans)
        self.days = 6

    @actions.add(".do_work")
    def do_work(self, term, intention):
        category = random.choice(CATEGORY_NAMES)
        c, d = self.compute_change_probability()

        if schedule.tick >= START_TICK_LAST_STAGE:
            num_deleted = numpy.random.geometric(min(1, 1 / d * 2.2))
            num_updated = numpy.random.geometric(0.35)
            num_created = numpy.random.geometric(min(1, 1 / c))
        else:
            num_deleted = numpy.random.geometric(min(1, 1 / d * 1.6))
            num_updated = numpy.random.geometric(0.425)
            num_created = numpy.random.geometric(min(1, 1 / c * 1.7475))

        changed = []
        self.delete_files(num_deleted, category)
        changed += self.update_files(num_updated, category)
        changed += self.create_files(num_created, category)

        self.create_coupling(changed)

        self.bugfix()
        yield

    @actions.add(".do_update")
    def do_update(self, term, intention):
        num_updated = numpy.random.geometric(0.3275)
        category = random.choice(CATEGORY_NAMES)
        updated = self.update_files(num_updated, category)
        self.create_coupling(updated)
        yield

    def bugfix(self):
        bug = self.get_random_bug()
        if not bug:
            return

        p_fix = random.random()
        if p_fix <= 0.75:
            bug.closed = schedule.tick
        elif self.is_owner(bug) and p_fix <= 0.95:
            bug.closed = schedule.tick
Пример #2
0
from __future__ import print_function

import pyson
import pyson.runtime
import pyson.stdlib
import math
import random
import sys
import os
import os.path

# Actions

files = set()

actions = pyson.Actions(pyson.stdlib.actions)

actions.add_function(".sin", float, math.sin)


@actions.add_function(".f", float)
def f(val):
    return val * 3


@actions.add_function(".add_file", ())
def add_file():
    global files
    filename = "".join(random.choice("abcdefghij") for _ in range(10))
    files.add(filename)
    return filename
Пример #3
0
#   - .drop_all_desires
#   - .drop_all_events
#   - .drop_all_intentions
#   - .drop_desire
#   - .drop_event
#   - .drop_intention
#   - .fail_goal
#   - .intend
#   - .succeed_goal
#   - .add_anot
#   - .at
#   - .create_agent
#   - .kill_agent
#   - .perceive

actions = pyson.Actions()


@actions.add(".broadcast", 2)
def _broadcast(agent, term, intention):
    # Illocutionary force.
    ilf = pyson.grounded(term.args[0], intention.scope)
    if not pyson.is_atom(ilf):
        return
    if ilf.functor == "tell":
        goal_type = pyson.GoalType.belief
    elif ilf.functor == "achieve":
        goal_type = pyson.GoalType.achievement
    else:
        raise pyson.PysonError("unknown illocutionary force: %s" % ilf)
Пример #4
0
import asyncio
import logging

from lxml import etree

from heapq import heapify, heappop

import pyson
import pyson.runtime
import pyson.ext_stdlib

LOGGER = pyson.get_logger(__name__)

actions = pyson.Actions(pyson.ext_stdlib.actions)

PERCEPT_TAG = frozenset(
    [pyson.Literal("source", (pyson.Literal("percept"), ))])


class Environment(pyson.runtime.Environment):
    def time(self):
        return asyncio.get_event_loop().time()

    def run(self):
        super(Environment, self).run()
        self.dispatch_wait_until()

    def dispatch_wait_until(self):
        earliest = None
        for agent in self.agents.values():
            for intention_stack in agent.intentions: