Skip to content

feat(mab): integrate Lin-Kernighan with Multi-Armed Bandit scheduler#28

Merged
lv416e merged 69 commits intomainfrom
feat/lk-mab-integration
Oct 16, 2025
Merged

feat(mab): integrate Lin-Kernighan with Multi-Armed Bandit scheduler#28
lv416e merged 69 commits intomainfrom
feat/lk-mab-integration

Conversation

@lv416e
Copy link
Copy Markdown
Owner

@lv416e lv416e commented Oct 14, 2025

Summary

Implements Task 6.2: Integration of Lin-Kernighan local search with Multi-Armed Bandit (MAB) scheduler for adaptive local search operator selection in memetic algorithms.

Changes

Core Implementation

  • LocalSearchOperator concept: Type-safe interface for local search algorithms

    • Requires improve(problem, genome, rng) -> Fitness method
    • Works with LinKernighan, TwoOpt, Random2Opt, and future local search operators
  • AdaptiveLocalSearchSelector: Template class for adaptive local search selection

    • Mirrors AdaptiveOperatorSelector design pattern for consistency
    • Supports both UCB and Thompson Sampling schedulers
    • Type aliases: UCBLocalSearchSelector<Problem>, ThompsonLocalSearchSelector<Problem>

Performance Tracking

  • Execution time measurement: Uses std::chrono::steady_clock
  • Improvement rate tracking: Leverages existing OperatorStats infrastructure
  • Reward-based learning: UCB and Thompson Sampling learn which local search works best

Testing

  • New test suite: tests/test_mab_local_search.cpp (21 tests, all passing)
  • Enhanced test helper: Added assert_le and assert_gt(double) methods
  • All existing tests pass (14/14 test suites)

Integration

  • Added include/evolab/local_search/lk.hpp to main evolab.hpp header
  • Formatted with clang-format, passes all lint checks

Usage Example

#include <evolab/evolab.hpp>
using namespace evolab;

// Create MAB local search selector
schedulers::UCBLocalSearchSelector<problems::TSP> ls_selector(3, 2.0, rng);

// Add local search operators
ls_selector.add_operator(local_search::LinKernighan(20, 5), "LK");
ls_selector.add_operator(local_search::TwoOpt(), "2opt");
ls_selector.add_operator(local_search::Random2Opt(100), "Random2opt");

// Apply adaptive local search
auto fitness = ls_selector.apply_local_search(tsp, tour, rng);
ls_selector.report_fitness_improvement(old_fitness - fitness.value);

// Check performance stats
const auto& stats = ls_selector.get_operator_stats();
for (size_t i = 0; i < stats.size(); ++i) {
    std::cout << ls_selector.get_operator_names()[i] 
              << ": " << stats[i].success_rate << std::endl;
}

Known Limitations (Pre-v1.0)

⚠️ Important: This feature is currently experimental and requires additional validation before being considered research-grade.

Thread Safety

  • NOT THREAD-SAFE: Both AdaptiveOperatorSelector and AdaptiveLocalSearchSelector maintain mutable state
  • Sharing a selector across threads will cause race conditions and corrupt MAB learning
  • Solution: Create one selector instance per thread (e.g., one per island in Island Model GAs)
  • Impact: Incorrect results in parallel GAs if not properly isolated

Minimization Problems Only

  • report_fitness_change(old_fitness, new_fitness) assumes minimization (lower = better)
  • Calculates improvement as: old_fitness - new_fitness
  • For maximization problems: Calculate improvement manually and use report_fitness_improvement() directly:
    double improvement = new_fitness - old_fitness;  // For maximization
    selector.report_fitness_improvement(improvement);

