Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add conflict-free invariant check to Configuration
[simgrid.git] / src / mc / explo / udpor / UnfoldingEvent.cpp
index 88f4b82dc7f132d121c78030fda10ef09f0b8d5b..83e1d7dba3e3b2197d284e306cfce2e6b2064d26 100644 (file)
@@ -40,4 +40,55 @@ EventSet UnfoldingEvent::get_history() const
   return History(this).get_all_events();
 }
 
+bool UnfoldingEvent::related_to(const UnfoldingEvent* other) const
+{
+  return this->in_history_of(other) or other->in_history_of(this);
+}
+
+bool UnfoldingEvent::in_history_of(const UnfoldingEvent* other) const
+{
+  return History(other).contains(this);
+}
+
+bool UnfoldingEvent::conflicts_with(const UnfoldingEvent* other) const
+{
+  // Events that have a causal relation never are in conflict
+  // in an unfolding structure. Two events in conflict must
+  // not be contained in each other's histories
+  if (related_to(other)) {
+    return false;
+  }
+
+  const EventSet my_history      = get_history();
+  const EventSet other_history   = other->get_history();
+  const EventSet unique_to_me    = my_history.subtracting(other_history);
+  const EventSet unique_to_other = other_history.subtracting(my_history);
+
+  for (const auto e_me : unique_to_me) {
+    for (const auto e_other : unique_to_other) {
+      if (e_me->has_conflicting_transition_with(e_other)) {
+        return true;
+      }
+    }
+  }
+  return false;
+}
+
+bool UnfoldingEvent::conflicts_with(const Configuration& config) const
+{
+  // A configuration is itself already conflict-free. Thus, it is
+  // simply a matter of testing whether or not the transition associated
+  // with the event is dependent with any already in `config` that are
+  // OUTSIDE this event's history (in an unfolding, events only conflict
+  // if they are not related)
+  const EventSet potential_conflicts = config.get_events().subtracting(get_history());
+  return std::any_of(potential_conflicts.cbegin(), potential_conflicts.cend(),
+                     [&](const UnfoldingEvent* e) { return this->has_conflicting_transition_with(e); });
+}
+
+bool UnfoldingEvent::has_conflicting_transition_with(const UnfoldingEvent* other) const
+{
+  return associated_transition->depends(other->associated_transition.get());
+}
+
 } // namespace simgrid::mc::udpor