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

Wrapper for domains. (BitVector / StateSparseSet) #46

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

Wrapper for domains. (BitVector / StateSparseSet) #46

Whebon opened this issue May 4, 2024 · 0 comments

Comments

@Whebon
Copy link
Contributor

Whebon commented May 4, 2024

Holes can have domains of two different types:

  • StateSparseSet (for stateful holes)
  • BitVector (for all other holes)

Propagators can use domain functions to check certain properties. For example:

  • findfirst, to get the smallest/minimum value of the domain
  • sum, to get the number of rules in the domain

These functions are used as if the domain was a BitVector. However, they are not intuitive for what they are supposed to do. For a StateSparseSet this is even more confusing, because sum seems like it should behave completely different.

Solution

Use a wrapper function around domains and give intuitive names to domain operations. (Like minimum and size)

abstract type AbstractDomain end

struct BitVetorDomain
    domain::BitVector
end

struct StateDomain
    domain::StateSparseSet
end

It should support at least the following operations:

  • Base.minimum(::AbstractDomain). return the lowest rule index.
  • Base.maximum(::AbstractDomain). return the highest rule index.
  • Base.iterate(::AbstractDomain). iterate over all rules in the domain.
  • Base.size(::AbstractDomain). return the number of rules in the domain.
  • Base.in(::AbstractDomain). check if a rule is in the domain.
  • Base.findall(::AbstractDomain). return all rules in the domain.
  • Base.isempty(::AbstractDomain). check if the domain is empty.
  • remove!(::AbstractDomain, rule::Int). remove a rule from the domain.
  • remove_all_but!(::AbstractDomain, rule::Int). remove all but a single rule from the domain.
  • remove_below!(::AbstractDomain, rule::Int) remove all remove with a lower rule index from the domain.
  • remove_above!(::AbstractDomain, rule::Int) remove all remove with a higher rule index from the domain.
  • are_disjoint(::AbstractDomain, ::AbstractDomain) return true if two domains have an empty intersection.
  • get_intersection(::AbstractDomain, ::AbstractDomain) returns rules that are in both domains.
  • is_subdomain(sub::AbstractDomain, dom::AbstractDomain) check if sub sub-domain of dom.

Why is this not here yet

Adding the wrapper might cause overhead when copying over many holes during program iteration.

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