Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3 #102

Merged
merged 94 commits into from
May 15, 2024
Merged

v0.3 #102

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
d26d98d
Add the Solver as an optional argument to the program iterator
Whebon Feb 25, 2024
c2f5225
Update heuristics to only search for VariableShapedHoles
Whebon Feb 25, 2024
4ad771f
Rewrite TopDownIteration for the Solver
Whebon Feb 25, 2024
a35ea2d
Move the creation of the Solver outside the iterator
Whebon Feb 26, 2024
696c54e
Add basic implementation of a `FixedShapedIterator`
Whebon Mar 1, 2024
50cc556
Add a test for the new Forbidden constraint
Whebon Mar 2, 2024
211e517
check if the solver state is still feasible after a tree manipulation
Whebon Mar 5, 2024
c45e9ce
Reduce the number of `save_state!` calls
Whebon Mar 6, 2024
6e8f6f9
Track the number of fixed shaped trees
Whebon Mar 7, 2024
6386396
Add tests for searches with the `Ordered` constraint
Whebon Mar 9, 2024
51aa284
Add tests for Forbidden
Whebon Mar 9, 2024
5f0b17f
Enable old tests
Whebon Mar 11, 2024
4a5dfec
Remove `test_context_sensitive_iterators`
Whebon Mar 11, 2024
ef2b51b
Rename `Solver` to `GenericSolver`
Whebon Mar 14, 2024
6639d3c
Add the `FixedShapedSolver` to the top down iterator
Whebon Mar 15, 2024
1d8296f
Pass the `SolverStatistics` object to the inner solver
Whebon Mar 18, 2024
f44eb0f
Add a test for a DomainRuleNode in a Forbidden Constraint
Whebon Mar 22, 2024
7f9a199
Add a test for a DomainRuleNode in an Ordered constraint
Whebon Mar 26, 2024
74592e4
Add a test for the `Contains` constraint
Whebon Mar 26, 2024
fcf8adc
Rename is_feasible
Whebon Mar 27, 2024
50238da
Grammar -> AbstractGrammar; Update version
THinnerichs Apr 3, 2024
213c816
Add the Solver as an optional argument to the program iterator
Whebon Feb 25, 2024
3c69357
Update heuristics to only search for VariableShapedHoles
Whebon Feb 25, 2024
774c096
Rewrite TopDownIteration for the Solver
Whebon Feb 25, 2024
3aee905
Move the creation of the Solver outside the iterator
Whebon Feb 26, 2024
6ba598d
Add basic implementation of a `FixedShapedIterator`
Whebon Mar 1, 2024
db6ec8a
Add a test for the new Forbidden constraint
Whebon Mar 2, 2024
c58227c
check if the solver state is still feasible after a tree manipulation
Whebon Mar 5, 2024
c962dc7
Reduce the number of `save_state!` calls
Whebon Mar 6, 2024
9652a00
Track the number of fixed shaped trees
Whebon Mar 7, 2024
e5e797b
Add tests for searches with the `Ordered` constraint
Whebon Mar 9, 2024
319ea4d
Add tests for Forbidden
Whebon Mar 9, 2024
2a92521
Enable old tests
Whebon Mar 11, 2024
032f1da
Remove `test_context_sensitive_iterators`
Whebon Mar 11, 2024
abd2b6d
Merge branch solver
THinnerichs Apr 3, 2024
c7d4b3a
Merge branch 'solver' into dfs-solver
THinnerichs Apr 3, 2024
a63cd1e
merge dfs-solver into dev
THinnerichs Apr 3, 2024
c730f97
Update `HerbCore` to v0.3.0
ReubenJ Apr 17, 2024
f16f655
Make the stochastic iterator compatible with the solver
Whebon Apr 4, 2024
32dd11f
Reorganise stochastic tests
Whebon Apr 5, 2024
32a233e
Rename `State` to `SolverState`
Whebon Apr 5, 2024
7100907
Remove `statefixedshapedhole2rulenode`. Let the iterator return `Stat…
Whebon Apr 5, 2024
88e3f83
Work in progress to fix stackoverflow. A bug in removenode.
nicolaefilat Apr 5, 2024
0cd625a
Typo in the test sampling
Whebon Apr 6, 2024
c685ea0
Fix minor bugs
Whebon Apr 6, 2024
3e85d00
Pass the `max_depth` to the BFSIterator in `enumerate_neighbours_prop…
Whebon Apr 6, 2024
6b4e8e9
Add `derivation_heuristic` and `RandomIterator`
Whebon Apr 6, 2024
3eb9b3e
Re-enqueue the `FixedShapedSolver` in the priority queue of the `TopD…
Whebon Apr 9, 2024
eb2a64c
Replace the `RandomSearchIterator` with a `RandomIterator` (that exte…
Whebon Apr 9, 2024
1869914
Rename according to HerbCore 3, bump version for HerbCore=0.3.0
Whebon Apr 10, 2024
cada97b
Merge pull request #82 from Herb-AI/stochastic-using-solver
ReubenJ Apr 18, 2024
b3ffbe6
Replace `collect(length(iter))` with `count_expressions(iter)`
Whebon Apr 23, 2024
3eb6ffc
Rename "variable shaped" to "non-uniform"
Whebon Apr 23, 2024
300e3ef
Move iteration out of the UniformSolver
Whebon Apr 24, 2024
3d4ee03
reverse the derivation heuristic
Whebon Apr 24, 2024
3440d6a
rename fixed_shaped to uniform
Whebon Apr 24, 2024
139c486
Refactor program iterator to have 3 constructors
nicolaefilat Apr 24, 2024
1112837
Refactored main code to use solver instead of the iterator to acccess…
nicolaefilat Apr 25, 2024
5bc88cc
Refactor tests to use the right iterator constructors
nicolaefilat Apr 25, 2024
3fc8cf7
The solver constructor also takes max_size and max_depth.
nicolaefilat Apr 25, 2024
a5267e6
Add max_depth and max_size to the "simple" constructor that only uses…
nicolaefilat Apr 25, 2024
27af9cd
Move the start_symbol function call outside of for loop that initiali…
nicolaefilat Apr 25, 2024
1151fa7
Refactor `count_expressions` to `Base.length`
Whebon Apr 25, 2024
c2013b9
Add a test for the fixed local ordered propagator (requires the `loca…
Whebon Apr 27, 2024
4c4fc84
Merge pull request #83 from Herb-AI/uniform-solver
ReubenJ Apr 30, 2024
c8cdb1c
Add a test for the ordered constraint
Whebon Apr 30, 2024
0348ab3
Change signature of `track!`
Whebon May 1, 2024
0e8145c
Add tests for the `Unique` and `ForbiddenSequence` constraints
Whebon May 2, 2024
99c5d06
Remove recursion from generate_branches
Whebon May 2, 2024
67b1a2d
Merge changed with 'dev'
nicolaefilat May 3, 2024
d556e41
Removed unused file
nicolaefilat May 3, 2024
7de357c
Merge pull request #84 from Herb-AI/program-iterator-refactor
ReubenJ May 6, 2024
234b6d1
Fix Base.iterate of the uniform iterator
Whebon May 6, 2024
1ae483f
Merge branch 'dev' of https://github.com/Herb-AI/HerbSearch.jl into dev
Whebon May 6, 2024
8a736d6
Remove imports in test
Whebon May 6, 2024
563a8ca
Remove imports in test 2
Whebon May 6, 2024
ec160f5
Remove TODOs
Whebon May 6, 2024
bd5f8a5
Merge branch 'forbidden-path' of https://github.com/Herb-AI/HerbSearc…
Whebon May 6, 2024
5bc6094
Merge branch 'dev' into forbidden-path
ReubenJ May 7, 2024
a807386
Merge pull request #93 from Herb-AI/forbidden-path
ReubenJ May 7, 2024
95e32ab
Add tests for `ContainsSubtree`
Whebon May 7, 2024
39d7203
Rewrite test for the ordered constraint with the `test_constraint!` h…
Whebon May 7, 2024
83f0cf1
Add tests for interaction between multiple constraints
Whebon May 8, 2024
cf1da81
Fix a bug related to nesting different propagate functions
Whebon May 8, 2024
d5f1cde
Merge branch 'dev' into contains-subtree
Whebon May 8, 2024
98b4249
Fix tests to work with the new @programiterator macro
Whebon May 8, 2024
c858944
Update Project.toml
ReubenJ May 14, 2024
40d91c5
Update Project.toml
ReubenJ May 14, 2024
4fe8ca8
Merge pull request #99 from Herb-AI/deps/bump-constraints
ReubenJ May 14, 2024
6378cae
Fix Constraints version number
ReubenJ May 14, 2024
c372f80
Merge branch 'dev' into contains-subtree
ReubenJ May 15, 2024
5651e49
Merge pull request #95 from Herb-AI/contains-subtree
ReubenJ May 15, 2024
498e27a
Update Project.toml
ReubenJ May 15, 2024
a43eb05
Update HerbInterpret compat
ReubenJ May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HerbSearch"
uuid = "3008d8e8-f9aa-438a-92ed-26e9c7b4829f"
authors = ["Sebastijan Dumancic <[email protected]>", "Jaap de Jong <[email protected]>", "Nicolae Filat <[email protected]>", "Piotr Cichoń <[email protected]>", "Tilman Hinnerichs <[email protected]>"]
version = "0.2.0"
version = "0.3.0"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand All @@ -17,11 +17,12 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
DataStructures = "0.17,0.18"
HerbConstraints = "^0.1.0"
HerbCore = "^0.2.0"
HerbGrammar = "^0.2.0"
HerbInterpret = "^0.1.1"
HerbConstraints = "^0.2.0"
HerbCore = "^0.3.0"
HerbGrammar = "^0.3.0"
HerbInterpret = "^0.1.3"
HerbSpecification = "^0.1.0"
MLStyle = "^0.4.17"
StatsBase = "^0.34"
julia = "^1.8"

