+ // Stop immediately if there's nothing to search
+ if (topological_ordering.empty()) {
+ current_maximal_set = std::nullopt;
+ return;
+ }
+
+ const auto next_event_ref = [&]() {
+ if (not has_started_searching) {
+ has_started_searching = true;
+ return bookkeeper.find_next_candidate_event(topological_ordering.begin(), topological_ordering.end());
+ } else {
+ return continue_traversal_of_maximal_events_tree();
+ }
+ }();
+
+ // Out of events: we've finished
+ if (next_event_ref == topological_ordering.end()) {
+ current_maximal_set = std::nullopt;
+ return;
+ }
+
+ // We found some other event `e'` which is not in causally related with anything
+ // that currently exists in `current_maximal_set`, so add it in
+ add_element_to_current_maximal_set(*next_event_ref);
+ backtrack_points.push(next_event_ref);
+}
+
+maximal_subsets_iterator::topological_order_position
+maximal_subsets_iterator::continue_traversal_of_maximal_events_tree()
+{
+ // Nothing needs to be done if there isn't anyone to search for...
+ if (backtrack_points.empty()) {
+ return topological_ordering.end();
+ }
+
+ xbt_assert(current_maximal_set.has_value(), "Traversal continued even after the termination condition "
+ "was met. Please verify that the termination condition "
+ "of the iterator has not been modified");
+
+ // 1. First, check if we can keep expanding from the
+ // maximal set that we currently have
+ if (can_grow_maximal_set()) {