namespace simgrid::mc::udpor {
-maximal_subsets_iterator::maximal_subsets_iterator(const EventSet& events, std::optional<node_filter_function> filter)
- : current_maximal_set({EventSet()})
+maximal_subsets_iterator::maximal_subsets_iterator(const EventSet& events, std::optional<node_filter_function> filter,
+ std::optional<size_t> maximum_subset_size)
+ : maximum_subset_size(maximum_subset_size), current_maximal_set({EventSet()})
{
const auto candidate_ordering = events.get_topological_ordering_of_reverse_graph();
if (filter.has_value()) {
void maximal_subsets_iterator::increment()
{
+ // Termination condition
if (current_maximal_set == std::nullopt) {
return;
}
+ // Stop immediately if there's nothing to search
if (topological_ordering.empty()) {
- // Stop immediately if there's nothing to search
current_maximal_set = std::nullopt;
return;
}
}
}();
+ // Out of events: we've finished
if (next_event_ref == topological_ordering.end()) {
current_maximal_set = std::nullopt;
return;
return topological_ordering.end();
}
+ xbt_assert(current_maximal_set.has_value(), "Traversal continued even after the termination condition "
+ "was met. Please verify that the termination condition "
+ "of the iterator has not been modified");
+
// 1. First, check if we can keep expanding from the
// maximal set that we currently have
- {
+ if (can_grow_maximal_set()) {
// This is an iterator which points to the latest event `e` that
// was added to what is currently the maximal set
const auto latest_event_ref = backtrack_points.top();
void maximal_subsets_iterator::add_element_to_current_maximal_set(const UnfoldingEvent* e)
{
+ xbt_assert(can_grow_maximal_set(), "Attempting to add an event to the maximal set "
+ "when doing so would increase the size past the "
+ "prescribed limit. This indicates that detecting when "
+ "to stop growing the maximal set when continuing the "
+ "search is broken");
xbt_assert(current_maximal_set.has_value(), "Attempting to add an event to the maximal set "
"when iteration has completed. This indicates that "
"the termination condition for the iterator is broken");
bookkeeper.mark_removed_from_maximal_set(e);
}
+bool maximal_subsets_iterator::can_grow_maximal_set() const
+{
+ if (not current_maximal_set.has_value()) {
+ return true;
+ }
+ if (maximum_subset_size.has_value()) {
+ return current_maximal_set.value().size() < maximum_subset_size.value();
+ }
+ return true;
+}
+
maximal_subsets_iterator::topological_order_position
maximal_subsets_iterator::bookkeeper::find_next_candidate_event(topological_order_position first,
topological_order_position last) const
using topological_order_position = std::vector<const UnfoldingEvent*>::const_iterator;
maximal_subsets_iterator() = default;
- explicit maximal_subsets_iterator(const Configuration& config) : maximal_subsets_iterator(config.get_events()) {}
- explicit maximal_subsets_iterator(const EventSet& events) : maximal_subsets_iterator(events, std::nullopt) {}
-
- maximal_subsets_iterator(const Configuration& config, std::optional<node_filter_function> filter)
- : maximal_subsets_iterator(config.get_events(), filter)
+ explicit maximal_subsets_iterator(const Configuration& config,
+ std::optional<node_filter_function> filter = std::nullopt,
+ std::optional<size_t> maximum_subset_size = std::nullopt)
+ : maximal_subsets_iterator(config.get_events(), filter, maximum_subset_size)
{
}
- maximal_subsets_iterator(const EventSet& events, std::optional<node_filter_function> filter);
+ explicit maximal_subsets_iterator(const EventSet& events, std::optional<node_filter_function> filter = std::nullopt,
+ std::optional<size_t> maximum_subset_size = std::nullopt);
private:
std::vector<const UnfoldingEvent*> topological_ordering;
// after the empty set" and "we've finished the search" since the resulting
// maximal set and backtracking point stack will both be empty in both cases
bool has_started_searching = false;
+ std::optional<size_t> maximum_subset_size = std::nullopt;
std::optional<EventSet> current_maximal_set = std::nullopt;
std::stack<topological_order_position> backtrack_points = std::stack<topological_order_position>();
*/
topological_order_position continue_traversal_of_maximal_events_tree();
+ /**
+ * @brief: Whether or not the current maximal set can
+ * grow based on the size limit imposed on the maximal
+ * sets that can be produced
+ */
+ bool can_grow_maximal_set() const;
+
// boost::iterator_facade<...> interface to implement
void increment();
bool equal(const maximal_subsets_iterator& other) const { return current_maximal_set == other.current_maximal_set; }