Skip to content

unstable performance of PSO in v3.4.2 #126

@songjhaha

Description

@songjhaha

MWE:

using Metaheuristics

function particleswarm(func, lb, ub)
    bounds = float([lb ub])'
    pso = PSO(; N=100, C1=1.5, C2=1.5, ω=0.7)
    res = Metaheuristics.optimize(func, bounds, pso)
    x = minimizer(res)
    fval = minimum(res)
    f_calls = res.f_calls
    iterations = res.iteration
    time_run = res.final_time - res.start_time
    termination_status = termination_status_message(res)    
    return x,
    fval,
    (;
        iterations=iterations,
        f_calls=f_calls,
        time_run=time_run,
        termination_status=termination_status,
    )
end

func(x) = exp(-sum(x)) + x[5000] * sin(x[1] + x[end])
lb = -10 * ones(10000)
ub = 10 * ones(10000)
@time particleswarm(func, lb, ub)

Julia version:

julia> versioninfo()
Julia Version 1.10.10
Commit 95f30e51f41 (2025-06-27 09:51 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 12 × 11th Gen Intel(R) Core(TM) i5-11500H @ 2.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, tigerlake)
Threads: 1 default, 0 interactive, 1 GC (on 12 virtual cores)
Environment:
  JULIA_PKG_SERVER = https://releases-dev.tongyuan.cc

for Metaheuristics v3.3.5:

julia> @time particleswarm(func, lb, ub)
  9.289682 seconds (972.16 k allocations: 16.291 GiB, 28.53% gc time, 2.58% compilation time)

for Metaheuristics v3.4.2:

# somtime repl stuck
# or run with 100+ secs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions