示例#1
0
def anHungerToStarve():
    """ Description: Runs multiple simulations. 
                     Hunger threshold tested from 0.6 through 0.9.
                     Records effect on animal deaths by starvation.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.HUNGRY_PERCENT  # grab value for restoring value

    hunger = [0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9]
    output = []

    for k in range(len(hunger)):
        const.HUNGRY_PERCENT = hunger[k]

        numStarve = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            numStarve.append(eco.animalsDeath[0])

        output.append(sum(numStarve) / len(numStarve))

    plt.plot(hunger, output)
    plt.xlabel("Animal Hungry Threshold Percent")
    plt.ylabel("Animals Starved")
    plt.title("Hungry Threashold v. Animal Starved")
    plt.show()

    const.HUNGRY_PERCENT = hold  # restore value
示例#2
0
def anPlantWaterToNumDrinks():
    """ Description: Runs multiple simulations. 
                     Amount of water a plant provides is tested from 1 through 5.
                     Records effect on amount of times animals drink.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.FLORA_WATER_PERCENT  # grab value for restoring value

    floraWater = [0.0, 0.025, 0.05, 0.075, 0.1]
    output = []

    for k in range(len(floraWater)):
        const.FLORA_WATER_PERCENT = floraWater[k]

        drinks = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            drinks.append(eco.timesDrunk)

        output.append(sum(drinks) / len(drinks))

    plt.plot(floraWater, output)
    plt.xlabel("Plant Water Consumed Percent")
    plt.ylabel("Times Fauna Drunk")
    plt.title("Plant Water Percent v. Times Drunk")
    plt.show()

    const.FLORA_WATER_PERCENT = hold  # restore value
示例#3
0
def anThirstToDessicate():
    """ Description: Runs multiple simulations. 
                     Thirst threshold tested from 0.4 through 0.7.
                     Records effect on animal deaths by dessication.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.THIRSTY_PERCENT  # grab value for restoring value

    thirst = [0.4, 0.45, 0.5, 0.55, 0.6, 0.65, 0.7]
    output = []

    for k in range(len(thirst)):
        const.THIRSTY_PERCENT = thirst[k]

        numDessicate = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            numDessicate.append(eco.animalsDeath[1])

        output.append(sum(numDessicate) / len(numDessicate))

    plt.plot(thirst, output)
    plt.xlabel("Animal Thirst Threashold Percent")
    plt.ylabel("Animals Dessicated")
    plt.title("Thirst Threashold v. Animal Dessicated")
    plt.show()

    const.THIRSTY_PERCENT = hold  # restore value
示例#4
0
def anFoxStepToRab():
    """ Description: Runs multiple simulations. 
                     Amount of extra steps given to foxes tested from 1 through 5.
                     Records effect on animal consumption.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.EXTRA_FOX_STEPS  # grab value for restoring value

    foxsteps = [1, 2, 3, 4, 5]
    output = []

    for k in range(len(foxsteps)):
        const.EXTRA_FOX_STEPS = foxsteps[k]
        eatenRabbits = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            eatenRabbits.append(eco.animalsDeath[4])

        output.append(sum(eatenRabbits) / len(eatenRabbits))

    plt.plot(foxsteps, output)
    plt.xlabel("Number of Extra Fox Moves per Hour")
    plt.ylabel("Number Animals Eaten")
    plt.title("Extra Fox Movement v. Animals Consumption")
    plt.show()

    const.EXTRA_FOX_STEPS = hold
示例#5
0
def anEnergyCostToStarve():
    """ Description: Runs multiple simulations. 
                     Amount of energy consumed per move command tested from
                     2 through 10.
                     Records effect on animal deaths by starvation.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.ENERGY_MOVE_FACTOR  # grab value for restoring value

    energyMove = [2, 4, 6, 8, 10]
    output = []

    for k in range(len(energyMove)):
        const.ENERGY_MOVE_FACTOR = energyMove[k]

        numStarve = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            numStarve.append(eco.animalsDeath[0])

        output.append(sum(numStarve) / len(numStarve))

    plt.plot(energyMove, output)
    plt.xlabel("Energy Move Cost Factor")
    plt.ylabel("Animals Starved")
    plt.title("Energy Move Cost v. Animal Starved")
    plt.show()

    const.ENERGY_MOVE_FACTOR = hold  # restore value
示例#6
0
def anDissipationtoRab():
    """ Description: Runs multiple simulations. 
                     Dissipation of Scent tested from 0.5 through 0.9.
                     Records effect on animal consumption.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    scentFade = [0.5, 0.6, 0.7, 0.8, 0.9]
    output = []

    for k in range(len(scentFade)):
        hold = const.DISSIPATION_RATE  # grab value for restoring value

        const.DISSIPATION_RATE = scentFade[k]

        eatenRabbits = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            eatenRabbits.append(eco.animalsDeath[4])

        output.append(sum(eatenRabbits) / len(eatenRabbits))

        const.DISSIPATION_RATE = hold  # restore value

    plt.plot(scentFade, output)
    plt.xlabel("Scent Trail Fade Percent")
    plt.ylabel("Animals Eaten")
    plt.title("Scent Dissipation v. Animals Consumption")
    plt.show()
