Skip to content

Commit ef39ebf

Browse files
committed
Updates for ConstraintExplorer
1 parent acbc2ec commit ef39ebf

File tree

5 files changed

+34
-8
lines changed

5 files changed

+34
-8
lines changed

src/ConstraintDomains.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import TestItems: @testitem
1010
export AbstractDomain
1111
export ContinuousDomain
1212
export DiscreteDomain
13-
export Explore, ExploreSettings
13+
export Explorer, ExploreSettings
1414
export RangeDomain
1515
export SetDomain
1616

src/common.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Convert various arguments into valid domains format.
6363
"""
6464
to_domains(domain_sizes::Vector{Int}) = map(ds -> domain(0:ds), domain_sizes)
6565

66-
function to_domains(X, ds::Int = δ_extrema(X) + 1)
66+
function to_domains(X, ds::Int=δ_extrema(X) + 1)
6767
d = domain(0:ds-1)
6868
return fill(d, length(first(X)))
6969
end
@@ -98,6 +98,9 @@ function Base.string(D::Vector{<:AbstractDomain})
9898
end
9999
Base.string(d::AbstractDomain) = replace(string(d.domain), " " => "")
100100

101+
merge_domains(::EmptyDomain, d::D) where {D<:AbstractDomain} = d
102+
merge_domains(d::D, ::EmptyDomain) where {D<:AbstractDomain} = d
103+
101104
## SECTION - Test Items
102105
@testitem "EmptyDomain" tags = [:domains, :empty] begin
103106
ed = domain()

src/continuous.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ domain(intervals::Vector{I}) where {I<:Interval} = Intervals(intervals)
2727
Base.length(itv::Intervals)
2828
Return the sum of the length of each interval in `itv`.
2929
"""
30-
Base.length(itv::Intervals) = sum(size, get_domain(itv); init = 0)
30+
Base.length(itv::Intervals) = sum(size, get_domain(itv); init=0)
3131

3232
"""
3333
Base.rand(itv::Intervals)
@@ -114,7 +114,6 @@ function intersect_domains(
114114
return Intervals(new_itvls)
115115
end
116116

117-
118117
"""
119118
Base.size(i::I) where {I <: Interval}
120119

src/explore.jl

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin
4444
state::ExplorerState{T}
4545

4646
function Explorer(concepts, domains, objective=nothing; settings=ExploreSettings(domains))
47-
F1 = Union{map(typeof, concepts)...}
48-
D = Union{map(typeof, domains)...}
47+
F1 = isempty(concepts) ? Function : Union{map(typeof, concepts)...}
48+
D = isempty(domains) ? AbstractDomain : Union{map(typeof, domains)...}
4949
F2 = typeof(objective)
50-
T = isempty(domains) ? Any : Union{map(eltype, domains)...}
50+
T = isempty(domains) ? Real : Union{map(eltype, domains)...}
5151
d_c = Dict(enumerate(concepts))
5252
d_d = Dict(enumerate(domains))
5353
return new{F1,D,F2,T}(d_c, d_d, objective, settings, ExplorerState{T}())
@@ -62,6 +62,30 @@ function Explorer()
6262
return Explorer(concepts, domains, objective; settings)
6363
end
6464

65+
function Base.push!(explorer::Explorer, concept::Function)
66+
max_key = maximum(keys(explorer.concepts))
67+
explorer.concepts[max_key+1] = concept
68+
return nothing
69+
end
70+
71+
function delete_concept!(explorer::Explorer, key::Int)
72+
delete!(explorer.concepts, key)
73+
return nothing
74+
end
75+
76+
function Base.push!(explorer::Explorer, domain::AbstractDomain)
77+
max_key = maximum(keys(explorer.domains))
78+
explorer.domains[max_key+1] = domain
79+
return nothing
80+
end
81+
82+
function delete_domain!(explorer::Explorer, key::Int)
83+
delete!(explorer.domains, key)
84+
return nothing
85+
end
86+
87+
set!(explorer::Explorer, objective::Function) = explorer.objective = objective
88+
6589
function update_exploration!(explorer, f, c, search=explorer.settings.search)
6690
solutions = explorer.state.solutions
6791
non_sltns = explorer.state.non_solutions

src/general.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function Base.convert(::Type{Intervals}, d::RangeDomain{T}) where {T<:Real}
1616
return domain(Interval{T,Closed,Closed}(a, b))
1717
end
1818

19-
function Base.convert(::Type{RangeDomain}, d::Intervals{T}) where {T<:Real}
19+
function Base.convert(::Type{RangeDomain}, d::Intervals)
2020
i = get_domain(d)[1]
2121
a = Int(i.first)
2222
b = Int(i.last)

0 commit comments

Comments
 (0)