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

Remove notify_new_nodes for the UniformSolver #40

Open
Whebon opened this issue May 4, 2024 · 0 comments
Open

Remove notify_new_nodes for the UniformSolver #40

Whebon opened this issue May 4, 2024 · 0 comments

Comments

@Whebon
Copy link
Contributor

Whebon commented May 4, 2024

In the current implementation, the UniformSolver posts all possible LocalConstraints from scratch:

"""
    notify_new_nodes(node::AbstractRuleNode, path::Vector{Int})

Notify all grammar constraints about the `node` and its (grand)children
"""
function notify_new_nodes(solver::UniformSolver, node::AbstractRuleNode, path::Vector{Int})
    for (i, childnode)  enumerate(get_children(node))
        notify_new_nodes(solver, childnode, push!(copy(path), i))
    end
    solver.path_to_node[path] = node
    solver.node_to_path[node] = path
    for c  get_grammar(solver).constraints
        on_new_node(solver, c, path)
    end
end

on_new_node(solver, c, path) is responsible for creating a related local constraint.

Target implementation

UniformSolver is instantiated inside another search. The outer search already keeps track of a list of active local constraints. It would be more efficient to copy the list of active constraints from the outer solver instead of trying to post all constraints from scratch.

This can be achieved by accepting a Set{LocalConstraint} in the constructor of the UniformSolver.
And skipping posting new constraints (on_new_node(solver, c, path)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant