def test_calc_relat(self):
        relat_sim = HamadryasSim()
        relat_pop = HamaPopulation()
        group = HamadryasGroup(1)
        relat_pop.groupsdict[1] = group
        self.setup(relat_sim, relat_pop, group)

        output = relatedness.main(relat_pop, relat_sim.parent_dict)

        self.assertTrue(output)
    def test_half_sib(self):
        relat_sim = HamadryasSim()
        relat_pop = HamaPopulation()
        group = HamadryasGroup(1)
        relat_pop.groupsdict[1] = group
        self.setup(relat_sim, relat_pop, group)

        R = relatedness.calc_relatedness(
            [relat_pop.dict[4], relat_pop.dict[5]], relat_sim.parent_dict)
        self.assertEqual(R, 0.25)
    def test_full_grandniece(self):
        relat_sim = HamadryasSim()
        relat_pop = HamaPopulation()
        group = HamadryasGroup(1)
        relat_pop.groupsdict[1] = group
        self.setup(relat_sim, relat_pop, group)

        R = relatedness.calc_relatedness(
            [relat_pop.dict[9], relat_pop.dict[15]], relat_sim.parent_dict)
        self.assertEqual(R, 0.125)
    def setup(self, OMU1clan, OMU1band, OMU2clan, OMU2band):
        recog_sim = HamadryasSim()
        recog_pop = HamaPopulation()

        if OMU1band == OMU2band:
            group1 = HamadryasGroup(OMU1band)
            recog_pop.groupsdict[OMU1band] = group1
            group2 = group1
        else:
            group1 = HamadryasGroup(OMU1band)
            recog_pop.groupsdict[OMU1band] = group1
            group2 = HamadryasGroup(OMU2band)
            recog_pop.groupsdict[OMU2band] = group2

        HamadryasSeed.addagenttoseed(OMU1band, group1, recog_pop, 'm', None,
                                     None, 10.0, recog_sim)
        recog_pop.dict[1].clanID = OMU1clan
        group1.leadermales.add(recog_pop.dict[1].index)
        HamadryasSeed.addagenttoseed(OMU1band, group1, recog_pop, 'f', 7, 8,
                                     10.0, recog_sim)
        HamadryasDispersal.add_female_to_omu(recog_pop.dict[1],
                                             recog_pop.dict[2], recog_pop,
                                             recog_sim)

        HamadryasSeed.addagenttoseed(OMU2band, group2, recog_pop, 'm', None,
                                     None, 10.0, recog_sim)
        recog_pop.dict[3].clanID = OMU2clan
        group2.leadermales.add(recog_pop.dict[1].index)
        HamadryasSeed.addagenttoseed(OMU2band, group2, recog_pop, 'f', None,
                                     None, 10.0, recog_sim)
        HamadryasDispersal.add_female_to_omu(recog_pop.dict[3],
                                             recog_pop.dict[4], recog_pop,
                                             recog_sim)

        HamadryasSeed.addagenttoseed(1, recog_pop.groupsdict[1], recog_pop,
                                     'f', 7, 8, 10.0, recog_sim)
        recog_pop.dict[5].clanID = 1

        return recog_pop
    def setup_rhp(self):
        hama_rhp_pop = HamaPopulation()
        hama_rhp_group = HamadryasGroup(1)
        hama_rhp_pop.groupsdict[1] = hama_rhp_group
        hamadryas_sim = HamadryasSim()

        HamadryasSeed.addagenttoseed(1, hama_rhp_group, hama_rhp_pop, 'm',
                                     None, None, 10, hamadryas_sim)
        HamadryasSeed.addagenttoseed(1, hama_rhp_group, hama_rhp_pop, 'm',
                                     None, None, 10, hamadryas_sim)
        HamadryasSeed.addagenttoseed(1, hama_rhp_group, hama_rhp_pop, 'm',
                                     None, None, 13.5, hamadryas_sim)
        HamadryasSeed.addagenttoseed(1, hama_rhp_group, hama_rhp_pop, 'm',
                                     None, None, 13.5, hamadryas_sim)

        hama_rhp_pop.dict[1].rhp = '1'
        hama_rhp_pop.dict[2].rhp = '2'
        hama_rhp_pop.dict[3].rhp = '3'
        hama_rhp_pop.dict[4].rhp = '4'

        return hama_rhp_pop
Exemple #6
0
    def makeseed(groupindex, population, sim):
        group = HamadryasGroup(groupindex)

        #  make adult males
        for i in range(0, 13):
            HamadryasSeed.addagenttoseed(
                groupindex, group, population, 'm', None, None,
                (float(random.randrange(12.0, 40.0)) / 2.0), sim)

        # make some leaders, fols, and sols, and give clans and OMUs
        for j in range(0, len(group.agents)):
            male = population.dict[group.agents[j]]
            male.dispersed = True
            if j < 3:
                male.clanID = 1 + groupindex
                if j == 0 or j == 2:
                    male.maleState = MaleState.lea
                    male.OMUID = male.index
                    group.leadermales.add(male.index)
                else:
                    male.maleState = MaleState.fol
                    male.OMUID = group.agents[j - 1]
                    population.dict[group.agents[j - 1]].malefols.append(
                        male.index)

            elif j < 8:
                male.clanID = 2 + groupindex

                if j == 3 or j == 5 or j == 6:
                    male.maleState = MaleState.lea
                    male.OMUID = male.index
                    group.leadermales.add(male.index)

                elif j == 4:
                    male.maleState = MaleState.fol
                    male.OMUID = group.agents[j - 1]
                    population.dict[group.agents[j - 1]].malefols.append(
                        male.index)

                else:
                    male.maleState = MaleState.sol
                    male.OMUID = None
            else:
                male.clanID = 3 + groupindex
                if j < 11:
                    male.maleState = MaleState.lea
                    male.OMUID = male.index
                    group.leadermales.add(male.index)

                elif j == 11:
                    male.maleState = MaleState.fol
                    male.OMUID = group.agents[j - 1]
                    population.dict[group.agents[j - 1]].malefols.append(
                        male.index)

                else:
                    male.maleState = MaleState.sol
                    male.OMUID = None

        for k in range(0, 23):
            HamadryasSeed.addagenttoseed(
                groupindex, group, population, 'f', None, None,
                (float(random.randrange(10.0, 40.0)) / 2.0), sim)

        for l in range(0, 15):
            HamadryasSeed.addagenttoseed(
                groupindex, group, population, 'f', None, None,
                (float(random.randrange(0.0, 10.0)) / 2.0), sim)

        for m in range(0, 14):
            HamadryasSeed.addagenttoseed(
                groupindex, group, population, 'm', None, None,
                (float(random.randrange(0.0, 11.0)) / 2.0), sim)

        assert len(group.leadermales) == 8

        population.groupsdict[groupindex] = group

        return population