Beispiel #1
0
def testgene(org, arraylist, env):
    #Creates organism.cpp file and compiles it
    writec("./habitat/" +org.folder, org) 
    call('g++ ./habitat/' + org.folder + '*.cpp ./habitat/biosort.o -o ./habitat/' + org.folder + 'organism.out -g', shell = True) 
    

    total_opcount = 0 #Sum of all individual opcounts   
    #Runs an organism x times where x is the number of runs per generation
    for i in range(env.runs):
        array = ' '.join(str(x) for x in arraylist[i]) #Pulls array to sort from the given arraylist.
        command = './habitat/' + org.folder + 'organism.out '+str(env.pressure)+' '+array #Command to run organism on array from the command line
        fileout = Popen(command, stdin = PIPE, stdout = PIPE, stderr = PIPE, bufsize = 1, shell = True) #Retrieves the operations performed by the C++ before it ended 
      
        # Gets opcount and adds to total_opcount 
        ops = fileout.stdout.readline() 
        org.ops.append(int(ops)) 
      
        if org.ops[i] >= env.pressure:
            org.ops[i] += env.penalty

        total_opcount += org.ops[i]
        
     
    # Calculates mean number of ops 
    org.avgops = total_opcount / env.runs 
    return
Beispiel #2
0
def make_random_kid(env, folder, num, parent_num):
    org = makegene(random.randint(1, env.maxgenes+1)) # make a random gene
    org.folder = folder.path # set org folder (created in init of bfolder)
    org.logloc = "P_"+str(num+1)+"_B_"+str(parent_num+1) # set log output for location
    org.is_primeval = True # came from random, so its primeval
    folder.org = org # add the org to the folder
    writec(folder.path, folder.org) # write out the file
    if env.debug == True:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -g -O0', shell = True) 
    else:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -O0', shell = True) 
Beispiel #3
0
def make_random(env, folder, num):
    org = makegene(random.randint(1, env.maxgenes+1))
    org.folder = folder.path
    org.logloc = "R_"+str(num)
    org.is_primeval = True
    folder.org = org
    writec(folder.path, folder.org)
    if env.debug == True:
        call('g++ '+folder.path+'*.cpp ./habitat/biosort.o -o '+folder.path+'organism.out -g -O0', shell = True)
    else:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -O0', shell = True) 
Beispiel #4
0
def make_random_breeder(env, folder, num):
    org = makegene(random.randint(1, env.maxgenes+1)) # Make a random gene
    org.is_primeval = True # Came from random, so its primeval
    org.folder = folder.path # set org folder (needed for mutate)
    org.logloc = "B_"+str(num) # set log output for location
    folder.org = org
    writec(folder.path, folder.org) # write out the file
    if env.debug == True:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -g -O0', shell = True)
    else:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -O0', shell = True)
    copy('./habitat/biosort.h', './habitat/breeder'+str(num))
Beispiel #5
0
def make_kid(env, folder, orgfrom, kidnum, breedernum):
    org = Organism(orgfrom.genesequence) # create a new organism based off parent
    org.folder = folder.path # set organism folder
    org.logloc = "P_"+str(kidnum+1)+"_B_"+str(breedernum+1) # set log file representation of folder
    org.lineage_id = orgfrom.lineage_id
    org.is_primeval = False # Did not come from random, not primeval
    folder.org = org # place org in folder
    mutate(folder.org, env.mutations+env.adds*kidnum, env.weight, env.maxgenes) # mutate the gene and write mutation to file
    writec(folder.path, folder.org)
    if env.debug == True:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -g -O0', shell = True) 
    else:
        call('g++ '+ folder.path + '*.cpp ./habitat/biosort.o -o ' + folder.path + 'organism.out -O0', shell = True)