Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / mc / transition / TransitionAny.cpp
1 /* Copyright (c) 2015-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 "src/mc/transition/TransitionAny.hpp"
7 #include "simgrid/config.h"
8 #include "xbt/asserts.h"
9 #include "xbt/string.hpp"
10
11 #include <sstream>
12
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_any, mc_transition, "Logging specific to MC WaitAny / TestAny transitions");
14
15 namespace simgrid::mc {
16
17 TestAnyTransition::TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
18     : Transition(Type::TESTANY, issuer, times_considered)
19 {
20   int size;
21   xbt_assert(stream >> size);
22   for (int i = 0; i < size; i++) {
23     Transition* t = deserialize_transition(issuer, 0, stream);
24     XBT_DEBUG("TestAny received a transition %s", t->to_string(true).c_str());
25     transitions_.push_back(t);
26   }
27 }
28 std::string TestAnyTransition::to_string(bool verbose) const
29 {
30   auto res = xbt::string_printf("TestAny{ ");
31   for (auto const* t : transitions_)
32     res += t->to_string(verbose);
33   res += " }";
34   return res;
35 }
36 bool TestAnyTransition::depends(const Transition* other) const
37 {
38   // Actions executed by the same actor are always dependent
39   if (other->aid_ == aid_)
40     return true;
41
42   return transitions_[times_considered_]->depends(other);
43 }
44 WaitAnyTransition::WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
45     : Transition(Type::WAITANY, issuer, times_considered)
46 {
47   int size;
48   xbt_assert(stream >> size);
49   for (int i = 0; i < size; i++) {
50     Transition* t = deserialize_transition(issuer, 0, stream);
51     transitions_.push_back(t);
52   }
53 }
54 std::string WaitAnyTransition::to_string(bool verbose) const
55 {
56   auto res = xbt::string_printf("WaitAny{ ");
57   for (auto const* t : transitions_)
58     res += t->to_string(verbose);
59   res += " }";
60   return res;
61 }
62 bool WaitAnyTransition::depends(const Transition* other) const
63 {
64   // Actions executed by the same actor are always dependent
65   if (other->aid_ == aid_)
66     return true;
67   return transitions_[times_considered_]->depends(other);
68 }
69
70 } // namespace simgrid::mc