Expand Down
13 changes: 11 additions & 2 deletions src/HerbSearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ using MLStyle
include("sampling_grammar.jl")

include("program_iterator.jl")
include("count_expressions.jl")
include("uniform_iterator.jl")

include("heuristics.jl")

include("fixed_shaped_iterator.jl")
include("top_down_iterator.jl")

include("evaluate.jl")
Expand All @@ -35,8 +36,9 @@ include("genetic_functions/crossover.jl")
include("genetic_functions/select_parents.jl")
include("genetic_search_iterator.jl")

include("random_iterator.jl")

export
count_expressions,
ProgramIterator,
@programiterator,

Expand All @@ -47,12 +49,19 @@ export
heuristic_random,
heuristic_smallest_domain,

derivation_heuristic,

synth,
SynthResult,
optimal_program,
suboptimal_program,

FixedShapedIterator,
UniformIterator,
next_solution!,

TopDownIterator,
RandomIterator,
BFSIterator,
DFSIterator,
MLFSIterator,
Expand Down
20 changes: 0 additions & 20 deletions src/count_expressions.jl

This file was deleted.

107 changes: 107 additions & 0 deletions src/fixed_shaped_iterator.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
Base.@doc """
@programiterator FixedShapedIterator()

Enumerates all programs that extend from the provided fixed shaped tree.
The [Solver](@ref) is required to be in a state without any [Hole](@ref)s.

!!! warning: this iterator is used as a baseline for the constraint propagation thesis. After the thesis, this iterator can (and should) be deleted.
""" FixedShapedIterator
@programiterator FixedShapedIterator()

