Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Replace state copy with recipe: list of transition to replay a state
[simgrid.git] / src / mc / api / guide / GuidedState.hpp
1 /* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "xbt/asserts.h"
7
8 #ifndef SIMGRID_MC_GUIDEDSTATE_HPP
9 #define SIMGRID_MC_GUIDEDSTATE_HPP
10
11 namespace simgrid::mc {
12
13 class GuidedState {
14 protected:
15   /** State's exploration status by actor. Not all the actors are there, only the ones that are ready-to-run in this
16    * state */
17   std::map<aid_t, ActorState> actors_to_run_;
18
19 public:
20   virtual ~GuidedState()                                   = default;
21   virtual std::pair<aid_t, double> next_transition() const = 0;
22   virtual void execute_next(aid_t aid, RemoteApp& app)     = 0;
23   virtual void consider_best()                             = 0;
24
25   // Mark the first enabled and not yet done transition as todo
26   // If there's already a transition marked as todo, does nothing
27   void consider_one(aid_t aid)
28   {
29     xbt_assert(actors_to_run_.at(aid).is_enabled() and not actors_to_run_.at(aid).is_done(),
30                "Tried to mark as TODO actor %ld but it is either not enabled or already done", aid);
31     actors_to_run_.at(aid).mark_todo();
32   }
33   // Matk as todo all actors enabled that are not done yet
34   unsigned long consider_all()
35   {
36     unsigned long count = 0;
37     for (auto& [_, actor] : actors_to_run_)
38       if (actor.is_enabled() and not actor.is_done()) {
39         actor.mark_todo();
40         count++;
41       }
42     return count;
43   }
44
45   friend class State;
46 };
47
48 } // namespace simgrid::mc
49
50 #endif