Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Finish the removal of mc::api by moving the last bits to the side
[simgrid.git] / src / mc / explo / Exploration.hpp
1 /* Copyright (c) 2016-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 #ifndef SIMGRID_MC_CHECKER_HPP
7 #define SIMGRID_MC_CHECKER_HPP
8
9 #include "simgrid/forward.h"
10 #include "src/mc/api/RemoteApp.hpp"
11 #include "src/mc/mc_record.hpp"
12 #include <xbt/Extendable.hpp>
13
14 #include <memory>
15
16 namespace simgrid::mc {
17
18 /** A model-checking exploration algorithm
19  *
20  *  This is an abstract base class used to group the data, state, configuration
21  *  of a model-checking algorithm.
22  *
23  *  Implementing this interface will probably not be really mandatory,
24  *  you might be able to write your model-checking algorithm as plain
25  *  imperative code instead.
26  *
27  *  It is expected to interact with the model-checked application through the
28  * `RemoteApp` interface (that is currently not perfectly sufficient to that extend). */
29 // abstract
30 class Exploration : public xbt::Extendable<Exploration> {
31   std::unique_ptr<RemoteApp> remote_app_;
32
33 public:
34   explicit Exploration(const std::vector<char*>& args);
35
36   // No copy:
37   Exploration(Exploration const&) = delete;
38   Exploration& operator=(Exploration const&) = delete;
39
40   virtual ~Exploration() = default;
41
42   /** Main function of this algorithm */
43   virtual void run() = 0;
44
45   /* These methods are callbacks called by the model-checking engine
46    * to get and display information about the current state of the
47    * model-checking algorithm: */
48
49   /** Show the current trace/stack
50    *
51    *  Could this be handled in the Session/ModelChecker instead? */
52   virtual RecordTrace get_record_trace() = 0;
53
54   /** Generate a textual execution trace of the simulated application */
55   virtual std::vector<std::string> get_textual_trace() = 0;
56
57   /** Log additional information about the state of the model-checker */
58   virtual void log_state();
59
60   RemoteApp& get_remote_app() { return *remote_app_.get(); }
61 };
62
63 // External constructors so that the types (and the types of their content) remain hidden
64 XBT_PUBLIC Exploration* create_liveness_checker(const std::vector<char*>& args);
65 XBT_PUBLIC Exploration* create_dfs_exploration(const std::vector<char*>& args);
66 XBT_PUBLIC Exploration* create_communication_determinism_checker(const std::vector<char*>& args);
67 XBT_PUBLIC Exploration* create_udpor_checker(const std::vector<char*>& args);
68
69 // FIXME: kill this template and use lambdas in boost::range_equal
70 struct DerefAndCompareByActorsCountAndUsedHeap {
71   template <class X, class Y> bool operator()(X const& a, Y const& b) const
72   {
73     return std::make_pair(a->actor_count_, a->heap_bytes_used) < std::make_pair(b->actor_count_, b->heap_bytes_used);
74   }
75 };
76 static inline DerefAndCompareByActorsCountAndUsedHeap compare_pair_by_actor_count_and_used_heap()
77 {
78   return DerefAndCompareByActorsCountAndUsedHeap();
79 }
80
81 } // namespace simgrid::mc
82
83 #endif