示例#1
0
def do_init(limit,
            period,
            runnum,
            screen_off=False,
            print_moment=True,
            print_moment_period=1000):
    """

    :param limit: moment limit
    :param period:
    :param runnum: run id
    :return:
    """
    w = init_world()
    times = []
    pc_list = []
    samples = []
    dof = lambda w: pc_and_sample_dofun(w, pc_list, times, samples, period)
    endf = lambda w: limit_endfun(w, limit)
    returnf = lambda w: pc_and_sample_returnfun(pc_list, times, samples, runnum
                                                )
    exputil.do(w,
               k,
               dof,
               endf,
               returnf,
               screen_off=screen_off,
               print_moment=print_moment,
               print_moment_period=print_moment_period,
               print_script=str(runnum) + "th run")
示例#2
0
def test(testname,
         runnum,
         iter_per_sample,
         limit=None,
         thres=None,
         index=None,
         screen_off=True):
    print("doing", runnum, "-", testname)
    filename = resultdir + str(runnum) + "_time"
    f = open(filename, 'rb')
    times = pickle.load(f)
    print("times:", times)
    f.close()
    filename = resultdir + str(runnum) + "_sample"
    samples = world.read_list_of_dnas_file(filename)
    assert len(times) == len(samples)
    n = len(times)
    for iteration in range(iter_per_sample):
        results = []
        for i, (t, dnas) in enumerate(zip(times, samples)):  #for each moment
            w = test_world(testname, dnas)
            dof = lambda w: test_dofun(w, testname)
            endf = lambda w: test_endfun(w, testname, limit=limit, thres=thres)
            returnf = lambda w: test_returnfun(
                w, testname, index=index, ininum=ininum)
            results.append(
                exputil.do(w,
                           test_k if testtype(testname) == 2 else k,
                           dof,
                           endf,
                           returnf,
                           screen_off=screen_off,
                           print_moment=False))
            print("done", runnum, t, "-", iteration)
        util.write_results(resultdir, runnum, iteration, testname, results,
                           times)
    print("done", runnum, "-", testname)
示例#3
0
    for i in range(ininum_red):
        mis.append(
            world.construct_minion(red_dnas[i % len(red_dnas)],
                                   alen=1,
                                   pos=(-1, -1),
                                   do_freeze=False))
    for i in range(ininum_blue):
        mis.append(
            world.construct_minion(blue_dnas[i % len(blue_dnas)],
                                   alen=1,
                                   pos=(-1, -1),
                                   do_freeze=False))
    mis = world.dll_from_list(mis)
    w=world.World(xsize,ysize,total_mass,mis,no_age=False,no_birth=False,no_eat=False,\
              no_energy=False,no_excrete=False,no_hunt=False,halluc=False,record_pedigree=False)
    red_keep, blue_keep = [False], [False]
    tmp_red_dnas.clear()
    w.append_red_dnas(tmp_red_dnas)
    tmp_blue_dnas.clear()
    w.append_blue_dnas(tmp_blue_dnas)
    dof = lambda w: dofun(w, red_keep, blue_keep, tmp_red_dnas, tmp_blue_dnas)
    win = exputil_cy.do(w,
                        k,
                        dof=dof,
                        endf=endf,
                        returnf=returnf,
                        screen_off=True,
                        print_moment=True,
                        print_moment_period=1,
                        screen_period=50)
示例#4
0
def returnf(w):
    pedigree = w.get_pedigree()
    print(pedigree)
    return
    for id in range(360):
        print(get_num_child(pedigree, id, 1000))
    """
    id1=pedigree[0][0]
    id2=pedigree[0][1]
    id3=pedigree[1][0]
    id4=pedigree[2][1]
    print("first dad until 1000:",get_num_child(pedigree,id1,1000))
    print("first dad until 1500:", get_num_child(pedigree, id1, 1500))
    print("first mom until 1000:", get_num_child(pedigree, id2, 1000))
    print("first mom until 1500:", get_num_child(pedigree, id2, 1500))
    print("second dad until 1000:", get_num_child(pedigree, id3, 1000))
    print("second dad until 1500:", get_num_child(pedigree, id3, 1500))
    print("second mom until 1000:", get_num_child(pedigree, id4, 1000))
    print("second mom until 1500:", get_num_child(pedigree, id4, 1500))
    """


exputil_cy.do(w,
              k,
              dof=lambda w: w.one_step(),
              endf=lambda w: w.extincted() or w.limit(limit),
              returnf=returnf,
              screen_off=True,
              print_moment=True,
              print_moment_period=10)
示例#5
0
ininum_red,ininum_blue=120,240
red_maxsize,red_uptake,red_maxage=6,0.6,1600
blue_maxsize,blue_uptake,blue_maxage=4,0.4,1600
avg_consum_rate,consum_exp=0.01,0.5

exputil_cy.set_size(xsize, ysize)
exputil_cy.set_heredity(merge_thres, mut_per_diff)
world.set_consum(avg_consum_rate,consum_exp)

red_dna=world.randLinearDNA_with(c=(255,0,0),mst_a=red_maxsize,utt_a=red_uptake,mat_a=red_maxage)
blue_dna=world.randLinearDNA_with(c=(0,0,255),mst_a=blue_maxsize,utt_a=blue_uptake,mat_a=blue_maxage)
mis=[]
for _ in range(ininum_red):
    mis.append(world.construct_minion(red_dna,alen=1,pos=(-1,-1),do_freeze=False))
for _ in range(ininum_blue):
    mis.append(world.construct_minion(blue_dna,alen=1,pos=(-1,-1),do_freeze=False))
print(len(mis))
mis=world.dll_from_list(mis)

w=world.World(xsize,ysize,total_mass,mis,no_age=False,no_birth=False,no_eat=False,\
              no_energy=False,no_excrete=False,no_hunt=False,halluc=False,record_pedigree=False)


def dof(w):
    w.one_step()
    print(w.get_population())
    ct,mst,utt,mat,wt=w.get_nth_mi(0).get_dna().get_traits()
    print(ct.get_c(),mst.get_a(),utt.get_a(),mat.get_a())
exputil_cy.do(w, k, dof=dof, endf=lambda w: w.extincted() or w.limit(limit),
              returnf=lambda w: None, screen_off=True, print_moment=True, print_moment_period=1,screen_period=50)
示例#6
0
     mis.append(
         world.construct_minion(blue_dna,
                                alen=1,
                                pos=(-1, -1),
                                do_freeze=False))
 print(len(mis))
 mis = world.dll_from_list(mis)
 w = world.World(xsize, ysize, total_mass, mis, no_age=False, no_birth=False, no_eat=False, \
                 no_energy=False, no_excrete=False, no_hunt=False, halluc=False, record_pedigree=False)
 rs, bs = [], []
 dof = lambda w: dofun(w, rs, bs)
 moment, population, r, b = exputil_cy.do(w,
                                          k,
                                          dof,
                                          endf,
                                          returnf,
                                          screen_off=True,
                                          print_moment=True,
                                          print_moment_period=1,
                                          screen_period=50)
 with open(resultdir + "result" + str(args.n) + ".txt", 'a') as f:
     f.write(
         str(i) + " , " + str(j) + " - " + str(moment) + " , " +
         str(r) + " , " + str(b) + " , " + str(population - r - b) +
         "\n")
 with open(
         resultdir + "population_" + str(args.n) + "_" + str(i) +
         "_" + str(j) + "_" + str(iternum) + ".txt", 'w') as f:
     for r, b in zip(rs, bs):
         f.write(str(r) + " , " + str(b) + "\n")
     f.close()