Skip to content

[Algorithm] Add algorithm interfaces and base implementations - #97

Merged
tryuan99 merged 21 commits into
titan/hierarchicalfrom
titan/algorithm_interfaces
Nov 6, 2025
Merged

tryuan99 merged 21 commits into
titan/hierarchicalfrom
titan/algorithm_interfaces

Conversation

@tryuan99

Copy link
Copy Markdown
Member

This PR adds the swarm algorithm interfaces and base implementations, according to the design doc (https://docs.google.com/document/d/1FINN_yEZ02AkopUn-ev0bzoi4oKenHYyIpEO6bSFrlE/edit?usp=sharing). There is no effect on the current state of the simulator as I have just renamed existing conflicting classnames and struct names with a Legacy suffix. The only unit-testable class is the Cluster class, so I have added unit tests for that class.

@tryuan99
tryuan99 requested a review from daniellovell October 12, 2025 22:12
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @tryuan99, 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 lays the groundwork for a more robust and scalable algorithm framework by introducing a set of well-defined interfaces and base implementations for clustering, prediction, and assignment algorithms. The changes involve a significant refactoring of existing components, moving them to 'Legacy' versions and establishing a new, cleaner architecture that leverages a hierarchical object model. This strategic update aims to facilitate the integration of future swarm algorithms without disrupting current simulator functionality.

Highlights

  • New Algorithm Interfaces and Base Implementations: Introduced new interfaces (IClusterer, IPredictor, IAssignment) and their corresponding base abstract classes (ClustererBase, PredictorBase, AssignmentBase) to establish a modular and extensible architecture for swarm algorithms. This aligns with the design document for future algorithm development.
  • Legacy Class Renaming: Existing algorithm-related classes and structs (e.g., Cluster, IClusterer, PredictorState, IPredictor, IAssignment, AssignmentItem) have been renamed with a Legacy suffix (e.g., ClusterLegacy, IClustererLegacy) to prevent naming conflicts and clearly delineate the older implementations from the new interface-driven architecture.
  • Refactored Cluster Class: The Cluster class has been significantly refactored. The original functionality was moved to ClusterLegacy, and a new Cluster class was introduced that inherits from HierarchicalBase, simplifying its responsibilities and integrating with the new hierarchical object model.
  • New Hierarchical Object Model Integration: The new algorithm interfaces and base classes now operate on IHierarchical objects, promoting a more generic and reusable design. A FixedHierarchical class was also added for testing purposes.
  • Updated Existing Implementations: Existing concrete implementations of clustering (AgglomerativeClusterer, KMeansClusterer), prediction (LinearExtrapolator), and assignment (MaxSpeedAssignment, RoundRobinAssignment, ThreatAssignment) have been updated to reference the *Legacy versions of the interfaces and classes they previously implemented or used.
  • Unit Test Updates: New unit tests for the ClusterLegacy class were added, and the existing ClusterTests were updated to reflect the changes in the Cluster class and its new dependency on FixedHierarchical.
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

coderabbitai Bot commented Oct 12, 2025 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch titan/algorithm_interfaces

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 gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This PR introduces a new set of interfaces and base classes for swarm algorithms, which is a great step towards a more modular and testable architecture. The separation of legacy code is clean. My review focuses on the design of the new interfaces and classes.

I have two main suggestions:

  1. The new Cluster class has a manual caching mechanism for its centroid, which is redundant with the Position property from HierarchicalBase and can lead to bugs from stale data. I've suggested a refactoring to simplify the class and make it more robust by removing the manual cache.
  2. The new interfaces IClusterer, IPredictor, and IAssignment use a stateful pattern where a void method is called to perform a calculation and the result is then retrieved from a property. I've suggested changing these methods to return their results directly, which leads to a cleaner, more functional, and less error-prone API.

Details and code suggestions are in the specific comments.

Base automatically changed from titan/interceptor_threat_interfaces to titan/hierarchical November 6, 2025 06:49
@stacklane-pr-stack-visualizer

stacklane-pr-stack-visualizer Bot commented Nov 6, 2025 •

Copy link
Copy Markdown

🧱 Stack PR · Base of stack

Stack Structure:

@tryuan99
tryuan99 merged commit 6260e51 into titan/hierarchical Nov 6, 2025
19 checks passed
@tryuan99
tryuan99 deleted the titan/algorithm_interfaces branch November 6, 2025 07:23
tryuan99 added a commit that referenced this pull request Dec 18, 2025
[All] Implement fully hierarchical defense strategy

* [Agent] Add agent-related interfaces and base implementations (#95)
* [Interceptor/Threat] Add interceptor and threat interfaces (#96)
* [Algorithm] Add algorithm interfaces and base implementations (#97)
* [Movements] Implement all aerial and ground-based movements (#99)
* [Gemini] Disable Gemini pull request summary (#142)
* [Sensor] Add sensor interface and ideal sensor implementation (#100)
* [Chore] Clean up private properties (#101)
* [Evasion] Implement evasion behaviors (#102)
* [Agent] Add agent-related interfaces and base implementations (#95)
* [Interceptor/Threat] Add interceptor and threat interfaces (#96)
* [Algorithm] Add algorithm interfaces and base implementations (#97)
* [Movements] Implement all aerial and ground-based movements (#99)
* [Sensor] Add sensor interface and ideal sensor implementation (#100)
* [Chore] Clean up private properties (#101)
* [Evasion] Implement evasion behaviors (#102)
* [Attack Behavior] Implement direct attack behavior (#103)
* [Controller] Add controller interface and implementations (#105)
* [Predictor/Planner] Clean up predictor and planner classes (#108)
* [Clustering] Change clustering algorithms to act on hierarchical objects (#111)
* [Utils] Clean up coordinates classes and tests (#112)
* [Assignment] Refactor assignment algorithms (#113)
* [Accessor] Use init accessor for read-only fields (#116)
* [Interceptors/Threats] Add Legacy prefix to existing interceptor and threat class names (#121)
* [Interceptors/Threats] Implement all interceptor and threat types (#122)
* [Proto/Configs] Add launcher types to proto definition and simulation configs (#123)
* [IADS] Clean up IADS and simulation manager (#124)
* [UI] Remove swarm status dialog and tactical panel (#125)
* [All] Remove all legacy code (#127)
* [Prefabs] Add prefabs for launchers (#128)
* [Release] Adjust minimum distance in proximity release (#129)
* [Configs] Add simulation configuration with 2 launchers (#130)
* [Simulation] Destroy terminated game objects (#132)
* [UI] Draw gizmos for agents (#133)
* [UI] Fix summary text label sizes (#134)
* [Clustering] Implement recursive clustering within hierarchy (#139)
* [UI] Clean up UI scripts (#140)
* [Reassignment] Assign new targets to excess interceptors (#141)
* [Evasion] Fix threat evasion of interceptors (#143)
* [Reassignment] Use capacity remaining to reassign interceptors (#144)
* [Agent] Add IsPursuable property (#145)
* [Reassignment] Implement threat reassignment (#146)
* [Escape] Add escape detectors (#147)
* [Escape] Check for escaping targets (#148)
* [Movement] Fix missile movement to avoid the ground (#149)
* [Reassignment] Fix relaunching multiple carrier interceptors (#150)
* [Unity] Fix serializable fields and references (#152)
* [Docs] Update docs with hierarchical strategy (#153)
* [Utils] Sample from normal distribution (#154)
* [Proto] Add run configuration proto (#155)
* [Visualization] Fix visualizing simulation monitor logs (#157)
* [Tools] Build standalone player (#158)
* [Manager] Add run manager to handle run configurations (#159)
* [Tools] Refactor common simulation-related constants and utilities (#160)
* [Tools] Add metric and aggregator classes (#161)
* [Tools] Process the aggregated logs of a simulation run (#162)
* [Docs] Update documentation with run configuration and logging (#163)
* [Tests] Remove unused Rigidbody variables from unit tests (#166)
* [Agent] Add target model API in Agent interface (#167)
* [Logging] Emit more detailed events (#168)
* [Metrics] Consider only missile interceptors in metrics (#169)
* [Logging] Remove logging from CP-SAT solver (#171)
* [Tools] Add script to animate telemetry log (#172)
* [Docs] Remove unnecessary docs image files (#174)
* [Interceptor] Rename IsPursuable to IsPursuer (#175)
* [UI] Reimplement tactical panel (#176)
* [UI] Add camera to follow and rotate around interceptors or threats (#177)
* [Configs] Add configuration for 5 swarms and 1000 UCAVs (#179)
* [Agent] Cache the agent transform (#180)
* [Agent] Clean up finding relative transformations (#181)
* [Configs] Exclude 5_swarms_1000_ucav configuration from CI (#182)
* [Agents] Fix collisions with terminated agents (#184)
* [Controls] Implement vector proportional navigation (#186)
* [Reassignment] Find subhierarchicals with at least one active target (#187)
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.

2 participants