HerbConstraints.jl Documentation

HerbConstraints.AbstractLocalConstraintType
abstract type AbstractLocalConstraint <: AbstractConstraint

Abstract type representing all local constraints. Each local constraint contains a path that points to a specific location in the tree at which the constraint applies.

Each local constraint should implement a propagate!-function. Inside the propagate! function, the constraint can use the following solver functions:

  • remove!: Elementary tree manipulation. Removes a value from a domain. (other tree manipulations are: remove_above!, remove_below!, remove_all_but!)
  • deactivate!: Prevent repropagation. Call this as soon as the constraint is satisfied.
  • set_infeasible!: Report a non-trivial inconsistency. Call this if the constraint can never be satisfied. An empty domain is considered a trivial inconsistency, such inconsistencies are already handled by tree manipulations.
  • isfeasible: Check if the current tree is still feasible. Return from the propagate function, as soon as infeasibility is detected.
source
HerbConstraints.AbstractStateManagerType

Manages all changes made to StateInts using StateIntBackups. Support the following functions:

  • StateInt Creates a new stateful integer
  • save_state! Creates a checkpoint for all stateful integers
  • restore! Restores the values to the latest checkpoint
source
HerbConstraints.ContainsType

Contains <: AbstractGrammarConstraint This [AbstractGrammarConstraint] enforces that a given rule appears in the program tree at least once.

source
HerbConstraints.ContainsSubtreeType
ContainsSubtree <: AbstractGrammarConstraint

This [AbstractGrammarConstraint] enforces that a given subtree appears in the program tree at least once.

!!! warning: This constraint can only be propagated by the UniformSolver

source
HerbConstraints.DomainRuleNodeType
struct DomainRuleNode <: AbstractRuleNode

Matches any 1 rule in its domain. Example usage:

DomainRuleNode(Bitvector((0, 0, 1, 1)), [RuleNode(1), RuleNode(1)])

This matches RuleNode(3, [RuleNode(1), RuleNode(1)]) and RuleNode(4, [RuleNode(1), RuleNode(1)]) and UniformHole({3, 4}, [RuleNode(1), RuleNode(1)])

source
HerbConstraints.ForbiddenType
Forbidden <: AbstractGrammarConstraint

This [AbstractGrammarConstraint] forbids any subtree that matches the pattern given by tree to be generated. A pattern is a tree of AbstractRuleNodes. Such a node can either be a RuleNode, which contains a rule index corresponding to the rule index in the AbstractGrammar and the appropriate number of children, similar to RuleNodes. It can also contain a VarNode, which contains a single identifier symbol. A VarNode can match any subtree, but if there are multiple instances of the same variable in the pattern, the matched subtrees must be identical. Any rule in the domain that makes the match attempt successful is removed.

For example, consider the tree 1(a, 2(b, 3(c, 4)))):

  • Forbidden(RuleNode(3, [RuleNode(5), RuleNode(4)])) forbids c to be filled with 5.
  • Forbidden(RuleNode(3, [VarNode(:v), RuleNode(4)])) forbids c to be filled, since a [VarNode] can match any rule, thus making the match attempt successful for the entire domain of c. Therefore, this tree invalid.
  • Forbidden(RuleNode(3, [VarNode(:v), VarNode(:v)])) forbids c to be filled with 4, since that would make both assignments to v equal, which causes a successful match.
source
HerbConstraints.ForbiddenSequenceType
ForbiddenPath <: AbstractGrammarConstraint

This [AbstractGrammarConstraint] forbids the given sequence of rule nodes. Sequences are strictly vertical and may include gaps. Consider the tree 1(a, 2(b, 3(c, d)))):

  • [2, 3, d] is a sequence
  • [1, 3, d] is a sequence
  • [3, c, d] is not a sequence

Examples:

  • ForbiddenSequence([3, 4]) enforces that rule 4 cannot be applied at c or d.
  • ForbiddenSequence([1, 2, 4]) enforces that rule 4 cannot be applied at b, c or d.
  • ForbiddenSequence([1, 4]) enforces that rule 4 cannot be applied anywhere.

If any of the rules in ignore_if appears in the sequence, the constraint is ignored. Suppose the forbidden sequence = [1, 2, 3] and ignore_if = [99] Consider the following paths from the root:

  • [1, 2, 2, 3] is forbidden, as the sequence does not contain 99
  • [1, 99, 2, 3] is NOT forbidden, as the sequence does contain 99
  • [1, 99, 1, 2, 3] is forbidden, as there is a subsequence that does not contain 99
source
HerbConstraints.GenericSolverType
GenericSolver

Maintains a feasible partial program in a SolverState. A ProgramIterator may manipulate the partial tree with the following tree manipulations:

  • substitute!
  • remove!
  • remove_below!
  • remove_above!
  • remove_all_but!

Each SolverState holds an independent propagation program. Program iterators can freely move back and forth between states using:

  • new_state!
  • save_state!
  • load_state!
source
HerbConstraints.LessThanOrEqualSoftFailType
struct LessThanOrEqualSoftFail <: LessThanOrEqualResult

node1 <= node2 and node1 > node2 are both possible depending on the assignment of hole1 and hole2. Includes two cases:

  • hole2::AbstractHole: A failed AbstractHole-AbstractHole comparison. (e.g. AbstractHole(BitVector((1, 0, 1))) vs AbstractHole(BitVector((0, 1, 1))))
  • hole2::Nothing: A failed AbstractHole-RuleNode comparison. (e.g. AbstractHole(BitVector((1, 0, 1))) vs RuleNode(2))
source
HerbConstraints.LessThanOrEqualSuccessWithHolesType
struct LessThanOrEqualSuccessWithHoles <: LessThanOrEqualSuccess end

node1 <= node2 is guaranteed under all possible assignments of the holes involved. Because of the holes involved, it is not possible to specify '<' or '=='.

source
HerbConstraints.LocalContainsSubtreeType

LocalContains

Enforces that a given tree appears at or below the given path at least once.

!!! warning: This is a stateful constraint can only be propagated by the UniformSolver. The indices and candidates fields should not be set by the user.

source
HerbConstraints.LocalForbiddenType
LocalForbidden

Forbids the a subtree that matches the tree to be generated at the location provided by the path. Use a Forbidden constraint for enforcing this throughout the entire search space.

source
HerbConstraints.LocalForbiddenSequenceType
LocalForbiddenSequence <: AbstractLocalConstraint

Forbids the given sequence of rule nodes ending at the node at the path. If any of the rules in ignore_if appears in the sequence, the constraint is ignored.

source
HerbConstraints.LocalOrderedType

Enforces an order over two or more subtrees that fill the variables specified in order when the pattern is applied at the location given by path. Use an Ordered constraint for enforcing this throughout the entire search space.

source
HerbConstraints.LocalUniqueType
LocalUnique <: AbstractLocalConstraint

Enforces that a given rule appears at or below the given path at most once. In case of the UniformSolver, cache the list of holes, since no new holes can appear.

source
HerbConstraints.MakeEqualSoftFailType
struct MakeEqualSoftFail <: MakeEqualResult end

Making node1 == node2 is ambiguous. Examples:

  • RuleNode(1, [Hole({1, 2, 3})]) == RuleNode(1, [VarNode(:a)]). The hole can be filled with any rule.
  • Hole({1, 2, 3}) == DomainRuleNode({1, 2, 3}). The hole can be filled with any rule.
source
HerbConstraints.OrderedType
Ordered <: AbstractGrammarConstraint

A AbstractGrammarConstraint that enforces a specific order in MatchVar assignments in the pattern defined by tree. Nodes in the pattern can either be a RuleNode, which contains a rule index corresponding to the rule index in the AbstractGrammar and the appropriate number of children. It can also contain a VarNode, which contains a single identifier symbol. A VarNode can match any subtree. If there are multiple instances of the same variable in the pattern, the matched subtrees must be identical.

The order defines an order between the variable assignments. For example, if the order is [x, y], the constraint will require the assignment to x to be less than or equal to the assignment to y. The order is recursively defined by RuleNode indices. For more information, see Base.isless(rn₁::AbstractRuleNode, rn₂::AbstractRuleNode).

