diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8d2bac..e978604 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,7 +1,15 @@ name: CI on: - - push - - pull_request + push: + branches: + - main + tags: '*' + pull_request: +concurrency: + # Skip intermediate builds: always. + # Cancel intermediate builds: only if it is a pull request build. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }} jobs: test: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} @@ -11,8 +19,7 @@ jobs: matrix: version: - '1.6' - - '1.7' - - "^1.8.0-0" + - '1.8' - 'nightly' os: - ubuntu-latest diff --git a/Project.toml b/Project.toml index f721af1..fc831cc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ConstraintDomains" uuid = "5800fd60-8556-4464-8d61-84ebf7a0bedb" authors = ["Jean-François Baffier"] -version = "0.3.4" +version = "0.3.5" [deps] ConstraintCommons = "e37357d9-0691-492f-a822-e5ea6a920954" diff --git a/src/continuous.jl b/src/continuous.jl index 1231f0a..dbd7407 100644 --- a/src/continuous.jl +++ b/src/continuous.jl @@ -8,8 +8,8 @@ abstract type ContinuousDomain{T<:Real} <: AbstractDomain end Intervals{T <: Real} <: ContinuousDomain{T} An encapsuler to store a vector of `PatternFolds.Interval`. Dynamic changes to `Intervals` are not handled yet. """ -struct Intervals{T<:Real,L,R} <: ContinuousDomain{T} - domain::Vector{Interval{T,L,R}} +struct Intervals{T<:Real,I<:Interval{T}} <: ContinuousDomain{T} + domain::Vector{I} end """ @@ -76,8 +76,14 @@ function merge_domains(d1::D, d2::D) where {D<:ContinuousDomain} end function intersect_domains(i₁::I1, i₂::I2) where {I1<:Interval,I2<:Interval} - a = a_ismore(i₁, i₂) ? i₁.a : i₂.a - b = b_isless(i₁, i₂) ? i₁.b : i₂.b + if i₁.first > i₂.first + return intersect_domains(i₂, i₁) + end + if i₁.last < i₂.first + return domain() + end + a = i₂.first + b = min(i₁.last, i₂.last) return Interval(a, b) end diff --git a/src/explore.jl b/src/explore.jl index 35804d5..cd60ce7 100644 --- a/src/explore.jl +++ b/src/explore.jl @@ -15,40 +15,36 @@ function ExploreSettings( return ExploreSettings(complete_search_limit, max_samplings, search, solutions_limit) end -function _explore(domains, concept, param, s, ::Val{:partial}) +function _explore(domains, f, s, ::Val{:partial}) solutions = Set{Vector{Int}}() non_sltns = Set{Vector{Int}}() sl = s.solutions_limit - f = isnothing(param) ? ((x; param = p) -> concept(x)) : concept - for _ in 1:s.max_samplings length(solutions) ≥ sl && length(non_sltns) ≥ sl && break config = map(rand, domains) - c = f(config; param) ? solutions : non_sltns + c = f(config) ? solutions : non_sltns length(c) < sl && push!(c, config) end return solutions, non_sltns end -function _explore(domains, concept, param, ::ExploreSettings, ::Val{:complete}) +function _explore(domains, f, ::ExploreSettings, ::Val{:complete}) solutions = Set{Vector{Int}}() non_sltns = Set{Vector{Int}}() - f = isnothing(param) ? ((x; param = p) -> concept(x)) : concept - configurations = Base.Iterators.product(map(d -> get_domain(d), domains)...) foreach( - c -> (cv = collect(c); push!(f(cv; param) ? solutions : non_sltns, cv)), + c -> (cv = collect(c); push!(f(cv) ? solutions : non_sltns, cv)), configurations, ) return solutions, non_sltns end -function _explore(domains, concept, param, s, ::Val{:flexible}) +function _explore(domains, f, s, ::Val{:flexible}) search = s.max_samplings < s.complete_search_limit ? :complete : :partial - return _explore(domains, concept, param, s, Val(search)) + return _explore(domains, f, s, Val(search)) end """ @@ -67,8 +63,9 @@ Beware that if the density of the solutions in the search space is low, `solutio function explore( domains, concept; - param=nothing, settings = ExploreSettings(domains), + parameters... ) - return _explore(domains, concept, param, settings, Val(settings.search)) + f = x -> concept(x; parameters...) + return _explore(domains, f, settings, Val(settings.search)) end diff --git a/src/general.jl b/src/general.jl index 7fd60eb..60798d6 100644 --- a/src/general.jl +++ b/src/general.jl @@ -2,12 +2,12 @@ Base.eltype(::D) where {T, D <: Union{DiscreteDomain{T}, ContinuousDomain{T}}} = function Base.convert(::Type{Intervals}, d::RangeDomain{T}) where {T <: Real} a, b = extrema(get_domain(d)) - return domain((Float64(a), true), (Float64(b), true)) + return domain(Float64(a)..Float64(b)) end function Base.convert(::Type{RangeDomain}, d::Intervals{T}) where {T <: Real} i = get_domain(d)[1] - a = Int(value(i, :a) + (closed(i, :a) ? 0 : 1)) - b = Int(value(i, :b) - (closed(i, :b) ? 0 : 1)) + a = Int(i.first) + b = Int(i.last) return domain(a:b) end