Пример #1
0
    def __init__(self, name, agents, s1, s2):

        super().__init__(name, agents)

        buzz = Buzz('stuff', ('number',))
        agents[0].set_message(buzz)
        agents[0].set_organ(Sensor('S1', self.f_sense, buzz, 
                            sensor_func_kwargs={'xxx':s1}))
        buzz = Buzz('stuff', ('number',))
        agents[1].set_message(buzz)
        agents[1].set_organ(Sensor('S2', self.f_sense, buzz, 
                            sensor_func_kwargs={'xxx':s2}))
def test_main():
    #
    # Define Messages
    #
    buzz = Buzz('view_of_dice', ['dice_1', 'dice_2', 'dice_3', 
                                 'dice_4', 'dice_5'])
    belief = Belief('world_is_good', ['joy_index'])
    
    #
    # Define Organs and their associated messages
    #
    sensor = Sensor('check_roll', dice_sensor, buzz)
    interpreter = Interpreter('was_it_good_roll', roll_interpreter, buzz, belief,
                              belief_updater=True)
    
    #
    # Initialize Agent
    #
    agent = Agent('test_agent', strict_engine=True)
    agent.set_organ(sensor)
    agent.set_organ(interpreter)
    
    beliefs = []
    for k in range(0, 5):
        agent.sense('check_roll')
        agent.interpret('was_it_good_roll')
        beliefs.append(agent.belief['world_is_good'].values()[0])
    
    assert (beliefs == REF_OUTCOME)
Пример #3
0
    def __init__(self, name, agents, env_atom):

        super().__init__(name, agents, agent_env=env_atom)

        for agent in agents:
            sensor = Sensor('Feel for gene in Env',
                            self.feeler,
                            agent.buzz['Env Feeling'],
                            agent_id_to_engine=True)
            stuff = ResourceMap('Env Payload', 'reset', 'External gene',
                                ('item', ))
            actuator_r = Actuator('Suck up gene',
                                  self.retriever,
                                  agent.direction['Receive'],
                                  stuff,
                                  agent_id_to_engine=True)
            actuator_e = Actuator('Eject gene',
                                  self.ejecter,
                                  agent.direction['Eject'],
                                  agent_id_to_engine=True)
            actuator_b = Actuator('Birth baby',
                                  self.birth,
                                  agent.direction['Eject'],
                                  agent_id_to_engine=True)
            agent.set_organs(sensor, actuator_r, actuator_e, actuator_b)
Пример #4
0
def test_main():

    # Not fully implemented
    assert 1==2

    battery = Resource('battery power', ('potential',))
    battery.set_values(0.401)
    suck_power = ResourceMap('suck power', 'delta', 'potential', ('reduction',))
    b1 = Buzz('sound stimulation', ('band_1', 'band_2', 'band_3'))
    s1 = Sensor('sound in surrounding', listen, b1, suck_power)
    belief_1 = Belief('The word was spoken', ('probability',))
    int1 = Interpreter('Was the word spoken?', word_estimator, b1, belief_1)
    dir_1 = Direction('follow up request', ('word_section_1', 'word_section_2',
                                            'word_section_3', 'word_section_4'))
    moul1 = Moulder('What response to give', responder, belief_1, dir_1)
    a1 = Actuator('loudspeaker vibrations', loudspeaker_api, dir_1, suck_power)
    moul2 = Moulder('Select warn statement', warn_statement, None, dir_1,
                    resource_op_input=battery)

    bc = AutoBeliefCondition('Sufficiently confident of word spoken',
                             lambda p: p > 0.75, 'The word was spoken')
    rc = AutoResourceCondition('Sufficient power left',
                               lambda pot: pot > 0.2, 'potential')
    clausul_1 = Clause('listen for the word',
                       [('sense', 'sound in surrounding'),
                        ('interpret', 'Was the word spoken?')],
                       condition=bc)

    clausul_2 = Clause('say something to the user',
                       [('mould', 'What response to give'),
                        ('act', 'loudspeaker vibrations')])
    clausul_3 = Clause('power check', condition=rc)
    clausul_4 = Clause('power warn',
                       [('mould', 'Select warn statement'),
                        ('act', 'loudspeaker vibrations')])

    plan = Plan('Clever stuff')
    plan.add_cargo('pronounce', 'listen for the word')
    plan.add_cargo('pronounce', 'say something to the user')
    plan.add_cargo('pronounce', 'power check')
    plan.add_cargo('pronounce', 'power warn')
    plan.add_dependency(2, 0, 3)
    plan.add_dependency(0, 1)
    plan.stamp_and_approve()

    agent = Agent('smart loudspeaker')
    agent.set_organs(s1, int1, moul1, moul2, a1)
    agent.set_messages(b1, belief_1, dir_1)
    agent.set_scaffold(battery)
    agent.set_policies(clausul_1, clausul_2, clausul_3, clausul_4, plan)

    agent.enact('Clever stuff')
    agent.enact('Clever stuff')
    agent.enact('Clever stuff')
    agent.enact('Clever stuff')
