-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
100 lines (87 loc) · 3.04 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import worm_gen
import worm_fitness as fit
import worm_breeding as breed
from heapq import merge, heapify, heappop
import bitsey as bit
import sys
import test_wormAvgs as wormAvg
# Notes: give worm boolean to see if tested with bitsey. DO NOT want to run worm through bitsey more than once.
NUM_GENS = 20
def main():
trait_file = open(sys.argv[1], "r")
population, trait_bounds = worm_gen.gen_worms(trait_file)
i = 0
time = int(input("How long do you want the worms to run?"))
while i < NUM_GENS:
print("Gen {}".format(i))
bitsey(population,time)
if i == 1:
print("Parents Grads: ")
#wormAvg.parents_avg(population)
wormResults(population)
print("--------------")
sorted_pop = fit.population_fitness(population)
best_worms_pop = fit.purge_bad_worms(sorted_pop)
child_list = breed.breed_worms(best_worms_pop, trait_bounds)
# an unordered list of new worms without fitness levels - not BITSEYed yet.
# Doubles population
# Make heap of child worms with fitness levels gotten through BITSEY:
child_pop = fit.population_fitness(child_list)
# Pass child_pop and the best_worms_pop into a function that merges them into a single heap:
population = mergeHeaps(best_worms_pop, child_pop)
i = i + 1
wormAvg.average_Km(population)
wormAvg.average_N(population)
wormAvg.average_Gj_scale(population)
# heapify(population)
wormResults(population)
trait_file.close()
return
def wormResults(pop):
population = pop.copy()
pop_size = len(population)
to_print = list()
i = 0
while i < pop_size:
worm = heappop(population)
to_print.append(worm)
i = i + 1
i = pop_size
while i > 0:
worm = to_print[i - 1]
print("Grad Stren: {}".format(worm[0]))
i = i - 1
def bitsey(population,time):
pop_size = len(population)
i = 0
popC = population.copy()
if type(population) == set:
while i < pop_size:
worm_to_work = popC.pop()
bit.setup_and_sim(worm_to_work, time)
i = i + 1
if type(population) == list:
while i < pop_size:
worm_to_work = popC[i]
bit.setup_and_sim(worm_to_work[1], time)
i = i + 1
def print_heap(population, num_worms):
i = 0
print("\n")
while(i < num_worms):
to_print = population[i]
print("Worm Fitness = " + str(to_print[1].fitness))
print("Km = " + str(to_print[1].Km))
print("N = " + str(to_print[1].N))
print("Gj_scale = " + str(to_print[1].Gj_scale))
print("num_cells = " + str(to_print[1].num_cells))
print("G_k = " + str(to_print[1].G_k))
print("G_k = " + str(to_print[1].G_na))
print("G_cl = " + str(to_print[1].G_cl))
print("Gj_diff_m = " + str(to_print[1].Gj_diff_m))
print("value")
print("\n")
i = i + 1
def mergeHeaps(heap1, heap2):
return list(merge(heap1, heap2))
main()