Skip to content

PSO: fix memory mode to preserve full internal state across evolve calls - #628

Merged
darioizzo merged 1 commit into
esa:masterfrom
jschueller:issue486
May 23, 2026
Merged

PSO: fix memory mode to preserve full internal state across evolve calls#628
darioizzo merged 1 commit into
esa:masterfrom
jschueller:issue486

Conversation

@jschueller

Copy link
Copy Markdown
Contributor

When memory=true, consecutive evolve() calls with gen=1 should produce the same trajectory as a single call with gen=N. The previous partial fix only preserved particle velocities (m_V), but not the rest of the internal state (current positions X, local bests lbX/lbfit, topology, etc.), causing divergent behaviour between repeated gen=1 calls and a single gen=N call.

This commit stores and restores the full internal PSO state via a memory struct (V, X, lbX, fit, lbfit, best_fit, neighb, best_neighb) wrapped in boost::optional, replacing the incomplete mutable m_V approach.

Fix contributed by tarcisiofischer (PR #487), applied to both pso and pso_gen with serialization support.

Closes #486

When memory=true, consecutive evolve() calls with gen=1 should produce
the same trajectory as a single call with gen=N. The previous partial fix
only preserved particle velocities (m_V), but not the rest of the internal
state (current positions X, local bests lbX/lbfit, topology, etc.), causing
divergent behaviour between repeated gen=1 calls and a single gen=N call.

This commit stores and restores the full internal PSO state via a memory
struct (V, X, lbX, fit, lbfit, best_fit, neighb, best_neighb) wrapped
in boost::optional, replacing the incomplete mutable m_V approach.

Fix contributed by tarcisiofischer (PR esa#487), applied to both pso
and pso_gen with serialization support.

Closes esa#486
@darioizzo
darioizzo merged commit 4aead6c into esa:master May 23, 2026
7 checks passed
@darioizzo

Copy link
Copy Markdown
Member

Merging this, thanks for the contribution. With the added test we should be safe on intended behaviour.

@jschueller
jschueller deleted the issue486 branch May 23, 2026 12:26
@jschueller jschueller mentioned this pull request May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Consecutive calls to PSO is not necessarily the same of running with multiple generations

2 participants