"""
priority_function(::FixedShapedIterator, g::AbstractGrammar, tree::AbstractRuleNode, parent_value::Union{Real, Tuple{Vararg{Real}}})

Assigns a priority value to a `tree` that needs to be considered later in the search. Trees with the lowest priority value are considered first.
"""
function priority_function(

Check warning on line 16 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L16

Added line #L16 was not covered by tests
::FixedShapedIterator,
g::AbstractGrammar,
tree::AbstractRuleNode,
parent_value::Union{Real, Tuple{Vararg{Real}}}
)
parent_value + 1;

Check warning on line 22 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L22

Added line #L22 was not covered by tests
end


"""
hole_heuristic(::FixedShapedIterator, node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}

Defines a heuristic over fixed shaped holes. Returns a [`HoleReference`](@ref) once a hole is found.
"""
function hole_heuristic(::FixedShapedIterator, node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
return heuristic_leftmost_fixed_shaped_hole(node, max_depth);

Check warning on line 32 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L31-L32

Added lines #L31 - L32 were not covered by tests
end

"""
Base.iterate(iter::FixedShapedIterator)

Describes the iteration for a given [`TopDownIterator`](@ref) over the grammar. The iteration constructs a [`PriorityQueue`](@ref) first and then prunes it propagating the active constraints. Recursively returns the result for the priority queue.
"""
function Base.iterate(iter::FixedShapedIterator)

Check warning on line 40 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L40

Added line #L40 was not covered by tests
# Priority queue with number of nodes in the program
pq :: PriorityQueue{SolverState, Union{Real, Tuple{Vararg{Real}}}} = PriorityQueue()

Check warning on line 42 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L42

Added line #L42 was not covered by tests

solver = iter.solver
@assert !contains_nonuniform_hole(get_tree(iter.solver)) "A FixedShapedIterator cannot iterate partial programs with Holes"

Check warning on line 45 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L44-L45

Added lines #L44 - L45 were not covered by tests

if isfeasible(solver)
enqueue!(pq, get_state(solver), priority_function(iter, get_grammar(solver), get_tree(solver), 0))

Check warning on line 48 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L47-L48

Added lines #L47 - L48 were not covered by tests
end
return _find_next_complete_tree(solver, pq, iter)

Check warning on line 50 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L50

Added line #L50 was not covered by tests
end


"""
Base.iterate(iter::FixedShapedIterator, pq::DataStructures.PriorityQueue)

Describes the iteration for a given [`TopDownIterator`](@ref) and a [`PriorityQueue`](@ref) over the grammar without enqueueing new items to the priority queue. Recursively returns the result for the priority queue.
"""
function Base.iterate(iter::FixedShapedIterator, pq::DataStructures.PriorityQueue)
return _find_next_complete_tree(iter.solver, pq, iter)

Check warning on line 60 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L59-L60

Added lines #L59 - L60 were not covered by tests
end

"""
_find_next_complete_tree(solver::Solver, pq::PriorityQueue, iter::FixedShapedIterator)::Union{Tuple{RuleNode, PriorityQueue}, Nothing}

Takes a priority queue and returns the smallest AST from the grammar it can obtain from the queue or by (repeatedly) expanding trees that are in the queue.
Returns `nothing` if there are no trees left within the depth limit.
"""
function _find_next_complete_tree(

Check warning on line 69 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L69

Added line #L69 was not covered by tests
solver::Solver,
pq::PriorityQueue,
iter::FixedShapedIterator
)::Union{Tuple{RuleNode, PriorityQueue}, Nothing}
while length(pq) ≠ 0
(state, priority_value) = dequeue_pair!(pq)
load_state!(solver, state)

Check warning on line 76 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L74-L76

Added lines #L74 - L76 were not covered by tests

hole_res = hole_heuristic(iter, get_tree(solver), typemax(Int))
if hole_res ≡ already_complete

Check warning on line 79 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L78-L79

Added lines #L78 - L79 were not covered by tests
#the tree is complete
return (get_tree(solver), pq)
elseif hole_res ≡ limit_reached

Check warning on line 82 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L81-L82

Added lines #L81 - L82 were not covered by tests
# The maximum depth is reached
continue
elseif hole_res isa HoleReference

Check warning on line 85 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L84-L85

Added lines #L84 - L85 were not covered by tests
# UniformHole was found
(; hole, path) = hole_res

Check warning on line 87 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L87

Added line #L87 was not covered by tests

rules = findall(hole.domain)
number_of_rules = length(rules)
for (i, rule_index) ∈ enumerate(findall(hole.domain))
if i < number_of_rules
state = save_state!(solver)

Check warning on line 93 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L89-L93

Added lines #L89 - L93 were not covered by tests
end
@assert isfeasible(solver) "Attempting to expand an infeasible tree: $(get_tree(solver))"
remove_all_but!(solver, path, rule_index)
if isfeasible(solver)
enqueue!(pq, get_state(solver), priority_function(iter, get_grammar(solver), get_tree(solver), priority_value))

Check warning on line 98 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L95-L98

Added lines #L95 - L98 were not covered by tests
end
if i < number_of_rules
load_state!(solver, state)

Check warning on line 101 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L100-L101

Added lines #L100 - L101 were not covered by tests
end
end

Check warning on line 103 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L103

Added line #L103 was not covered by tests
end
end
return nothing

Check warning on line 106 in src/fixed_shaped_iterator.jl

View check run for this annotation

Codecov / codecov/patch

src/fixed_shaped_iterator.jl#L105-L106

Added lines #L105 - L106 were not covered by tests
end
12 changes: 7 additions & 5 deletions src/genetic_search_iterator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ Returns the best program within the population with respect to the fitness funct
function get_best_program(population::Array{RuleNode}, iter::GeneticSearchIterator)::RuleNode
best_program = nothing
best_fitness = 0
grammar = get_grammar(iter.solver)
for index ∈ eachindex(population)
chromosome = population[index]
zipped_outputs = zip([example.out for example in iter.spec], execute_on_input(iter.grammar, chromosome, [example.in for example in iter.spec]))
zipped_outputs = zip([example.out for example in iter.spec], execute_on_input(grammar, chromosome, [example.in for example in iter.spec]))
fitness_value = fitness(iter, chromosome, collect(zipped_outputs))
if isnothing(best_program)
best_fitness = fitness_value
Expand All @@ -137,13 +138,14 @@ Iterates the search space using a genetic algorithm. First generates a populatio
"""
function Base.iterate(iter::GeneticSearchIterator)
validate_iterator(iter)
grammar = iter.grammar
grammar = get_grammar(iter.solver)

population = Vector{RuleNode}(undef,iter.population_size)

start_symbol = get_starting_symbol(iter.solver)
for i in 1:iter.population_size
# sample a random nodes using start symbol and grammar
population[i] = rand(RuleNode, grammar, iter.sym, iter.maximum_initial_population_depth)
population[i] = rand(RuleNode, grammar, start_symbol, iter.maximum_initial_population_depth)
end
best_program = get_best_program(population, iter)
return (best_program, GeneticIteratorState(population))
Expand All @@ -160,7 +162,7 @@ function Base.iterate(iter::GeneticSearchIterator, current_state::GeneticIterato
current_population = current_state.population

# Calculate fitness
zipped_outputs(chromosome) = zip([example.out for example in iter.spec], execute_on_input(iter.grammar, chromosome, [example.in for example in iter.spec]))
zipped_outputs(chromosome) = zip([example.out for example in iter.spec], execute_on_input(get_grammar(iter.solver), chromosome, [example.in for example in iter.spec]))
fitness_array = [fitness(iter, chromosome, collect(zipped_outputs(chromosome))) for chromosome in current_population]

new_population = Vector{RuleNode}(undef,iter.population_size)
Expand All @@ -187,7 +189,7 @@ function Base.iterate(iter::GeneticSearchIterator, current_state::GeneticIterato
for chromosome in new_population
random_number = rand()
if random_number < iter.mutation_probability
mutate!(iter, chromosome, iter.grammar)
mutate!(iter, chromosome, get_grammar(iter.solver))
end
end

Expand Down
36 changes: 32 additions & 4 deletions src/heuristics.jl
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
using Random

"""
heuristic_leftmost_fixed_shaped_hole(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}

Defines a heuristic over [FixedShapeHole](@ref)s, where the left-most hole always gets considered first. Returns a [`HoleReference`](@ref) once a hole is found. This is the default option for enumerators.
"""
function heuristic_leftmost_fixed_shaped_hole(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
function leftmost(node::AbstractRuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
if max_depth == 0 return limit_reached end

Check warning on line 10 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L8-L10

Added lines #L8 - L10 were not covered by tests

for (i, child) in enumerate(node.children)
new_path = push!(copy(path), i)
hole_res = leftmost(child, max_depth-1, new_path)
if (hole_res == limit_reached) || (hole_res isa HoleReference)
return hole_res

Check warning on line 16 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L12-L16

Added lines #L12 - L16 were not covered by tests
end
end

Check warning on line 18 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L18

Added line #L18 was not covered by tests

return already_complete

Check warning on line 20 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L20

Added line #L20 was not covered by tests
end

function leftmost(hole::UniformHole, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
if max_depth == 0 return limit_reached end
return HoleReference(hole, path)

Check warning on line 25 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L23-L25

Added lines #L23 - L25 were not covered by tests
end

return leftmost(node, max_depth, Vector{Int}())

Check warning on line 28 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L28

Added line #L28 was not covered by tests
end


"""
heuristic_leftmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}

