Skip to content

Commit d6fa593

Browse files
committed
Update to check satisfaction in ConstraintExplorer
1 parent feb220d commit d6fa593

File tree

1 file changed

+25
-15
lines changed

1 file changed

+25
-15
lines changed

src/explore.jl

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ struct ExploreSettings
66
end
77

88
"""
9-
ExploreSettings(domains;
10-
complete_search_limit = 10^6,
11-
max_samplings = sum(domain_size, domains),
12-
search = :flexible,
9+
ExploreSettings(domains;
10+
complete_search_limit = 10^6,
11+
max_samplings = sum(domain_size, domains),
12+
search = :flexible,
1313
solutions_limit = floor(Int, sqrt(max_samplings)))
1414
1515
Create an `ExploreSettings` object to configure the exploration of a search space composed of a collection of domains.
@@ -26,10 +26,10 @@ Create an `ExploreSettings` object to configure the exploration of a search spac
2626
"""
2727
function ExploreSettings(
2828
domains;
29-
complete_search_limit = 10^6,
30-
max_samplings = sum(domain_size, domains; init = 0),
31-
search = :flexible,
32-
solutions_limit = floor(Int, sqrt(max_samplings)),
29+
complete_search_limit=10^6,
30+
max_samplings=sum(domain_size, domains; init=0),
31+
search=:flexible,
32+
solutions_limit=floor(Int, sqrt(max_samplings)),
3333
)
3434
return ExploreSettings(complete_search_limit, max_samplings, search, solutions_limit)
3535
end
@@ -54,8 +54,8 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin
5454
function Explorer(
5555
concepts,
5656
domains,
57-
objective = nothing;
58-
settings = ExploreSettings(domains),
57+
objective=nothing;
58+
settings=ExploreSettings(domains),
5959
)
6060
F1 = isempty(concepts) ? Function : Union{map(c -> typeof(c[1]), concepts)...}
6161
D = isempty(domains) ? AbstractDomain : Union{map(typeof, domains)...}
@@ -76,7 +76,7 @@ function Explorer()
7676
end
7777

7878
function Base.push!(explorer::Explorer, concept::Tuple{Function,Vector{Int}})
79-
max_key = maximum(keys(explorer.concepts); init = 0)
79+
max_key = maximum(keys(explorer.concepts); init=0)
8080
explorer.concepts[max_key+1] = concept
8181
return max_key + 1
8282
end
@@ -87,7 +87,7 @@ function delete_concept!(explorer::Explorer, key::Int)
8787
end
8888

8989
function Base.push!(explorer::Explorer, domain::AbstractDomain)
90-
max_key = maximum(keys(explorer.domains); init = 0)
90+
max_key = maximum(keys(explorer.domains); init=0)
9191
explorer.domains[max_key+1] = domain
9292
return max_key + 1
9393
end
@@ -99,7 +99,7 @@ end
9999

100100
set!(explorer::Explorer, objective::Function) = explorer.objective = objective
101101

102-
function update_exploration!(explorer, f, c, search = explorer.settings.search)
102+
function update_exploration!(explorer, f, c, search=explorer.settings.search)
103103
solutions = explorer.state.solutions
104104
non_sltns = explorer.state.non_solutions
105105
obj = explorer.objective
@@ -124,7 +124,7 @@ end
124124
125125
Internals of the `explore` function. Behavior is automatically adjusted on the kind of exploration: `:flexible`, `:complete`, `:partial`.
126126
"""
127-
function _explore!(explorer, f, ::Val{:partial})
127+
function _explore!(explorer, f, ::Val{:partial};)
128128
sl = explorer.settings.solutions_limit
129129
ms = explorer.settings.max_samplings
130130

@@ -174,13 +174,23 @@ Search (a part of) a search space and return a pair of vectors of configurations
174174
# Returns
175175
- A tuple of sets: `(solutions, non_solutions)`.
176176
"""
177-
function explore(domains, concept; settings = ExploreSettings(domains), parameters...)
177+
function explore(domains, concept; settings=ExploreSettings(domains), parameters...)
178178
f = x -> concept(x; parameters...)
179179
explorer = Explorer([(f, Vector{Int}())], domains; settings)
180180
explore!(explorer)
181181
return explorer.state.solutions, explorer.state.non_solutions
182182
end
183183

184+
function _check!(explorer, configurations)
185+
g =
186+
x -> all([
187+
f(isempty(vars) ? x : @view x[vars]) for
188+
(f, vars) in explorer.concepts |> values
189+
])
190+
foreach(c -> update_exploration!(explorer, g, c, :complete), configurations)
191+
return nothing
192+
end
193+
184194
## SECTION - Test Items
185195
@testitem "Exploration" tags = [:exploration] begin
186196
domains = [domain([1, 2, 3, 4]) for i = 1:4]

0 commit comments

Comments
 (0)