-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Herb-AI/dev
v0.3
- Loading branch information
Showing
34 changed files
with
1,634 additions
and
738 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -17,10 +17,10 @@ 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" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( | ||
::FixedShapedIterator, | ||
g::AbstractGrammar, | ||
tree::AbstractRuleNode, | ||
parent_value::Union{Real, Tuple{Vararg{Real}}} | ||
) | ||
parent_value + 1; | ||
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); | ||
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) | ||
# Priority queue with number of nodes in the program | ||
pq :: PriorityQueue{SolverState, Union{Real, Tuple{Vararg{Real}}}} = PriorityQueue() | ||
|
||
solver = iter.solver | ||
@assert !contains_nonuniform_hole(get_tree(iter.solver)) "A FixedShapedIterator cannot iterate partial programs with Holes" | ||
|
||
if isfeasible(solver) | ||
enqueue!(pq, get_state(solver), priority_function(iter, get_grammar(solver), get_tree(solver), 0)) | ||
end | ||
return _find_next_complete_tree(solver, pq, iter) | ||
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) | ||
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( | ||
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) | ||
|
||
hole_res = hole_heuristic(iter, get_tree(solver), typemax(Int)) | ||
if hole_res ≡ already_complete | ||
#the tree is complete | ||
return (get_tree(solver), pq) | ||
elseif hole_res ≡ limit_reached | ||
# The maximum depth is reached | ||
continue | ||
elseif hole_res isa HoleReference | ||
# UniformHole was found | ||
(; hole, path) = hole_res | ||
|
||
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) | ||
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)) | ||
end | ||
if i < number_of_rules | ||
load_state!(solver, state) | ||
end | ||
end | ||
end | ||
end | ||
return nothing | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
24c3600
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
24c3600
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/106867
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: