1
- struct ExploreSettings
1
+ mutable struct ExploreSettings
2
2
complete_search_limit:: Int
3
3
max_samplings:: Int
4
4
search:: Symbol
@@ -42,22 +42,45 @@ function ExploreSettings(
42
42
return ExploreSettings (complete_search_limit, max_samplings, search, solutions_limit)
43
43
end
44
44
45
- struct ExplorerState{T}
45
+ abstract type AbstractExplorerState end
46
+
47
+ struct CompleteExplorerState{N,T} <: AbstractExplorerState
46
48
best:: Vector{T}
47
- solutions:: Vector{Vector{T}}
48
- non_solutions:: Vector{Vector{T}}
49
+ solutions:: Vector{NTuple{N,T}}
50
+ non_solutions:: Vector{NTuple{N,T}}
51
+
52
+ CompleteExplorerState {N,T} () where {N,T} = new {N,T} (Vector {T} (), Vector {NTuple{N,T}} (), Vector {NTuple{N,T}} ())
53
+ end
49
54
50
- ExplorerState {T} () where {T} = new {T} (Vector {T} (), Vector {Vector{T}} (), Vector {Vector{T}} ())
55
+ function explorer_state (domains, :: Val{:complete} )
56
+ return CompleteExplorerState {length(domains),Union{map(eltype, domains)...}} ()
51
57
end
52
58
53
- ExplorerState (domains) = ExplorerState {Union{map(eltype, domains)...}} ()
59
+ struct PartialExplorerState{T} <: AbstractExplorerState
60
+ best:: Vector{T}
61
+ solutions:: Set{Vector{T}}
62
+ non_solutions:: Set{Vector{T}}
63
+
64
+ PartialExplorerState {T} () where {T} = new {T} (Vector {T} (), Set {Vector{T}} (), Set {Vector{T}} ())
65
+ end
66
+ function explorer_state (domains, :: Val{:partial} )
67
+ return PartialExplorerState {Union{map(eltype, domains)...}} ()
68
+ end
54
69
55
- mutable struct Explorer{F1<: Function ,D<: AbstractDomain ,F2<: Union{Function,Nothing} ,T }
70
+ mutable struct Explorer{F1<: Function ,D<: AbstractDomain ,F2<: Union{Function,Nothing} ,S <: AbstractExplorerState }
56
71
concepts:: Dict{Int,Tuple{F1,Vector{Int}}}
57
72
domains:: Dict{Int,D}
58
73
objective:: F2
59
74
settings:: ExploreSettings
60
- state:: ExplorerState{T}
75
+ state:: S
76
+
77
+ function Explorer (concepts, domains, objective, settings, state)
78
+ F1 = isempty (concepts) ? Function : typeof (concepts). parameters[2 ]. parameters[1 ]
79
+ D = isempty (domains) ? AbstractDomain : typeof (domains). parameters[2 ]
80
+ F2 = typeof (objective)
81
+ S = typeof (state)
82
+ return new {F1,D,F2,S} (concepts, domains, objective, settings, state)
83
+ end
61
84
end
62
85
63
86
"""
@@ -88,13 +111,13 @@ function Explorer(
88
111
objective= nothing ;
89
112
settings= ExploreSettings (domains),
90
113
)
91
- F1 = isempty (concepts) ? Function : Union{ map (c -> typeof (c[ 1 ]), concepts) ... }
92
- D = isempty (domains) ? AbstractDomain : Union{ map (typeof, domains) ... }
93
- F2 = typeof (objective)
94
- T = isempty (domains) ? Real : Union{ map (eltype, domains) ... }
114
+ if settings . search == :flexible
115
+ settings . search = settings . max_samplings < settings . complete_search_limit ? :complete : :partial
116
+ end
117
+ state = explorer_state (domains, Val (settings . search))
95
118
d_c = Dict (enumerate (concepts))
96
119
d_d = Dict (enumerate (domains))
97
- return Explorer {F1,D,F2,T} (d_c, d_d, objective, settings, ExplorerState {T} () )
120
+ return Explorer (d_c, d_d, objective, settings, state )
98
121
end
99
122
100
123
function Explorer ()
@@ -225,15 +248,14 @@ function update_exploration!(explorer, f, c, search=explorer.settings.search)
225
248
obj = explorer. objective
226
249
sl = search == :complete ? Inf : explorer. settings. solutions_limit
227
250
228
- cv = collect (c)
229
- if f (cv)
251
+ if f (c)
230
252
if length (solutions) < sl
231
- push! (solutions, cv )
253
+ push! (solutions, c )
232
254
obj != = nothing && (explorer. state. best = argmin (obj, solutions))
233
255
end
234
256
else
235
257
if length (non_sltns) < sl
236
- push! (non_sltns, cv )
258
+ push! (non_sltns, c )
237
259
end
238
260
end
239
261
return nothing
@@ -257,8 +279,6 @@ function _explore!(explorer, f, ::Val{:partial};)
257
279
config = map (rand, domains)
258
280
update_exploration! (explorer, f, config)
259
281
end
260
- unique! (explorer. state. solutions)
261
- unique! (explorer. state. non_solutions)
262
282
return nothing
263
283
end
264
284
@@ -295,12 +315,7 @@ function explore!(explorer::Explorer)
295
315
f (isempty (vars) ? x : @view x[vars]) for
296
316
(f, vars) in explorer. concepts |> values
297
317
])
298
- s = explorer. settings
299
- search = s. search
300
- if search == :flexible
301
- search = s. max_samplings < s. complete_search_limit ? :complete : :partial
302
- end
303
- return _explore! (explorer, c, Val (search))
318
+ return _explore! (explorer, c, Val (explorer. settings. search))
304
319
end
305
320
306
321
0 commit comments