For example, consider the tree 1(a, 2(b, 3(c, 4)))):

  • Ordered(RuleNode(3, [VarNode(:v), VarNode(:w)]), [:v, :w]) removes every rule with an index of 5 or greater from the domain of c, since that would make the index of the assignment to v greater than the index of the assignment to w, violating the order.
  • Ordered(RuleNode(3, [VarNode(:v), VarNode(:w)]), [:w, :v]) removes every rule with an index of 4 or less from the domain of c, since that would make the index of the assignment to v less than the index of the assignment to w, violating the order.
source
HerbConstraints.PatternMatchSoftFailType

The pattern can still be matched in a non-trivial way. Includes two cases:

  • multiple holes are involved. this result stores a reference to one of them
  • a single hole is involved, but needs to be filled with a node of size >= 2
source
HerbConstraints.SolverType
abstract type Solver

Abstract constraint solver. Each solver should have at least the following fields:

  • statistics::SolverStatistics
  • fix_point_running::Bool
  • schedule::PriorityQueue{AbstractLocalConstraint, Int}

Each solver should implement at least:

  • post!
  • get_tree
  • get_grammar
  • set_infeasible!
  • isfeasible
  • HerbCore.get_node_at_location
  • get_hole_at_location
  • notify_tree_manipulation
  • deactivate!
source
HerbConstraints.SolverStateType
mutable struct SolverState

A state to be solved by the GenericSolver. A state contains of:

  • tree: A partial AST
  • active_constraints: The local constraints that apply to this tree. These constraints are enforced each time the tree is modified.
  • isfeasible: Flag to indicate if this state is still feasible. When a propagator spots an inconsistency, this field will be set to false. Tree manipulations and further propagations are not allowed on infeasible states
source
HerbConstraints.StateHoleType
StateHole <: AbstractUniformHole

StateHoles 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.
source
HerbConstraints.StateSparseSetMethod

Converts a BitVector domain representation to a StateSparseSet Example:

set = StateSparseSet(sm, BitVector((1, 1, 0, 0, 1, 0, 0))) #{1, 2, 5}
source
HerbConstraints.UniqueType
Unique <: AbstractGrammarConstraint

This [AbstractGrammarConstraint] enforces that a given rule appears in the program tree at most once.

source
HerbConstraints.VarNodeType
struct VarNode <: AbstractRuleNode

Matches any subtree and assigns it to a variable name. The LocalForbidden constraint will not match if identical variable symbols match to different trees. Example usage:

RuleNode(3, [VarNode(:x), VarNode(:x)])

This matches RuleNode(3, [RuleNode(1), RuleNode(1)]), RuleNode(3, [RuleNode(2), RuleNode(2)]), etc. but also larger subtrees such as RuleNode(3, [RuleNode(4, [RuleNode(1)]), RuleNode(4, [RuleNode(1)])])

source
HerbConstraints.@csgrammar_annotatedMacro

@csgrammar_annotated Define an annotated grammar and return it as a ContextSensitiveGrammar. Allows for adding optional annotations per rule. As well as that, allows for adding optional labels per rule, which can be referenced in annotations. Syntax is backwards-compatible with @csgrammar. Examples:

g₁ = @csgrammar_annotated begin
    Element = 1
    Element = x
    Element = Element + Element := commutative
    Element = Element * Element := (commutative, transitive)
end
g₁ = @csgrammar_annotated begin
    Element = 1
    Element = x
    Element = Element + Element := forbidden_path([3, 1])
    Element = Element * Element := (commutative, transitive)
end
g₁ = @csgrammar_annotated begin
    one::            Element = 1
    variable::       Element = x
    addition::       Element = Element + Element := (
                                                       commutative,
                                                       transitive,
                                                       forbidden_path([:addition, :one]) || forbidden_path([:one, :variable])
                                                    )
    multiplication:: Element = Element * Element := (commutative, transitive)
end
source
Base.collectMethod
function Base.collect(stack::StateStack)

Return the internal Vector representation of the stack. !!! warning: The returned vector is read-only.

source
Base.findfirstMethod

Returns the minimum value in the set. This function name is used instead of min to allow code reuse for domains of type BitVector and StateSparseSet.

source
Base.findlastMethod

Returns the maximum value in the set. This function name is used instead of min to allow code reuse for domains of type BitVector and StateSparseSet.

source
Base.getindexMethod

Checks if value val is in StateSparseSet s. !!! warning: This allows a StateSparseSet to be used as if it were a BitVector representation of a set

source
Base.inMethod

