Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Move dot_label() from Observer to Transition (+ some reorgs)
[simgrid.git] / src / mc / api / Transition.cpp
1 /* Copyright (c) 2015-2022. 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/api/Transition.hpp"
7 #include "xbt/asserts.h"
8 #include "xbt/string.hpp"
9 #include <simgrid/config.h>
10
11 #if SIMGRID_HAVE_MC
12 #include "src/mc/ModelChecker.hpp"
13 #endif
14
15 #include <sstream>
16
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_transition, mc, "Logging specific to MC transitions");
18
19 namespace simgrid {
20 namespace mc {
21 unsigned long Transition::executed_transitions_ = 0;
22 unsigned long Transition::replayed_transitions_ = 0;
23
24 // Do not move this to the header, to ensure that we have a vtable for Transition
25 Transition::~Transition() = default;
26
27 std::string Transition::to_string(bool) const
28 {
29   return "";
30 }
31 std::string Transition::dot_label() const
32 {
33   return xbt::string_printf("[(%ld)] %s", aid_, Transition::to_c_str(type_));
34 }
35 void Transition::replay() const
36 {
37   replayed_transitions_++;
38
39 #if SIMGRID_HAVE_MC
40   mc_model_checker->handle_simcall(aid_, times_considered_, false);
41   mc_model_checker->wait_for_requests();
42 #endif
43 }
44 std::string RandomTransition::to_string(bool verbose) const
45 {
46   return xbt::string_printf("Random([%d;%d] ~> %d)", min_, max_, times_considered_);
47 }
48
49 RandomTransition::RandomTransition(aid_t issuer, int times_considered, char* buffer)
50     : Transition(Type::RANDOM, issuer, times_considered)
51 {
52   std::stringstream stream(buffer);
53   stream >> min_ >> max_;
54 }
55 std::string RandomTransition::dot_label() const
56 {
57   return Transition::dot_label() + to_c_str(type_);
58 }
59
60 } // namespace mc
61 } // namespace simgrid