-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sets.py
More file actions
24 lines (21 loc) · 791 Bytes
/
create_sets.py
File metadata and controls
24 lines (21 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from ast import literal_eval
from calculate_digit import calculate_digit as cd
import settings as S
def create_sets(GENERATION, member):
"""
param: Creates the sets for a given DNA.
type: int, int
return: None
"""
print("Creating sets for member: " + str(member + 1))
with open(S.GEN_FOLDER + str(GENERATION) + '/dna_' + str(member), "r") as dna_file:
dna = literal_eval(dna_file.read())
dna_file.close()
with open(S.GEN_FOLDER + str(GENERATION) + '/dna_' + str(member) + '_sets', 'w') as sets_file:
for i in range(S.SET_SIZE):
line = ""
for number in range(S.SET_LENGTH):
line += str(cd(dna)) + ','
line = line[:-1] + '\n'
sets_file.write(line)
sets_file.close()