{
XBT_DEBUG("Search for an actor to run. %zu actors to consider", strategy_->actors_to_run_.size());
for (auto const& [aid, actor] : strategy_->actors_to_run_) {
+ XBT_DEBUG("Current penalty for actor %ld:%f", aid, strategy_->penalties_[aid]);
/* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */
if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) {
if (not actor.is_todo())
std::pair<aid_t, double> State::next_transition_guided() const
{
+ for (auto const& [aid, actor] : strategy_->actors_to_run_) {
+ /* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */
+ if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) {
+ if (not actor.is_todo())
+ XBT_DEBUG("Can't run actor %ld because it is not todo", aid);
+
+ if (not actor.is_enabled())
+ XBT_DEBUG("Can't run actor %ld because it is not enabled", aid);
+
+ if (actor.is_done())
+ XBT_DEBUG("Can't run actor %ld because it has already been done", aid);
+ }
+ }
return strategy_->next_transition();
}
#ifndef SIMGRID_MC_BASICSTRATEGY_HPP
#define SIMGRID_MC_BASICSTRATEGY_HPP
+#include "src/mc/transition/Transition.hpp"
+
namespace simgrid::mc {
/** Basic MC guiding class which corresponds to no guide at all (random choice) */
class BasicStrategy : public Strategy {
public:
- void operator=(const BasicStrategy&) { return; }
+ void operator=(const BasicStrategy& other) { this->penalties_ = other.penalties_; }
- std::pair<aid_t, double> next_transition() const override
+ std::pair<aid_t, double> best_transition(bool need_to_be_todo) const
{
+ auto min = std::make_pair(-1, 10000);
for (auto const& [aid, actor] : actors_to_run_) {
/* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application */
- if (not actor.is_todo() || not actor.is_enabled() || actor.is_done()) {
+ if ((not actor.is_todo() and need_to_be_todo) || not actor.is_enabled() || actor.is_done()) {
continue;
}
+ if (actor.get_transition(actor.get_times_considered())->type_ != Transition::Type::TESTANY)
+ return std::make_pair(aid, 0.0);
- return std::make_pair(aid, 1.0);
+ double dist;
+ auto iterator = penalties_.find(aid);
+ if (iterator != penalties_.end())
+ dist = (*iterator).second;
+ else
+ dist = 0;
+ if (dist < min.second)
+ min = std::make_pair(aid, dist);
}
- return std::make_pair(-1, 0.0);
+ if (min.first == -1)
+ return std::make_pair(-1, -1000);
+ return min;
+ }
+
+ std::pair<aid_t, double> next_transition() const override { return best_transition(true); }
+
+ void execute_next(aid_t aid, RemoteApp& app) override
+ {
+ auto actor = actors_to_run_.at(aid);
+ if (actor.get_transition(actor.get_times_considered())->type_ != Transition::Type::TESTANY)
+ penalties_[aid] += 1.0;
+ return;
}
- void execute_next(aid_t aid, RemoteApp& app) override { return; }
void consider_best() override
{
+ const auto& [aid, _] = this->best_transition(false);
+ auto actor = actors_to_run_.find(aid);
+ if (actor != actors_to_run_.end()) {
+ actor->second.mark_todo();
+ return;
+ }
for (auto& [_, actor] : actors_to_run_) {
if (actor.is_todo())
return;
std::map<aid_t, ActorState> actors_to_run_;
public:
+ /** Used to store penalties computed by the strategy to each actor */
+ std::map<aid_t, double> penalties_;
virtual ~Strategy() = default;
virtual std::pair<aid_t, double> next_transition() const = 0;
virtual void execute_next(aid_t aid, RemoteApp& app) = 0;
// If there are processes to interleave and the maximum depth has not been
// reached then perform one step of the exploration algorithm.
- XBT_VERB("Execute %ld: %.60s (stack depth: %zu, state: %ld, %zu interleaves)", state->get_transition()->aid_,
- state->get_transition()->to_string().c_str(), stack_.size(), state->get_num(), state->count_todo());
+ XBT_VERB("Execute %ld: %.60s (stack depth: %zu, state: %ld, %zu interleaves out of %zu enabled)",
+ state->get_transition()->aid_, state->get_transition()->to_string().c_str(), stack_.size(),
+ state->get_num(), state->count_todo(), state->get_actor_count());
/* Create the new expanded state (copy the state of MCed into our MCer data) */
std::shared_ptr<State> next_state = std::make_shared<State>(get_remote_app(), state);