示例#7
0
def anPondsToAnimals():
    """ Description: Runs multiple simulations. 
                     Amount of ponds in sim tested from 0 through 6.
                     Records effect on plant and animal deaths.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    temp = const.MIN_MOISTURE
    const.MIN_MOISTURE = 0
    hold = const.NUM_PONDS  # grab value for restoring value

    ponds = [0, 1, 2, 3, 4, 5, 6]
    output1 = []
    output2 = []
    output3 = []

    for k in range(len(ponds)):
        const.NUM_PONDS = ponds[k]

        deadHerbi = []
        deadCarni = []
        deadPlants = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            deadHerbi.append(eco.herbiDied)
            deadCarni.append(eco.carniDied)
            deadPlants.append(eco.plantsDied)

        output1.append(sum(deadHerbi) / len(deadHerbi))
        output2.append(sum(deadCarni) / len(deadCarni))
        output3.append(sum(deadPlants) / len(deadPlants))

    plt.plot(ponds, output1, label='Herbivores')
    plt.plot(ponds, output2, label='Carnivores')
    plt.xlabel("Number of Ponds")
    plt.ylabel("Animals Dead")
    plt.title("Pond Count v. Animal Deaths")
    plt.legend()
    plt.show()

    plt.plot(ponds, output3)
    plt.xlabel("Number of Ponds")
    plt.ylabel("Plants Dead")
    plt.title("Pond Count v. Plant Deaths")
    plt.show()

    const.NUM_PONDS = hold  # restore value
    const.MIN_MOISTURE = temp
示例#8
0
def anPlantUnitsToDeaths():
    """ Description: Runs multiple simulations. 
                     Amount of units per plant tested from 1 through 5.
                     Records effect on plant and animal deaths.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.PLANT_UNITS_TO_EAT  # grab value for restoring value

    plantUnits = [1, 2, 3, 4, 5]
    output1 = []
    output2 = []
    output3 = []

    for k in range(len(plantUnits)):
        const.PLANT_UNITS_TO_EAT = plantUnits[k]

        deadHerbi = []
        deadCarni = []
        deadPlants = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            deadHerbi.append(eco.herbiDied)
            deadCarni.append(eco.carniDied)
            deadPlants.append(eco.plantsEaten)

        output1.append(sum(deadHerbi) / len(deadHerbi))
        output2.append(sum(deadCarni) / len(deadCarni))
        output3.append(sum(deadPlants) / len(deadPlants))

    plt.plot(plantUnits, output1, label='Herbivores')
    plt.plot(plantUnits, output2, label='Carnivores')
    plt.xlabel("Units of Plant Eaten at A Time")
    plt.ylabel("Animals Dead")
    plt.title("Plant Units v. Animal Deaths")
    plt.legend()
    plt.show()

    plt.plot(plantUnits, output3)
    plt.xlabel("Units of Plant Eaten at A Time")
    plt.ylabel("Plants Dead")
    plt.title("Plant Units v. Plant Deaths")
    plt.show()

    const.PLANT_UNITS_TO_EAT = hold  # restore value
