Skip to content

Commit

Permalink
Learn changes for Constraints.jl (#20)
Browse files Browse the repository at this point in the history
* temp save

* Typo in string evaluation

* Typo in string evaluation 2/?

* Typo in string evaluation 3/?

* Typo in string evaluation 4/?

* Typo in string evaluation 5/?
  • Loading branch information
Azzaare authored Jan 14, 2021
1 parent 363f28b commit 761e74d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "CompositionalNetworks"
uuid = "4b67e4b5-442d-4ef5-b760-3f5df3a57537"
authors = ["Jean-François Baffier"]
version = "0.1.1"
version = "0.1.2"

[deps]
ConstraintDomains = "5800fd60-8556-4464-8d61-84ebf7a0bedb"
Expand Down
16 changes: 10 additions & 6 deletions src/learn.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
function _partial_search_space(domains, concept; sol_number=100)
function _partial_search_space(domains, concept, param=nothing; sol_number=100)
solutions = Set{Vector{Int}}()
non_sltns = Set{Vector{Int}}()

while length(solutions) < 100 || length(non_sltns) < 100
config = map(_draw, domains)
c = concept(config)
c = concept(config; param = param)
c && length(solutions) < 100 && push!(solutions, config)
!c && length(non_sltns) < 100 && push!(non_sltns, config)
end
return solutions, non_sltns
end

function _complete_search_space(domains, concept)
function _complete_search_space(domains, concept, param=nothing)
solutions = Set{Vector{Int}}()
non_sltns = Set{Vector{Int}}()

Expand All @@ -24,8 +24,10 @@ function _complete_search_space(domains, concept)
@warn message space_size
end

f = isnothing(param) ? ((x; param = p) -> concept(x)) : concept

configurations = product(map(d -> _get_domain(d), domains)...)
foreach(c -> (cv = collect(c); push!(concept(cv) ? solutions : non_sltns, cv)), configurations)
foreach(c -> (cv = collect(c); push!(f(cv; param=param) ? solutions : non_sltns, cv)), configurations)

return solutions, non_sltns
end
Expand Down Expand Up @@ -54,7 +56,7 @@ function explore_learn_compose(concept; domains, param=nothing,
)
dom_size = maximum(_length, domains)
if search == :complete
X_sols, X = _complete_search_space(domains, concept)
X_sols, X = _complete_search_space(domains, concept, param)
union!(X, X_sols)
return learn_compose(X, X_sols, dom_size, param;
local_iter=local_iter, global_iter=global_iter, action=action)
Expand All @@ -72,7 +74,9 @@ function _compose_to_string(symbols, name)
co = _reduce_symbols(symbols[4], ", ", false; prefix=CN * "_co_")

julia_string = """
$name = x -> fill(x, $tr_length) .|> $tr |> $ar |> $ag |> $co
function $name(x; param=nothing, dom_size)
fill(x, $tr_length) .|> map(f -> (y -> f(y; param=param)), $tr) |> $ar |> $ag |> (y -> $co(y; param=param, dom_size=dom_size, nvars=length(x)))
end
"""

return julia_string
Expand Down

0 comments on commit 761e74d

Please sign in to comment.