Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
BasicGuide handle next_transition if asked to
authormlaurent <mathieu.laurent@ens-rennes.fr>
Sat, 18 Mar 2023 13:05:13 +0000 (14:05 +0100)
committermlaurent <mathieu.laurent@ens-rennes.fr>
Sat, 18 Mar 2023 13:05:13 +0000 (14:05 +0100)
src/mc/api/State.cpp
src/mc/api/State.hpp
src/mc/api/guide/BasicGuide.hpp
src/mc/api/guide/GuidedState.hpp
src/mc/explo/DFSExplorer.cpp

index ba6c787..008a844 100644 (file)
@@ -78,7 +78,6 @@ Transition* State::get_transition() const
   return transition_;
 }
 
-// This should be intierely done in GuidedState
 aid_t State::next_transition() const
 {
   XBT_DEBUG("Search for an actor to run. %zu actors to consider", guide->actors_to_run_.size());
@@ -103,6 +102,11 @@ aid_t State::next_transition() const
   return -1;
 }
 
+std::pair<aid_t, double> State::next_transition_guided() const
+{
+  return guide->next_transition();
+}
+
 // This should be done in GuidedState, or at least interact with it
 void State::execute_next(aid_t next, RemoteApp& app)
 {
index a9dd2c4..5415ac8 100644 (file)
@@ -55,6 +55,9 @@ public:
   explicit State(RemoteApp& remote_app, const State* parent_state);
   /* Returns a positive number if there is another transition to pick, or -1 if not */
   aid_t next_transition() const;
+  /* Same as next_transition, but choice is now guided, and a double corresponding to the
+   internal cost of the transition is returned */
+  std::pair<aid_t, double> next_transition_guided() const;
 
   /* Explore a new path on the remote app; the parameter 'next' must be the result of a previous call to
    * next_transition() */
index 631db33..4fcd9f6 100644 (file)
@@ -12,8 +12,20 @@ namespace simgrid::mc {
 // Not Yet fully implemented
 class BasicGuide : public GuidedState {
 public:
-  std::pair<aid_t, double> next_transition() const override { return std::make_pair(0, 0); }
-  virtual void execute_next(aid_t aid) override { return; }
+  std::pair<aid_t, double> next_transition() const override
+  {
+
+    for (auto const& [aid, actor] : actors_to_run_) {
+      /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */
+      if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) {
+        continue;
+      }
+
+      return std::make_pair(aid, 1.0);
+    }
+    return std::make_pair(-1, 0.0);
+  }
+  void execute_next(aid_t aid, RemoteApp& app) override { return; }
 };
 
 } // namespace simgrid::mc
index 81dc19b..6eb3a96 100644 (file)
@@ -9,13 +9,14 @@
 namespace simgrid::mc {
 
 class GuidedState {
+protected:
   /** State's exploration status by actor. Not all the actors are there, only the ones that are ready-to-run in this
    * state */
   std::map<aid_t, ActorState> actors_to_run_;
 
 public:
   virtual std::pair<aid_t, double> next_transition() const = 0;
-  virtual void execute_next(aid_t aid)                     = 0;
+  virtual void execute_next(aid_t aid, RemoteApp& app)     = 0;
   friend class State;
 };
 
index 8475395..ad1bd08 100644 (file)
@@ -128,19 +128,19 @@ void DFSExplorer::run()
     }
 
     // Search for the next transition
-    aid_t next = state->next_transition();
+    // next_transition returns a pair<aid_t, double> in case we want to consider multiple state
+    auto [next, _] = state->next_transition_guided();
 
     if (next < 0) { // If there is no more transition in the current state, backtrack.
       XBT_DEBUG("There remains %lu actors, but none to interleave (depth %zu).", state->get_actor_count(),
                 stack_.size() + 1);
-      
+
       if (state->get_actor_count() == 0) {
         get_remote_app().finalize_app();
         XBT_VERB("Execution came to an end at %s (state: %ld, depth: %zu)", get_record_trace().to_string().c_str(),
                  state->get_num(), stack_.size());
-
       }
-      
+
       this->backtrack();
       continue;
     }
@@ -167,7 +167,6 @@ void DFSExplorer::run()
 
     on_state_creation_signal(next_state.get(), get_remote_app());
 
-               
     if (_sg_mc_termination)
       this->check_non_termination(next_state.get());
 
@@ -209,12 +208,12 @@ void DFSExplorer::backtrack()
   /* We may backtrack from somewhere either because it's leaf, or because every enabled process are in done/sleep set.
    * In the first case, we need to remove the last transition corresponding to the Finalize */
   if (stack_.back()->get_transition()->aid_ == 0)
-      stack_.pop_back();
-  
+    stack_.pop_back();
+
   /* Traverse the stack backwards until a state with a non empty interleave set is found, deleting all the states that
    *  have it empty in the way. For each deleted state, check if the request that has generated it (from its
-   *  predecessor state) depends on any other previous request executed before it on another process. If there exists one,
-   *  find the more recent, and add its process to the interleave set. If the process is not enabled at this point,
+   *  predecessor state) depends on any other previous request executed before it on another process. If there exists
+   * one, find the more recent, and add its process to the interleave set. If the process is not enabled at this point,
    *  then add every enabled process to the interleave */
   bool found_backtracking_point = false;
   while (not stack_.empty() && not found_backtracking_point) {
@@ -265,7 +264,8 @@ void DFSExplorer::backtrack()
     } else {
       XBT_DEBUG("Back-tracking to state %ld at depth %zu: %lu transitions left to be explored", state->get_num(),
                 stack_.size() + 1, state->count_todo());
-      stack_.push_back(std::move(state)); // Put it back on the stack so we can explore the next transition of the interleave
+      stack_.push_back(
+          std::move(state)); // Put it back on the stack so we can explore the next transition of the interleave
       found_backtracking_point = true;
     }
   }