X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/8d3909773bd555ba7a4e5184df0430b44daa08b9..cddc05516f6bb5cb50d472ac61079cdee0243d20:/src/mc/explo/udpor/UnfoldingEvent.cpp diff --git a/src/mc/explo/udpor/UnfoldingEvent.cpp b/src/mc/explo/udpor/UnfoldingEvent.cpp index ee6de7cba1..83e1d7dba3 100644 --- a/src/mc/explo/udpor/UnfoldingEvent.cpp +++ b/src/mc/explo/udpor/UnfoldingEvent.cpp @@ -4,10 +4,11 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "src/mc/explo/udpor/UnfoldingEvent.hpp" +#include "src/mc/explo/udpor/History.hpp" namespace simgrid::mc::udpor { -UnfoldingEvent::UnfoldingEvent(std::initializer_list init_list) +UnfoldingEvent::UnfoldingEvent(std::initializer_list init_list) : UnfoldingEvent(EventSet(std::move(init_list))) { } @@ -34,4 +35,60 @@ bool UnfoldingEvent::operator==(const UnfoldingEvent& other) const return this->immediate_causes == other.immediate_causes; } +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