Skip to content

Commit

Permalink
interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
jankrk committed Dec 19, 2023
1 parent 19d0224 commit ffadcd4
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
4 changes: 2 additions & 2 deletions antlr/MyGPMiniVisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def __init__(self, counter, input):
def visitProgram(self, ctx:GPMiniParser.ProgramContext):
for s in ctx.statement():
if self.counter == 0:
return self.output
return [self.output, self.counter]
self.visitStatement(s)
return self.output
return [self.output, self.counter]


# Visit a parse tree produced by GPMiniParser#statement.
Expand Down
8 changes: 4 additions & 4 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ def __init__(self):
self.data = 'data.txt'
self.heuristic = '1.1.B'

self.max_interpreter_steps = 100
self.max_interpreter_steps = 1000

self.min_inital_vars = 1
self.max_initial_vars = 4
Expand All @@ -16,8 +16,8 @@ def __init__(self):
self.max_blocks = 5

self.max_blocks_depth = 2
self.max_operations_depth = 3
self.max_logic_depth = 3
self.max_operations_depth = 2
self.max_logic_depth = 2

# between 0 and 1
# 0 means no complexity
Expand All @@ -27,7 +27,7 @@ def __init__(self):

self.population = 50
self.generations = 100
self.tournament_size = 20
self.tournament_size = 40

self.not_prob = 30
self.evolution_prob = {
Expand Down
9 changes: 9 additions & 0 deletions data.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
1 2 3 4 5 : 9 8 7 6
1 2 3 : 90 60
7 7 7 : 4 4 4 4
1 2 3 4 5 : 9 8 7 6
1 2 3 : 90 60
7 7 7 : 4 4 4 4
1 2 3 4 5 : 9 8 7 6
1 2 3 : 90 60
7 7 7 : 4 4 4 4
1 2 3 4 5 : 9 8 7 6
1 2 3 : 90 60
7 7 7 : 4 4 4 4
4 changes: 3 additions & 1 deletion fitness.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def fitness_function(self, indiv):
tree = parser.program()
for i in range(len(self.input)):
visitor = MyGPMiniVisitor(self.config.max_interpreter_steps, self.input[i])
output_generated = visitor.visitProgram(tree)
tab = visitor.visitProgram(tree)
output_generated = tab[0]
fitness += tab[1] - self.config.max_interpreter_steps
if 'ERROR' in output_generated:
fitness -= math.inf
else:
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import timeit

class TinyGPGenerator:
def __init__(self, tree_factory=TreeFactory):
def __init__(self):
self.config = Config()
self.state = State(self.config)
self.heuristic = Heuristic()
Expand Down

0 comments on commit ffadcd4

Please sign in to comment.