Skip to content

Commit

Permalink
ugly fix to run Alhazen
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura authored and Laura committed Jan 15, 2025
1 parent f323351 commit 32d2c77
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions docs/code/Alhazen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit 32d2c77

Please sign in to comment.