コード例 #1
0
ファイル: test_island.py プロジェクト: larly77/biosim-project
    def test_migration(self):
        """
        Test for migration

        Returns
        -------

        """
        i1 = Island(ISLE_MAP2)
        Herbivore.set_parameters({'mu': 1.0})
        Carnivore.set_parameters({'mu': 1.0})

        coordinate = (2, 3)
        i1.add_animal_island(coordinate, INI_HERB[0]['pop'])
        i1.add_animal_island(coordinate, INI_CARN[0]['pop'])

        for herbivore in i1.cells[2, 3].herbivores:
            herbivore.fitness = 1
        for carnivore in i1.cells[2, 3].carnivores:
            carnivore.fitness = 1

        i1.migration()

        # can only move left or down
        len_left_herb = len(i1.cells[2, 2].herbivores)
        len_down_herb = len(i1.cells[3, 3].herbivores)
        len_left_carn = len(i1.cells[2, 2].carnivores)
        len_down_carn = len(i1.cells[3, 3].carnivores)

        assert (len_down_herb + len_left_herb,
                len_left_carn + len_down_carn) == (20, 20)
コード例 #2
0
ファイル: test_island.py プロジェクト: larly77/biosim-project
    def set_default_animal(self):
        """
        Method for resetting parameters for herbivores and carnivores.

        Returns
        -------

        """
        Herbivore.set_parameters(DEFAULT_HERBIVORE_PARAMETERS)
        Carnivore.set_parameters(DEFAULT_CARNIVORE_PARAMETERS)
コード例 #3
0
    def test_set_parameters(self):
        """
        Test for method set_parameters.

        Returns
        -------

        """
        h1 = Herbivore(age=5, weight=20)
        Herbivore.set_parameters({'xi': 1.3, 'w_half': 20})

        assert h1.parameters['xi'] == 1.3
        assert h1.parameters['w_half'] == 20
コード例 #4
0
ファイル: test_simulation.py プロジェクト: Wisetorsk/BioSim
    def test_heatmap(self):
        """
        Tests that heatmap makes array with correct number of herbivores.
        :return:
        """
        Carnivore.set_parameters({"gamma": 0, "omega": 0, "mu": 0})
        Herbivore.set_parameters({"gamma": 0, "omega": 0, "mu": 0})
        initial_herbivores = 80
        initial_carnivores = 20
        herbivores, carnivores = self.sim.heatmap(self.sim.island.one_year())
        nt.assert_equal(initial_carnivores, np.sum(carnivores))
        nt.assert_equal(initial_herbivores, np.sum(herbivores))

        nt.assert_equal(initial_herbivores, herbivores[2][2])
        nt.assert_equal(initial_carnivores, carnivores[4][2])
コード例 #5
0
    def set_animal_parameters(self, species, params):
        """
        Sets parameter for animals
        Parameters
        ----------
        species: object
        params: dict

        Returns
        -------

        """
        if species == 'Herbivore':
            Herbivore.set_parameters(params)
        elif species == 'Carnviore':
            Carnivore.set_parameters(params)
コード例 #6
0
 def test_animals_must_migrate(self):
     """
     Tests that no animals are left in cell after migration
     """
     Herbivore.set_parameters({"mu": 1})
     Carnivore.set_parameters({"mu": 1})
     island = Island(self.geogr_simple)
     island.build_map()
     island.island[1][1].herbivores = [Herbivore() for _ in range(20)]
     island.island[1][1].carnivores = [Carnivore() for _ in range(20)]
     for herb in island.island[1][1].herbivores:
         herb.fitness = 1
     for carn in island.island[1][1].carnivores:
         carn.fitness = 1
     island.migration()
     nt.assert_equal(island.island[1][1].herbivores, [])
     nt.assert_equal(island.island[1][1].carnivores, [])
コード例 #7
0
 def test_procreation(self):
     """
     Test that the number of animals increase
     :return:
     """
     Herbivore.set_parameters({"gamma": 1})
     Carnivore.set_parameters({"gamma": 1})
     original = 60
     new = 0
     self.island.procreation()
     for row in self.island.island:
         for cell in row:
             new += \
                 cell.number_of_individuals()["herbivores"] + \
                 cell.number_of_individuals()["carnivores"]
     nt.assert_greater(new, original)
     nt.assert_less_equal(new, original * 2)
コード例 #8
0
 def test_one_year(self):
     """
     tests that attributes changes after a year
     """
     island = Island(self.geogr_simple)
     island.build_map()
     Herbivore.set_parameters({"mu": 0})
     Carnivore.set_parameters({"mu": 0})
     island.island[1][1].herbivores = [Herbivore(40, 5)]
     island.island[1][1].carnivores = [Carnivore(20, 5)]
     for carnivore in island.island[1][1].carnivores:
         carnivore.fitness = 1
     for herbivore in island.island[1][1].herbivores:
         herbivore.fitness = 1
     island.one_year()
     nt.assert_equal(island.island[1][1].herbivores[0].age, 6)
     nt.assert_equal(island.island[1][1].carnivores[0].age, 6)
     nt.assert_not_equal(island.island[1][1].herbivores[0].weight, 40)
     nt.assert_not_equal(island.island[1][1].carnivores[0].weight, 20)
