- const auto p = parent_state_->get_transition_out()->aid_;
- const auto branch = std::find_if(
- parent_state_->wakeup_tree_.begin(), parent_state_->wakeup_tree_.end(),
- [=](const odpor::WakeupTreeNode* node) { return node->is_single_process() && node->get_first_actor() == p; });
- xbt_assert(branch != parent_state_->wakeup_tree_.end(),
- "Attempted to create a subtree from the wakeup tree of the parent "
- "state using actor `%ld`, but no such subtree could be found. "
- "This implies that the wakeup tree management is broken, "
- "and more specifically that subtree formation is not working "
- "as intended; for if this state was generated by the parent "
- "having taken an action by actor `%ld`, this implies that "
- "ODPOR found `%ld` as a candidate branch prior",
- p, p, p);
- this->wakeup_tree_ = odpor::WakeupTree::make_subtree_rooted_at(*branch);
-}
-
-void State::remove_subtree_starting_with(aid_t p)
-{
- const auto branch = std::find_if(wakeup_tree_.begin(), wakeup_tree_.end(), [=](const odpor::WakeupTreeNode* node) {
- return node->is_single_process() && node->get_first_actor() == p;
- });
- xbt_assert(branch != wakeup_tree_.end(), "Attempted to remove a subtree of this state's "
- "wakeup tree that does not exist");
- this->wakeup_tree_.remove_subtree_rooted_at(*branch);
+ const auto min_process_node = parent_state_->wakeup_tree_.get_min_single_process_node();
+ xbt_assert(min_process_node.has_value(), "Attempting to construct a subtree for a substate from a "
+ "parent with an empty wakeup tree. This indicates either that ODPOR "
+ "actor selection in State.cpp is incorrect, or that the code "
+ "deciding when to make subtrees in ODPOR is incorrect");
+ if (not(get_transition_in()->aid_ == min_process_node.value()->get_actor() &&
+ get_transition_in()->type_ == min_process_node.value()->get_action()->type_)) {
+ XBT_ERROR("We tried to make a subtree from a parent state who claimed to have executed `%s` on actor %ld "
+ "but whose wakeup tree indicates it should have executed `%s` on actor %ld. This indicates "
+ "that exploration is not following ODPOR. Are you sure you're choosing actors "
+ "to schedule from the wakeup tree? Trace so far:",
+ get_transition_in()->to_string(false).c_str(), get_transition_in()->aid_,
+ min_process_node.value()->get_action()->to_string(false).c_str(), min_process_node.value()->get_actor());
+ for (auto const& elm : Exploration::get_instance()->get_textual_trace())
+ XBT_ERROR("%s", elm.c_str());
+ xbt_abort();
+ }
+ this->wakeup_tree_ = odpor::WakeupTree::make_subtree_rooted_at(min_process_node.value());
+}
+
+void State::remove_subtree_using_current_out_transition()
+{
+ if (auto out_transition = get_transition_out(); out_transition != nullptr) {
+ if (const auto min_process_node = wakeup_tree_.get_min_single_process_node(); min_process_node.has_value()) {
+ xbt_assert((out_transition->aid_ == min_process_node.value()->get_actor()) &&
+ (out_transition->type_ == min_process_node.value()->get_action()->type_),
+ "We tried to make a subtree from a parent state who claimed to have executed `%s` "
+ "but whose wakeup tree indicates it should have executed `%s`. This indicates "
+ "that exploration is not following ODPOR. Are you sure you're choosing actors "
+ "to schedule from the wakeup tree?",
+ out_transition->to_string(false).c_str(),
+ min_process_node.value()->get_action()->to_string(false).c_str());
+ }
+ }
+ wakeup_tree_.remove_min_single_process_subtree();
+}
+
+void State::remove_subtree_at_aid(const aid_t proc)
+{
+ wakeup_tree_.remove_subtree_at_aid(proc);
+}
+
+odpor::WakeupTree::InsertionResult State::insert_into_wakeup_tree(const odpor::PartialExecution& pe,
+ const odpor::Execution& E)
+{
+ return this->wakeup_tree_.insert(E, pe);
+}
+
+void State::do_odpor_unwind()
+{
+ if (auto out_transition = get_transition_out(); out_transition != nullptr) {
+ remove_subtree_using_current_out_transition();
+
+ // Only when we've exhausted all variants of the transition which
+ // can be chosen from this state do we finally add the actor to the
+ // sleep set. This ensures that the current logic handling sleep sets
+ // works with ODPOR in the way we intend it to work. There is not a
+ // good way to perform transition equality in SimGrid; instead, we
+ // effectively simply check for the presence of an actor in the sleep set.
+ if (not get_actors_list().at(out_transition->aid_).has_more_to_consider())
+ add_sleep_set(std::move(out_transition));
+ }