feat(moeo): add finalize() lifecycle hook for algorithm post-processing#84
feat(moeo): add finalize() lifecycle hook for algorithm post-processing#84evvaletov wants to merge 2 commits into
Conversation
9066a5d to
45b4623
Compare
|
Good idea, thanks! I would be willing to merge this if I can review the code (same comment than for PR #83 ) |
Add virtual finalize() and hasFinalize() to moeoAlgo/moeoPopAlgo hierarchy. NSGA-II implements finalize() to recompute fitness and diversity assignments after population modifications (e.g. immigrant integration in island model).
45b4623 to
d306ef8
Compare
|
Rebased onto HEAD, should be reviewable now. On the design: |
|
This is a good idea. I'm just wondering why adding a const check for the feature instead of derivating a new interface? My immediate thought would have been to add some kind of But maybe there is some problem with that? |
Replace the hasFinalize()/finalize() pattern with a moeoAlgoFinalized<MOEOT> abstract interface. Algorithms opt in by inheriting from it. Consumers check at compile time via std::is_base_of_v instead of a runtime bool.
|
You're right, a separate interface is cleaner. I've refactored it.
In the island model (PR #86), the consumer becomes a compile-time check: if constexpr (std::is_base_of_v<moeoAlgoFinalized<algoEOT>, EOAlgo<algoEOT>>)
algo.finalize(pop);This works because the island template already knows the concrete algorithm type. The compiler enforces the interface, and algorithms without finalize pay zero cost (the branch is eliminated at compile time). NSGA-II now inherits from both I've updated PRs #83, #86, and #87 accordingly (rebased onto this change). |
Summary
Adds a
finalize()extension point to the multi-objective algorithmhierarchy, allowing algorithms to perform post-processing after external
population modifications.
moeoAlgo: virtual destructor +hasFinalize() const(default false)moeoPopAlgo<MOEOT>: virtualfinalize(eoPop<MOEOT>&)(default no-op)moeoNSGAII: implementsfinalize()to recompute dominance-depthfitness and crowding diversity assignments
Motivation
In island model configurations, immigrant individuals are integrated into
an island's population between generations. NSGA-II's fitness and diversity
values become stale after integration — the non-dominated sorting ranks and
crowding distances no longer reflect the actual population composition.
Without recomputation, selection pressure degrades until the next natural
generation boundary.
The
finalize()/hasFinalize()pattern lets the island model triggerrecomputation only on algorithms that need it, without coupling the island
infrastructure to specific algorithm internals.
Changes
moeo/src/algo/moeoAlgo.hhasFinalize() constmoeo/src/algo/moeoPopAlgo.hvirtual void finalize(eoPop<MOEOT>&) {}moeo/src/algo/moeoNSGAII.hfitnessAssignment+diversityAssignment