Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Install package non-interactively on CI
[simgrid.git] / src / mc / api / strategy / WaitStrategy.hpp
index edf75b2..ed5b9a0 100644 (file)
@@ -6,6 +6,7 @@
 #ifndef SIMGRID_MC_WAITSTRATEGY_HPP
 #define SIMGRID_MC_WAITSTRATEGY_HPP
 
+#include "Strategy.hpp"
 #include "src/mc/transition/Transition.hpp"
 
 namespace simgrid::mc {
@@ -13,11 +14,18 @@ namespace simgrid::mc {
 /** Wait MC guiding class that aims at minimizing the number of in-fly communication.
  *  When possible, it will try to take the wait transition. */
 class WaitStrategy : public Strategy {
-  double taken_wait_ = 0;
-  bool taking_wait_  = false;
+  int taken_wait_   = 0;
+  bool taking_wait_ = false;
 
 public:
-  void operator=(const WaitStrategy& guide) { taken_wait_ = guide.taken_wait_; }
+  WaitStrategy()                     = default;
+  ~WaitStrategy() override           = default;
+  WaitStrategy(const WaitStrategy&)  = delete;
+  WaitStrategy& operator=(const WaitStrategy& guide)
+  {
+    taken_wait_ = guide.taken_wait_;
+    return *this;
+  }
 
   bool is_transition_wait(Transition::Type type) const
   {
@@ -25,9 +33,9 @@ public:
            type == Transition::Type::MUTEX_WAIT or type == Transition::Type::SEM_WAIT;
   }
 
-  std::pair<aid_t, double> next_transition() const override
+  std::pair<aid_t, int> next_transition() const override
   {
-    std::pair<aid_t, double> if_no_wait = std::make_pair(-1, 0.0);
+    std::pair<aid_t, int> if_no_wait = std::make_pair(-1, 0);
     for (auto const& [aid, actor] : actors_to_run_) {
       if (not actor.is_todo() || not actor.is_enabled() || actor.is_done())
         continue;
@@ -43,7 +51,7 @@ public:
    *  to decrease the count. */
   void execute_next(aid_t aid, RemoteApp& app) override
   {
-    auto& actor = actors_to_run_.at(aid);
+    auto const& actor = actors_to_run_.at(aid);
     if ((not taking_wait_) and is_transition_wait(actor.get_transition(actor.get_times_considered())->type_)) {
       taken_wait_++;
       taking_wait_ = true;
@@ -58,9 +66,8 @@ public:
 
   void consider_best() override
   {
-    const auto& [aid, _] = this->next_transition();
-    auto actor           = actors_to_run_.find(aid);
-    if (actor != actors_to_run_.end()) {
+    aid_t aid = next_transition().first;
+    if (auto actor = actors_to_run_.find(aid); actor != actors_to_run_.end()) {
       actor->second.mark_todo();
       return;
     }