+bool check_for_cycle(const std::vector<simgrid::s4u::ActivityPtr>& dag)
+{
+ std::vector<simgrid::s4u::ActivityPtr> current;
+
+ for (const auto& a : dag)
+ if (dynamic_cast<simgrid::s4u::Exec*>(a.get()) != nullptr && a->is_waited_by() == 0)
+ current.push_back(a);
+
+ while (not current.empty()) {
+ std::vector<simgrid::s4u::ActivityPtr> next;
+ for (auto const& a : current) {
+ a->mark();
+ for (auto const& pred : a->get_dependencies()) {
+ if (dynamic_cast<simgrid::s4u::Comm*>(pred.get()) != nullptr) {
+ pred->mark();
+ // Comms have only one predecessor
+ auto pred_pred = *(pred->get_dependencies().begin());
+ if (std::none_of(pred_pred->get_successors().begin(), pred_pred->get_successors().end(),
+ [](const simgrid::s4u::ActivityPtr& a) { return not a->is_marked(); }))
+ next.push_back(pred_pred);
+ } else {
+ if (std::none_of(pred->get_successors().begin(), pred->get_successors().end(),
+ [](const simgrid::s4u::ActivityPtr& a) { return not a->is_marked(); }))
+ next.push_back(pred);
+ }
+ }
+ }
+ current.clear();
+ current = next;
+ }
+
+ return not std::any_of(dag.begin(), dag.end(), [](const simgrid::s4u::ActivityPtr& a) { return not a->is_marked(); });
+}
+