Skip to content

Commit

Permalink
Merge pull request #77 from LaPlei96/master
Browse files Browse the repository at this point in the history
Grammar usage and import
  • Loading branch information
andreas-zeller authored Jan 16, 2025
2 parents 1c20f34 + 32d2c77 commit df687db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
12 changes: 8 additions & 4 deletions docs/code/Alhazen.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def task_sqrt(x):
from math import cos as rcos
from math import sin as rsin

from numpy import nanmax, isnan

if __name__ == '__main__':
"""
This file contains the code under test for the example bug.
Expand Down Expand Up @@ -1645,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 @@ -1716,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 @@ -1756,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 @@ -1773,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
8 changes: 4 additions & 4 deletions notebooks/Alhazen.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2745,11 +2745,11 @@
"metadata": {},
"outputs": [],
"source": [
"def best_trees(forest, spec):\n",
"def best_trees(forest, spec, grammar):\n",
" samples = [tree_to_string(tree) for tree in forest]\n",
" fulfilled_fractions= []\n",
" for sample in samples:\n",
" gen_features = collect_features([sample], CALC_GRAMMAR)\n",
" gen_features = collect_features([sample], grammar)\n",
"\n",
" # calculate percentage of fulfilled requirements (used to rank the sample)\n",
" fulfilled_count = 0\n",
Expand Down Expand Up @@ -2823,7 +2823,7 @@
" done = False\n",
" starttime = time.time()\n",
" best_chosen = [fuzzer.fuzz_tree() for _ in range(100)]\n",
" done, best_chosen = best_trees(best_chosen, spec)\n",
" done, best_chosen = best_trees(best_chosen, spec, grammar)\n",
" if done:\n",
" final_samples.append(tree_to_string(best_chosen))\n",
"\n",
Expand Down Expand Up @@ -2863,7 +2863,7 @@
" curr = s[0]\n",
" except SyntaxError:\n",
" pass\n",
" done, best_chosen = best_trees(best_chosen, spec)\n",
" done, best_chosen = best_trees(best_chosen, spec, grammar)\n",
" if done:\n",
" final_samples.append(tree_to_string(best_chosen))\n",
" if not done:\n",
Expand Down

0 comments on commit df687db

Please sign in to comment.