Skip to content

Commit

Permalink
FixedShapedSolver -> UniformSolver
Browse files Browse the repository at this point in the history
  • Loading branch information
ReubenJ committed Apr 18, 2024
1 parent 11a4510 commit d590aed
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
26 changes: 13 additions & 13 deletions src/solver/fixed_shaped_solver/fixed_shaped_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/solver/fixed_shaped_solver/state_fixed_shaped_hole.jl
Original file line number Diff line number Diff line change
@@ -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.
"""
Expand Down
10 changes: 5 additions & 5 deletions src/solver/generic_solver/generic_solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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
Expand Down

0 comments on commit d590aed

Please sign in to comment.