Defines a heuristic over holes, where the left-most hole always gets considered first. Returns a [`HoleReference`](@ref) once a hole is found. This is the default option for enumerators.
"""
function heuristic_leftmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
function leftmost(node::RuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
function leftmost(node::AbstractRuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
if max_depth == 0 return limit_reached end

for (i, child) in enumerate(node.children)
Expand Down Expand Up @@ -35,7 +63,7 @@
Defines a heuristic over holes, where the right-most hole always gets considered first. Returns a [`HoleReference`](@ref) once a hole is found.
"""
function heuristic_rightmost(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
function rightmost(node::RuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
function rightmost(node::AbstractRuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}

Check warning on line 66 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L66

Added line #L66 was not covered by tests
if max_depth == 0 return limit_reached end

for (i, child) in Iterators.reverse(enumerate(node.children))
Expand Down Expand Up @@ -64,7 +92,7 @@
Defines a heuristic over holes, where random holes get chosen randomly using random exploration. Returns a [`HoleReference`](@ref) once a hole is found.
"""
function heuristic_random(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
function random(node::RuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
function random(node::AbstractRuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}

Check warning on line 95 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L95

Added line #L95 was not covered by tests
if max_depth == 0 return limit_reached end

for (i, child) in shuffle(collect(enumerate(node.children)))
Expand Down Expand Up @@ -92,7 +120,7 @@
Defines a heuristic over all available holes in the unfinished AST, by considering the size of their respective domains. A domain here describes the number of possible derivations with respect to the constraints. Returns a [`HoleReference`](@ref) once a hole is found.
"""
function heuristic_smallest_domain(node::AbstractRuleNode, max_depth::Int)::Union{ExpandFailureReason, HoleReference}
function smallest_domain(node::RuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}
function smallest_domain(node::AbstractRuleNode, max_depth::Int, path::Vector{Int})::Union{ExpandFailureReason, HoleReference}

Check warning on line 123 in src/heuristics.jl

View check run for this annotation

Codecov / codecov/patch

src/heuristics.jl#L123

Added line #L123 was not covered by tests
if max_depth == 0 return limit_reached end

smallest_size::Int = typemax(Int)
Expand Down
Loading
Loading