Пример #5
0
def test_main():
    buzz_1 = Buzz('B1', ('value', ))
    sensor_1 = Sensor('S1', s1, buzz_1)
    buzz_2 = Buzz('B2', ('value', ))
    sensor_2 = Sensor('S2', s2, buzz_2)

    agent = Agent('test', strict_engine=True)
    agent.set_organs(sensor_1, sensor_2)
    agent.set_messages(buzz_1, buzz_2)

    plan = Plan('silly simple')
    plan.add_cargo('sense', 'S1')
    plan.add_cargo('sense', 'S2')
    plan.add_dependency(0, 1)
    plan.stamp_and_approve()
    plan.enacted_by(agent)

    assert (TEST_ORDER == REF_ORDER)
    assert (buzz_1.values() == [1.0])
    assert (buzz_2.values() == [2.0])
Пример #6
0
def test_main():
    # Define Messages
    #
    buzz = Buzz('audio_trigger',
                (tuple(['a' + str(n) for n in range(1, 20)]), ))
    belief = Belief('trigger_spoken', ['probability'])
    direction = Direction('say_this', ['sentence'])

    #
    # Define Organs and their associated messages
    #
    env = Env()
    sensor = Sensor('listen', env.ear, buzz)
    interpreter = Interpreter('was_trigger_word_spoken', trigger_word, buzz,
                              belief)
    moulder = Moulder('follow_up_question', question_maker, belief, direction)
    actuator = Actuator('speak', env.mouth, direction)

    #
    # Autonomous constraints
    #
    belief_condition = AutoBeliefCondition('heard_it', lambda x: x > 0.9,
                                           'trigger_spoken')

    #
    # Plan
    #
    clause_1 = Clause('sound_trigger',
                      [('sense', 'listen'),
                       ('interpret', 'was_trigger_word_spoken')],
                      condition=belief_condition)
    clause_2 = Clause('response_formation', [('mould', 'follow_up_question'),
                                             ('act', 'speak')])
    heart = Heartbeat('beater', max_ticker=N_HEARTS)
    #
    # Initialize Agent
    #
    agent = SlimAgent('test_agent')
    agent.set_organ(sensor)
    agent.set_organ(interpreter)
    agent.set_organ(moulder)
    agent.set_organ(actuator)
    agent.set_policy(clause_1)
    agent.set_policy(clause_2)
    agent.set_policy(heart)

    agent()

    assert (env.env_interactions == REF)
Пример #7
0
    def __init__(self, name, agents, graph):

        super().__init__(name, agents, full_agents_graph=graph)

        for node in self:
            agent = node.agent_content
            if agent is None:
                continue
            if agent.name == 'Coordinator':
                continue

            motion_sense = Sensor('Feel microwaves', self.feel_spectrum,
                                  agent.buzz['Power Spectrum Sample'],
                                  agent_id_to_engine=True)
            agent.set_organ(motion_sense)
