def test_infanticide(self):
        infant_died = 0
        sires = []
        for i in range(0, 1000):
            inf_sim = HamadryasSim()
            inf_pop = HamaPopulation()

            inf_pop = HamadryasSeed.makeseed(0, inf_pop, inf_sim)

            HamadryasSeed.addagenttoseed(0, inf_pop.groupsdict[0], inf_pop,
                                         'f', None, None, 10, inf_sim)
            mom = inf_pop.dict[66]
            mom.sire_of_fetus = inf_pop.dict[1]
            inf_sim.birthagent(mom, inf_pop, 50)
            infant = mom.offspring[0]
            sires.append(inf_pop.dict[infant].parents[1])

            inf_sim.male_eligibility(inf_pop)
            HamadryasDispersal.opportun_takeover(mom, inf_pop, inf_sim)

            if infant not in inf_pop.all:
                infant_died += 1

        print str(infant_died) + " infants died."
        self.assertAlmostEqual(500, infant_died, delta=50)
Esempio n. 2
0
    def run_simulation(self):
        population = HamaPopulation()

        for groupindex in range(0, 10):
            population = HamadryasSeed.makeseed(groupindex, population, self)

        for halfyear in range(0, self.duration):
            population.halfyear = halfyear
            for group in population.groupsdict.values():
                group.leadermales = set()

            self.mortality_check(population, halfyear)
            self.male_eligibility(population)
            self.get_young_natal_females(population)

            if population.avail_females:
                for female in population.avail_females:
                    female = population.dict[female]
                    HamadryasDispersal.opportun_takeover(
                        female, population, self)
                population.avail_females = []
            males = [
                male for male in population.dict.values() if male.sex == 'm'
            ]
            for male in males:
                self.male_choices(male, population)
            if population.avail_females:
                for female in population.avail_females:
                    female = population.dict[female]
                    HamadryasDispersal.opportun_takeover(
                        female, population, self)
                population.avail_females = []

            self.birth_check(population, halfyear)
            self.promotions(population)

            #  print "Population: " + str(len(population.dict.keys()))
            # print "Hamadryas half-year " + str(halfyear) + " done!"
            if len(population.all) == 0:
                break

        ratios = self.get_sex_age_ratios(population)
        self.siring_success = collections.Counter(self.siring_success.values())

        return {
            "sires": self.siring_success,
            "pop size": len(population.all),
            "adult sex ratio": ratios["adult sex ratio"],
            "adult to nonadult ratio": ratios["adult to nonadult ratio"]
        }
    def test_disp_between_bands(self):
        change_OMU = 0
        change_clan = 0
        change_band = 0

        for i in range(0, 100):
            band_disp_sim = HamadryasSim()
            band_disp_pop = HamaPopulation()

            for groupindex in range(0, 10):
                band_disp_pop = HamadryasSeed.makeseed(groupindex,
                                                       band_disp_pop,
                                                       band_disp_sim)

            female_to_disp = band_disp_pop.dict[14]
            start_OMU = female_to_disp.OMUID
            start_clan = female_to_disp.clanID
            start_band = female_to_disp.bandID

            band_disp_sim.kill_agent(band_disp_pop.dict[female_to_disp.OMUID],
                                     band_disp_pop,
                                     band_disp_pop.groupsdict[0], 50)
            band_disp_sim.male_eligibility(band_disp_pop)
            self.assertTrue(band_disp_pop.eligible_males)

            HamadryasDispersal.opportun_takeover(female_to_disp, band_disp_pop,
                                                 band_disp_sim)

            if female_to_disp.OMUID != start_OMU:
                change_OMU += 1
            if female_to_disp.clanID != start_clan and female_to_disp.bandID == start_band:
                change_clan += 1
            if female_to_disp.bandID != start_band:
                change_band += 1

        print "Moved between OMUs: " + str(change_OMU)
        print "Stayed in natal clan: " + str(100 - change_band - change_clan)
        print "Moved between clans within a band: " + str(change_clan)
        print "Moved between bands: " + str(change_band)

        self.assertEqual(100, change_OMU)
        self.assertAlmostEqual(15, change_clan, delta=0)
        self.assertAlmostEqual(60, change_band, delta=0)
    def test_opp_take_outcome_simple(self):
        taken_over_by_1 = 0
        taken_over_by_2 = 0

        for i in range(1, 1000):
            sim = HamadryasSim()
            sim.recog = True
            pop = self.setup(1, 1, 1, 1)

            sim.male_eligibility(pop)
            HamadryasDispersal.opportun_takeover(pop.dict[5], pop, sim)

            if pop.dict[5].OMUID == 1:
                taken_over_by_1 += 1
            elif pop.dict[5].OMUID == 3:
                taken_over_by_2 += 1
            else:
                break

        self.assertAlmostEqual(666, taken_over_by_1, delta=66)
    def test_opp_take_outcome_5(self):
        #  OMU with relative is outside band, other OMU is in clan
        taken_over_by_1 = 0
        taken_over_by_2 = 0

        for i in range(1, 1000):
            sim = HamadryasSim()
            sim.recog = True
            pop = self.setup(OMU1clan=2, OMU1band=2, OMU2clan=1, OMU2band=1)
            sim.male_eligibility(pop)
            HamadryasDispersal.opportun_takeover(pop.dict[5], pop, sim)

            if pop.dict[5].OMUID == 1:
                taken_over_by_1 += 1
            elif pop.dict[5].OMUID == 3:
                taken_over_by_2 += 1
            else:
                break

        self.assertAlmostEqual(110, taken_over_by_1, delta=100)
    def test_opp_take_outcome_strength(self):
        #  adjust the strength to make sure that works
        taken_over_by_1 = 0
        taken_over_by_2 = 0

        for i in range(1, 1000):
            sim = HamadryasSim()
            sim.recog = True
            sim.attraction_strength = 10
            pop = self.setup(1, 1, 1, 1)

            sim.male_eligibility(pop)
            HamadryasDispersal.opportun_takeover(pop.dict[5], pop, sim)

            if pop.dict[5].OMUID == 1:
                taken_over_by_1 += 1
            elif pop.dict[5].OMUID == 3:
                taken_over_by_2 += 1
            else:
                break

        self.assertAlmostEqual(910, taken_over_by_1, delta=91)
    def test_codispersal(self):
        codi_sim = HamadryasSim()
        codi_pop = HamaPopulation()
        codi_sim.codispersal = True

        for i in range(0, 10):
            codi_pop = HamadryasSeed.makeseed(i, codi_pop, codi_sim)

        HamadryasSeed.addagenttoseed(0, codi_pop.groupsdict[0], codi_pop, 'f',
                                     100, None, 10, codi_sim)
        HamadryasSeed.addagenttoseed(0, codi_pop.groupsdict[0], codi_pop, 'f',
                                     100, None, 10, codi_sim)
        sister1 = codi_pop.dict[codi_pop.all[-1]]
        sister2 = codi_pop.dict[codi_pop.all[-2]]

        HamadryasDispersal.add_female_to_omu(codi_pop.dict[sister1.OMUID],
                                             sister2, codi_pop, codi_sim)

        codi_sim.kill_agent(codi_pop.dict[sister1.OMUID], codi_pop,
                            codi_pop.groupsdict[0], 0)
        codi_sim.male_eligibility(codi_pop)
        HamadryasDispersal.opportun_takeover(sister1, codi_pop, codi_sim)

        self.assertTrue(1 == 1)