Skip to content

Commit

Permalink
Updates for ConstraintExplorer
Browse files Browse the repository at this point in the history
  • Loading branch information
Azzaare committed Oct 4, 2024
1 parent acbc2ec commit ef39ebf
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ConstraintDomains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import TestItems: @testitem
export AbstractDomain
export ContinuousDomain
export DiscreteDomain
export Explore, ExploreSettings
export Explorer, ExploreSettings
export RangeDomain
export SetDomain

Expand Down
5 changes: 4 additions & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Convert various arguments into valid domains format.
"""
to_domains(domain_sizes::Vector{Int}) = map(ds -> domain(0:ds), domain_sizes)

function to_domains(X, ds::Int = δ_extrema(X) + 1)
function to_domains(X, ds::Int=δ_extrema(X) + 1)
d = domain(0:ds-1)
return fill(d, length(first(X)))
end
Expand Down Expand Up @@ -98,6 +98,9 @@ function Base.string(D::Vector{<:AbstractDomain})
end
Base.string(d::AbstractDomain) = replace(string(d.domain), " " => "")

merge_domains(::EmptyDomain, d::D) where {D<:AbstractDomain} = d
merge_domains(d::D, ::EmptyDomain) where {D<:AbstractDomain} = d

## SECTION - Test Items
@testitem "EmptyDomain" tags = [:domains, :empty] begin
ed = domain()
Expand Down
3 changes: 1 addition & 2 deletions src/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ domain(intervals::Vector{I}) where {I<:Interval} = Intervals(intervals)
Base.length(itv::Intervals)
Return the sum of the length of each interval in `itv`.
"""
Base.length(itv::Intervals) = sum(size, get_domain(itv); init = 0)
Base.length(itv::Intervals) = sum(size, get_domain(itv); init=0)

"""
Base.rand(itv::Intervals)
Expand Down Expand Up @@ -114,7 +114,6 @@ function intersect_domains(
return Intervals(new_itvls)
end


"""
Base.size(i::I) where {I <: Interval}
Expand Down
30 changes: 27 additions & 3 deletions src/explore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin
state::ExplorerState{T}

function Explorer(concepts, domains, objective=nothing; settings=ExploreSettings(domains))
F1 = Union{map(typeof, concepts)...}
D = Union{map(typeof, domains)...}
F1 = isempty(concepts) ? Function : Union{map(typeof, concepts)...}
D = isempty(domains) ? AbstractDomain : Union{map(typeof, domains)...}
F2 = typeof(objective)
T = isempty(domains) ? Any : Union{map(eltype, domains)...}
T = isempty(domains) ? Real : Union{map(eltype, domains)...}
d_c = Dict(enumerate(concepts))
d_d = Dict(enumerate(domains))
return new{F1,D,F2,T}(d_c, d_d, objective, settings, ExplorerState{T}())
Expand All @@ -62,6 +62,30 @@ function Explorer()
return Explorer(concepts, domains, objective; settings)
end

function Base.push!(explorer::Explorer, concept::Function)
max_key = maximum(keys(explorer.concepts))
explorer.concepts[max_key+1] = concept
return nothing
end

function delete_concept!(explorer::Explorer, key::Int)
delete!(explorer.concepts, key)
return nothing
end

function Base.push!(explorer::Explorer, domain::AbstractDomain)
max_key = maximum(keys(explorer.domains))
explorer.domains[max_key+1] = domain
return nothing
end

function delete_domain!(explorer::Explorer, key::Int)
delete!(explorer.domains, key)
return nothing
end

set!(explorer::Explorer, objective::Function) = explorer.objective = objective

function update_exploration!(explorer, f, c, search=explorer.settings.search)
solutions = explorer.state.solutions
non_sltns = explorer.state.non_solutions
Expand Down
2 changes: 1 addition & 1 deletion src/general.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function Base.convert(::Type{Intervals}, d::RangeDomain{T}) where {T<:Real}
return domain(Interval{T,Closed,Closed}(a, b))
end

function Base.convert(::Type{RangeDomain}, d::Intervals{T}) where {T<:Real}
function Base.convert(::Type{RangeDomain}, d::Intervals)
i = get_domain(d)[1]
a = Int(i.first)
b = Int(i.last)
Expand Down

0 comments on commit ef39ebf

Please sign in to comment.