Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Respect coding style for boolean operators.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Jun 2023 13:14:48 +0000 (15:14 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Jun 2023 15:15:12 +0000 (17:15 +0200)
21 files changed:
src/dag/loaders.cpp
src/mc/api/State.cpp
src/mc/api/strategy/MaxMatchComm.hpp
src/mc/api/strategy/MinMatchComm.hpp
src/mc/api/strategy/Strategy.hpp
src/mc/api/strategy/UniformStrategy.hpp
src/mc/explo/DFSExplorer.cpp
src/mc/explo/odpor/Execution.cpp
src/mc/explo/odpor/Execution_test.cpp
src/mc/explo/odpor/ReversibleRaceCalculator.cpp
src/mc/explo/odpor/WakeupTree.cpp
src/mc/explo/udpor/Configuration.cpp
src/mc/explo/udpor/Configuration_test.cpp
src/mc/explo/udpor/EventSet.cpp
src/mc/explo/udpor/UnfoldingEvent.cpp
src/mc/explo/udpor/maximal_subsets_iterator.cpp
src/plugins/battery.cpp
src/plugins/photovoltaic.cpp
src/xbt/utils/iter/powerset.hpp
src/xbt/utils/iter/subsets.hpp
src/xbt/utils/iter/variable_for_loop.hpp

index 218aa71..8520de5 100644 (file)
@@ -156,7 +156,7 @@ std::vector<ActivityPtr> create_DAG_from_json(const std::string& filename)
 
   // Start only Activities with dependencies solved
   for (auto const& activity: dag) {
-    if (dynamic_cast<Exec*>(activity.get()) != nullptr and activity->dependencies_solved())
+    if (dynamic_cast<Exec*>(activity.get()) != nullptr && activity->dependencies_solved())
       activity->start();
   }
   return dag;
index d1919db..e1e5b8a 100644 (file)
@@ -183,7 +183,7 @@ std::unordered_set<aid_t> State::get_backtrack_set() const
 {
   std::unordered_set<aid_t> actors;
   for (const auto& [aid, state] : get_actors_list()) {
-    if (state.is_todo() or state.is_done()) {
+    if (state.is_todo() || state.is_done()) {
       actors.insert(aid);
     }
   }
@@ -291,7 +291,7 @@ void State::do_odpor_unwind()
     // works with ODPOR in the way we intend it to work. There is not a
     // good way to perform transition equality in SimGrid; instead, we
     // effectively simply check for the presence of an actor in the sleep set.
-    if (!get_actors_list().at(out_transition->aid_).has_more_to_consider())
+    if (not get_actors_list().at(out_transition->aid_).has_more_to_consider())
       add_sleep_set(std::move(out_transition));
   }
 }
index 2f99c78..7ec0af9 100644 (file)
@@ -42,7 +42,7 @@ public:
 
   std::pair<aid_t, int> best_transition(bool must_be_todo) const override
   {
-          std::pair<aid_t, int> min_found = std::make_pair(-1, value_of_state_+2);
+    std::pair<aid_t, int> min_found = std::make_pair(-1, value_of_state_ + 2);
     for (auto const& [aid, actor] : actors_to_run_) {
        if ((not actor.is_todo() && must_be_todo) || not actor.is_enabled() || actor.is_done())
            continue;
@@ -51,21 +51,19 @@ public:
       const Transition* transition = actor.get_transition(actor.get_times_considered()).get();
 
       if (auto const* cast_recv = dynamic_cast<CommRecvTransition const*>(transition)) {
-         if (mailbox_.count(cast_recv->get_mailbox()) > 0 and
-             mailbox_.at(cast_recv->get_mailbox()) > 0) { 
-             aid_value--; // This means we have waiting recv corresponding to this recv
-         } else { 
-             aid_value++; 
-         }
+        if (mailbox_.count(cast_recv->get_mailbox()) > 0 && mailbox_.at(cast_recv->get_mailbox()) > 0) {
+          aid_value--; // This means we have waiting recv corresponding to this recv
+        } else {
+          aid_value++;
+        }
       }
 
       if (auto const* cast_send = dynamic_cast<CommSendTransition const*>(transition)) {
-         if (mailbox_.count(cast_send->get_mailbox()) > 0 and
-             mailbox_.at(cast_send->get_mailbox()) < 0) {
-             aid_value--; // This means we have waiting recv corresponding to this send
-         }else {
-             aid_value++;
-         }
+        if (mailbox_.count(cast_send->get_mailbox()) > 0 && mailbox_.at(cast_send->get_mailbox()) < 0) {
+          aid_value--; // This means we have waiting recv corresponding to this send
+        } else {
+          aid_value++;
+        }
       }
 
       if (aid_value < min_found.second)
index 9041937..e8fc1f4 100644 (file)
@@ -46,7 +46,7 @@ public:
 
  std::pair<aid_t, int> best_transition(bool must_be_todo) const override
   {
-    std::pair<aid_t, int> min_found = std::make_pair(-1, value_of_state_+2);
+    std::pair<aid_t, int> min_found = std::make_pair(-1, value_of_state_ + 2);
     for (auto const& [aid, actor] : actors_to_run_) {
        if ((not actor.is_todo() && must_be_todo) || not actor.is_enabled() || actor.is_done())
            continue;
@@ -55,18 +55,18 @@ public:
       const Transition* transition = actor.get_transition(actor.get_times_considered()).get();
 
       if (auto const* cast_recv = dynamic_cast<CommRecvTransition const*>(transition)) {
-         if ((mailbox_.count(cast_recv->get_mailbox()) > 0 and
-              mailbox_.at(cast_recv->get_mailbox()) <= 0) or mailbox_.count(cast_recv->get_mailbox()) == 0) 
-             aid_value--; // This means we don't have waiting recv corresponding to this recv
-         else 
-             aid_value++; 
+        if ((mailbox_.count(cast_recv->get_mailbox()) > 0 && mailbox_.at(cast_recv->get_mailbox()) <= 0) ||
+            mailbox_.count(cast_recv->get_mailbox()) == 0)
+          aid_value--; // This means we don't have waiting recv corresponding to this recv
+        else
+          aid_value++;
       }
       if (auto const* cast_send = dynamic_cast<CommSendTransition const*>(transition)) {
-         if ((mailbox_.count(cast_send->get_mailbox()) > 0 and
-              mailbox_.at(cast_send->get_mailbox()) >= 0) or mailbox_.count(cast_send->get_mailbox()) == 0)
-             aid_value--;
-         else
-             aid_value++;
+        if ((mailbox_.count(cast_send->get_mailbox()) > 0 && mailbox_.at(cast_send->get_mailbox()) >= 0) ||
+            mailbox_.count(cast_send->get_mailbox()) == 0)
+          aid_value--;
+        else
+          aid_value++;
       }
 
       if (aid_value < min_found.second)
index 82bc998..f496ef5 100644 (file)
@@ -56,7 +56,7 @@ public:
   // else raise an error
   void consider_one(aid_t aid)
   {
-    xbt_assert(actors_to_run_.at(aid).is_enabled() and not actors_to_run_.at(aid).is_done(),
+    xbt_assert(actors_to_run_.at(aid).is_enabled() && not actors_to_run_.at(aid).is_done(),
                "Tried to mark as TODO actor %ld but it is either not enabled or already done", aid);
     actors_to_run_.at(aid).mark_todo();
   }
@@ -66,7 +66,7 @@ public:
   {
     unsigned long count = 0;
     for (auto& [_, actor] : actors_to_run_)
-      if (actor.is_enabled() and not actor.is_done()) {
+      if (actor.is_enabled() && not actor.is_done()) {
         actor.mark_todo();
         count++;
       }
index 2a90f7b..472c571 100644 (file)
@@ -35,7 +35,7 @@ public:
 
     // Consider only valid actors
     for (auto const& [aid, actor] : actors_to_run_) {
-       if ((actor.is_todo() or not must_be_todo) and (not actor.is_done()) and actor.is_enabled())
+      if ((actor.is_todo() || not must_be_todo) && (not actor.is_done()) && actor.is_enabled())
         possibilities++;
     }
 
@@ -48,7 +48,7 @@ public:
        chosen = xbt::random::uniform_int(0, possibilities-1);
 
     for (auto const& [aid, actor] : actors_to_run_) {
-       if (((not actor.is_todo()) and must_be_todo) or actor.is_done() or (not actor.is_enabled()))
+      if (((not actor.is_todo()) && must_be_todo) || actor.is_done() || (not actor.is_enabled()))
         continue;
       if (chosen == 0) {
         return std::make_pair(aid, valuation.at(aid));
index 80bd804..3c13ad3 100644 (file)
@@ -300,7 +300,7 @@ void DFSExplorer::run()
       for (const auto e_race : execution_seq_.get_reversible_races_of(next_E_p)) {
         State* prev_state  = stack_[e_race].get();
         const auto choices = execution_seq_.get_missing_source_set_actors_from(e_race, prev_state->get_backtrack_set());
-        if (!choices.empty()) {
+        if (not choices.empty()) {
           // NOTE: To incorporate the idea of attempting to select the "best"
           // backtrack point into SDPOR, instead of selecting the `first` initial,
           // we should instead compute all choices and decide which is best
@@ -401,7 +401,7 @@ std::shared_ptr<State> DFSExplorer::next_odpor_state()
     XBT_DEBUG("\tPerformed ODPOR 'clean-up'. Sleep set has:");
     for (const auto& [aid, transition] : state->get_sleep_set())
       XBT_DEBUG("\t  <%ld,%s>", aid, transition->to_string().c_str());
-    if (!state->has_empty_tree()) {
+    if (not state->has_empty_tree()) {
       return state;
     }
   }
index 1ac75ce..3f10062 100644 (file)
@@ -87,7 +87,7 @@ std::unordered_set<Execution::EventHandle> Execution::get_racing_events_of(Execu
       // 2. disqualified_events.count(e_j) > 0
       // then e_i --->_E target indirectly (either through
       // e_j directly, or transitively through e_j)
-      if (disqualified_events.count(e_j) > 0 and happens_before(e_i, e_j)) {
+      if (disqualified_events.count(e_j) > 0 && happens_before(e_i, e_j)) {
         disqualified_events.insert(e_i);
         break;
       }
@@ -164,7 +164,7 @@ Execution::get_missing_source_set_actors_from(EventHandle e, const std::unordere
     // happen after `e` is a member of `v`. In addition to marking
     // the event in `v`, we also "simulate" running the action `v`
     // from E'
-    if (not happens_before(e, e_prime) or e_prime == next_E_p) {
+    if (not happens_before(e, e_prime) || e_prime == next_E_p) {
       // First, push the transition onto the hypothetical execution
       E_prime_v.push_transition(get_event_with_handle(e_prime).get_transition());
       const EventHandle e_prime_in_E_prime_v = E_prime_v.get_latest_event_handle().value();
@@ -206,7 +206,7 @@ Execution::get_missing_source_set_actors_from(EventHandle e, const std::unordere
       }
     }
   }
-  xbt_assert(!I_E_prime_v.empty(),
+  xbt_assert(not I_E_prime_v.empty(),
              "For any non-empty execution, we know that "
              "at minimum one actor is an initial since "
              "some execution is possible with respect to a "
index 364d9a0..302ccea 100644 (file)
@@ -160,7 +160,7 @@ TEST_CASE("simgrid::mc::odpor::Execution: Testing Happens-Before")
             const bool e_j_before_e_k = execution.happens_before(e_j, e_k);
             const bool e_i_before_e_k = execution.happens_before(e_i, e_k);
             // Logical equivalent of `e_i_before_e_j ^ e_j_before_e_k --> e_i_before_e_k`
-            REQUIRE((!(e_i_before_e_j and e_j_before_e_k) or e_i_before_e_k));
+            REQUIRE((not(e_i_before_e_j && e_j_before_e_k) || e_i_before_e_k));
           }
         }
       }
index 105a0f9..f2db6b6 100644 (file)
@@ -100,7 +100,7 @@ bool ReversibleRaceCalculator::is_race_reversible_CommWait(const Execution& E, E
   // If the other event is a communication event, then we
   // are not reversible; otherwise we are reversible.
   const auto e1_action = E.get_transition_for_handle(e1)->type_;
-  return e1_action != Transition::Type::COMM_ASYNC_SEND and e1_action != Transition::Type::COMM_ASYNC_RECV;
+  return e1_action != Transition::Type::COMM_ASYNC_SEND && e1_action != Transition::Type::COMM_ASYNC_RECV;
 }
 
 bool ReversibleRaceCalculator::is_race_reversible_CommTest(const Execution&, Execution::EventHandle e1,
@@ -143,7 +143,7 @@ bool ReversibleRaceCalculator::is_race_reversible_MutexWait(const Execution& E,
 {
   // TODO: Get the semantics correct here
   const auto e1_action = E.get_transition_for_handle(e1)->type_;
-  return e1_action != Transition::Type::MUTEX_ASYNC_LOCK and e1_action != Transition::Type::MUTEX_UNLOCK;
+  return e1_action != Transition::Type::MUTEX_ASYNC_LOCK && e1_action != Transition::Type::MUTEX_UNLOCK;
 }
 
 bool ReversibleRaceCalculator::is_race_reversible_SemAsyncLock(const Execution&, Execution::EventHandle e1,
index 4489dd5..22b0352 100644 (file)
@@ -26,7 +26,7 @@ PartialExecution WakeupTreeNode::get_sequence() const
   // and instead track this with the iterator
   PartialExecution seq_;
   const WakeupTreeNode* cur_node = this;
-  while (cur_node != nullptr and !cur_node->is_root()) {
+  while (cur_node != nullptr && not cur_node->is_root()) {
     seq_.push_front(cur_node->action_);
     cur_node = cur_node->parent_;
   }
@@ -181,7 +181,7 @@ WakeupTree::InsertionResult WakeupTree::insert(const Execution& E, const Partial
         shortest_sequence.has_value()) {
       // Insert the sequence as a child of `node`, but only
       // if the node is not already a leaf
-      if (not node->is_leaf() or node == this->root_) {
+      if (not node->is_leaf() || node == this->root_) {
         // NOTE: It's entirely possible that the shortest
         // sequence we are inserting is empty. Consider the
         // following two cases:
index 44ec270..635d90a 100644 (file)
@@ -32,7 +32,7 @@ Configuration::Configuration(const History& history) : Configuration(history.get
 
 Configuration::Configuration(const EventSet& events) : events_(events)
 {
-  if (!events_.is_valid_configuration()) {
+  if (not events_.is_valid_configuration()) {
     throw std::invalid_argument("The events do not form a valid configuration");
   }
 
@@ -67,7 +67,7 @@ void Configuration::add_event(const UnfoldingEvent* e)
   this->latest_event_mapping[e->get_actor()] = e;
 
   // Preserves the property that the configuration is causally closed
-  if (auto history = History(e); !this->events_.contains(history)) {
+  if (auto history = History(e); not this->events_.contains(history)) {
     throw std::invalid_argument("The newly added event has dependencies "
                                 "which are missing from this configuration");
   }
@@ -82,7 +82,7 @@ bool Configuration::is_compatible_with(const UnfoldingEvent* e) const
   // 2. `e` itself must not conflict with any events of
   // the configuration; otherwise adding the event would
   // violate the invariant that a configuration is conflict-free
-  return contains(e->get_history()) and (not e->conflicts_with_any(this->events_));
+  return contains(e->get_history()) && (not e->conflicts_with_any(this->events_));
 }
 
 bool Configuration::is_compatible_with(const History& history) const
index dc3d900..2972ad9 100644 (file)
@@ -969,7 +969,7 @@ TEST_CASE("simgrid::mc::udpor::Configuration: Computing Full Alternatives in Rea
     // The first alternative that is found is the one that is chosen. Since
     // traversal over the elements of an unordered_set<> are not guaranteed,
     // both {e0, e4} and {e0, e7} are valid alternatives
-    REQUIRE((alternative.value().get_events() == EventSet({e0_handle, e4_handle}) or
+    REQUIRE((alternative.value().get_events() == EventSet({e0_handle, e4_handle}) ||
              alternative.value().get_events() == EventSet({e0_handle, e7_handle})));
   }
 
@@ -1059,8 +1059,8 @@ TEST_CASE("simgrid::mc::udpor::Configuration: Computing Full Alternatives in Rea
 
     const auto alternative = C.compute_alternative_to(D_plus_e, U);
     REQUIRE(alternative.has_value());
-    REQUIRE((alternative.value().get_events() == EventSet({e0_handle, e7_handle}) or
-             alternative.value().get_events() == EventSet({e0_handle, e4_handle, e7_handle}) or
+    REQUIRE((alternative.value().get_events() == EventSet({e0_handle, e7_handle}) ||
+             alternative.value().get_events() == EventSet({e0_handle, e4_handle, e7_handle}) ||
              alternative.value().get_events() == EventSet({e0_handle, e4_handle, e7_handle, e8_handle})));
   }
 
index feef1dd..8f017f9 100644 (file)
@@ -220,7 +220,7 @@ std::vector<const UnfoldingEvent*> EventSet::get_topological_ordering() const
         temporarily_marked_events.insert(evt);
 
         EventSet immediate_causes = evt->get_immediate_causes();
-        if (!immediate_causes.empty() && immediate_causes.is_subset_of(temporarily_marked_events)) {
+        if (not immediate_causes.empty() && immediate_causes.is_subset_of(temporarily_marked_events)) {
           throw std::invalid_argument("Attempted to perform a topological sort on a configuration "
                                       "whose contents contain a cycle. The configuration (and the graph "
                                       "connecting all of the events) is an invalid event structure");
@@ -285,4 +285,4 @@ std::vector<const UnfoldingEvent*> EventSet::move_into_vector() const&&
   return contents;
 }
 
-} // namespace simgrid::mc::udpor
\ No newline at end of file
+} // namespace simgrid::mc::udpor
index fd4dc2e..8b71842 100644 (file)
@@ -77,7 +77,7 @@ EventSet UnfoldingEvent::get_local_config() const
 
 bool UnfoldingEvent::related_to(const UnfoldingEvent* other) const
 {
-  return this->in_history_of(other) or other->in_history_of(this);
+  return this->in_history_of(other) || other->in_history_of(this);
 }
 
 bool UnfoldingEvent::in_history_of(const UnfoldingEvent* other) const
@@ -103,7 +103,7 @@ bool UnfoldingEvent::conflicts_with(const UnfoldingEvent* other) const
                                                 [&](const UnfoldingEvent* e) { return e->is_dependent_with(other); });
   const bool conflicts_with_other = std::any_of(unique_to_other.begin(), unique_to_other.end(),
                                                 [&](const UnfoldingEvent* e) { return e->is_dependent_with(this); });
-  return conflicts_with_me or conflicts_with_other;
+  return conflicts_with_me || conflicts_with_other;
 }
 
 bool UnfoldingEvent::conflicts_with_any(const EventSet& events) const
index 472855a..3aa7047 100644 (file)
@@ -34,7 +34,7 @@ void maximal_subsets_iterator::increment()
   }
 
   const auto next_event_ref = [&]() {
-    if (!has_started_searching) {
+    if (not has_started_searching) {
       has_started_searching = true;
       return bookkeeper.find_next_candidate_event(topological_ordering.begin(), topological_ordering.end());
     } else {
index b6cfd2a..21d1ceb 100644 (file)
@@ -427,7 +427,7 @@ void Battery::update()
   simgrid::kernel::actor::simcall_answered([this] {
     double now             = simgrid::s4u::Engine::get_clock();
     double time_delta_real = now - last_updated_;
-    if (time_delta_real <= 0 or not is_active())
+    if (time_delta_real <= 0 || not is_active())
       return;
     double time_delta_until_event = next_event_ - last_updated_;
     bool event                    = next_event_ != -1 and time_delta_until_event <= time_delta_real;
index 923153b..9d8a717 100644 (file)
@@ -218,9 +218,9 @@ void Photovoltaic::update()
     if (now <= last_updated_)
       return;
     double power_w = conversion_efficiency_ * area_m2_ * solar_irradiance_w_per_m2_;
-    if (min_power_w_ > 0 and power_w_ < min_power_w_)
+    if (min_power_w_ > 0 && power_w_ < min_power_w_)
       power_w = 0;
-    if (max_power_w_ > 0 and power_w_ > max_power_w_)
+    if (max_power_w_ > 0 && power_w_ > max_power_w_)
       power_w = max_power_w_;
     power_w_ = power_w;
     if (eval_cost_) {
@@ -288,4 +288,4 @@ double sg_photovoltaic_get_power(const_sg_host_t host)
 {
   ensure_plugin_inited();
   return host->extension<Photovoltaic>()->get_power();
-}
\ No newline at end of file
+}
index b83bad7..68e0970 100644 (file)
@@ -74,8 +74,8 @@ template <typename Iterator> const std::vector<Iterator>& powerset_iterator<Iter
 
 template <typename Iterator> void powerset_iterator<Iterator>::increment()
 {
-  if (!current_subset_iter.has_value() || !current_subset_iter_end.has_value() || !current_subset_iter.has_value() ||
-      !iterator_end.has_value()) {
+  if (not current_subset_iter.has_value() || not current_subset_iter_end.has_value() ||
+      not current_subset_iter.has_value() || not iterator_end.has_value()) {
     return; // We've traversed all subsets at this point, or we're the "last" iterator
   }
 
index 1abea21..f948b38 100644 (file)
@@ -73,7 +73,7 @@ subsets_iterator<Iterator>::subsets_iterator(unsigned k, Iterator begin, Iterato
 
 template <typename Iterator> bool subsets_iterator<Iterator>::equal(const subsets_iterator<Iterator>& other) const
 {
-  if (this->end == std::nullopt and other.end == std::nullopt) {
+  if (this->end == std::nullopt && other.end == std::nullopt) {
     return true;
   }
   if (this->k != other.k) {
@@ -82,7 +82,7 @@ template <typename Iterator> bool subsets_iterator<Iterator>::equal(const subset
   if (this->k == 0) { // this->k == other.k == 0
     return true;
   }
-  return this->end != std::nullopt and other.end != std::nullopt and this->P[0] == other.P[0];
+  return this->end != std::nullopt && other.end != std::nullopt && this->P[0] == other.P[0];
 }
 
 template <typename Iterator> const std::vector<Iterator>& subsets_iterator<Iterator>::dereference() const
index cbcb0a2..f283f66 100644 (file)
@@ -51,7 +51,7 @@ public:
     const auto has_effect =
         std::none_of(collections.begin(), collections.end(), [](const auto& c) { return c.get().empty(); });
 
-    if (has_effect and (not collections.empty())) {
+    if (has_effect && (not collections.empty())) {
       std::transform(collections.begin(), collections.end(), std::back_inserter(current_subset),
                      [](const auto& c) { return c.get().cbegin(); });
       underlying_collections = std::move(collections);
@@ -76,7 +76,7 @@ template <typename IterableType> void variable_for_loop<IterableType>::increment
 {
   // Termination occurs when `current_subset := the empty set`
   // or if we have nothing to iterate over
-  if (current_subset.empty() or underlying_collections.empty()) {
+  if (current_subset.empty() || underlying_collections.empty()) {
     return;
   }