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 / LivenessChecker.cpp
index 3b61b6b..ab212dc 100644 (file)
@@ -25,7 +25,7 @@ VisitedPair::VisitedPair(int pair_num, xbt_automaton_state_t prop_state,
   this->app_state_ = std::move(app_state);
   if (not this->app_state_->get_system_state())
     this->app_state_->set_system_state(std::make_shared<Snapshot>(pair_num));
-  this->heap_bytes_used     = Api::get().get_remote_heap_bytes();
+  this->heap_bytes_used     = mc_model_checker->get_remote_process().get_remote_heap_bytes();
   this->actor_count_        = app_state_->get_actor_count();
   this->other_num           = -1;
   this->atomic_propositions = std::move(atomic_propositions);
@@ -62,21 +62,20 @@ std::shared_ptr<VisitedPair> LivenessChecker::insert_acceptance_pair(simgrid::mc
   auto new_pair =
       std::make_shared<VisitedPair>(pair->num, pair->prop_state_, pair->atomic_propositions, pair->app_state_);
 
-  auto [res_begin, res_end] = boost::range::equal_range(acceptance_pairs_, new_pair.get(), Api::get().compare_pair());
+  auto [res_begin, res_end] =
+      boost::range::equal_range(acceptance_pairs_, new_pair.get(), compare_pair_by_actor_count_and_used_heap());
 
   if (pair->search_cycle)
     for (auto i = res_begin; i != res_end; ++i) {
       std::shared_ptr<simgrid::mc::VisitedPair> const& pair_test = *i;
       if (xbt_automaton_state_compare(pair_test->prop_state_, new_pair->prop_state_) != 0 ||
           *(pair_test->atomic_propositions) != *(new_pair->atomic_propositions) ||
-          not Api::get().snapshot_equal(pair_test->app_state_->get_system_state(),
-                                        new_pair->app_state_->get_system_state()))
+          (*pair_test->app_state_->get_system_state() != *new_pair->app_state_->get_system_state()))
         continue;
       XBT_INFO("Pair %d already reached (equal to pair %d) !", new_pair->num, pair_test->num);
       exploration_stack_.pop_back();
-      if (dot_output != nullptr)
-        fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", this->previous_pair_, pair_test->num,
-                this->previous_request_.c_str());
+      mc_model_checker->dot_output("\"%d\" -> \"%d\" [%s];\n", this->previous_pair_, pair_test->num,
+                                   this->previous_request_.c_str());
       return nullptr;
     }
 
@@ -141,24 +140,20 @@ int LivenessChecker::insert_visited_pair(std::shared_ptr<VisitedPair> visited_pa
         std::make_shared<VisitedPair>(pair->num, pair->prop_state_, pair->atomic_propositions, pair->app_state_);
 
   auto [range_begin, range_end] =
-      boost::range::equal_range(visited_pairs_, visited_pair.get(), Api::get().compare_pair());
+      boost::range::equal_range(visited_pairs_, visited_pair.get(), compare_pair_by_actor_count_and_used_heap());
 
   for (auto i = range_begin; i != range_end; ++i) {
     const VisitedPair* pair_test = i->get();
     if (xbt_automaton_state_compare(pair_test->prop_state_, visited_pair->prop_state_) != 0 ||
         *(pair_test->atomic_propositions) != *(visited_pair->atomic_propositions) ||
-        not Api::get().snapshot_equal(pair_test->app_state_->get_system_state(),
-                                      visited_pair->app_state_->get_system_state()))
+        (*pair_test->app_state_->get_system_state() != *visited_pair->app_state_->get_system_state()))
       continue;
     if (pair_test->other_num == -1)
       visited_pair->other_num = pair_test->num;
     else
       visited_pair->other_num = pair_test->other_num;
-    if (dot_output == nullptr)
-      XBT_DEBUG("Pair %d already visited ! (equal to pair %d)", visited_pair->num, pair_test->num);
-    else
-      XBT_DEBUG("Pair %d already visited ! (equal to pair %d (pair %d in dot_output))", visited_pair->num,
-                pair_test->num, visited_pair->other_num);
+    XBT_DEBUG("Pair %d already visited ! (equal to pair %d (pair %d in dot_output))", visited_pair->num, pair_test->num,
+              visited_pair->other_num);
     (*i) = std::move(visited_pair);
     return (*i)->other_num;
   }
@@ -388,11 +383,10 @@ void LivenessChecker::run()
     if (not current_pair->exploration_started) {
       int visited_num = this->insert_visited_pair(reached_pair, current_pair.get());
       if (visited_num != -1) {
-        if (dot_output != nullptr) {
-          fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", this->previous_pair_, visited_num,
-                  this->previous_request_.c_str());
-          fflush(dot_output);
-        }
+        mc_model_checker->dot_output("\"%d\" -> \"%d\" [%s];\n", this->previous_pair_, visited_num,
+                                     this->previous_request_.c_str());
+        mc_model_checker->dot_output_flush();
+
         XBT_DEBUG("Pair already visited (equal to pair %d), exploration on the current path stopped.", visited_num);
         current_pair->requests = 0;
         this->backtrack();
@@ -403,18 +397,17 @@ void LivenessChecker::run()
     current_pair->app_state_->execute_next(current_pair->app_state_->next_transition());
     XBT_DEBUG("Execute: %s", current_pair->app_state_->get_transition()->to_string().c_str());
 
-    if (dot_output != nullptr) {
-      if (this->previous_pair_ != 0 && this->previous_pair_ != current_pair->num) {
-        fprintf(dot_output, "\"%d\" -> \"%d\" [%s];\n", this->previous_pair_, current_pair->num,
-                this->previous_request_.c_str());
-        this->previous_request_.clear();
-      }
-      this->previous_pair_    = current_pair->num;
-      this->previous_request_ = current_pair->app_state_->get_transition()->dot_string();
-      if (current_pair->search_cycle)
-        fprintf(dot_output, "%d [shape=doublecircle];\n", current_pair->num);
-      fflush(dot_output);
+    /* Update the dot output */
+    if (this->previous_pair_ != 0 && this->previous_pair_ != current_pair->num) {
+      mc_model_checker->dot_output("\"%d\" -> \"%d\" [%s];\n", this->previous_pair_, current_pair->num,
+                                   this->previous_request_.c_str());
+      this->previous_request_.clear();
     }
+    this->previous_pair_    = current_pair->num;
+    this->previous_request_ = current_pair->app_state_->get_transition()->dot_string();
+    if (current_pair->search_cycle)
+      mc_model_checker->dot_output("%d [shape=doublecircle];\n", current_pair->num);
+    mc_model_checker->dot_output_flush();
 
     if (not current_pair->exploration_started)
       visited_pairs_count_++;