37
37
ExplorerState (domains) = ExplorerState {Union{map(eltype, domains)...}} ()
38
38
39
39
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}} }
41
41
domains:: Dict{Int,D}
42
42
objective:: F2
43
43
settings:: ExploreSettings
44
44
state:: ExplorerState{T}
45
45
46
46
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)... }
48
48
D = isempty (domains) ? AbstractDomain : Union{map (typeof, domains)... }
49
49
F2 = typeof (objective)
50
50
T = isempty (domains) ? Real : Union{map (eltype, domains)... }
@@ -55,17 +55,17 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin
55
55
end
56
56
57
57
function Explorer ()
58
- concepts = Vector {Function} ()
58
+ concepts = Vector {Tuple{ Function,Vector{Int}} } ()
59
59
domains = Vector {AbstractDomain} ()
60
60
objective = nothing
61
61
settings = ExploreSettings (domains)
62
62
return Explorer (concepts, domains, objective; settings)
63
63
end
64
64
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 )
67
67
explorer. concepts[max_key+ 1 ] = concept
68
- return nothing
68
+ return max_key + 1
69
69
end
70
70
71
71
function delete_concept! (explorer:: Explorer , key:: Int )
@@ -74,9 +74,9 @@ function delete_concept!(explorer::Explorer, key::Int)
74
74
end
75
75
76
76
function Base. push! (explorer:: Explorer , domain:: AbstractDomain )
77
- max_key = maximum (keys (explorer. domains))
77
+ max_key = maximum (keys (explorer. domains); init = 0 )
78
78
explorer. domains[max_key+ 1 ] = domain
79
- return nothing
79
+ return max_key + 1
80
80
end
81
81
82
82
function delete_domain! (explorer:: Explorer , key:: Int )
@@ -134,7 +134,7 @@ function _explore!(explorer, f, ::Val{:complete})
134
134
end
135
135
136
136
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])
138
138
s = explorer. settings
139
139
search = s. search
140
140
if search == :flexible
@@ -158,7 +158,7 @@ Beware that if the density of the solutions in the search space is low, `solutio
158
158
"""
159
159
function explore (domains, concept; settings= ExploreSettings (domains), parameters... )
160
160
f = x -> concept (x; parameters... )
161
- explorer = Explorer ([f ], domains; settings)
161
+ explorer = Explorer ([(f, Vector {Int} ()) ], domains; settings)
162
162
explore! (explorer)
163
163
return explorer. state. solutions, explorer. state. non_solutions
164
164
end
0 commit comments