Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Now handle random transition and multiple times transitions
[simgrid.git] / src / mc / explo / UdporChecker.cpp
index c8b2b94..98bab5e 100644 (file)
@@ -16,7 +16,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_udpor, mc, "Logging specific to verification
 
 namespace simgrid::mc::udpor {
 
-UdporChecker::UdporChecker(const std::vector<char*>& args) : Exploration(args)
+UdporChecker::UdporChecker(const std::vector<char*>& args) : Exploration(args, true)
 {
   // Initialize the map
 }
@@ -53,7 +53,6 @@ void UdporChecker::explore(const Configuration& C, EventSet D, EventSet A, std::
   // exploration would lead to a so-called
   // "sleep-set blocked" trace.
   if (enC.is_subset_of(D)) {
-
     if (not C.get_events().empty()) {
       // Report information...
     }
@@ -62,10 +61,11 @@ void UdporChecker::explore(const Configuration& C, EventSet D, EventSet A, std::
     // are no enabled transitions that can be executed from the
     // state reached by `C` (denoted `state(C)`), i.e. by some
     // execution of the transitions in C obeying the causality
-    // relation. Here, then, we would be in a deadlock.
+    // relation. Here, then, we may be in a deadlock (the other
+    // possibility is that we've finished running everything, and
+    // we wouldn't be in deadlock then)
     if (enC.empty()) {
       get_remote_app().check_deadlock();
-      DIE_IMPOSSIBLE;
     }
 
     return;
@@ -97,7 +97,7 @@ void UdporChecker::explore(const Configuration& C, EventSet D, EventSet A, std::
   D.insert(e);
 
   constexpr unsigned K = 10;
-  if (auto J_minus_C = compute_k_partial_alternative(D, C, K); J_minus_C.has_value()) {
+  if (auto J = C.compute_k_partial_alternative_to(D, this->unfolding, K); J.has_value()) {
     // Before searching the "right half", we need to make
     // sure the program actually reflects the fact
     // that we are searching again from `stateC` (the recursive
@@ -105,7 +105,8 @@ void UdporChecker::explore(const Configuration& C, EventSet D, EventSet A, std::
     restore_program_state_to(*stateC);
 
     // Explore(C, D + {e}, J \ C)
-    explore(C, D, std::move(J_minus_C.value()), std::move(stateC), std::move(prev_exC));
+    auto J_minus_C = J.value().get_events().subtracting(C.get_events());
+    explore(C, D, std::move(J_minus_C), std::move(stateC), std::move(prev_exC));
   }
 
   // D <-- D - {e}
@@ -158,7 +159,9 @@ EventSet UdporChecker::compute_exC_by_enumeration(const Configuration& C, const
        begin != maximal_subsets_iterator(); ++begin) {
     const EventSet& maximal_subset = *begin;
 
-    // TODO: Determine if `a` is enabled here
+    // Determining if `a` is enabled here might not be possible while looking at `a` opaquely
+    // We leave the implementation as-is to ensure that any addition would be simple
+    // if it were ever added
     const bool enabled_at_config_k = false;
 
     if (enabled_at_config_k) {
@@ -194,7 +197,7 @@ void UdporChecker::move_to_stateCe(State& state, const UnfoldingEvent& e)
                               "one transition of the state of an visited event is enabled, yet no\n"
                               "state was actually enabled. Please report this as a bug.\n"
                               "*********************************\n\n");
-  state.execute_next(next_actor);
+  state.execute_next(next_actor, get_remote_app());
 }
 
 void UdporChecker::restore_program_state_to(const State& stateC)
@@ -210,7 +213,7 @@ std::unique_ptr<State> UdporChecker::record_current_state()
   auto next_state = this->get_current_state();
 
   // In UDPOR, we care about all enabled transitions in a given state
-  next_state->mark_all_enabled_todo();
+  next_state->consider_all();
 
   return next_state;
 }
@@ -229,68 +232,6 @@ const UnfoldingEvent* UdporChecker::select_next_unfolding_event(const EventSet&
   return nullptr;
 }
 
-std::vector<const UnfoldingEvent*> UdporChecker::pick_k_partial_alternative_events(const EventSet& D,
-                                                                                   const unsigned k) const
-{
-  const unsigned size = std::min(k, static_cast<unsigned>(D.size()));
-  std::vector<const UnfoldingEvent*> D_hat(size);
-
-  // Potentially select intelligently here (e.g. perhaps pick events
-  // with transitions that we know are totally independent)...
-  //
-  // For now, simply pick the first `k` events (any subset suffices)
-  std::copy_n(D.begin(), size, D_hat.begin());
-  return D_hat;
-}
-
-std::optional<EventSet> UdporChecker::compute_k_partial_alternative(const EventSet& D, const Configuration& C,
-                                                                    const unsigned k) const
-{
-  // 1. Select k (of |D|, whichever is smaller) arbitrary events e_1, ..., e_k from D
-  const auto D_hat = pick_k_partial_alternative_events(D, k);
-
-  // 2. Build a U-comb <s_1, ..., s_k> of size k, where spike `s_i` contains
-  // all events in conflict with `e_i`
-  //
-  // 3. EXCEPT those events e' for which [e'] + C is not a configuration or
-  // [e'] intersects D
-  Comb comb(k);
-
-  for (const auto* e : this->unfolding) {
-    for (unsigned i = 0; i < k; i++) {
-      const auto& e_i = D_hat[i];
-      if (const auto e_local_config = History(e);
-          e_i->conflicts_with(e) and (not D.contains(e_local_config)) and C.is_compatible_with(e_local_config)) {
-        comb[i].push_back(e);
-      }
-    }
-  }
-
-  // 4. Find any such combination <e_1', ..., e_k'> in comb satisfying
-  // ~(e_i' # e_j') for i != j
-  // Note: This is a VERY expensive operation: it enumerates all possible
-  // ways to select an element from each spike
-
-  const auto map_events = [](const std::vector<Spike::const_iterator>& spikes) {
-    std::vector<const UnfoldingEvent*> events;
-    for (const auto& event_in_spike : spikes) {
-      events.push_back(*event_in_spike);
-    }
-    return EventSet(std::move(events));
-  };
-  const auto alternative =
-      std::find_if(comb.combinations_begin(), comb.combinations_end(),
-                   [&map_events](const auto& vector) { return map_events(vector).is_conflict_free(); });
-
-  // No such alternative exists
-  if (alternative == comb.combinations_end()) {
-    return std::nullopt;
-  }
-
-  // 5. J := [e_1] + [e_2] + ... + [e_k] is a k-partial alternative
-  return History(map_events(*alternative)).get_event_diff_with(C);
-}
-
 void UdporChecker::clean_up_explore(const UnfoldingEvent* e, const Configuration& C, const EventSet& D)
 {
   const EventSet C_union_D              = C.get_events().make_union(D);