forked from martinventer/virtual_creatures
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmontepython.py
80 lines (62 loc) · 1.81 KB
/
montepython.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
from CreatureTools import Creature
import numpy as np
from tqdm import tqdm
from joblib import Parallel, delayed
import multiprocessing as mp
def genGen():
params = {
'num_char': 100,
'variables': 'X',
'constants': 'F+-',
'axiom': 'FX',
'rules': {
'X': {
'options': ['+FX', '-FX'],
'probabilities': [0.5, 0.5]
}
},
'point': np.array([0, 0]),
'vector': np.array([0, 1]),
'length': 1.0,
'angle': 25 # random
}
return Creature(params).coords
if __name__ == "__main__":
iter = 1000
# def parallel_monte_carlo(iter):
pool = mp.Pool(4)
pbar = tqdm(total=iter)
population = []
def update(*a):
pbar.update()
for i in range(pbar.total):
results = [pool.apply_async(genGen, callback=update)]
population.append([f.get() for f in results])
pool.close()
pool.join()
print(population[0])
# return res
# final_results = parallel_monte_carlo(100000)
# pbar = tqdm(total=generations, position=2, unit='generation',
# ascii=True, dynamic_ncols=True, smoothing=0.5)
# while generation < (generations + 1):
# params = {
# 'num_char': 100,
# 'variables': 'X',
# 'constants': 'F+-',
# 'axiom': 'FX',
# 'rules': {
# 'X': {
# 'options': ['+FX', '-FX'],
# 'probabilities': [0.5, 0.5]
# }
# },
# 'point': np.array([0, 0]),
# 'vector': np.array([0, 1]),
# 'length': 1.0,
# 'angle': 25 # random
# }
# generation += 1
# population.append(Creature(params).coords)
# pbar.update()
print()