示例#9
0
def anWaterCostToDessicate():
    """ Description: Runs multiple simulations. 
                     Amount of water consumed per move command tested from
                     2 through 10.
                     Records effect on animal deaths by dessication.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.WATER_MOVE_FACTOR  # grab value for restoring value

    waterMove = [2, 4, 6, 8, 10]
    output1 = []
    output2 = []

    for k in range(len(waterMove)):
        const.WATER_MOVE_FACTOR = waterMove[k]

        numDessicate = []
        drinks = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            numDessicate.append(eco.animalsDeath[1])
            drinks.append(eco.timesDrunk)

        output1.append(sum(numDessicate) / len(numDessicate))
        output2.append(sum(drinks) / len(drinks))

    plt.plot(waterMove, output1)
    plt.xlabel("Water Move Cost Factor")
    plt.ylabel("Animals Dessicated")
    plt.title("Water Move Cost v. Animal Dessicated")
    plt.show()

    plt.plot(waterMove, output2)
    plt.xlabel("Water Move Cost Factor")
    plt.ylabel("Times Fauna Drunk")
    plt.title("Water Move Cost v. Times Drunk")
    plt.show()

    const.WATER_MOVE_FACTOR = hold  # restore value
示例#10
0
def anFoxToRabAndPlant():
    """ Description: Runs multiple simulations. 
                     Amount of foxes in sim tested from 1 through 7.
                     Records effect on plant and animal consumption.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    foxes = [1, 2, 3, 4, 5, 6, 7]
    output1 = []
    output2 = []

    for k in range(len(foxes)):
        hold = const.NUM_FOXES  # grab value for restoring value

        const.NUM_FOXES = foxes[k]
        eatenRabbits = []
        eatenPlants = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            eatenRabbits.append(eco.animalsDeath[4])
            eatenPlants.append(eco.plantsEaten)

        output1.append(sum(eatenRabbits) / len(eatenRabbits))
        output2.append(sum(eatenPlants) / len(eatenPlants))

        const.NUM_FOXES = hold  # restore value

    plt.plot(foxes, output1)
    plt.xlabel("Number of Inital Foxes")
    plt.ylabel("Number Animals Eaten")
    plt.title("Initial Foxes v. Animals Consumption")
    plt.show()

    plt.plot(foxes, output2)
    plt.xlabel("Number of Initial Foxes")
    plt.ylabel("Number Plants Eaten")
    plt.title("Initial Foxes v. Plant Consumption")
    plt.show()