Empirical Validation Pending

  • No experimental validation of research value (convergence, overhead, comparison with baselines)
  • No performance characterization for real-world use cases
  • Not publication-ready until validation complete (see Issue MAB Scheduler: Empirical Validation #33)
  • Current status: Functionally correct, unit-tested, but unvalidated for research use

Future Work

Before v1.0 Release (Blocking)

  • Empirical validation (Issue MAB Scheduler: Empirical Validation #33) - HIGH PRIORITY
    • Convergence validation: Verify MAB learns operator quality
    • Performance overhead: Quantify selection cost vs operator cost
    • Baseline comparisons: MAB vs random/round-robin selection
    • Real-world GA integration: TSPLIB benchmarks
    • Est. effort: 2-3 days of experimental work

Post-v1.0 (Enhancement)

  • Selector refactoring (Issue MAB Scheduler: Refactor Selector Classes #32) - MEDIUM PRIORITY

    • Eliminate ~110 lines of code duplication
    • Templated base class or CRTP pattern
    • Trigger: When 3rd selector type is added
  • Configuration system integration - MEDIUM PRIORITY

    • Requires runtime operator selection (std::variant or type erasure)
    • Enable TOML-based operator configuration
    • Example: scheduler.operators = ["LK", "2-opt"] in config files
  • Maximization support - LOW PRIORITY

    • Enhanced API or automatic problem type detection
    • Or simply document current minimization-only constraint

Testing Results

=== EvoLab MAB Local Search Integration Tests ===
Passed: 21
Failed: 0
Total:  21

All test suites: 14/14 passed

Related Work

Checklist

  • All tests passing
  • Code formatted with clang-format
  • Lint checks passing
  • Documentation updated (tasks.md, code comments)
  • Git hooks passing (format, lint, build-check)
  • Pre-push hooks passing (changed-check, build, test)
  • Thread-safety warnings added
  • Minimization assumption documented
  • Empirical validation roadmap documented (Issue MAB Scheduler: Empirical Validation #33)
  • Known limitations clearly stated

Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

Summary by CodeRabbit

  • New Features
    • Adaptive local‑search integrated into the MAB workflow with UCB and Thompson Sampling; Lin‑Kernighan, 2‑Opt, and Random 2‑Opt available.
  • Performance
    • Per‑operator execution‑time, improvement‑rate and expanded success/reward metrics.
  • Bug Fixes
    • Stronger validation, clearer error handling and safer thread‑local RNG defaults.
  • Tests
    • New comprehensive local‑search test suite (21 passing tests) and double‑value assertion helpers.
  • Documentation
    • Specs updated; runtime configuration templates deferred.

…ector

Implements Task 6.2: Integration of Lin-Kernighan with Multi-Armed Bandit scheduler.

Core Changes:
- Add LocalSearchOperator concept to define interface for local search algorithms
- Implement AdaptiveLocalSearchSelector class template for adaptive local search selection
- Add UCBLocalSearchSelector and ThompsonLocalSearchSelector type aliases
- Include Lin-Kernighan header in main evolab.hpp

Features:
- Performance tracking with execution time measurement (chrono-based)
- Improvement rate tracking via OperatorStats
- Unified interface matching AdaptiveOperatorSelector pattern
- Support for both UCB and Thompson Sampling schedulers

Testing:
- Add comprehensive test suite (test_mab_local_search.cpp) with 21 tests
- Add assert_le and assert_gt(double) methods to test_helper.hpp
- All tests pass (TDD GREEN phase)

The AdaptiveLocalSearchSelector enables researchers to automatically select
the best-performing local search operator based on historical performance,
allowing for hybrid memetic algorithms that adapt during evolution.

Related: Task 6.1 (Lin-Kernighan implementation)
Ref: .kiro/specs/evolab/tasks.md
Task 6.2 (Lin-Kernighan with Multi-Armed Bandit scheduler) is complete.

Completed:
- LocalSearchOperator concept
- AdaptiveLocalSearchSelector implementation
- Performance tracking (execution time, improvement rate)
- Comprehensive test coverage (21 tests)

Deferred for future work:
- Configuration system integration (needs runtime operator selection)
- Hybrid Memetic GA configuration templates

The core MAB local search integration is functional and tested.
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @lv416e, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the evolab framework by introducing an adaptive mechanism for selecting local search operators within memetic algorithms. It implements a Multi-Armed Bandit (MAB) approach, allowing the system to intelligently learn and apply the most effective local search strategies (such as Lin-Kernighan, TwoOpt, and Random2Opt) based on their observed performance in terms of fitness improvement and execution time. This change provides a more flexible and efficient way to optimize complex problems by dynamically adjusting the local search components.

Highlights

  • Adaptive Local Search Integration: Introduced AdaptiveLocalSearchSelector to dynamically choose local search operators (Lin-Kernighan, TwoOpt, Random2Opt) using Multi-Armed Bandit (MAB) strategies like UCB and Thompson Sampling.
  • New LocalSearchOperator Concept: Defined a type-safe C++ concept for local search algorithms, requiring an improve method, ensuring compile-time validation of operator interfaces.
  • Enhanced Performance Tracking: Implemented tracking of local search operator performance, including execution time using std::chrono and fitness improvement rates via OperatorStats, enabling the MAB schedulers to learn effectively.
  • Comprehensive Testing: Added a new test suite (test_mab_local_search.cpp) with 21 passing tests to validate the new MAB local search integration, covering various aspects of its functionality.
  • Core Header Update: Included the Lin-Kernighan header (lk.hpp) in the main evolab.hpp for broader accessibility of the local search algorithm.
  • Deferred Features: Noted that integration with the configuration system and creation of hybrid Memetic GA templates are deferred for future work due to current C++ template limitations requiring runtime operator selection design.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 14, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds AdaptiveLocalSearchSelector (UCB/Thompson) and LocalSearchOperator support with chrono-based timing and expanded OperatorStats; exposes Lin–Kernighan via public include; introduces thread-local RNG accessor; expands tests, test helpers, and CTest entry for MAB local-search integration. (≤50 words)

Changes

Cohort / File(s) Summary
Specs update
.kiro/specs/evolab/tasks.md
Marks Lin–Kernighan MAB integration as completed; documents LocalSearchOperator, AdaptiveLocalSearchSelector, timing/improvement instrumentation, supported operators (LinKernighan, TwoOpt, Random2Opt), expanded tests, and deferred configuration/templates.
Public include surface
include/evolab/evolab.hpp
Adds public include for local-search header (local_search/lk.hpp) to expose Lin–Kernighan.
MAB schedulers & selectors
include/evolab/schedulers/mab.hpp
Adds inline std::mt19937& get_thread_rng() (thread-local RNG) and uses it as default; expands OperatorStats with timing/success metrics; instruments timing in apply paths; strengthens runtime guards; introduces AdaptiveOperatorSelector enhancements and new AdaptiveLocalSearchSelector (UCB/Thompson aliases) with add/apply/report/reset and operator-stats APIs.
Test build config
tests/CMakeLists.txt
Adds test_mab_local_search executable and CTest MABLocalSearchTests with labels integration;mab;local-search;adaptive.
Test helpers
tests/test_helper.hpp
Adds TestResult overloads for double comparisons: assert_ge, assert_gt, assert_le, assert_lt.
Local-search tests
tests/test_mab_local_search.cpp
New comprehensive test suite (~21 tests) covering LocalSearchOperator concept, AdaptiveLocalSearchSelector (UCB/Thompson), operator registration/names/counts, apply_local_search timing/improvement tracking, error cases, and hybrid memetic scenarios.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant GA as GeneticAlgorithm
  participant ALS as AdaptiveLocalSearchSelector
  participant SCH as Scheduler (UCB/Thompson)
  participant OP as LocalSearchOperator
  participant RNG as ThreadRNG
  participant T as Timer

  rect rgb(230,245,255)
  GA->>ALS: apply_local_search(problem, genome, RNG)
  end

  rect rgb(255,250,230)
  ALS->>T: start timing
  ALS->>SCH: select_operator(operator_stats)
  SCH-->>ALS: selected_index
  end

  rect rgb(240,255,240)
  ALS->>OP: invoke selected operator(problem, genome, RNG)
  OP-->>ALS: new_fitness
  ALS->>T: stop timing
  ALS->>ALS: compute improvement & record execution time
  ALS->>SCH: report_reward(improvement)
  ALS-->>GA: return new_fitness
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related issues

  • MAB Scheduler: Empirical Validation #33 — The PR’s AdaptiveLocalSearchSelector, enhanced OperatorStats, timing instrumentation, and public RNG accessor directly address the scheduler improvements and TODOs described in this issue.

Possibly related PRs

Poem

I nibble through tours with nimble little paws, 🥕
I time each hop and tally every clause.
LK trims the track, Two‑Opt smooths the map,
Bandits pick, I cheer, then tidy my lap.
A rabbit’s joy: select, report, and nap.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly describes the primary enhancement of integrating the Lin-Kernighan local search operator with the existing Multi-Armed Bandit scheduler, matching the core changes in the pull request and following conventional commit style.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/lk-mab-integration

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c5de55f and daa8aa9.

📒 Files selected for processing (1)
  • tests/test_helper.hpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_helper.hpp

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

gemini-code-assist[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

lv416e and others added 3 commits October 14, 2025 16:09
… corruption

Critical fix: When selected operator index is out of bounds,
throw std::out_of_range instead of returning default Fitness{0.0}.
This prevents incorrect reward calculation that could corrupt
the MAB scheduler's learning process.

- Add <stdexcept> header for exception support
- Replace silent failure with explicit exception
- Provide clear error message about configuration mismatch

Addresses Gemini code review critical issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Performance and correctness improvements:
- Pass operator by value and move into lambda capture
- Mark lambda as mutable for non-const improve() methods
- Avoids unnecessary copies for large operator objects
- Enables move-only operator types in the future

Follows modern C++ best practices for type-erased storage

Addresses Gemini code review medium priority issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Reduce code duplication:
- Create TestTSPInstance helper struct to encapsulate
  TSP instance and tour initialization
- Used in 5 test functions: test_apply_local_search,
  test_performance_tracking, test_execution_time_tracking,
  test_improvement_rate_tracking, test_thompson_sampling_integration
- Improves maintainability and readability

Addresses Gemini code review medium priority issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

lv416e and others added 3 commits October 14, 2025 16:24
Critical fixes to prevent crashes when no operators are configured:

1. AdaptiveLocalSearchSelector::apply_local_search:
   - Check if operators_ is empty before calling scheduler
   - Throw logic_error with clear message

2. UCBScheduler::select_operator:
   - Check if stats_ is empty before selection
   - Prevents out-of-bounds access on empty vector

3. ThompsonSamplingScheduler::select_operator:
   - Check if distributions_ is empty before sampling
   - Prevents invalid max_element and distance calls

These checks ensure fail-fast behavior with clear error
messages instead of undefined behavior or crashes.

Addresses Gemini and CodeRabbit critical review issues

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add bounds check in AdaptiveLocalSearchSelector::add_operator:
- Throw logic_error if operators_.size() >= num_operators
- Prevents silent failures where extra operators are never selected
- Provides clear error message about capacity mismatch

This ensures API misuse is caught early rather than leading
to confusing runtime behavior.

Addresses Gemini code review medium priority issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Simplify improvement rate tracking test:
- Remove redundant calculation: success_count / selection_count
- Use pre-computed stat.success_rate from OperatorStats
- Update assertion messages to "Success rate" for accuracy

The OperatorStats struct already maintains success_rate,
so recalculating it in tests is unnecessary duplication.

Addresses Gemini code review medium priority issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai

This comment was marked as resolved.

@coderabbitai

This comment was marked as resolved.

coderabbitai Bot added a commit that referenced this pull request Oct 14, 2025
Docstrings generation was requested by @lv416e.

* #28 (comment)

The following files were modified:

* `include/evolab/schedulers/mab.hpp`
* `tests/test_helper.hpp`
* `tests/test_mab_local_search.cpp`
gemini-code-assist[bot]

This comment was marked as resolved.

Consolidate LocalSearchOperator concept definitions:
- Remove duplicate concept from mab.hpp (was lines 24-28)
- Include core/concepts.hpp for canonical definition
- Update template constraint to use core::LocalSearchOperator
- Remove unnecessary mutable keyword from lambda capture
- Update test to use core::LocalSearchOperator

The core/concepts.hpp definition requires const-qualified
improve() methods, which all operators (LinKernighan, TwoOpt,
Random2Opt) already satisfy.

Benefits:
- Single source of truth for core abstractions
- Eliminates confusion from duplicate definitions
- Ensures consistency across the codebase
- Simplifies maintenance

Addresses Gemini code review high priority issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

Add tracking state validation to prevent silent failures:

1. AdaptiveLocalSearchSelector::apply_local_search:
   - Check if tracking_improvement_ is true before starting
   - Throw logic_error if apply_local_search is called again
     before report_fitness_improvement

2. AdaptiveOperatorSelector::apply_crossover:
   - Same check to prevent consecutive calls without reporting
   - Ensures scheduler learning is not corrupted by lost tracking

Problem scenario:
- User calls apply_local_search() twice consecutively
- First call's tracking is overwritten by second call
- When report_fitness_improvement() is finally called,
  only the second operation's reward is recorded
- Scheduler learns from incorrect data

Solution:
- Fail fast with clear error message
- Forces correct API usage pattern:
  apply_local_search -> report_fitness_improvement -> repeat

Benefits:
- Prevents silent bugs in scheduler learning
- Makes API contract explicit and enforceable
- Easier debugging with clear error messages

Addresses Gemini code review medium priority issue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Address code review feedback from Gemini and CodeRabbit:

1. Add missing <limits> include for std::numeric_limits
   - Prevents fragile transitive dependency issues

2. Add defensive checks to apply_crossover
   - Add empty() check to match apply_local_search parity
   - Replace silent fallback with std::out_of_range exception
   - Improves API contract enforcement

3. Fix tracking_improvement_ timing for exception safety
   - Move assignment after successful operator execution
   - Prevents sticky state when exceptions occur
   - Applies to both apply_crossover and apply_local_search

4. Replace high_resolution_clock with steady_clock
   - Guarantees monotonic time measurement
   - Prevents time anomalies from clock adjustments

All tests pass (21/21).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

lv416e and others added 2 commits October 14, 2025 17:12
Move timing start point after OOB validation in apply_local_search.
This provides more accurate operator performance metrics by excluding
the validation overhead from execution time measurement.

Address CodeRabbit nitpick feedback.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Add TODO comment documenting Gemini's suggestion to extract common
functionality into a base class. While the suggestion is valid from
a DRY perspective, we defer this refactoring for the following reasons:

1. YAGNI principle: Only two selector types exist currently
2. Complexity trade-off: Template+inheritance would increase complexity
3. Clear separation: Each selector has distinct responsibilities
4. Maintainability: Current duplication is manageable and understandable

The TODO serves as a reminder to revisit this decision if a third
selector type is needed, at which point the refactoring would provide
clear value.

Address Gemini medium-priority suggestion with reasoned deferral.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

Update the TODO comment to reflect that the code duplication between
AdaptiveOperatorSelector and AdaptiveLocalSearchSelector has reached
~110 lines, exceeding the original 100-line threshold. The comment now
acknowledges this and prioritizes refactoring before adding a third
selector type to prevent further code multiplication.

This addresses code review feedback noting that the duplication
threshold may have already been met.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

Add reference to GitHub Issue #32 in the TODO comment about selector
class refactoring. This provides traceability for the planned work to
eliminate ~110 lines of code duplication between AdaptiveOperatorSelector
and AdaptiveLocalSearchSelector.

The issue tracks the medium-high priority refactoring that should be
completed before adding a third selector type.

Addresses code review feedback recommending follow-up refactoring.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

Improve error diagnostics in AdaptiveOperatorSelector and
AdaptiveLocalSearchSelector:

- add_operator(): Include both maximum allowed and current operator
  counts to help identify configuration mismatches between constructor
  parameter and actual operator additions

- apply_crossover()/apply_local_search(): Include the actual selected
  operator index in out-of-bounds error to pinpoint scheduler selection
  issues

These changes make debugging configuration errors significantly easier
by providing concrete values instead of generic messages.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

lv416e and others added 2 commits October 16, 2025 14:56
Add inline comment explaining why the 64-bit clock_seed is split into
two 32-bit values via right shift (>> 32). This improves code
comprehension by making the entropy distribution strategy explicit.

The split ensures both the lower and upper 32 bits of the timestamp
contribute independently to the seed sequence, maximizing entropy
utilization for thread-local RNG initialization.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Address research integrity and correctness issues identified in
critical analysis. These changes are essential for safe and correct
use of MAB scheduler in research contexts.

Changes:
1. Thread-safety warnings (CRITICAL - Research Integrity):
   - Add explicit warnings to AdaptiveOperatorSelector class docs
   - Add explicit warnings to AdaptiveLocalSearchSelector class docs
   - Document race condition risks in parallel GAs
   - Specify requirement: one selector instance per thread
   - Impact: Prevents incorrect research results from data races

2. Minimization assumption documentation (CRITICAL - Correctness):
   - Document report_fitness_change() assumes minimization problems
   - Add @warning tags for maximization problem usage
   - Provide code examples for both problem types
   - Applied to both AdaptiveOperatorSelector and AdaptiveLocalSearchSelector
   - Impact: Prevents incorrect operator learning from wrong improvement calculation

3. Empirical validation roadmap (HIGH PRIORITY - Research Quality):
   - Add comprehensive TODO comment documenting required validation
   - Detail 6 categories of validation experiments needed
   - Specify acceptance criteria and success metrics
   - Estimate effort (2-3 days) and priority (HIGH, blocks v1.0)
   - Reference GitHub Issue #33 for tracking
   - Impact: Clarifies path to research-grade quality

4. PR description updates:
   - Remove inaccurate TDD claim (tests were added after implementation)
   - Add "Known Limitations" section with thread-safety and minimization constraints
   - Add detailed "Future Work" section with Issue #33 link
   - Update checklist to reflect documentation improvements
   - Impact: Sets accurate expectations for feature maturity

Rationale:
After critical thinking + ultrathink analysis, these issues were
identified as blocking concerns for a research framework:
- Thread-safety: Silent data corruption in parallel GAs → wrong results
- Minimization assumption: Breaks for maximization problems → wrong learning
- Validation gap: No evidence feature works as claimed → not research-grade

These 30 minutes of documentation work address research ethics and
correctness issues that could lead to incorrect published results.

Related: Issue #33 (Empirical Validation)
Related: PR #28 (MAB Implementation)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]

This comment was marked as resolved.

Extract ~60 lines of detailed validation plan from inline comment to
Issue #33 for better maintainability and task tracking. Code comment
now contains brief reference to issue with link.

Addresses CodeRabbit review feedback on code readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

lv416e and others added 5 commits October 16, 2025 15:57
…ction

Add <sstream> header include to support stringstream-based error message
construction, replacing inefficient string concatenation with + operator.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rator error

Replace inefficient string concatenation with std::stringstream for
constructing error messages in AdaptiveOperatorSelector::add_operator().
This avoids multiple temporary string allocations and improves code
readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…rossover error

Replace inefficient string concatenation with std::stringstream for
constructing error messages in AdaptiveOperatorSelector::apply_crossover().
This avoids multiple temporary string allocations and improves code
readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…operator error

Replace inefficient string concatenation with std::stringstream for
constructing error messages in AdaptiveLocalSearchSelector::add_operator().
This avoids multiple temporary string allocations and improves code
readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…y_local_search error

Replace inefficient string concatenation with std::stringstream for
constructing error messages in AdaptiveLocalSearchSelector::apply_local_search().
This avoids multiple temporary string allocations and improves code
readability.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

lv416e and others added 2 commits October 16, 2025 16:22
Add <thread> header include to support thread ID incorporation in
random number generator seeding, enabling more robust seed generation
in parallel execution scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…tion

Enhance thread-local random number generator seeding by incorporating
thread ID hash into seed sequence. This provides an additional entropy
source that is guaranteed to be unique per thread, significantly reducing
the risk of seed collisions in parallel execution scenarios with rapid,
concurrent thread creation.

This improvement is particularly important for parallel genetic algorithms
(e.g., Island Model) where multiple threads may be spawned simultaneously,
ensuring better reproducibility and statistical independence across threads.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

lv416e and others added 2 commits October 16, 2025 16:56
…d_operator

Apply perfect forwarding to the operator parameter in add_operator() method
of AdaptiveOperatorSelector. This optimization avoids unnecessary copies when
l-value operators are passed and correctly handles move semantics for both
l-values and r-values, improving performance and adhering to modern C++ best
practices.

Changes:
- Changed parameter from `OpType op` to `OpType&& op`
- Updated lambda capture from `std::move(op)` to `std::forward<OpType>(op)`

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…:add_operator

Apply perfect forwarding to the operator parameter in add_operator() method
of AdaptiveLocalSearchSelector. This optimization provides the same benefits
as the corresponding change in AdaptiveOperatorSelector: avoiding unnecessary
copies for l-value operators and correctly handling move semantics for both
l-values and r-values.

Changes:
- Changed parameter from `OpType op` to `OpType&& op`
- Updated lambda capture from `std::move(op)` to `std::forward<OpType>(op)`

This ensures both selector classes follow modern C++ best practices and
maintain consistent implementation patterns.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
coderabbitai[bot]

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

Add optional tolerance parameters to double comparison functions to improve
test reliability and prevent flaky tests from floating-point precision issues.

Changes:
- assert_ge(double): Add eps parameter (default: 0.0)
- assert_gt(double): Add eps parameter (default: 1e-9) with diff output
- assert_le(double): Add tol parameter (default: 1e-9)
- assert_lt(double): Add tol parameter (default: 1e-9) with diff output

Based on CodeRabbit review feedback to make comparisons more robust.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@lv416e lv416e merged commit c77f161 into main Oct 16, 2025
5 checks passed
@lv416e lv416e deleted the feat/lk-mab-integration branch October 16, 2025 12:33
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.

1 participant