Checks if value val is in StateSparseSet s.

source
Base.inMethod
function Base.in(stack::StateStack, value)::Bool

Checks whether the value is in the stack.

source
Base.push!Method
function Base.push!(stack::StateStack, item)

Place an item on top of the stack.

source
Base.sizeMethod

Returns the number of values in the StateSparseSet.

source
Base.sizeMethod
function Base.size(stack::StateStack)

Get the current size of the stack.

source
Base.sumMethod

Returns the number of values in the StateSparseSet. !!! warning: This is not actually the sum of the set. It is the length of the set. This allows a StateSparseSet to be used as if it were a BitVector representation of a set

source
HerbConstraints._containsMethod
_contains(node::AbstractRuleNode, rule::Int)::Bool

Recursive helper function for the LocalContains constraint Returns one of the following:

  • true, if the node does contains the rule
  • false, if the node does not contain the rule
  • Vector{AbstractHole}, if the node contains the rule if one the holes gets filled with the target rule
source
HerbConstraints._count_occurrences!Method
function _count_occurrences!(node::AbstractRuleNode, rule::Int, holes::Vector{AbstractHole})::Int

Recursive helper function for the LocalUnique constraint. Returns the number of certain occurrences of the rule in the tree. All holes that potentially can hold the target rule are stored in the holes vector.

!!! warning: Stops counting if the rule occurs more than once. Counting beyond 2 is not needed for LocalUnique.

source
HerbConstraints._count_occurrencesMethod
function _count_occurrences(holes::Vector{AbstractHole}, rule::Int)

Counts the occurences of the rule in the cached list of holes.

!!! warning: Stops counting if the rule occurs more than once. Counting beyond 2 is not needed for LocalUnique.

source
HerbConstraints._update_bounds_val_removed!Method

This function should be called whenever the minimum or maximum value from the set might have been removed. The minimum and maximum value of the set will be updated to the actual bounds of the set.

source
HerbConstraints._update_max_val_removed!Method

This function should be called whenever the maximum value from the set might have been removed. The maximum value of the set will be updated to the actual maximum of the set.

source
HerbConstraints._update_min_val_removed!Method

This function should be called whenever the minimum value from the set might have been removed. The minimum value of the set will be updated to the actual minimum of the set.

source
HerbConstraints.annotation2constraintMethod

Converts an annotation to a constraint. commutative: creates an Ordered constraint transitive: creates an (incorrect) Forbidden constraint forbidden_path(path::Vector{Union{Symbol, Int}}): creates a ForbiddenPath constraint with the original rule included ... || ...: creates a OneOf constraint (also works with ... || ... || ... et cetera, though not very performant)

source
HerbConstraints.are_disjointMethod
are_disjoint(domain1::BitVector, domain2::BitVector)::Bool

Returns true if there is no overlap in values between domain1 and domain2

source
HerbConstraints.backup!Method

Should be called whenever the state of a StateInt is modified. Creates a StateIntBackup for the given StateInt. Only backup the value if this integer has not been stored during this state before Example usecase:

a = StateInt(sm, 10)
save_state!(sm)
set_value!(a, 9) #backup value 10
set_value!(a, 8) #no need to backup again
set_value!(a, 3) #no need to backup again
restore!(sm) #restores a to value 10
source
HerbConstraints.deactivate!Method
deactivate!(solver::GenericSolver, constraint::AbstractLocalConstraint)

Function that should be called whenever the constraint is already satisfied and never has to be repropagated.

source
HerbConstraints.deactivate!Method
deactivate!(solver::UniformSolver, constraint::AbstractLocalConstraint)

Function that should be called whenever the constraint is already satisfied and never has to be repropagated.

source
HerbConstraints.freeze_stateMethod
freeze_state(hole::StateHole)::RuleNode

Converts a [StateHole])(@ref) to a [RuleNode]@(ref). The hole and its children are assumed to be filled.

source
HerbConstraints.get_nodes_on_pathMethod
function get_nodes_on_path(root::AbstractRuleNode, path::Vector{Int})::Vector{AbstractRuleNode}

Gets a list of nodes on the path, starting (and including) the root.

source
HerbConstraints.get_priorityMethod
function get_priority(::AbstractLocalConstraint)

