-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmeasure_productivity_details.py
101 lines (101 loc) · 2.81 KB
/
measure_productivity_details.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
101
#
# Measure Productivity Details
#
# Peter Turney, August 21, 2020
#
# Productivity is the number of ashes observed.
#
import golly as g
import model_classes as mclass
import model_functions as mfunc
import model_parameters as mparam
import apgsearch_repurposed as apg
import pickle
import glob
from statistics import mean
#
# Specify the layer to process.
#
layer_num = "4"
#
# Specify the generation to process
#
generation_num = 100
#
# Log file for reporting the results (output).
#
log_file = "C:/Users/peter/Peter's Projects/autopoiesis" + \
"/Paper Sections/Part 3 - Productivity/layer_" + layer_num + \
"_productivity_details.txt"
#
# The layer of pickles to process (input).
#
pickle_layer = "C:/Users/peter/Peter's Projects/autopoiesis/" + \
"Pickles/Layer " + layer_num
#
# Some parameters.
#
elite_size = 50 # number of seeds in a pickle
num_runs = 12 # runs range from 1 to 12
#
# Specify rule and symmetry.
#
rulestring = "B3/S23" # Game of Life
symmstring = "C1" # C1 means the soup is asymmetric
numsoups = 1 # soup count
#
# Open log file.
#
f = open(log_file, "w", 0) # 0 means no buffer, so instant results
f.write("\n\nLog File for Productivity Report\n\n")
f.write("generation number\trun number\tavg seed productivity\n")
#
# Iterate over the runs
#
for run in range(1, num_runs + 1):
#
# Look in the directory pickle_layer for the file
# with the current run number. The file will match
# the pattern "run[run]/log-...-pickle-[gen].bin". Note
# that glob.glob returns a list, since there may be many
# matching files, but we hope there is only one matching
# file.
#
pickle_paths = glob.glob(pickle_layer + "/run" + \
str(run) + "/log-*-pickle-" + str(generation_num) + ".bin")
assert len(pickle_paths) == 1 # should be exactly one match
pickle_path = pickle_paths[0] # extract the match from the list
#
# Load the pickle.
#
pickle_handle = open(pickle_path, "rb") # rb = read binary
seed_list = pickle.load(pickle_handle)
pickle_handle.close()
#
# Iterate over the seeds in the pickle.
#
seed_productivity = list() # a list of type counts for seeds
#
for seed in seed_list:
soup = apg.Soup()
soup.rg.setrule(rulestring)
soup.rg.saveAllRules()
soup.stabilise_seed(seed)
[objects, frequencies] = soup.basic_census()
total_ash_count = sum(frequencies) # number of tokens of ash
seed_productivity.append(total_ash_count)
#
avg_seed_productivity = mean(seed_productivity)
#
# Report the statistics for the given generation.
#
f.write("{:5d}\t{:5d}\t{:8.2f}\n".format( \
generation_num, run, avg_seed_productivity))
#
#
# Close file.
#
f.close()
#
#
#