コード例 #9
0
ファイル: test_simulation.py プロジェクト: Wisetorsk/BioSim
    def test_standard_arguments():
        """
        Tests that simulation works without any given arguments.
        """
        initial_herbivores = 150
        initial_carnivores = 40
        sim_ = BioSim()
        Carnivore.set_parameters({"gamma": 0, "omega": 0, "mu": 0})
        Herbivore.set_parameters({"gamma": 0, "omega": 0, "mu": 1})

        for row in sim_.island.island:
            for cell in row:
                for herb in cell.herbivores:
                    herb.fitness = 1
        sim_.island.migration()
        herbivores, carnivores = sim_.heatmap(sim_.island.one_year())
        nt.assert_equal(initial_carnivores, np.sum(carnivores))
        nt.assert_equal(initial_herbivores, np.sum(herbivores))

        nt.assert_equal(initial_carnivores, carnivores[2][2])
コード例 #10
0
def reset_parameters():
    herbivore_parameters_right = {
        'w_birth': 8.0,
        'sigma_birth': 1.5,
        'beta': 0.9,
        'eta': 0.05,
        'a_half': 40.0,
        'phi_age': 0.2,
        'w_half': 10.0,
        'phi_weight': 0.1,
        'mu': 0.25,
        'lambda_': 1.0,
        'gamma': 0.2,
        'zeta': 3.5,
        'xi': 1.2,
        'omega': 0.4,
        'F': 10.0
    }
    carnivore_parameters_right = {
        'w_birth': 6.0,
        'sigma_birth': 1.0,
        'beta': 0.75,
        'eta': 0.125,
        'a_half': 60.0,
        'phi_age': 0.4,
        'w_half': 4.0,
        'phi_weight': 0.4,
        'mu': 0.4,
        'lambda_': 1.0,
        'gamma': 0.8,
        'zeta': 3.5,
        'xi': 1.1,
        'omega': 0.9,
        'F': 50.0,
        'DeltaPhiMax': 10.0
    }
    Carnivore.set_parameters(**carnivore_parameters_right)
    Herbivore.set_parameters(**herbivore_parameters_right)
コード例 #11
0
ファイル: test_island.py プロジェクト: larly77/biosim-project
    def test_cell_move_herbivore_and_carnivore(self):
        """
        Test for moving herbivore and carnivore

        Returns
        -------

        """
        i1 = Island(ISLE_MAP2)
        Herbivore.set_parameters({'mu': 1.0})
        Carnivore.set_parameters({'mu': 1.0})

        coordinate = (2, 3)
        i1.add_animal_island(coordinate, INI_HERB[0]['pop'])
        i1.add_animal_island(coordinate, INI_CARN[0]['pop'])
        for herbivore in i1.cells[2, 3].herbivores:
            herbivore.fitness = 1
        for carnivore in i1.cells[2, 3].carnivores:
            carnivore.fitness = 1

        assert len(i1.cells[2, 3].herbivores) == 20
        assert len(i1.cells[2, 3].carnivores) == 20
        i1.cell_move_herbivores(coordinate)
        i1.cell_move_carnivores(coordinate)

        assert len(i1.cells[2, 3].herbivores) == 0
        assert len(i1.cells[2, 3].carnivores) == 0

        # can only move left or down
        len_left_herb = len(i1.cells[2, 2].herbivores_new)
        len_down_herb = len(i1.cells[3, 3].herbivores_new)

        len_left_carn = len(i1.cells[2, 2].carnivores_new)
        len_down_carn = len(i1.cells[3, 3].carnivores_new)

        assert (len_down_herb + len_left_herb,
                len_left_carn + len_down_carn) == (20, 20)
コード例 #12
0
 def test_death(self):
     """
     Runs multiple times to minimise chance of failure due to all animals
      surviving.
     :return:
     """
     original = 40 * 5
     new = 0
     test = Island(self.geogr_simple)
     test.build_map()
     Herbivore.set_parameters({"omega": 1})
     Carnivore.set_parameters({"omega": 1})
     test.island[1][1].herbivores = [Herbivore() for _ in range(10)]
     test.island[1][2].herbivores = [Herbivore() for _ in range(10)]
     test.island[1][1].carnivores = [Carnivore() for _ in range(10)]
     test.island[1][2].carnivores = [Carnivore() for _ in range(10)]
     test.death()
     for _ in range(5):
         for row in test.island:
             for cell in row:
                 new += \
                     cell.number_of_individuals()["herbivores"] + \
                     cell.number_of_individuals()["carnivores"]
     nt.assert_less(new, original)
コード例 #13
0
        'pop': [{
            'species': 'Herbivore',
            'age': 5,
            'weight': 20
        } for _ in range(150)]
    }]
    ini_carns = [{
        'loc': (10, 10),
        'pop': [{
            'species': 'Carnivore',
            'age': 5,
            'weight': 20
        } for _ in range(40)]
    }]

    Herbivore.set_parameters({'zeta': 3.2, 'xi': 1.8})
    Carnivore.set_parameters({
        'a_half': 70,
        'phi_age': 0.5,
        'omega': 0.3,
        'F': 65,
        'DeltaPhiMax': 9.
    })
    landscape.Jungle.set_parameters({'f_max': 700})

    sim = biosim.simulation.\
        BioSim(island_map=geogr, ini_pop=ini_herbs, seed=123456,
               img_dir=biosim.simulation.DEFAULT_GRAPHICS_DIR)

    sim.simulate(num_steps=100, vis_steps=1, img_steps=1)
    sim.add_population(population=ini_carns)