Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Better handling of test any
[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 #if SIMGRID_HAVE_MC
11 #include "src/mc/api/RemoteApp.hpp"
12 #include "src/mc/api/State.hpp"
13 #endif
14
15 #include <sstream>
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_trans_any, mc_transition, "Logging specific to MC WaitAny / TestAny transitions");
18
19 namespace simgrid::mc {
20
21 TestAnyTransition::TestAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
22     : Transition(Type::TESTANY, issuer, times_considered)
23 {
24   int size;
25   xbt_assert(stream >> size);
26   for (int i = 0; i < size; i++) {
27     Transition* t = deserialize_transition(issuer, 0, stream);
28     XBT_DEBUG("TestAny received a transition %s", t->to_string(true).c_str());
29     transitions_.push_back(t);
30   }
31 }
32 std::string TestAnyTransition::to_string(bool verbose) const
33 {
34   auto res = xbt::string_printf("TestAny(%s){ ", this->result() ? "TRUE" : "FALSE");
35   for (auto const* t : transitions_) {
36     res += t->to_string(verbose);
37     res += "; ";
38   }
39   res += " }";
40   return res;
41 }
42 bool TestAnyTransition::depends(const Transition* other) const
43 {
44   return transitions_[times_considered_]->depends(other);
45 }
46 WaitAnyTransition::WaitAnyTransition(aid_t issuer, int times_considered, std::stringstream& stream)
47     : Transition(Type::WAITANY, issuer, times_considered)
48 {
49   int size;
50   xbt_assert(stream >> size);
51   for (int i = 0; i < size; i++) {
52     Transition* t = deserialize_transition(issuer, 0, stream);
53     transitions_.push_back(t);
54   }
55 }
56 std::string WaitAnyTransition::to_string(bool verbose) const
57 {
58   auto res = xbt::string_printf("WaitAny{ ");
59   for (auto const* t : transitions_)
60     res += t->to_string(verbose);
61   res += " }";
62   return res;
63 }
64 bool WaitAnyTransition::depends(const Transition* other) const
65 {
66   return transitions_[times_considered_]->depends(other);
67 }
68
69 } // namespace simgrid::mc