Пример #8
0
    def __init__(self, name, agents):

        super().__init__(name, agents)

        for agent in agents:
            if agent.name == 'Teacher':
                actuator = Actuator('Share', self.share_to_external, 
                                    agent.direction['Share this'],
                                    agent_id_to_engine=True)
                agent.set_organ(actuator)

            if agent.name == 'Student':
                sensor = Sensor('Listen for knowledge', self.listen,
                                agent.buzz['Knowledge feed'],
                                agent_id_to_engine=True)
                agent.set_organ(sensor)
Пример #9
0
    def __init__(self, name, agents_init):

        super().__init__(name, agents_init)

        for node in self:
            agent = node.agent_content
            buzz = Buzz('type_discovery', ('type_sense', 'honesty_sense'))
            sensor = Sensor('discover_neighbour_type',
                            self.type_query,
                            buzz,
                            agent_id_to_engine=True)
            feature = Feature('revealed_type', ('revealed_type', ))
            essence = Essence('who_am_i', ('my_type', 'my_mood'))
            cortex = Cortex('my_type', agent.reveal_type, essence, feature)
            agent.set_organs(sensor, cortex)

            essence.set_values([FLOATPOOL.pop(0), FLOATPOOL.pop(0)])
            agent.set_scaffold(essence)
            print(agent.essence.values())
def test_main():

    buzz = Buzz('nose_tingle', ['nerve_1', 'nerve_2'])
    sensor = Sensor('smell_the_roses', smeller, buzz)
    belief = Belief('world_blossoms', ['certainty'])
    interpreter = Interpreter('does_the_world_blossom', nerve_analyzer, buzz,
                              belief)
    direction = Direction('words_to_say', ['first_word', 'second_word'])
    moulder = Moulder('what_to_say', word_smith, belief, direction)
    actuator = Actuator('say_it',
                        speak,
                        direction,
                        actuator_func_kwargs={'well': True})

    agent = Agent('simple human', strict_engine=True)
    agent.set_organs(sensor, interpreter, moulder, actuator)

    agent.sense('smell_the_roses')
    agent.interpret('does_the_world_blossom')
    agent.mould('what_to_say')
    agent.act('say_it')

    agent.sense('smell_the_roses')
    agent.interpret('does_the_world_blossom')
    agent.mould('what_to_say')
    agent.act('say_it')

    agent.sense('smell_the_roses')
    agent.interpret('does_the_world_blossom')
    agent.mould('what_to_say')
    agent.act('say_it')

    agent.sense('smell_the_roses')
    agent.interpret('does_the_world_blossom')
    agent.mould('what_to_say')
    agent.act('say_it')

    agent.sense('smell_the_roses')
    agent.interpret('does_the_world_blossom')
    agent.mould('what_to_say')
    agent.act('say_it')

    assert (read_env() == REF)
