当前位置: 首页>>代码示例>>Python>>正文


Python Animal.init_genes_class方法代码示例

本文整理汇总了Python中animal.Animal.init_genes_class方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.init_genes_class方法的具体用法?Python Animal.init_genes_class怎么用?Python Animal.init_genes_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在animal.Animal的用法示例。


在下文中一共展示了Animal.init_genes_class方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: action_callback

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import init_genes_class [as 别名]
#!/bin/python

"""
Test some hypothesis about empathy
"""
import random

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
开发者ID:dionisos2,项目名称:evolve,代码行数:33,代码来源:pro_social.py

示例2: action_callback

# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import init_genes_class [as 别名]
#!/bin/python

"""
Test some hypothesis about fairness
"""
import random

from generation_manager import GenerationManager
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
开发者ID:dionisos2,项目名称:evolve,代码行数:33,代码来源:fairness.py


注:本文中的animal.Animal.init_genes_class方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。