X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/97e2219ed6c0e511f6165460cec79afadf42f589..222bdffb8f8c4d7e5660c049c2c2bdadd8f7cc07:/src/mc/api/State.hpp?ds=sidebyside diff --git a/src/mc/api/State.hpp b/src/mc/api/State.hpp index dd243f862a..6e963ca276 100644 --- a/src/mc/api/State.hpp +++ b/src/mc/api/State.hpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2007-2022. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -6,52 +6,96 @@ #ifndef SIMGRID_MC_STATE_HPP #define SIMGRID_MC_STATE_HPP -#include "src/mc/mc_pattern.hpp" -#include "src/mc/sosp/Snapshot.hpp" +#include "src/mc/api/ActorState.hpp" +#include "src/mc/api/ClockVector.hpp" +#include "src/mc/api/RemoteApp.hpp" +#include "src/mc/api/strategy/Strategy.hpp" #include "src/mc/transition/Transition.hpp" -namespace simgrid { -namespace mc { +#if SIMGRID_HAVE_STATEFUL_MC +#include "src/mc/sosp/Snapshot.hpp" +#endif + +namespace simgrid::mc { /* A node in the exploration graph (kind-of) */ class XBT_PRIVATE State : public xbt::Extendable { static long expended_states_; /* Count total amount of states, for stats */ - /* Outgoing transition: what was the last transition that we took to leave this state? */ - std::unique_ptr transition_; + /** @brief The outgoing transition is the last transition that we took to leave this state. */ + std::shared_ptr outgoing_transition_ = nullptr; - /** Sequential state number (used for debugging) */ - long num_ = 0; + /** @brief The incoming transition is what led to this state, coming from its parent */ + std::shared_ptr incoming_transition_ = nullptr; - /** State's exploration status by process */ - std::vector actor_states_; + /** Sequential state ID (used for debugging) */ + long num_ = 0; /** Snapshot of system state (if needed) */ std::shared_ptr system_state_; -public: - explicit State(); + /** Unique parent of this state. Required both for sleep set computation + and for guided model-checking */ + std::shared_ptr parent_state_ = nullptr; + + std::shared_ptr strategy_; + /* Sleep sets are composed of the actor and the corresponding transition that made it being added to the sleep + * set. With this information, it is check whether it should be removed from it or not when exploring a new + * transition */ + std::map sleep_set_; + +public: + explicit State(RemoteApp& remote_app); + explicit State(RemoteApp& remote_app, std::shared_ptr parent_state); /* Returns a positive number if there is another transition to pick, or -1 if not */ - int next_transition() const; + aid_t next_transition() const; // this function should disapear as it is redundant with the next one - /* Explore a new path; the parameter must be the result of a previous call to next_transition() */ - void execute_next(int next); + /* Same as next_transition, but choice is now guided, and an integer corresponding to the + internal cost of the transition is returned */ + std::pair next_transition_guided() const; + + /** + * @brief Explore a new path on the remote app; the parameter 'next' must be the result of a previous call to + * next_transition() + */ + std::shared_ptr execute_next(aid_t next, RemoteApp& app); long get_num() const { return num_; } std::size_t count_todo() const; - void mark_todo(aid_t actor) { this->actor_states_[actor].mark_todo(); } - bool is_done(aid_t actor) const { return this->actor_states_[actor].is_done(); } - Transition* get_transition() const; - void set_transition(Transition* t) { transition_.reset(t); } + std::size_t count_todo_multiples() const; + + /* Marking as TODO some actor in this state: + * + consider_one mark aid actor (and assert it is possible) + * + consider_best ensure one actor is marked by eventually marking the best regarding its guiding methode + * + conside_all mark all enabled actor that are not done yet */ + void consider_one(aid_t aid) const { strategy_->consider_one(aid); } + void consider_best() const { strategy_->consider_best(); } + unsigned long consider_all() const { return strategy_->consider_all(); } + + bool is_actor_done(aid_t actor) const { return strategy_->actors_to_run_.at(actor).is_done(); } + std::shared_ptr get_transition_out() const { return outgoing_transition_; } + std::shared_ptr get_transition_in() const { return incoming_transition_; } + std::shared_ptr get_parent_state() const { return parent_state_; } + + std::map const& get_actors_list() const { return strategy_->actors_to_run_; } + + unsigned long get_actor_count() const { return strategy_->actors_to_run_.size(); } + bool is_actor_enabled(aid_t actor) const { return strategy_->actors_to_run_.at(actor).is_enabled(); } Snapshot* get_system_state() const { return system_state_.get(); } void set_system_state(std::shared_ptr state) { system_state_ = std::move(state); } + std::unordered_set get_todo_actors() const; + std::map const& get_sleep_set() const { return sleep_set_; } + void add_sleep_set(std::shared_ptr t) + { + sleep_set_.insert_or_assign(t->aid_, Transition(t->type_, t->aid_, t->times_considered_)); + } + /* Returns the total amount of states created so far (for statistics) */ static long get_expanded_states() { return expended_states_; } }; -} // namespace mc -} // namespace simgrid +} // namespace simgrid::mc #endif