Ejemplo n.º 1
0
    def test_add_agent(self):
        locator = TorusLocator(2, 5)
        agent = DummyAgent()

        locator.add_agent(agent, (0, 1))

        self.assertIsNotNone(locator.get_allowed_moves(agent))
Ejemplo n.º 2
0
    def test_neighbourhood_radius(self):
        locator = TorusLocator(5, 6, 2)
        agent = DummyAgent()
        locator.add_agent(agent, (0, 0))

        self.assertEquals(locator.get_allowed_moves(agent),
                          {(0, 1), (0, 5), (1, 0), (1, 1), (1, 5), (4, 0), (4, 1), (4, 5), (0, 2), (1, 2), (2, 2),
                           (2, 1), (2, 0), (3, 0), (3, 1), (3, 2), (4, 2), (0, 4), (1, 4), (2, 4), (2, 5), (4, 4),
                           (3, 4), (3, 5)})
Ejemplo n.º 3
0
    def test_neighbourhood(self):
        locator = TorusLocator(5, 6)
        a1 = DummyAgent()
        a2 = DummyAgent()
        a3 = DummyAgent()
        locator.add_agent(a1, (0, 0))
        locator.add_agent(a2, (0, 1))
        locator.add_agent(a3, (0, 3))

        self.assertEqual(a2, locator.get_neighbour(a1))
        self.assertFalse(a3 == locator.get_neighbour(a1))
        self.assertIsNone(locator.get_neighbour(a3))
Ejemplo n.º 4
0
    def test_remove_agent(self):
        locator = TorusLocator(5, 6)
        agent = DummyAgent()
        locator.add_agent(agent, (0, 0))
        self.assertNotIn((0, 0), locator.get_empty_slots())

        locator.remove_agent(agent)

        self.assertIn((0, 0), locator.get_empty_slots())
Ejemplo n.º 5
0
    def test_allowed_moves(self):
        locator = TorusLocator(5, 6)
        agent = DummyAgent()
        locator.add_agent(agent, (0, 0))
        locator.add_agent(DummyAgent(), (1, 1))

        self.assertEquals(locator.get_allowed_moves(agent),
                          {(0, 1), (0, 5), (1, 0), (1, 5), (4, 0), (4, 1), (4, 5)})
Ejemplo n.º 6
0
    def test_remove_dead_agents(self):
        locator = TorusLocator(5, 6)
        a1 = DummyAgent()
        a2 = DummyAgent()
        locator.add_agent(a1, (0, 0))
        locator.add_agent(a2, (0, 1))

        self.assertEqual(a2, locator.get_neighbour(a1))
        a2.dead = True

        self.assertIsNone(locator.get_neighbour(a1))
Ejemplo n.º 7
0

logger = logging.getLogger(__name__)

agents_count = int(os.environ['AGENTS'])
logger.debug("EMAS, %s agents", agents_count)
agents = unnamed_agents(agents_count, AggregateAgent)

stop_condition = lambda: StepLimitStopCondition(1000)

aggregated_agents = lambda: float_emas_initializer(40, energy=100, size=50, lowerbound=-10, upperbound=10)

emas = EmasService

minimal_energy = lambda: 0
reproduction_minimum = lambda: 90
migration_minimum = lambda: 120
newborn_energy = lambda: 100
transferred_energy = lambda: 40

evaluation = FloatRastriginEvaluation
crossover = SinglePointCrossover
mutation = NormalMutation

address_provider = address.SequenceAddressProvider

migration = ParentMigration

locator = lambda: TorusLocator(10, 10)

stats = lambda: StepStatistics('fitness_%s_pyage.txt' % __name__)
Ejemplo n.º 8
0
    def test_get_empty_slots(self):
        locator = TorusLocator(2, 5)
        self.assertEqual(locator.get_empty_slots(), [(x, y) for x in range(2) for y in range(5)])

        locator.add_agent(DummyAgent(), (0, 1))
        self.assertFalse((0, 1) in locator.get_empty_slots())
Ejemplo n.º 9
0
 def test_should_not_add_when_full(self):
     locator = TorusLocator(1, 1)
     locator.add_agent(DummyAgent())
     locator.add_agent(DummyAgent())
Ejemplo n.º 10
0
 def test_should_not_add_to_occupied_cell(self):
     locator = TorusLocator(2, 5)
     locator.add_agent(DummyAgent(), (0, 1))
     locator.add_agent(DummyAgent(), (0, 1))
Ejemplo n.º 11
0
    def test_add_agent_random_position(self):
        locator = TorusLocator(2, 5)
        agent = DummyAgent()

        self.assertIsNotNone(locator.get_allowed_moves(agent))
Ejemplo n.º 12
0
    def test_add_all(self):
        locator = TorusLocator(2, 5)

        locator.add_all([DummyAgent(), DummyAgent()])

        self.assertEqual(len(locator.get_empty_slots()), 8)
Ejemplo n.º 13
0
 def test_remove_dead(self):
     locator = TorusLocator(1, 1)
     agent = DummyAgent()
     locator.add_agent(agent, (0, 0))
     agent.dead = True
     locator.add_agent(DummyAgent(), (0, 0))
Ejemplo n.º 14
0
 def test_add_too_many_agents(self):
     locator = TorusLocator(5, 5)
     self.assertEqual(25, locator.add_all([DummyAgent() for _ in range(30)]))