From d590aedc849eff19e31eed0ab65d336679580c18 Mon Sep 17 00:00:00 2001 From: Reuben Gardos Reid <5456207+ReubenJ@users.noreply.github.com> Date: Tue, 16 Apr 2024 17:17:15 +0200 Subject: [PATCH] `FixedShapedSolver` -> `UniformSolver` --- .../fixed_shaped_solver.jl | 26 +++++++++---------- .../state_fixed_shaped_hole.jl | 2 +- src/solver/generic_solver/generic_solver.jl | 10 +++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/solver/fixed_shaped_solver/fixed_shaped_solver.jl b/src/solver/fixed_shaped_solver/fixed_shaped_solver.jl index 7bee7fb..5dfc7d1 100644 --- a/src/solver/fixed_shaped_solver/fixed_shaped_solver.jl +++ b/src/solver/fixed_shaped_solver/fixed_shaped_solver.jl @@ -33,7 +33,7 @@ end """ UniformSolver(grammar::AbstractGrammar, fixed_shaped_tree::AbstractRuleNode) """ -function FixedShapedSolver(grammar::AbstractGrammar, fixed_shaped_tree::AbstractRuleNode; with_statistics=false, derivation_heuristic=nothing) +function UniformSolver(grammar::AbstractGrammar, fixed_shaped_tree::AbstractRuleNode; with_statistics=false, derivation_heuristic=nothing) @assert !contains_nonuniform_hole(fixed_shaped_tree) "$(fixed_shaped_tree) contains non-uniform holes" sm = StateManager() tree = StateHole(sm, fixed_shaped_tree) @@ -50,8 +50,8 @@ function FixedShapedSolver(grammar::AbstractGrammar, fixed_shaped_tree::Abstract ::Bool => with_statistics ? SolverStatistics("UniformSolver") : nothing ::Nothing => nothing end - if !isnothing(statistics) statistics.name = "FixedShapedSolver" end - solver = FixedShapedSolver(grammar, sm, tree, unvisited_branches, path_to_node, node_to_path, isactive, canceledconstraints, nsolutions, true, schedule, fix_point_running, statistics, derivation_heuristic) + if !isnothing(statistics) statistics.name = "UniformSolver" end + solver = UniformSolver(grammar, sm, tree, unvisited_branches, path_to_node, node_to_path, isactive, canceledconstraints, nsolutions, true, schedule, fix_point_running, statistics, derivation_heuristic) notify_new_nodes(solver, tree, Vector{Int}()) fix_point!(solver) if isfeasible(solver) @@ -80,11 +80,11 @@ end """ - get_path(solver::FixedShapedSolver, node::AbstractRuleNode) + get_path(solver::UniformSolver, node::AbstractRuleNode) Get the path at which the `node` is located. """ -function HerbCore.get_path(solver::FixedShapedSolver, node::AbstractRuleNode)::Vector{Int} +function HerbCore.get_path(solver::UniformSolver, node::AbstractRuleNode)::Vector{Int} return solver.node_to_path[node] end @@ -132,11 +132,11 @@ end """ - deactivate!(solver::FixedShapedSolver, constraint::AbstractLocalConstraint) + deactivate!(solver::UniformSolver, constraint::AbstractLocalConstraint) Function that should be called whenever the constraint is already satisfied and never has to be repropagated. """ -function deactivate!(solver::FixedShapedSolver, constraint::AbstractLocalConstraint) +function deactivate!(solver::UniformSolver, constraint::AbstractLocalConstraint) if constraint ∈ keys(solver.schedule) # remove the constraint from the schedule track!(solver.statistics, "deactivate! removed from schedule") @@ -155,12 +155,12 @@ end """ - post!(solver::FixedShapedSolver, constraint::AbstractLocalConstraint) + post!(solver::UniformSolver, constraint::AbstractLocalConstraint) Post a new local constraint. Converts the constraint to a state constraint and schedules it for propagation. """ -function post!(solver::FixedShapedSolver, constraint::AbstractLocalConstraint) +function post!(solver::UniformSolver, constraint::AbstractLocalConstraint) if !isfeasible(solver) return end # initial propagation of the new constraint propagate!(solver, constraint) @@ -210,7 +210,7 @@ end Function to be called if any inconsistency has been detected """ -function set_infeasible!(solver::FixedShapedSolver) +function set_infeasible!(solver::UniformSolver) solver.isfeasible = false end @@ -274,13 +274,13 @@ end """ - next_solution!(solver::FixedShapedSolver)::Union{RuleNode, StateHole, Nothing} + next_solution!(solver::UniformSolver)::Union{RuleNode, StateHole, Nothing} Built-in iterator. Search for the next unvisited solution. Returns nothing if all solutions have been found already. """ -function next_solution!(solver::FixedShapedSolver)::Union{RuleNode, StateHole, Nothing} - if solver.nsolutions == 1000000 @warn "FixedShapedSolver is iterating over more than 1000000 solutions..." end +function next_solution!(solver::UniformSolver)::Union{RuleNode, StateHole, Nothing} + if solver.nsolutions == 1000000 @warn "UniformSolver is iterating over more than 1000000 solutions..." end if solver.nsolutions > 0 # backtrack from the previous solution restore!(solver) diff --git a/src/solver/fixed_shaped_solver/state_fixed_shaped_hole.jl b/src/solver/fixed_shaped_solver/state_fixed_shaped_hole.jl index 8d20c4e..bf0ef3f 100644 --- a/src/solver/fixed_shaped_solver/state_fixed_shaped_hole.jl +++ b/src/solver/fixed_shaped_solver/state_fixed_shaped_hole.jl @@ -1,7 +1,7 @@ """ StateHole <: AbstractUniformHole -`StateHole`s are uniform holes used by the `FixedShapedSolver`. Domain manipulations are tracked for backpropagation. +`StateHole`s are uniform holes used by the `UniformSolver`. Domain manipulations are tracked for backpropagation. - `domain`: A `StateSparseSet` representing the rule nodes this hole can take. If size(domain) == 1, this hole should act like a `RuleNode` - `children`: The children of this hole in the expression tree. """ diff --git a/src/solver/generic_solver/generic_solver.jl b/src/solver/generic_solver/generic_solver.jl index 9835625..f4859a3 100644 --- a/src/solver/generic_solver/generic_solver.jl +++ b/src/solver/generic_solver/generic_solver.jl @@ -18,7 +18,7 @@ mutable struct GenericSolver <: Solver state::Union{SolverState, Nothing} schedule::PriorityQueue{AbstractLocalConstraint, Int} statistics::Union{SolverStatistics, Nothing} - use_fixedshapedsolver::Bool + use_uniformsolver::Bool fix_point_running::Bool max_size::Int max_depth::Int @@ -30,9 +30,9 @@ end Constructs a new solver, with an initial state using starting symbol `sym` """ -function GenericSolver(grammar::AbstractGrammar, sym::Symbol; with_statistics=false, use_fixedshapedsolver=true) +function GenericSolver(grammar::AbstractGrammar, sym::Symbol; with_statistics=false, use_uniformsolver=true) init_node = Hole(get_domain(grammar, sym)) - GenericSolver(grammar, init_node, with_statistics=with_statistics, use_fixedshapedsolver=use_fixedshapedsolver) + GenericSolver(grammar, init_node, with_statistics=with_statistics, use_uniformsolver=use_uniformsolver) end @@ -41,9 +41,9 @@ end Constructs a new solver, with an initial state of the provided [`AbstractRuleNode`](@ref). """ -function GenericSolver(grammar::AbstractGrammar, init_node::AbstractRuleNode; with_statistics=false, use_fixedshapedsolver=true) +function GenericSolver(grammar::AbstractGrammar, init_node::AbstractRuleNode; with_statistics=false, use_uniformsolver=true) stats = with_statistics ? SolverStatistics("GenericSolver") : nothing - solver = GenericSolver(grammar, nothing, PriorityQueue{AbstractLocalConstraint, Int}(), stats, use_fixedshapedsolver, false, typemax(Int), typemax(Int)) + solver = GenericSolver(grammar, nothing, PriorityQueue{AbstractLocalConstraint, Int}(), stats, use_uniformsolver, false, typemax(Int), typemax(Int)) new_state!(solver, init_node) return solver end