Пример #11
0
    def __init__(self, name, agents, full_agents_graph, midpoint_max_move,
                 max_max_move, mutate_prob, resource_jump_magnitude,
                 resource_jump_prob, mutate_essence):

        super().__init__(name,
                         agents,
                         full_agents_graph=full_agents_graph,
                         strict_engine=STRICT_ENGINE)

        self.midpoint_max_move = midpoint_max_move
        self.max_max_move = max_max_move

        for agent in agents:

            #
            # Sensor
            sensor = Sensor('Feel Neighbour Surface',
                            self._cmp_neighbour_coop,
                            agent.buzz['Neighbour Cooperator'],
                            agent_id_to_engine=True)
            agent.set_organ(sensor)

            #
            # Actuator
            a_a_subtract = ResourceMap('Consume A', 'delta', 'info_a',
                                       ('removal', ))
            a_b_subtract = ResourceMap('Consume B', 'delta', 'info_b',
                                       ('removal', ))
            a_c_subtract = ResourceMap('Consume C', 'delta', 'info_c',
                                       ('removal', ))
            consume_resources = MapCollection(
                [a_a_subtract, a_b_subtract, a_c_subtract])
            actuator = Actuator('Share Resources to Neighbours',
                                self._cmp_alter_env_resources,
                                agent.direction['Resources to Share'],
                                agent_id_to_engine=True,
                                resource_map_output=consume_resources)
            agent.set_organ(actuator)

            actuator = Actuator('Spread Lies to Neighbours',
                                self._cmp_spread_lies,
                                agent.direction['Lies to Eject'],
                                agent_id_to_engine=True,
                                resource_map_output=consume_resources)
            agent.set_organ(actuator)

            add_from_env = universal_map_maker(agent.resource, 'delta',
                                               ('add', ))
            actuator = Actuator('Gulp Environment',
                                self._cmp_gulp_env,
                                agent.direction['Fraction to Gulp'],
                                agent_id_to_engine=True,
                                resource_map_output=add_from_env)
            agent.set_organ(actuator)

            actuator = Actuator('Push Offspring Onto World',
                                self._cmp_offspring_onto_world,
                                agent.direction['Offspring'],
                                agent_id_to_engine=True)
            agent.set_organ(actuator)

        #
        # Mutation
        map_midpoint_share = EssenceMap('mutate_1', 'wiener', 'midpoint_share',
                                        ('range_step', ))
        map_midpoint_gulp = EssenceMap('mutate_2', 'wiener', 'midpoint_gulp',
                                       ('range_step', ))
        map_midpoint_tox = EssenceMap('mutate_3', 'wiener', 'midpoint_tox',
                                      ('range_step', ))
        map_max_share = EssenceMap('mutate_1b', 'wiener_bounded', 'max_share',
                                   ('range_step', 'lower', 'upper'))
        map_max_gulp = EssenceMap('mutate_2b', 'wiener_bounded', 'max_gulp',
                                  ('range_step', 'lower', 'upper'))
        map_max_tox = EssenceMap('mutate_3b', 'wiener_bounded', 'max_tox',
                                 ('range_step', 'lower', 'upper'))

        list_mid = []
        list_max = []
        if 'share' in mutate_essence:
            list_mid.append(map_midpoint_share)
            list_max.append(map_max_share)
        if 'gulp' in mutate_essence:
            list_mid.append(map_midpoint_gulp)
            list_max.append(map_max_gulp)
        if 'tox' in mutate_essence:
            list_mid.append(map_midpoint_tox)
            list_max.append(map_max_tox)

        if len(list_mid) > 0:
            mapper_midpoint = MapCollection(list_mid)
            mapper_max = MapCollection(list_max)
            mutate_midpoint = MultiMutation('Perturb Essence 1',
                                            self._midpoint_move,
                                            mapper_midpoint,
                                            mutation_prob=mutate_prob)
            mutate_max = MultiMutation('Perturb Essence 2',
                                       self._max_move,
                                       mapper_max,
                                       mutation_prob=mutate_prob)
            self.set_laws(mutate_midpoint, mutate_max)

        #
        # Random increase in internal resources
        self.resource_jump_magnitude = resource_jump_magnitude
        self.resource_jump_prob = resource_jump_prob
        a_jump = ResourceMap('Jump Increase A', 'delta', 'info_a', ('add', ))
        b_jump = ResourceMap('Jump Increase B', 'delta', 'info_b', ('add', ))
        c_jump = ResourceMap('Jump Increase C', 'delta', 'info_c', ('add', ))
        jump_resources = MapCollection([a_jump, b_jump, c_jump])
        resource_jump = Compulsion('Random Jump of Resources',
                                   self._cmp_resource_jump, jump_resources)
        self.set_law(resource_jump)