forked from ZJouba/virtual_creatures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mini_monte.py
88 lines (74 loc) · 2.08 KB
/
mini_monte.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
import multiprocessing as mp
import numpy as np
import tqdm
from itertools import repeat
import os
from datetime import datetime
import pickle
import pandas as pd
from CreatureTools_3 import Creature
def genPop(params, predef_rules=None):
np.random.seed()
if not predef_rules:
choices = [ 'F',
'+',
'-',
'X',
]
rule_A = ''.join([np.random.choice(choices)
for _ in range(5)])
rule_B = ''.join([np.random.choice(choices)
for _ in range(5)])
params['rules'] = {'X': { 1: rule_A, 2:rule_B}}
else:
if params.get('pairwise'):
params['rules'] = {'X': {
1: predef_rules[0],
2: predef_rules[1]
}}
else:
params['rules'] = {'X': {
1: predef_rules,
2: predef_rules
}}
c = Creature(params)
a = (
c.l_string,
c.area,
c.rules,
c.choices,
c.ratio,
)
return list(a)
def firstRun(iter):
population = []
population = [[
'L-string',
'Area',
'Rules',
'Choice vector',
'Ratios',
]]
with mp.Pool(6) as pool:
result = list(tqdm.tqdm(pool.imap(genPop, repeat(params, iter)), total=iter))
population = population + result
return population
if __name__ == "__main__":
curr_dir = os.path.dirname(__file__)
params = {
'chars': 500,
'recurs': 100,
'variables': 'X',
'constants': 'F+-',
'axiom': 'FX',
'length': 1.0,
'angle': 25,
'prune': True,
'pairwise': False,
}
population = firstRun(50000)
population = pd.DataFrame(population[1:], columns=population[0])
now = datetime.utcnow().strftime('%b %d, %Y @ %H.%M')
file_name = os.path.join(
curr_dir, 'CSVs/mini_monte_data ' + now + '.p')
pickle.dump(population, open(file_name, 'wb'))