Example #1
0
def getFig(primaryVary, secondaryVary):
    ylists = []
    xlist = [x/1000*(xupper[primaryVary]-xlower[primaryVary])+xlower[primaryVary] for x in baseXList]
    for mitNum in range(0,5):
        iteration = [*varydef]
        iteration[secondaryVary] = vary[secondaryVary][mitNum]
        ylist = []
        for itNum in xlist:
            iteration[primaryVary] = itNum
            ylist.append(population(*iteration).decay(maxIter))
        ylists.append(ylist)
            # Change point

        # Change line
    plt.clf()
    plt.plot(xlist, ylists[0], label=vary[secondaryVary][0], mfc='r', marker=',')
    plt.plot(xlist, ylists[1], label=vary[secondaryVary][1], mfc='b', marker=',')
    plt.plot(xlist, ylists[2], label=vary[secondaryVary][2], mfc='g', marker=',')
    plt.plot(xlist, ylists[3], label=vary[secondaryVary][3], mfc='y', marker=',')
    plt.plot(xlist, ylists[4], label=vary[secondaryVary][4], mfc='c', marker=',')
    plt.xlabel(labelList[primaryVary])
    plt.ylabel('Iterations Before Extinction')
    plt.title('Iterations vs ' + labelList[primaryVary] + ' with varying ' + labelList[secondaryVary])

    plt.axis([xlist[0], xlist[popNum-1],
    0, 20])# Change these values to make graph prettier

    plt.legend()
    return plt
Example #2
0

def getPopAttributes(iteration):
    #Determine population attributes based on iteration number

    # Initial population size
    popSize = 10000
    # percentage of initial pop. infected
    perInfect = .5
    # % chance that offspring of an infected male is male
    ratio = .5
    # Growth of population per generation. 0 means no growth, 1 means double every year, etc.
    growth = 6

    return (popSize, perInfect, ratio, growth)


start = time.process_time()

# Amount of populations to simulate
popNum = 1000
# Max iteration count
maxIter = 10000

for x in range(1, popNum):
    pop = population(*getPopAttributes(x))
    print(x, pop.decay(maxIter))

stop = time.process_time()
print("Time Elapsed:", stop - start)
Example #3
0
import time
from sim import population, nextGen

#This script simulates a single population slowly decaying due to infection

start = time.process_time()

# Initial population size
popSize = 10000
# percentage of initial pop. infected
perInfect = .5
# % chance that offspring of an infected male is male
ratio = .5
# Growth of population per generation. Zero means no growth, 1 means double every year, etc.
growth = 6

a = population(popSize, perInfect, ratio, growth)  # generation 0
gen = a.getInit()
iter = 0
print(iter, gen.population, gen.infected)
while (gen.population > 1 and gen.infected > 1
       and iter < 100000):  #a.infected > 0
    gen = nextGen(gen)
    iter += 1
    print(iter, gen.population, gen.infected)

stop = time.process_time()
print("Time Elapsed:", stop - start)