@@ -6,23 +6,31 @@ struct ExploreSettings
6
6
end
7
7
8
8
"""
9
- ExploreSettings(domains;
10
- complete_search_limit = 10^6,
11
- max_samplings = sum(domain_size, domains),
12
- search = :flexible,
13
- solutions_limit = floor(Int, sqrt(max_samplings)))
9
+ ExploreSettings(
10
+ domains;
11
+ complete_search_limit = 10^6,
12
+ max_samplings = sum(domain_size, domains),
13
+ search = :flexible,
14
+ solutions_limit = floor(Int, sqrt(max_samplings)),
15
+ )
14
16
15
- Create an `ExploreSettings` object to configure the exploration of a search space composed of a collection of domains.
17
+ Create settings for the exploration of a search space composed by a collection of domains.
16
18
17
19
# Arguments
18
- - `domains`: A collection of domains to be explored .
19
- - `complete_search_limit`: An integer specifying the maximum limit for complete search iterations. Default is 10^6 .
20
- - `max_samplings`: An integer specifying the maximum number of samplings. Default is the sum of domain sizes .
21
- - `search`: A symbol indicating the type of search to perform. Default is `:flexible` .
22
- - `solutions_limit`: An integer specifying the limit on the number of solutions. Default is the floor of the square root of `max_samplings` .
20
+ - `domains`: A collection of domains representing the search space .
21
+ - `complete_search_limit`: Maximum size of the search space for complete search.
22
+ - `max_samplings`: Maximum number of samples to take during partial search .
23
+ - `search`: Search strategy (`:flexible`, `:complete`, or `:partial`) .
24
+ - `solutions_limit`: Maximum number of solutions to store .
23
25
24
26
# Returns
25
- - `ExploreSettings` object with the specified settings.
27
+ An `ExploreSettings` object.
28
+
29
+ # Example
30
+ ```julia
31
+ domains = [domain([1, 2, 3]), domain([4, 5, 6])]
32
+ settings = ExploreSettings(domains, search = :complete)
33
+ ```
26
34
"""
27
35
function ExploreSettings (
28
36
domains;
@@ -50,21 +58,43 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin
50
58
objective:: F2
51
59
settings:: ExploreSettings
52
60
state:: ExplorerState{T}
61
+ end
53
62
54
- function Explorer (
55
- concepts,
56
- domains,
57
- objective = nothing ;
58
- settings = ExploreSettings (domains),
59
- )
60
- F1 = isempty (concepts) ? Function : Union{map (c -> typeof (c[1 ]), concepts)... }
61
- D = isempty (domains) ? AbstractDomain : Union{map (typeof, domains)... }
62
- F2 = typeof (objective)
63
- T = isempty (domains) ? Real : Union{map (eltype, domains)... }
64
- d_c = Dict (enumerate (concepts))
65
- d_d = Dict (enumerate (domains))
66
- return new {F1,D,F2,T} (d_c, d_d, objective, settings, ExplorerState {T} ())
67
- end
63
+ """
64
+ Explorer(concepts, domains, objective = nothing; settings = ExploreSettings(domains))
65
+
66
+ Create an Explorer object for searching a constraint satisfaction problem space.
67
+
68
+ # Arguments
69
+ - `concepts`: A collection of tuples, each containing a concept function and its associated variable indices.
70
+ - `domains`: A collection of domains representing the search space.
71
+ - `objective`: An optional objective function for optimization problems.
72
+ - `settings`: An `ExploreSettings` object to configure the exploration process.
73
+
74
+ # Returns
75
+ An `Explorer` object ready for exploration.
76
+
77
+ # Example
78
+ ```julia
79
+ domains = [domain([1, 2, 3]), domain([4, 5, 6])]
80
+ concepts = [(sum, [1, 2])]
81
+ objective = x -> x[1] + x[2]
82
+ explorer = Explorer(concepts, domains, objective)
83
+ ```
84
+ """
85
+ function Explorer (
86
+ concepts,
87
+ domains,
88
+ objective = nothing ;
89
+ settings = ExploreSettings (domains),
90
+ )
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)... }
95
+ d_c = Dict (enumerate (concepts))
96
+ d_d = Dict (enumerate (domains))
97
+ return Explorer {F1,D,F2,T} (d_c, d_d, objective, settings, ExplorerState {T} ())
68
98
end
69
99
70
100
function Explorer ()
@@ -75,28 +105,118 @@ function Explorer()
75
105
return Explorer (concepts, domains, objective; settings)
76
106
end
77
107
108
+ """
109
+ push!(explorer::Explorer, concept::Tuple{Function,Vector{Int}})
110
+
111
+ Add a new concept to the `Explorer` object.
112
+
113
+ # Arguments
114
+ - `explorer`: The `Explorer` object to modify.
115
+ - `concept`: A tuple containing a concept function and its associated variable indices.
116
+
117
+ # Returns
118
+ The key (index) of the newly added concept.
119
+
120
+ # Example
121
+ ```julia
122
+ explorer = Explorer()
123
+ key = push!(explorer, (sum, [1, 2]))
124
+ ```
125
+ """
78
126
function Base. push! (explorer:: Explorer , concept:: Tuple{Function,Vector{Int}} )
79
127
max_key = maximum (keys (explorer. concepts); init = 0 )
80
128
explorer. concepts[max_key+ 1 ] = concept
81
129
return max_key + 1
82
130
end
83
131
132
+ """
133
+ delete_concept!(explorer::Explorer, key::Int)
134
+
135
+ Remove a concept from the `Explorer` object by its key.
136
+
137
+ # Arguments
138
+ - `explorer`: The `Explorer` object to modify.
139
+ - `key`: The key (index) of the concept to remove.
140
+
141
+ # Returns
142
+ Nothing. The `Explorer` object is modified in-place.
143
+
144
+ # Example
145
+ ```julia
146
+ explorer = Explorer([(sum, [1, 2])], [domain([1, 2, 3])])
147
+ delete_concept!(explorer, 1)
148
+ ```
149
+ """
84
150
function delete_concept! (explorer:: Explorer , key:: Int )
85
151
delete! (explorer. concepts, key)
86
152
return nothing
87
153
end
88
154
155
+ """
156
+ push!(explorer::Explorer, domain::AbstractDomain)
157
+
158
+ Add a new domain to the `Explorer` object.
159
+
160
+ # Arguments
161
+ - `explorer`: The `Explorer` object to modify.
162
+ - `domain`: An `AbstractDomain` object to add to the search space.
163
+
164
+ # Returns
165
+ The key (index) of the newly added domain.
166
+
167
+ # Example
168
+ ```julia
169
+ explorer = Explorer()
170
+ key = push!(explorer, domain([1, 2, 3]))
171
+ ```
172
+ """
89
173
function Base. push! (explorer:: Explorer , domain:: AbstractDomain )
90
174
max_key = maximum (keys (explorer. domains); init = 0 )
91
175
explorer. domains[max_key+ 1 ] = domain
92
176
return max_key + 1
93
177
end
94
178
179
+ """
180
+ delete_domain!(explorer::Explorer, key::Int)
181
+
182
+ Remove a domain from the `Explorer` object by its key.
183
+
184
+ # Arguments
185
+ - `explorer`: The `Explorer` object to modify.
186
+ - `key`: The key (index) of the domain to remove.
187
+
188
+ # Returns
189
+ Nothing. The `Explorer` object is modified in-place.
190
+
191
+ # Example
192
+ ```julia
193
+ explorer = Explorer([], [domain([1, 2, 3])])
194
+ delete_domain!(explorer, 1)
195
+ ```
196
+ """
95
197
function delete_domain! (explorer:: Explorer , key:: Int )
96
198
delete! (explorer. domains, key)
97
199
return nothing
98
200
end
99
201
202
+ """
203
+ set!(explorer::Explorer, objective::Function)
204
+
205
+ Set the objective function for the `Explorer` object.
206
+
207
+ # Arguments
208
+ - `explorer`: The `Explorer` object to modify.
209
+ - `objective`: A function to use as the objective for optimization.
210
+
211
+ # Returns
212
+ Nothing. The `Explorer` object is modified in-place.
213
+
214
+ # Example
215
+ ```julia
216
+ explorer = Explorer()
217
+ set!(explorer, x -> sum(x))
218
+ ```
219
+ """
100
220
set! (explorer:: Explorer , objective:: Function ) = explorer. objective = objective
101
221
102
222
function update_exploration! (explorer, f, c, search = explorer. settings. search)
122
242
"""
123
243
_explore(args...)
124
244
125
- Internals of the `explore` function. Behavior is automatically adjusted on the kind of exploration: `:flexible`, `:complete`, `:partial`.
245
+ Internals of the `explore! ` function. Behavior is automatically adjusted on the kind of exploration: `:flexible`, `:complete`, `:partial`.
126
246
"""
127
247
function _explore! (explorer, f, :: Val{:partial} )
128
248
sl = explorer. settings. solutions_limit
@@ -146,6 +266,27 @@ function _explore!(explorer, f, ::Val{:complete})
146
266
return nothing
147
267
end
148
268
269
+ """
270
+ explore!(explorer::Explorer)
271
+
272
+ Perform exploration on the search space defined by the `Explorer` object.
273
+
274
+ This function explores the search space according to the settings specified in the `Explorer` object.
275
+ It updates the `Explorer`'s state with found solutions and non-solutions.
276
+
277
+ # Arguments
278
+ - `explorer`: An `Explorer` object containing the problem definition and exploration settings.
279
+
280
+ # Returns
281
+ Nothing. The `Explorer`'s state is updated in-place.
282
+
283
+ # Example
284
+ ```julia
285
+ explorer = Explorer(concepts, domains)
286
+ explore!(explorer)
287
+ println("Solutions found: ", length(explorer.state.solutions))
288
+ ```
289
+ """
149
290
function explore! (explorer:: Explorer )
150
291
c =
151
292
x -> all ([
@@ -160,19 +301,26 @@ function explore!(explorer::Explorer)
160
301
return _explore! (explorer, c, Val (search))
161
302
end
162
303
304
+
163
305
"""
164
306
explore(domains, concept; settings = ExploreSettings(domains), parameters...)
165
307
166
- Search (a part of) a search space and return a pair of vectors of configurations: `(solutions, non_solutions)`. The exploration behavior is determined based on the `settings` .
308
+ Explore a search space defined by domains and a concept .
167
309
168
310
# Arguments
169
- - `domains`: A collection of domains to be explored .
170
- - `concept`: The concept representing the constraint to be targeted .
171
- - `settings`: An optional `ExploreSettings` object to configure the exploration. Default is `ExploreSettings(domains)` .
172
- - `parameters... `: Additional parameters for the ` concept` .
311
+ - `domains`: A collection of domains representing the search space .
312
+ - `concept`: The concept function defining the constraint.
313
+ - `settings`: An `ExploreSettings` object to configure the exploration process .
314
+ - `parameters`: Additional parameters to pass to the concept function .
173
315
174
316
# Returns
175
- - A tuple of sets: `(solutions, non_solutions)`.
317
+ A tuple containing two sets: (solutions, non_solutions).
318
+
319
+ # Example
320
+ ```julia
321
+ domains = [domain([1, 2, 3]), domain([4, 5, 6])]
322
+ solutions, non_solutions = explore(domains, allunique)
323
+ ```
176
324
"""
177
325
function explore (domains, concept; settings = ExploreSettings (domains), parameters... )
178
326
f = x -> concept (x; parameters... )
0 commit comments