#include "src/kernel/activity/CommImpl.hpp"
#include "src/mc/remote/RemotePtr.hpp"
+#include <algorithm>
#include <exception>
#include <vector>
unsigned int get_max_considered() const { return max_consider_; }
unsigned int get_times_considered() const { return times_considered_; }
unsigned int get_times_not_considered() const { return max_consider_ - times_considered_; }
+ bool has_more_to_consider() const { return get_times_not_considered() > 0; }
aid_t get_aid() const { return aid_; }
/* returns whether the actor is marked as enabled in the application side */
}
void mark_done() { this->state_ = InterleavingType::done; }
- std::shared_ptr<Transition> get_transition() const { return get_transition(get_times_considered()); }
+ /**
+ * @brief Retrieves the transition that we should consider for execution by
+ * this actor from the State instance with respect to which this ActorState object
+ * is considered
+ */
+ std::shared_ptr<Transition> get_transition() const
+ {
+ // The rationale for this selection is as follows:
+ //
+ // 1. For transitions with only one possibility of execution,
+ // we always wish to select action `0` even if we've
+ // marked the transition already as considered (which
+ // we'll do if we explore a trace following that transition).
+ //
+ // 2. For transitions that can be considered multiple
+ // times, we want to be sure to select the most up-to-date
+ // action. In general, this means selecting that which is
+ // now being considered at this state. If, however, we've
+ // executed the
+ //
+ // The formula satisfies both of the above conditions:
+ //
+ // > std::clamp(times_considered_, 0u, max_consider_ - 1)
+ return get_transition(std::clamp(times_considered_, 0u, max_consider_ - 1));
+ }
std::shared_ptr<Transition> get_transition(unsigned times_considered) const
{
if (actor.is_enabled()) {
// For each variant of the transition, we want
// to insert the action into the tree. This ensures
- // that all variants are searched?
- //
- // TODO: How do we modify sleep sets then?
+ // that all variants are searched
for (unsigned times = 0; times < actor.get_max_considered(); ++times) {
wakeup_tree_.insert(prior, odpor::PartialExecution{actor.get_transition(times)});
}
{
if (auto out_transition = get_transition_out(); out_transition != nullptr) {
remove_subtree_using_current_out_transition();
- add_sleep_set(std::move(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 (!get_actors_list().at(out_transition->aid_).has_more_to_consider())
+ add_sleep_set(std::move(out_transition));
}
}
const Execution pre_E_e = get_prefix_before(e);
const auto sleeping_actors = state_at_e.get_sleeping_actors();
- // Check if any enabled actor independent with this execution after `v`
- // is contained in the sleep set
+ // Check if any enabled actor that is independent with
+ // this execution after `v` is contained in the sleep set
for (const auto& [aid, astate] : state_at_e.get_actors_list()) {
- // TODO: We have to be able to react appropriately here when adding new
- // types of transitions (multiple choices can be made :( )
- if (astate.is_enabled() and pre_E_e.is_independent_with_execution_of(v, astate.get_transition(0))) {
- if (sleeping_actors.count(aid) > 0) {
- return std::nullopt;
- }
+ const bool is_in_WI_E =
+ astate.is_enabled() and pre_E_e.is_independent_with_execution_of(v, astate.get_transition());
+ const bool is_in_sleep_set = sleeping_actors.count(aid) > 0;
+
+ // `action(aid)` is in `WI_[E](v)` but also is contained in the sleep set.
+ // This implies that the intersection between the two is non-empty
+ if (is_in_WI_E && is_in_sleep_set) {
+ return std::nullopt;
}
}
}