示例#11
0
def anPlantChanceToAnimals():
    """ Description: Runs multiple simulations. 
                     Chance for plant to spawn in empty grid at end of day
                     tested from 0.2 through 1.0.
                     Records effect on animal deaths.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    hold = const.PLANT_CHANCE  # grab value for restoring value

    plantChance = [0.2, 0.4, 0.6, 0.8, 1.0]
    output1 = []
    output2 = []

    for k in range(len(plantChance)):
        const.PLANT_CHANCE = plantChance[k]

        deadHerbi = []
        deadCarni = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            deadHerbi.append(eco.herbiDied)
            deadCarni.append(eco.carniDied)

        output1.append(sum(deadHerbi) / len(deadHerbi))
        output2.append(sum(deadCarni) / len(deadCarni))

    plt.plot(plantChance, output1, label='Herbivores')
    plt.plot(plantChance, output2, label='Carnivores')
    plt.xlabel("Plant Initialization Chance")
    plt.ylabel("Animals Dead")
    plt.title("Plant Chances v. Animal Deaths")
    plt.legend()
    plt.show()

    const.PLANT_CHANCE = hold  # restore value
示例#12
0
def anLakeToAnimals():
    """ Description: Runs multiple simulations. 
                     Spread of Lake tested from 1 through 7.
                     Records effect on animal deaths.
                     Will be tested for NUM_SIMS amount of times.
        
        Output: Average result of the simulations displayed in a line plot.
    """
    lakeSpread = [1, 2, 3, 4, 5, 6, 7]
    output1 = []
    output2 = []

    for k in range(len(lakeSpread)):
        hold = const.LAKE_SPREAD  # grab value for restoring value

        const.LAKE_SPREAD = lakeSpread[k]

        deadHerbi = []
        deadCarni = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            deadHerbi.append(eco.herbiDied)
            deadCarni.append(eco.carniDied)

        const.LAKE_SPREAD = hold  # restore value

        output1.append(sum(deadHerbi) / len(deadHerbi))
        output2.append(sum(deadCarni) / len(deadCarni))

    plt.plot(lakeSpread, output1, label='Herbivores')
    plt.plot(lakeSpread, output2, label='Carnivores')
    plt.xlabel("Lake Size Multiplyer")
    plt.ylabel("Animals Dead")
    plt.title("Lake Size v. Animal Deaths")
    plt.legend()
    plt.show()
示例#13
0
def anRabToPlant():
    """ Description: Runs multiple simulations with amount of rabbits spawned
                     for every burrow going from 1 through 7. Every variable
                     will be tested for NUM_SIMS amount of times.
                     Records effect on plant consumption.
        
        Output: Average result of the simulations displayed in a line plot.
    """

    rabbits = [1, 2, 3, 4, 5, 6, 7]
    output = []

    for k in range(len(rabbits)):
        # grab value for restoring value
        hold = const.RABBITS_PER_BURROW

        #Parameters passed
        const.RABBITS_PER_BURROW = rabbits[k]  # must be less than 9

        eatenPlants = []

        for j in range(const.NUM_SIMS):
            eco = sim.EcoSystem()  #Initialize Ecosystem
            for i in range(const.NUM_WEEKS):
                eco.runAWeek()
            eatenPlants.append(eco.plantsEaten)

        # restore value
        const.RABBITS_PER_BURROW = hold

        output.append(sum(eatenPlants) / len(eatenPlants))

    plt.plot(rabbits, output)
    plt.xlabel("Rabbits per Burrow")
    plt.ylabel("Grass Eaten")
    plt.title("Rabbit population v. Grass Consumption")
    plt.show()
示例#14
0
def main():
    setup_logger()
    logger.debug('DEBUG')
    print " *"*30, "\nWe start NOW!"  # ***
    # all_gene_names = extract_all_gene_names(my_example_of_ecosystem_settings)
    # all_strings = extract_all_strings(
    #    my_example_of_ecosystem_settings,
    #    exceptions = No_effect_directives + All_action_names)
    # print 'ALL GENES:', all_gene_names
    # print 'ALL STRINGS:', all_strings
    # print 'DIFFERENCE:', [
    #    item
    #    for item in all_strings
    #    if not item in all_gene_names and \
    #        not item in All_allowed_directives_in_expression]
    enable_graphics = True
    make_sleeps = False
    time_lapse = 4
    Total_time = 5000

    ecosystem = Ecosystem(my_example_of_ecosystem_settings)

    ecosystem.minimum_population_allowed = 200

    """ ***********************  TRIAL ZONE ****************************

    ecosystem.evolve()

    org = ecosystem.get_random_organisms(1)[0]

    print_dictionary(
        evaluate_functions_of_a_dictionary(
            org['offers to sell'], org
            )
        )

    f_set = {'-': ('nutrient A reserve', 'minimum nutrient A reserve for procreating')}
    f = ecosystem.function_maker.read_function_settings(
        '#organism',
        f_set)


    print_organism(org, 'nutrient A reserve', 'minimum nutrient A reserve for procreating')
    print_organism(org, 'nutrient A surplus')

    print f(org)

    print org['value in next cycle']['nutrient A surplus'](org)

    exit()

    f_set = {'curve from 0 to 1': 'photosynthesis capacity'}

    f = ecosystem.function_maker.read_function_settings(
        'output function #organism #input',
        f_set)

    for org in ecosystem.organisms_list:
        print f(org, 5)

    exit()

    f_set = {'extract #biotope sunlight (percentage)': (
                            'normalized location x',
                            'normalized location y',
                            0.8
                        )}

    f_2_set = {
        '#biotope sunlight': (
            'normalized location x',
            'normalized location y'
            )
        }

    org = choice(ecosystem.organisms_list)
    print_dictionary(org)

    f = ecosystem.function_maker.read_function_settings('#organism', f_set)
    f_2 = ecosystem.function_maker.read_function_settings('#organism', f_2_set)

    print f(org), f_2(org)

    for i in range(10):
        org.act()

    print_dictionary(org)

    # f_set = ecosystem.settings['constraints']['can procreate']
    # f_set = {'cost': 'procreate'}
    f_set = 'time'
    f = ecosystem.function_maker.read_function_settings('#organism', f_set)

    # print f(ecosystem)

    for org in ecosystem.organisms_list:
        print f(org)

    exit()

    *********************** (TRIAL ZONE) ************************** """

    if enable_graphics:
        gui = GUI(ecosystem)
    # Loop
    print "LOOPING:"
    while ((len(ecosystem.organisms_list) > 0) and
           (ecosystem.time < Total_time)):
        # Print ecosystem status:
        if ecosystem.time % time_lapse == 0:
            print_ecosystem_status(ecosystem)
            # organism1, organism2 = ecosystem.get_random_organisms(
            #    number_of_random_organisms = 2)
        if Store_data:
            ecosystem.data_storer.store_data()
        # Evolve:
        ecosystem.evolve()
        if enable_graphics:
            gui.handle_events()
            gui.draw_ecosystem()
        if make_sleeps:
            sleep(1.0)  # To remove
        if ecosystem.population() < ecosystem.minimum_population_allowed:
            n = ecosystem.minimum_population_allowed - ecosystem.population()
            ecosystem.create_new_organisms(n)
            print n, "organisms created",

    print "Time:", ecosystem.time, "Number of organisms:", \
        len(ecosystem.organisms_list)  # ***

    if enable_graphics:
        gui.delete()