Used to determine which constraint to propagate first in fix_point!. Constraints with fast propagators and/or strong inference should be propagated first.

source
HerbConstraints.get_treeMethod
function get_tree(solver::UniformSolver)::AbstractRuleNode

Get the root of the tree. This remains the same instance throughout the entire search.

source
HerbConstraints.is_subdomainMethod
is_subdomain(specific_tree::AbstractRuleNode, general_tree::AbstractRuleNode)

Checks if the specific_tree can be obtained by repeatedly removing values from the general_tree

source
HerbConstraints.is_subdomainMethod
 is_subdomain(subdomain::BitVector, domain::BitVector)
 is_subdomain(subdomain::StateSparseSet, domain::BitVector)

Checks if subdomain is a subdomain of domain. Example: [0, 0, 1, 0] is a subdomain of [0, 1, 1, 1]

source
HerbConstraints.isfeasibleMethod
isfeasible(solver::GenericSolver)

Returns true if no inconsistency has been detected. Used in several ways:

  • Iterators should check for infeasibility to discard infeasible states
  • After any tree manipulation with the possibility of an inconsistency (e.g. remove_below!, remove_above!, remove!)
  • fix_point! should check for infeasibility to clear its schedule and return
  • Some GenericSolver functions assert a feasible state for debugging purposes @assert isfeasible(solver)
  • Some GenericSolver functions have a guard that skip the function on an infeasible state: if !isfeasible(solver) return end
source
HerbConstraints.make_equal!Method
function make_equal!(solver::Solver, node1::AbstractRuleNode, node2::AbstractRuleNode)::MakeEqualResult

Tree manipulation that enforces node1 == node2 if unambiguous.

source
HerbConstraints.make_less_than_or_equal!Method
function make_less_than_or_equal!(h1::Union{RuleNode, AbstractHole}, h2::Union{RuleNode, AbstractHole}, guards::Vector{Tuple{AbstractHole, Int}})::LessThanOrEqualResult

Helper function that keeps track of the guards

source
HerbConstraints.make_less_than_or_equal!Method
function make_less_than_or_equal!(h1::Union{RuleNode, AbstractHole}, h2::Union{RuleNode, AbstractHole})::LessThanOrEqualResult

Ensures that n1<=n2 by removing impossible values from holes. Returns one of the following results:

source
HerbConstraints.make_less_than_or_equal!Method
function make_less_than_or_equal!(solver::Solver, nodes1::Vector{AbstractRuleNode}, nodes2::Vector{AbstractRuleNode}, guards::Vector{Tuple{AbstractHole, Int}})::LessThanOrEqualResult

Helper function that tiebreaks on children.

source
HerbConstraints.new_state!Method
new_state!(solver::GenericSolver, tree::AbstractRuleNode)

Overwrites the current state and propagates constraints on the tree from the ground up

source
HerbConstraints.notify_new_nodeMethod
notify_new_node(solver::GenericSolver, event_path::Vector{Int})

Notify all constraints that a new node has appeared at the event_path by calling their respective on_new_node function.

Warning

This does not notify the solver about nodes below the event_path. In that case, call notify_new_nodes instead.

source
HerbConstraints.notify_new_nodesMethod
notify_new_nodes(solver::GenericSolver, node::AbstractRuleNode, path::Vector{Int})

Notify all grammar constraints about the new node and its (grand)children

source
HerbConstraints.notify_new_nodesMethod
notify_new_nodes(solver::UniformSolver, node::AbstractRuleNode, path::Vector{Int})

Notify all grammar constraints about the new node and its (grand)children

source
HerbConstraints.notify_tree_manipulationMethod
notify_tree_manipulation(solver::GenericSolver, event_path::Vector{Int})

Notify subscribed constraints that a tree manipulation has occured at the event_path by scheduling them for propagation

source
HerbConstraints.notify_tree_manipulationMethod
notify_tree_manipulation(solver::UniformSolver, event_path::Vector{Int})

Notify subscribed constraints that a tree manipulation has occured at the event_path by scheduling them for propagation

source
HerbConstraints.pattern_matchMethod

Generic fallback function for commutativity. Swaps arguments 1 and 2, then dispatches to a more specific signature. If this gets stuck in an infinite loop, the implementation of an AbstractRuleNode type pair is missing.

