Skip to content

Commit 645b010

Browse files
authored
Merge pull request #493 from MilesCranmer/dont-store-invalids
fix: never store member if violating constraints
2 parents fae61b3 + 5f02bea commit 645b010

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/CheckConstraints.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ function check_constraints(
6767
ex::AbstractExpression,
6868
options::AbstractOptions,
6969
maxsize::Int,
70-
cursize::Union{Int,Nothing}=nothing,
70+
cached_size::Union{Int,Nothing}=nothing,
7171
)::Bool
7272
tree = get_tree(ex)
73-
return check_constraints(tree, options, maxsize, cursize)
73+
return check_constraints(tree, options, maxsize, cached_size)
7474
end
7575
function check_constraints(
7676
tree::AbstractExpressionNode,
7777
options::AbstractOptions,
7878
maxsize::Int,
79-
cursize::Union{Int,Nothing}=nothing,
79+
cached_size::Union{Int,Nothing}=nothing,
8080
)::Bool
81-
@something(cursize, compute_complexity(tree, options)) > maxsize && return false
81+
@something(cached_size, compute_complexity(tree, options)) > maxsize && return false
8282
count_depth(tree) > options.maxdepth && return false
8383
any_invalid = any(enumerate(options.op_constraints)) do (degree, degree_constraints)
8484
any(enumerate(degree_constraints)) do (op_idx, cons)

src/SearchUtils.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ using ..ProgressBarsModule: WrappedProgressBar, manually_iterate!, barlen
2424
using ..AdaptiveParsimonyModule: RunningSearchStatistics
2525
using ..ExpressionBuilderModule: strip_metadata
2626
using ..InterfaceDynamicExpressionsModule: takes_eval_options
27+
using ..CheckConstraintsModule: check_constraints
2728

2829
function logging_callback! end
2930

@@ -724,6 +725,9 @@ function update_hall_of_fame!(
724725
if !valid_size
725726
continue
726727
end
728+
if !check_constraints(member.tree, options, options.maxsize, size)
729+
continue
730+
end
727731
not_filled = !hall_of_fame.exists[size]
728732
better_than_current = member.cost < hall_of_fame.members[size].cost
729733
if not_filled || better_than_current

0 commit comments

Comments
 (0)