From d6fa593749f30292d87881f43957ceed92f326ab Mon Sep 17 00:00:00 2001 From: Azzaare Date: Mon, 21 Oct 2024 09:57:18 +0900 Subject: [PATCH 1/3] Update to check satisfaction in ConstraintExplorer --- src/explore.jl | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/explore.jl b/src/explore.jl index 52fe54d..c2b948a 100644 --- a/src/explore.jl +++ b/src/explore.jl @@ -6,10 +6,10 @@ struct ExploreSettings end """ - ExploreSettings(domains; - complete_search_limit = 10^6, - max_samplings = sum(domain_size, domains), - search = :flexible, + ExploreSettings(domains; + complete_search_limit = 10^6, + max_samplings = sum(domain_size, domains), + search = :flexible, solutions_limit = floor(Int, sqrt(max_samplings))) 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 """ function ExploreSettings( domains; - complete_search_limit = 10^6, - max_samplings = sum(domain_size, domains; init = 0), - search = :flexible, - solutions_limit = floor(Int, sqrt(max_samplings)), + complete_search_limit=10^6, + max_samplings=sum(domain_size, domains; init=0), + search=:flexible, + solutions_limit=floor(Int, sqrt(max_samplings)), ) return ExploreSettings(complete_search_limit, max_samplings, search, solutions_limit) end @@ -54,8 +54,8 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin function Explorer( concepts, domains, - objective = nothing; - settings = ExploreSettings(domains), + objective=nothing; + settings=ExploreSettings(domains), ) F1 = isempty(concepts) ? Function : Union{map(c -> typeof(c[1]), concepts)...} D = isempty(domains) ? AbstractDomain : Union{map(typeof, domains)...} @@ -76,7 +76,7 @@ function Explorer() end function Base.push!(explorer::Explorer, concept::Tuple{Function,Vector{Int}}) - max_key = maximum(keys(explorer.concepts); init = 0) + max_key = maximum(keys(explorer.concepts); init=0) explorer.concepts[max_key+1] = concept return max_key + 1 end @@ -87,7 +87,7 @@ function delete_concept!(explorer::Explorer, key::Int) end function Base.push!(explorer::Explorer, domain::AbstractDomain) - max_key = maximum(keys(explorer.domains); init = 0) + max_key = maximum(keys(explorer.domains); init=0) explorer.domains[max_key+1] = domain return max_key + 1 end @@ -99,7 +99,7 @@ end set!(explorer::Explorer, objective::Function) = explorer.objective = objective -function update_exploration!(explorer, f, c, search = explorer.settings.search) +function update_exploration!(explorer, f, c, search=explorer.settings.search) solutions = explorer.state.solutions non_sltns = explorer.state.non_solutions obj = explorer.objective @@ -124,7 +124,7 @@ end Internals of the `explore` function. Behavior is automatically adjusted on the kind of exploration: `:flexible`, `:complete`, `:partial`. """ -function _explore!(explorer, f, ::Val{:partial}) +function _explore!(explorer, f, ::Val{:partial};) sl = explorer.settings.solutions_limit ms = explorer.settings.max_samplings @@ -174,13 +174,23 @@ Search (a part of) a search space and return a pair of vectors of configurations # Returns - A tuple of sets: `(solutions, non_solutions)`. """ -function explore(domains, concept; settings = ExploreSettings(domains), parameters...) +function explore(domains, concept; settings=ExploreSettings(domains), parameters...) f = x -> concept(x; parameters...) explorer = Explorer([(f, Vector{Int}())], domains; settings) explore!(explorer) return explorer.state.solutions, explorer.state.non_solutions end +function _check!(explorer, configurations) + g = + x -> all([ + f(isempty(vars) ? x : @view x[vars]) for + (f, vars) in explorer.concepts |> values + ]) + foreach(c -> update_exploration!(explorer, g, c, :complete), configurations) + return nothing +end + ## SECTION - Test Items @testitem "Exploration" tags = [:exploration] begin domains = [domain([1, 2, 3, 4]) for i = 1:4] From a10a51497916eb38cb21d1dee6e7e5ed62617c19 Mon Sep 17 00:00:00 2001 From: Azzaare Date: Mon, 21 Oct 2024 10:00:39 +0900 Subject: [PATCH 2/3] Fix format --- src/explore.jl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/explore.jl b/src/explore.jl index c2b948a..1a3776b 100644 --- a/src/explore.jl +++ b/src/explore.jl @@ -26,10 +26,10 @@ Create an `ExploreSettings` object to configure the exploration of a search spac """ function ExploreSettings( domains; - complete_search_limit=10^6, - max_samplings=sum(domain_size, domains; init=0), - search=:flexible, - solutions_limit=floor(Int, sqrt(max_samplings)), + complete_search_limit = 10^6, + max_samplings = sum(domain_size, domains; init = 0), + search = :flexible, + solutions_limit = floor(Int, sqrt(max_samplings)), ) return ExploreSettings(complete_search_limit, max_samplings, search, solutions_limit) end @@ -54,8 +54,8 @@ mutable struct Explorer{F1<:Function,D<:AbstractDomain,F2<:Union{Function,Nothin function Explorer( concepts, domains, - objective=nothing; - settings=ExploreSettings(domains), + objective = nothing; + settings = ExploreSettings(domains), ) F1 = isempty(concepts) ? Function : Union{map(c -> typeof(c[1]), concepts)...} D = isempty(domains) ? AbstractDomain : Union{map(typeof, domains)...} @@ -76,7 +76,7 @@ function Explorer() end function Base.push!(explorer::Explorer, concept::Tuple{Function,Vector{Int}}) - max_key = maximum(keys(explorer.concepts); init=0) + max_key = maximum(keys(explorer.concepts); init = 0) explorer.concepts[max_key+1] = concept return max_key + 1 end @@ -87,7 +87,7 @@ function delete_concept!(explorer::Explorer, key::Int) end function Base.push!(explorer::Explorer, domain::AbstractDomain) - max_key = maximum(keys(explorer.domains); init=0) + max_key = maximum(keys(explorer.domains); init = 0) explorer.domains[max_key+1] = domain return max_key + 1 end @@ -99,7 +99,7 @@ end set!(explorer::Explorer, objective::Function) = explorer.objective = objective -function update_exploration!(explorer, f, c, search=explorer.settings.search) +function update_exploration!(explorer, f, c, search = explorer.settings.search) solutions = explorer.state.solutions non_sltns = explorer.state.non_solutions obj = explorer.objective @@ -174,7 +174,7 @@ Search (a part of) a search space and return a pair of vectors of configurations # Returns - A tuple of sets: `(solutions, non_solutions)`. """ -function explore(domains, concept; settings=ExploreSettings(domains), parameters...) +function explore(domains, concept; settings = ExploreSettings(domains), parameters...) f = x -> concept(x; parameters...) explorer = Explorer([(f, Vector{Int}())], domains; settings) explore!(explorer) From 8778c04e2973852a61c7afb1c86cfe2a55c1942e Mon Sep 17 00:00:00 2001 From: Jean-Francois Baffier Date: Mon, 21 Oct 2024 10:02:32 +0900 Subject: [PATCH 3/3] Update Project.toml --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 3705fc5..4abd2fa 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ConstraintDomains" uuid = "5800fd60-8556-4464-8d61-84ebf7a0bedb" authors = ["Jean-François Baffier"] -version = "0.3.14" +version = "0.3.15" [deps] ConstraintCommons = "e37357d9-0691-492f-a822-e5ea6a920954"