1 /* Copyright (c) 2007-2022. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SIMGRID_MC_LIVENESS_CHECKER_HPP
8 #define SIMGRID_MC_LIVENESS_CHECKER_HPP
10 #include "src/mc/api/State.hpp"
11 #include "src/mc/explo/Exploration.hpp"
12 #include "xbt/automaton.hpp"
18 namespace simgrid::mc {
20 class XBT_PRIVATE Pair {
23 bool search_cycle = false;
24 std::shared_ptr<State> graph_state = nullptr; /* System state included */
25 xbt_automaton_state_t automaton_state = nullptr;
26 std::shared_ptr<const std::vector<int>> atomic_propositions;
29 bool exploration_started = false;
31 explicit Pair(unsigned long expanded_pairs);
33 Pair(Pair const&) = delete;
34 Pair& operator=(Pair const&) = delete;
37 class XBT_PRIVATE VisitedPair {
40 int other_num = 0; /* Dot output for */
41 std::shared_ptr<State> graph_state = nullptr; /* System state included */
42 xbt_automaton_state_t automaton_state;
43 std::shared_ptr<const std::vector<int>> atomic_propositions;
44 std::size_t heap_bytes_used = 0;
47 VisitedPair(int pair_num, xbt_automaton_state_t automaton_state,
48 std::shared_ptr<const std::vector<int>> atomic_propositions, std::shared_ptr<State> graph_state);
51 class XBT_PRIVATE LivenessChecker : public Exploration {
53 explicit LivenessChecker(Session* session);
55 RecordTrace get_record_trace() override;
56 std::vector<std::string> get_textual_trace() override;
57 void log_state() override;
60 std::shared_ptr<const std::vector<int>> get_proposition_values() const;
61 std::shared_ptr<VisitedPair> insert_acceptance_pair(Pair* pair);
62 int insert_visited_pair(std::shared_ptr<VisitedPair> visited_pair, Pair* pair);
63 void show_acceptance_cycle(std::size_t depth);
65 void remove_acceptance_pair(int pair_num);
66 void purge_visited_pairs();
68 std::shared_ptr<Pair> create_pair(const Pair* pair, xbt_automaton_state_t state,
69 std::shared_ptr<const std::vector<int>> propositions);
71 // A stack of (application_state, automaton_state) pairs for DFS exploration:
72 std::list<std::shared_ptr<Pair>> exploration_stack_;
73 std::list<std::shared_ptr<VisitedPair>> acceptance_pairs_;
74 std::list<std::shared_ptr<VisitedPair>> visited_pairs_;
75 unsigned long visited_pairs_count_ = 0;
76 unsigned long expanded_pairs_count_ = 0;
77 int previous_pair_ = 0;
78 std::string previous_request_;
81 } // namespace simgrid::mc