Пример #1
0
from animal import Animal
from genes.compromise_gene import CompromiseGene

Animal.init_genes_class([CompromiseGene])


def action_callback(animal, animals):
    """ What happen in the environnement """
    assert isinstance(animal, Animal)
    teammate = random.randint(0, len(animals) - 1)
    teammate_compromise = animals[teammate].genes["compromise gene"].value

    choice_input = {"teammate_compromise": teammate_compromise}

    choice_output = animal.choose(choice_input)

    if choice_output["accept_cooperation"]:
        rate = choice_output["rate"]
        animal.reproductive_capacity += 2 * rate
        animals[teammate].reproductive_capacity += 5 * (1 - rate)
    else:
        animal.reproductive_capacity += -10
        animals[teammate].reproductive_capacity += -10
    return True


generation_manager = GenerationManager(500)
generation_manager.action_callback = action_callback

generation_manager.run(10)
Пример #2
0
from generation_manager import GenerationManager
from animal import Animal
from genes.empathetic_gene import EmpatheticGene
from genes.punisher_gene import PunisherGene

PunisherGene.type_of_punishment = "no empathy"
Animal.init_genes_class([EmpatheticGene, PunisherGene])

def action_callback(animal, animals):
    """ What happen in the environnement """
    assert isinstance(animal, Animal)
    teammate = random.randint(0, len(animals)-1)

    gain = random.uniform(-15, 5)
    teammate_gain = random.uniform(-15, 5)
    teammate_empathy = animals[teammate].genes["empathetic gene"].value
    choice_input = {"gain":gain,
                    "teammate_gain":teammate_gain,
                    "teammate_empathy":teammate_empathy}

    choice_output = animal.choose(choice_input)
    if choice_output["accept_cooperation"]:
        animal.reproductive_capacity += gain
        animals[teammate].reproductive_capacity += teammate_gain
    return True

generation_manager = GenerationManager(200)
generation_manager.action_callback = action_callback

generation_manager.run(20)
Пример #3
0
#!/bin/python
"""
Test how sex reproduction evolve to 50% male children and 50% female children
Whatever the starting configuration, if there is no extinction,
the equilibrium look like a gaussian curbe:
[0, 0, 0, 0, 0, 8, 55, 148, 298, 433, 448, 338, 197, 59, 16, 0, 0, 0, 0, 0, ]
"""

from generation_manager import GenerationManager
from animal import Animal
from genes.rate_of_male_gene import RateOfMaleGene
from genes.sd_gene import SDGene
from genes.anti_sd_gene import Anti_SDGene

Animal.init_genes_class([RateOfMaleGene])  #, SDGene, Anti_SDGene])

generation_manager = GenerationManager(2000)

generation_manager.run()