- for (const auto racing_event_handle : execution_seq_.get_racing_events_of(next_E_p)) {
- // To determine if the race is reversible, we have to ensure
- // that actor `p` running `next_E_p` (viz. the event such that
- // `racing_event -> (E_p) next_E_p` and no other event
- // "happens-between" the two) is enabled in any equivalent
- // execution where `racing_event` happens before `next_E_p`.
- //
- // Importantly, it is equivalent to checking if in ANY
- // such equivalent execution sequence where `racing_event`
- // happens-before `next_E_p` that `p` is enabled in `pre(racing_event, E.p)`.
- // Thus it suffices to check THIS execution
- //
- // If the actor `p` is not enabled at s_[E'], it is not a *reversible* race
- const std::shared_ptr<State> prev_state = stack_[racing_event_handle];
- if (prev_state->is_actor_enabled(p)) {
- // NOTE: To incorporate the idea of attempting to select the "best"
- // backtrack point into SDPOR, instead of selecting the `first` initial,
- // we should instead compute all choices and decide which is best
- const std::optional<aid_t> q =
- execution_seq_.get_first_sdpor_initial_from(racing_event_handle, prev_state->get_backtrack_set());
- if (q.has_value()) {
- prev_state->consider_one(q.value());
- opened_states_.emplace_back(std::move(prev_state));
- }
+ for (const auto e_race : execution_seq_.get_reversible_races_of(next_E_p)) {
+ State* prev_state = stack_[e_race].get();
+ const auto choices = execution_seq_.get_missing_source_set_actors_from(e_race, prev_state->get_backtrack_set());
+ if (not choices.empty()) {
+ // NOTE: To incorporate the idea of attempting to select the "best" backtrack point into SDPOR, instead of
+ // selecting the `first` initial, we should instead compute all choices and decide which is best
+ //
+ // Here, we choose the actor with the lowest ID to ensure we get deterministic results
+ const auto q =
+ std::min_element(choices.begin(), choices.end(), [](const aid_t a1, const aid_t a2) { return a1 < a2; });
+ prev_state->consider_one(*q);
+ opened_states_.emplace_back(std::move(prev_state));