source
HerbConstraints.pattern_matchMethod
pattern_match(h1::Union{RuleNode, AbstractHole}, h2::Union{RuleNode, AbstractHole}, vars::Dict{Symbol, AbstractRuleNode})::PatternMatchResult

Comparing any pair of Rulenode and/or AbstractHole. It is important to note that some AbstractHoles are already filled and should be treated as RuleNode. This is why this function is dispatched on (isfilled(h1), isfilled(h2)). The '(RuleNode, AbstractHole)' case could still include two nodes of type AbstractHole, but one of them should be treated as a rulenode.

source
HerbConstraints.pattern_matchMethod
pattern_match(rns::Vector{AbstractRuleNode}, mns::Vector{AbstractRuleNode}, vars::Dict{Symbol, AbstractRuleNode})::PatternMatchResult

Pairwise tries to match two ordered lists of AbstractRuleNodes. Typically, this function is used to pattern match the children two AbstractRuleNodes.

source
HerbConstraints.post!Method
post!(solver::GenericSolver, constraint::AbstractLocalConstraint)

Imposes the constraint to the current state. By default, the constraint will be scheduled for its initial propagation. Constraints can overload this method to add themselves to notify lists or triggers.

source
HerbConstraints.post!Method
post!(solver::UniformSolver, constraint::AbstractLocalConstraint)

Post a new local constraint. Converts the constraint to a state constraint and schedules it for propagation.

source
HerbConstraints.propagate!Method
function propagate!(::GenericSolver, ::LocalContainsSubtree)

!!! warning: LocalContainsSubtree uses stateful properties and can therefore not be propagated in the GenericSolver. (The GenericSolver shares constraints among different states, so they cannot use stateful properties)

source
HerbConstraints.propagate!Method
function propagate!(solver::Solver, c::LocalContains)

Enforce that the rule appears at or below the path at least once. Uses a helper function to retrieve a list of holes that can potentially hold the target rule. If there is only a single hole that can potentially hold the target rule, that hole will be filled with that rule.

source
HerbConstraints.propagate!Method
function propagate!(solver::Solver, c::LocalOrdered)

Enforce that the VarNodes in the tree are in the specified order. First the node located at the path is matched to see if the ordered constraint applies here. The nodes matching the variables are stored in the vars dictionary. Then the order is enforced within the make_less_than_or_equal! tree manipulation.

source
HerbConstraints.propagate!Method
function propagate!(solver::Solver, c::LocalUnique)

Enforce that the rule appears at or below the path at least once. Uses a helper function to retrieve a list of holes that can potentially hold the target rule. If there is only a single hole that can potentially hold the target rule, that hole will be filled with that rule.

source
HerbConstraints.propagate!Method
function propagate!(solver::UniformSolver, c::LocalContainsSubtree)

Enforce that the tree appears at or below the path at least once. Nodes that can potentially become the target sub-tree are considered candidates. In case of multiple candidates, a stateful set of indices is used to keep track of active candidates.

source
HerbConstraints.remove!Method
remove!(solver::GenericSolver, path::Vector{Int}, rule_index::Int)

Remove rule_index from the domain of the hole located at the path. It is assumed the path points to a hole, otherwise an exception will be thrown.

source
HerbConstraints.remove!Method
remove!(solver::GenericSolver, path::Vector{Int}, rules::Vector{Int})

Remove all rules from the domain of the hole located at the path. It is assumed the path points to a hole, otherwise an exception will be thrown.

source
HerbConstraints.remove!Method
remove!(set::StateSparseSet, val::Int)

Removes value val from StateSparseSet set. Returns true if val was in set.

source
HerbConstraints.remove!Method
remove!(solver::Solver, path::Vector{Int}, rule_index::Int)

Remove rule_index from the domain of the hole located at the path. It is assumed the path points to a hole, otherwise an exception will be thrown.

source
HerbConstraints.remove!Method
remove!(solver::UniformSolver, path::Vector{Int}, rules::Vector{Int})

Remove all rules from the domain of the hole located at the path. It is assumed the path points to a hole, otherwise an exception will be thrown.

source
HerbConstraints.remove_above!Method
remove_above!(solver::GenericSolver, path::Vector{Int}, rule_index::Int)

Reduce the domain of the hole located at the path by removing all rules indices above rule_index Example: rule_index = 2. hole with domain [1, 1, 0, 1] gets reduced to [1, 0, 0, 0] and gets simplified to a RuleNode

source
HerbConstraints.remove_above!Method
remove_above!(solver::UniformSolver, path::Vector{Int}, rule_index::Int)

Reduce the domain of the hole located at the path by removing all rules indices above rule_index Example: rule_index = 2. hole with domain {1, 2, 4} gets reduced to {1}

source
HerbConstraints.remove_all_but!Method
remove_all_but!(solver::GenericSolver, path::Vector{Int}, new_domain::BitVector)

Reduce the domain of the hole located at the path, to the new_domain. It is assumed the path points to a hole, otherwise an exception will be thrown. It is assumed new_domain ⊆ domain. For example: [1, 0, 1, 0] ⊆ [1, 0, 1, 1]

source
HerbConstraints.remove_all_but!Method
remove_all_but!(solver::GenericSolver, path::Vector{Int}, rule_index::Int)

Fill in the hole located at the path with rule rule_index. It is assumed the path points to a hole, otherwise an exception will be thrown. It is assumed rule_index ∈ hole.domain.

!!! warning: If the hole is known to be in the current tree, the hole can be passed directly. The caller has to make sure that the hole instance is actually present at the provided path.

source
HerbConstraints.remove_below!Method
remove_below!(solver::GenericSolver, path::Vector{Int}, rule_index::Int)

Reduce the domain of the hole located at the path by removing all rules indices below rule_index Example: rule_index = 2. hole with domain [1, 1, 0, 1] gets reduced to [0, 1, 0, 1]

source
HerbConstraints.remove_below!Method
remove_below!(solver::UniformSolver, path::Vector{Int}, rule_index::Int)

Reduce the domain of the hole located at the path by removing all rules indices below rule_index Example: rule_index = 2. hole with domain {1, 2, 4} gets reduced to {2, 4}

source
HerbConstraints.remove_node!Method
function remove_node!(solver::GenericSolver, path::Vector{Int})

Remove the node at the given path by substituting it with a hole of the same symbol.

source
HerbConstraints.save_state!Method
save_state!(solver::GenericSolver)

Returns a copy of the current state that can be restored by calling load_state!(solver, state)

source
HerbConstraints.shouldscheduleMethod
shouldschedule(solver::Solver, constraint::AbstractLocalConstraint, path::Vector{Int})::Bool

Function that is called when a tree manipulation occured at the path. Returns true if the constraint should be scheduled for propagation.

Default behavior: return true iff the manipulation happened at or below the constraint path.

source
HerbConstraints.shouldscheduleMethod
shouldschedule(::Solver, constraint::LocalForbiddenSequence, path::Vector{Int})::Bool

Return true iff the manipulation happened at or above the constraint path.

source
HerbConstraints.substitute!Method
substitute!(solver::GenericSolver, path::Vector{Int}, new_node::AbstractRuleNode; is_domain_increasing::Union{Nothing, Bool}=nothing)

Substitute the node at the path, with a new_node.

  • is_domain_increasing: indicates if all grammar constraints should be repropagated from the ground up.

Domain increasing substitutions are substitutions that cannot be achieved by repeatedly removing values from domains. Example of an domain increasing event: hole[{3, 4, 5}] -> hole[{1, 2}]. Example of an domain decreasing event: hole[{3, 4, 5}] -> rulenode(4, [hole[{1, 2}], rulenode(1)]).

source
HerbCore.contains_holeMethod
contains_hole(hole::StateHole)::Bool

Returns true if the hole or any of its (grand)children are not filled.

source
HerbCore.get_pathMethod
get_path(solver::GenericSolver, node::AbstractRuleNode)

Get the path at which the node is located.

source
HerbCore.get_pathMethod
get_path(solver::UniformSolver, node::AbstractRuleNode)

Get the path at which the node is located.

source
HerbCore.get_ruleMethod
get_rule(hole::StateHole)::Int

Assuming the hole has domain size 1, get the rule it is currently assigned to.

source
HerbCore.isfilledMethod
isfilled(hole::StateHole)::Bool

Holes with domain size 1 are fixed to a rule. Returns whether the hole has domain size 1. (holes with an empty domain are not considered to be fixed)

source

Index