Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement the RandomTransition
[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 Transition::~Transition() {
25 } // Make sure that we have a vtable for Transition by putting this virtual function out of the header
26
27 std::string Transition::to_string(bool verbose)
28 {
29   return textual_;
30 }
31 const char* Transition::to_cstring(bool verbose)
32 {
33   to_string();
34   return textual_.c_str();
35 }
36 void Transition::replay() const
37 {
38   replayed_transitions_++;
39
40 #if SIMGRID_HAVE_MC
41   mc_model_checker->handle_simcall(aid_, times_considered_, false);
42   mc_model_checker->wait_for_requests();
43 #endif
44 }
45 std::string RandomTransition::to_string(bool verbose)
46 {
47   return xbt::string_printf("Random([%d;%d] ~> %d)", min_, max_, times_considered_);
48 }
49
50 RandomTransition::RandomTransition(aid_t issuer, int times_considered, char* buffer)
51     : Transition(issuer, times_considered)
52 {
53   std::stringstream stream(buffer);
54   stream >> min_ >> max_;
55 }
56
57 } // namespace mc
58 } // namespace simgrid