Skip to content

Commit 88fa90e

Browse files
committed
Fix in explore
1 parent ef39ebf commit 88fa90e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/explore.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ end
3737
ExplorerState(domains) = ExplorerState{Union{map(eltype, domains)...}}()
3838

3939
mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothing},T}
40-
concepts::Dict{Int,F1}
40+
concepts::Dict{Int,Tuple{F1,Vector{Int}}}
4141
domains::Dict{Int,D}
4242
objective::F2
4343
settings::ExploreSettings
4444
state::ExplorerState{T}
4545

4646
function Explorer(concepts, domains, objective=nothing; settings=ExploreSettings(domains))
47-
F1 = isempty(concepts) ? Function : Union{map(typeof, concepts)...}
47+
F1 = isempty(concepts) ? Function : Union{map(c -> typeof(c[1]), concepts)...}
4848
D = isempty(domains) ? AbstractDomain : Union{map(typeof, domains)...}
4949
F2 = typeof(objective)
5050
T = isempty(domains) ? Real : Union{map(eltype, domains)...}
@@ -55,17 +55,17 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin
5555
end
5656

5757
function Explorer()
58-
concepts = Vector{Function}()
58+
concepts = Vector{Tuple{Function,Vector{Int}}}()
5959
domains = Vector{AbstractDomain}()
6060
objective = nothing
6161
settings = ExploreSettings(domains)
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))
65+
function Base.push!(explorer::Explorer, concept::Tuple{Function,Vector{Int}})
66+
max_key = maximum(keys(explorer.concepts); init=0)
6767
explorer.concepts[max_key+1] = concept
68-
return nothing
68+
return max_key + 1
6969
end
7070

7171
function delete_concept!(explorer::Explorer, key::Int)
@@ -74,9 +74,9 @@ function delete_concept!(explorer::Explorer, key::Int)
7474
end
7575

7676
function Base.push!(explorer::Explorer, domain::AbstractDomain)
77-
max_key = maximum(keys(explorer.domains))
77+
max_key = maximum(keys(explorer.domains); init=0)
7878
explorer.domains[max_key+1] = domain
79-
return nothing
79+
return max_key + 1
8080
end
8181

8282
function delete_domain!(explorer::Explorer, key::Int)
@@ -134,7 +134,7 @@ function _explore!(explorer, f, ::Val{:complete})
134134
end
135135

136136
function explore!(explorer::Explorer)
137-
c = x -> all([f(x) for f in explorer.concepts |> values])
137+
c = x -> all([f(isempty(vars) ? x : @view x[vars]) for (f, vars) in explorer.concepts |> values])
138138
s = explorer.settings
139139
search = s.search
140140
if search == :flexible
@@ -158,7 +158,7 @@ Beware that if the density of the solutions in the search space is low, `solutio
158158
"""
159159
function explore(domains, concept; settings=ExploreSettings(domains), parameters...)
160160
f = x -> concept(x; parameters...)
161-
explorer = Explorer([f], domains; settings)
161+
explorer = Explorer([(f, Vector{Int}())], domains; settings)
162162
explore!(explorer)
163163
return explorer.state.solutions, explorer.state.non_solutions
164164
end

0 commit comments

Comments
 (0)