Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/mwapl/simgrid
authormlaurent <mathieu.laurent@ens-rennes.fr>
Mon, 5 Jun 2023 18:56:26 +0000 (20:56 +0200)
committermlaurent <mathieu.laurent@ens-rennes.fr>
Mon, 5 Jun 2023 18:56:26 +0000 (20:56 +0200)
1  2 
src/mc/api/strategy/BasicStrategy.hpp
src/mc/transition/TransitionAny.cpp

  
  namespace simgrid::mc {
  
 -/** Basic MC guiding class which corresponds to no guide at all (random choice) */
 +/** Basic MC guiding class which corresponds to no guide. When asked for different states
 + *  it will follow a depth first search politics to minize the number of opened states. */
  class BasicStrategy : public Strategy {
 +    int depth_ = 100000; // Arbitrary starting point. next_transition must return a positiv value to work with threshold in DFSExplorer
 +
  public:
 -  void operator=(const BasicStrategy& other) { this->penalties_ = other.penalties_; }
 +  void copy_from(const Strategy* strategy) override
 +  {
 +    const BasicStrategy* cast_strategy = static_cast<BasicStrategy const*>(strategy);
 +    xbt_assert(cast_strategy != nullptr);
 +    depth_ = cast_strategy->depth_ - 1;
 +    xbt_assert(depth_ > 0, "The exploration reached a depth greater than 100000. We will stop here to prevent weird interaction with DFSExplorer.");
 +  }
 +  BasicStrategy()                     = default;
 +  ~BasicStrategy() override           = default;
  
 -  std::pair<aid_t, double> best_transition(bool need_to_be_todo) const
 +  std::pair<aid_t, int> next_transition() const override
    {
 -    auto min = std::make_pair(-1, 10000);
      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() and need_to_be_todo) || not actor.is_enabled() || actor.is_done()) {
 +      if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) {
          continue;
        }
 -      if (actor.get_transition(actor.get_times_considered())->type_ != Transition::Type::TESTANY)
 -        return std::make_pair(aid, 0.0);
 -
 -      double dist;
 -
 -      TestAnyTransition* transition =
 -          static_cast<TestAnyTransition*>(actor.get_transition(actor.get_times_considered()));
  
 -      auto iterator = penalties_.find(aid);
 -      if (iterator != penalties_.end())
 -        dist = (*iterator).second;
 -      else
 -        dist = 0;
 -
 -      if (not transition->result())
 -        dist += 5000;
 -
 -      if (dist < min.second)
 -        min = std::make_pair(aid, dist);
 +      return std::make_pair(aid, depth_);
      }
 -
 -    if (min.first == -1)
 -      return std::make_pair(-1, -1000);
 -    return min;
 -  }
 -
 -  std::pair<aid_t, double> next_transition() const override { return best_transition(true); }
 -
 -  void execute_next(aid_t aid, RemoteApp& app) override
 -  {
 -    auto actor = actors_to_run_.at(aid);
 -    if (actor.get_transition(actor.get_times_considered())->type_ == Transition::Type::TESTANY) {
 -      TestAnyTransition* transition =
 -          static_cast<TestAnyTransition*>(actor.get_transition(actor.get_times_considered()));
 -      if (not transition->result()) {
 -        penalties_[aid] = penalties_[aid] + 1.0;
 -        return;
 -      }
 -    }
 -    penalties_[aid] = 0;
 +    return std::make_pair(-1, depth_);
    }
-   void execute_next(aid_t aid, RemoteApp& app) override { return; }
  
    void consider_best() override
    {
 -    const auto& [aid, _] = this->best_transition(false);
 -    auto actor           = actors_to_run_.find(aid);
 -    if (actor != actors_to_run_.end()) {
 -      actor->second.mark_todo();
 -      return;
 -    }
--    for (auto& [_, actor] : actors_to_run_) {
--      if (actor.is_todo())
--        return;
--      if (actor.is_enabled() and not actor.is_done()) {
--        actor.mark_todo();
--        return;
--      }
--    }
++    for (auto& [_, actor] : actors_to_run_) 
++      if (actor.is_todo())
++          return;
++
++    for (auto& [_, actor] : actors_to_run_) 
++      if (actor.is_enabled() and not actor.is_done()) 
++          actor.mark_todo();
++      
++    
    }
  };
  
Simple merge