From 32d2c77863f04841a6b63fb00a082b21895c5245 Mon Sep 17 00:00:00 2001 From: Laura Date: Wed, 15 Jan 2025 16:25:49 +0100 Subject: [PATCH] ugly fix to run Alhazen --- docs/code/Alhazen.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/code/Alhazen.py b/docs/code/Alhazen.py index 2af8874c..9313efeb 100755 --- a/docs/code/Alhazen.py +++ b/docs/code/Alhazen.py @@ -1647,11 +1647,11 @@ def get_all_input_specifications(dec_tree, import random from itertools import chain -def best_trees(forest, spec): +def best_trees(forest, spec, grammar): samples = [tree_to_string(tree) for tree in forest] fulfilled_fractions= [] for sample in samples: - gen_features = collect_features([sample], CALC_GRAMMAR) + gen_features = collect_features([sample], grammar) # calculate percentage of fulfilled requirements (used to rank the sample) fulfilled_count = 0 @@ -1718,7 +1718,7 @@ def generate_samples_advanced(grammar: Grammar, done = False starttime = time.time() best_chosen = [fuzzer.fuzz_tree() for _ in range(100)] - done, best_chosen = best_trees(best_chosen, spec) + done, best_chosen = best_trees(best_chosen, spec, grammar) if done: final_samples.append(tree_to_string(best_chosen)) @@ -1758,7 +1758,7 @@ def generate_samples_advanced(grammar: Grammar, curr = s[0] except SyntaxError: pass - done, best_chosen = best_trees(best_chosen, spec) + done, best_chosen = best_trees(best_chosen, spec, grammar) if done: final_samples.append(tree_to_string(best_chosen)) if not done: @@ -1775,6 +1775,8 @@ def generate_samples_random(grammar, new_input_specifications, num): return data +generate_samples = generate_samples_advanced + if __name__ == '__main__': generate_samples = generate_samples_advanced