Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add History object skeleton
authorMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 20 Feb 2023 13:58:51 +0000 (14:58 +0100)
committerMaxwell Pirtle <maxwellpirtle@gmail.com>
Mon, 20 Feb 2023 13:58:51 +0000 (14:58 +0100)
The History class represents the entire
history of a collection of events "lazily",
i.e. without needing to compute the entire
history if it is not actually needed

MANIFEST.in
src/mc/explo/udpor/Configuration.hpp
src/mc/explo/udpor/History.cpp [new file with mode: 0644]
src/mc/explo/udpor/History.hpp [new file with mode: 0644]
src/mc/explo/udpor/udpor_forward.hpp
tools/cmake/DefinePackages.cmake

index 1decdf0..680a6f0 100644 (file)
@@ -2216,6 +2216,8 @@ include src/mc/explo/udpor/Configuration.hpp
 include src/mc/explo/udpor/Configuration.cpp
 include src/mc/explo/udpor/EventSet.cpp
 include src/mc/explo/udpor/EventSet.hpp
+include src/mc/explo/udpor/History.cpp
+include src/mc/explo/udpor/History.hpp
 include src/mc/explo/udpor/UnfoldingEvent.cpp
 include src/mc/explo/udpor/UnfoldingEvent.hpp
 include src/mc/explo/udpor/Unfolding.cpp
index 2e22036..d099a67 100644 (file)
@@ -34,6 +34,12 @@ private:
 
   /**
    * @brief The events which make up this configuration
+   *
+   * @invariant For each event `e` in `events_`, the set of
+   * dependencies of `e` is also contained in `events_`
+   *
+   * TODO: UDPOR enforces this invariant, but perhaps we should
+   * too?
    */
   EventSet events_;
 
@@ -41,7 +47,7 @@ private:
    * The <-maxmimal events of the configuration. These are
    * dynamically adjusted as events are added to the configuration
    *
-   * @invariant: Each event that is part of this set is
+   * @invariant Each event that is part of this set is
    *
    * 1. a <-maxmimal event of the configuration, in the sense that
    * there is no event in the configuration that is "greater" than it.
diff --git a/src/mc/explo/udpor/History.cpp b/src/mc/explo/udpor/History.cpp
new file mode 100644 (file)
index 0000000..e03ca4d
--- /dev/null
@@ -0,0 +1,13 @@
+/* Copyright (c) 2008-2023. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#include "src/mc/explo/udpor/History.hpp"
+#include "src/mc/explo/udpor/Configuration.hpp"
+
+namespace simgrid::mc::udpor {
+
+// TODO: Implement these methods
+
+} // namespace simgrid::mc::udpor
diff --git a/src/mc/explo/udpor/History.hpp b/src/mc/explo/udpor/History.hpp
new file mode 100644 (file)
index 0000000..df5cb32
--- /dev/null
@@ -0,0 +1,88 @@
+/* Copyright (c) 2007-2023. The SimGrid Team. All rights reserved.          */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
+#ifndef SIMGRID_MC_UDPOR_HISTORY_HPP
+#define SIMGRID_MC_UDPOR_HISTORY_HPP
+
+#include "src/mc/explo/udpor/EventSet.hpp"
+#include "src/mc/explo/udpor/udpor_forward.hpp"
+
+namespace simgrid::mc::udpor {
+
+/**
+ * @brief Conceptually describes the local configuration(s) of
+ * an event or a collection of events, encoding the history of
+ * the events without needing to actually fully compute all of
+ * the events contained in the history
+ *
+ * When you create an instance of `History`, you are effectively
+ * making a "lazy" configuration whose elements are the set of
+ * causes of a given event (if the `History` constists of a single
+ * event) or the union of all causes of all events (if the
+ * `History` consists of a set of events).
+ *
+ * Using a `History` object to represent the history of a set of
+ * events is more efficient (and reads more easily) than first
+ * computing the entire history of each of the events separately
+ * and combining the results. The former can take advantage of the
+ * fact that the histories of a set of events overlap greatly, and
+ * thus only a single BFS/DFS search over the event structure needs
+ * to be performed instead of many isolated searches for each event.
+ *
+ * The same observation also allows you to compute the difference between
+ * a configuration and a history of a set of events. This is used
+ * in UDPOR, for example, when determing the difference J / C and
+ * when using K-partial alternatives (which computes J as the union
+ * of histories of events)
+ */
+class History {
+private:
+  /**
+   * @brief The events whose history this instance describes
+   */
+  EventSet events_;
+
+public:
+  History()                          = default;
+  History(const History&)            = default;
+  History& operator=(History const&) = default;
+  History(History&&)                 = default;
+
+  explicit History(UnfoldingEvent* e) : events_({e}) {}
+  explicit History(EventSet event_set) : events_(std::move(event_set)) {}
+
+  /**
+   * @brief Whether or not the given event is contained in the history
+   *
+   * @note If you only need to determine whether a few events are contained
+   * in a history, prefer this method. If, however, you wish to repeatedly
+   * determine over time (e.g. over the course of a computation) whether
+   * some event is part of the history, it may be better to first compute
+   * all events (see `History::get_all_events()`) and reuse this set
+   *
+   * @param e the event to check
+   * @returns whether or not `e` is contained in the collection
+   */
+  bool contains(UnfoldingEvent* e) const;
+
+  /**
+   * @brief Computes all events in the history described by this instance
+   *
+   * Sometimes, it is useful to compute the entire set of events that
+   * comprise the history of some event `e` of some set of events `E`.
+   * This method performs that computation.
+   *
+   * @returns the set of all causal dependencies of all events this
+   * history represents. Equivalently, the method returns the full
+   * dependency graph for all events in this history
+   */
+  EventSet get_all_events() const;
+
+  EventSet get_event_diff_with(const EventSet& event_set) const;
+  EventSet get_event_diff_with(const Configuration& config) const;
+};
+
+} // namespace simgrid::mc::udpor
+#endif
index c8b12c0..1008235 100644 (file)
 namespace simgrid::mc::udpor {
 
 class EventSet;
-class UnfoldingEvent;
 class Configuration;
+class History;
 class Unfolding;
-using StateHandle = unsigned long long;
+class UnfoldingEvent;
 
 } // namespace simgrid::mc::udpor
 
index 054bc13..d13225e 100644 (file)
@@ -529,6 +529,8 @@ set(MC_SRC
   src/mc/explo/udpor/Configuration.cpp
   src/mc/explo/udpor/EventSet.cpp
   src/mc/explo/udpor/EventSet.hpp
+  src/mc/explo/udpor/History.cpp
+  src/mc/explo/udpor/History.hpp
   src/mc/explo/udpor/UnfoldingEvent.cpp
   src/mc/explo/udpor/UnfoldingEvent.hpp
   src/mc/explo/udpor/Unfolding.cpp