Skip to content

Commit

Permalink
feat: add output parsing in analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
suhdonghwi committed Jun 5, 2021
1 parent 7e1c076 commit 69c5b0c
Show file tree
Hide file tree
Showing 2 changed files with 1,449 additions and 0 deletions.
49 changes: 49 additions & 0 deletions analysis/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import re


class Specie:
def __init__(self, data):
pat = re.compile(
r"""\s+(\d+)\s+\|\s+(\d+)\s+\|\s+(\d+)\s+\|\s+(\d+)\s+\|\s+(\d+[.]\d+)"""
)
(id, age, size, offspring, fitness) = pat.match(data).groups()

self.id = int(id)
self.age = int(age)
self.size = int(size)
self.offspring = int(offspring)
self.fitness = float(fitness)


class Generation:
def __init__(self, data):
data = data.strip()

pat = re.compile(
r"""\[Generation (\d+)\]\n# Evaluation result\n - fitness max: (\d+\.\d+) \((\d+) nodes, (\d+) edges\)\n - fitness mean: (\d+\.\d+) .+\n\n# Speciation result:\n.+\n.+\n([\s\S]+)"""
)
(
generation_num,
fitness_max,
nodes,
edges,
fitness_mean,
species_data,
) = pat.match(data).groups()

self.generation_num = int(generation_num)
self.fitness_max = float(fitness_max)
self.best_nodes_count = int(nodes)
self.best_edges_count = int(edges)
self.fitness_mean = float(fitness_mean)

self.species = [Specie(l) for l in species_data.split("\n")]
print(self.species)


file = open("./analysis/output.txt", "r")

generations = [
Generation(g) for g in re.compile("[-]+\n").split(file.read()) if g.strip() != ""
]
print(generations)
Loading

0 comments on commit 69c5b0c

Please sign in to comment.