Skip to content

[Simulation] Mapping graph visitors#6087

Draft
alxbilger wants to merge 36 commits intosofa-framework:masterfrom
alxbilger:mappinggraphvisitor
Draft

[Simulation] Mapping graph visitors#6087
alxbilger wants to merge 36 commits intosofa-framework:masterfrom
alxbilger:mappinggraphvisitor

Conversation

@alxbilger
Copy link
Copy Markdown
Contributor

@alxbilger alxbilger commented Apr 17, 2026

Still a draft, not to be reviewed yet. Need to use the CI 🔥

[with-all-tests]


By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).


Reviewers will merge this pull-request only if

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).

@alxbilger alxbilger added pr: enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request labels Apr 17, 2026
@alxbilger alxbilger force-pushed the mappinggraphvisitor branch from 0adee88 to 583fbd5 Compare April 17, 2026 18:04
Adds support for targeted node traversal in `MappingGraph::traverseTopDown` using defined scopes:
*   `ONLY_MAPPED_NODES`: Visits only components involved in mappings.
*   `ONLY_MAIN_NODES`: Visits component groups that do not rely on external mapping inputs.

This change updates the API to provide fine-grained control over which nodes are processed during traversal, and includes new tests validating these scoped behaviors.
…ersal

Updates `MappingGraph::traverseBottomUp` to accept a `VisitorApplication` scope, ensuring consistent node filtering logic with top-down traversal.

This allows targeted processing of nodes (e.g., only mapped or main nodes) when traversing dependencies from the bottom up. Tests are updated to validate scoped bottom-up behavior.
Updates `BaseMappingGraphNode::isMapped()` to use `std::optional<bool>` for managing and lazily computing the node's mapped status, improving efficiency of repeated checks.
Updates `MappingGraph::traverseComponentGroups` to accept a scope parameter, allowing controlled filtering and processing of component groups during graph traversal.
Updates `MappingGraph2_test` to prepend descriptive prefixes (e.g., `[STATE]`, `[MAPPING]`) to node names visited during traversals, ensuring clear identification of the component type for accurate testing results.
Implements overloads for `traverseTopDown_` and `traverseBottomUp_` in `MappingGraph`, allowing users to pass a callable object or lambda directly.

This approach simplifies graph traversal by leveraging the new `CallableVisitor` pattern, which automatically handles invoking the provided logic against visited components. Tests are updated to validate lambda usage during complex graph traversals.
Introduces a `clear()` method for `MappingGraph` to reset the entire graph state. This function ensures that all internal members, such as root node pointers, build flags, mapping status tracking, and associated data containers, are properly initialized back to their default empty state.
Introduces `traverseComponentGroups_` in `MappingGraph`, allowing users to pass a callable object or lambda directly for graph component group traversal. This standardizes the usage of callable visitors across all major graph traversal methods, improving API consistency and reducing boilerplate code.
Extracts all core graph traversal methods (Top-Down, Bottom-Up, component group traversals) from `MappingGraph` and moves their implementation to a dedicated `MappingGraphAlgorithms` class. This improves modularity by separating the algorithm details from the main graph structure API.

Updates headers and tests to utilize the new `algorithms` member struct for all traversal calls.
Adds an overloaded `traverse` method to `MappingGraphAlgorithms`. This overload allows the graph traversal process to utilize a `TaskScheduler`, executing node visits concurrently for improved performance when processing large graphs on multi-threaded environments. It falls back to synchronous traversal if no scheduler is provided.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: enhancement About a possible enhancement pr: status to review To notify reviewers to review this pull-request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant