Parcourir la source

New coding style

Eric Ramat il y a 4 ans
Parent
commit
0fc53c8137
73 fichiers modifiés avec 6733 ajouts et 7163 suppressions
  1. 2 3
      src/apps/main.cpp
  2. 200 201
      src/artis-star/common/Any.hpp
  3. 38 41
      src/artis-star/common/Bag.hpp
  4. 111 120
      src/artis-star/common/Coordinator.hpp
  5. 85 90
      src/artis-star/common/ExternalEvent.hpp
  6. 67 70
      src/artis-star/common/GraphManager.hpp
  7. 36 40
      src/artis-star/common/InternalEvent.hpp
  8. 109 116
      src/artis-star/common/Links.hpp
  9. 1 1
      src/artis-star/common/Macro.hpp
  10. 234 259
      src/artis-star/common/Model.hpp
  11. 29 32
      src/artis-star/common/Node.hpp
  12. 7 7
      src/artis-star/common/Parameters.hpp
  13. 73 77
      src/artis-star/common/RootCoordinator.hpp
  14. 15 15
      src/artis-star/common/Scheduler.hpp
  15. 24 25
      src/artis-star/common/Simulator.hpp
  16. 78 82
      src/artis-star/common/States.hpp
  17. 166 172
      src/artis-star/common/Value.hpp
  18. 48 51
      src/artis-star/common/context/Context.hpp
  19. 71 77
      src/artis-star/common/context/State.hpp
  20. 48 51
      src/artis-star/common/context/StateValues.hpp
  21. 59 61
      src/artis-star/common/observer/Iterator.hpp
  22. 75 82
      src/artis-star/common/observer/Observer.hpp
  23. 63 64
      src/artis-star/common/observer/Output.hpp
  24. 138 145
      src/artis-star/common/observer/View.hpp
  25. 112 120
      src/artis-star/common/scheduler/HeapScheduler.hpp
  26. 10 10
      src/artis-star/common/scheduler/SchedulerHandle.hpp
  27. 77 83
      src/artis-star/common/scheduler/VectorScheduler.hpp
  28. 4 4
      src/artis-star/common/time/DoubleTime.hpp
  29. 4 4
      src/artis-star/common/time/IntegerTime.hpp
  30. 9 9
      src/artis-star/common/time/Limits.hpp
  31. 11 9
      src/artis-star/common/time/RationalTime.hpp
  32. 16 16
      src/artis-star/common/time/Time.hpp
  33. 28 40
      src/artis-star/common/utils/FormalismType.hpp
  34. 31 47
      src/artis-star/common/utils/FunctionType.hpp
  35. 22 27
      src/artis-star/common/utils/LevelType.hpp
  36. 199 210
      src/artis-star/common/utils/Multithreading.hpp
  37. 12 13
      src/artis-star/common/utils/String.hpp
  38. 179 192
      src/artis-star/common/utils/Trace.hpp
  39. 241 252
      src/artis-star/kernel/devs/Coordinator.hpp
  40. 52 58
      src/artis-star/kernel/devs/Dynamics.hpp
  41. 96 102
      src/artis-star/kernel/devs/GraphManager.hpp
  42. 157 165
      src/artis-star/kernel/devs/Simulator.hpp
  43. 247 260
      src/artis-star/kernel/dsde/Coordinator.hpp
  44. 230 241
      src/artis-star/kernel/dsde/Executive.hpp
  45. 80 86
      src/artis-star/kernel/dsde/GraphManager.hpp
  46. 167 173
      src/artis-star/kernel/dtss/Coordinator.hpp
  47. 93 104
      src/artis-star/kernel/dtss/Dynamics.hpp
  48. 122 130
      src/artis-star/kernel/dtss/GraphManager.hpp
  49. 63 65
      src/artis-star/kernel/dtss/Policy.hpp
  50. 151 159
      src/artis-star/kernel/dtss/Simulator.hpp
  51. 26 26
      src/artis-star/kernel/fddevs/Coordinator.hpp
  52. 69 79
      src/artis-star/kernel/fddevs/Dynamics.hpp
  53. 18 18
      src/artis-star/kernel/fddevs/GraphManager.hpp
  54. 170 177
      src/artis-star/kernel/fddevs/Simulator.hpp
  55. 19 19
      src/artis-star/kernel/pdevs/Context.hpp
  56. 224 234
      src/artis-star/kernel/pdevs/Coordinator.hpp
  57. 79 89
      src/artis-star/kernel/pdevs/Dynamics.hpp
  58. 139 150
      src/artis-star/kernel/pdevs/GraphManager.hpp
  59. 159 168
      src/artis-star/kernel/pdevs/Simulator.hpp
  60. 30 31
      src/artis-star/kernel/pdevs/mpi/Coordinator.hpp
  61. 26 24
      src/artis-star/kernel/pdevs/mpi/GraphManager.hpp
  62. 72 78
      src/artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp
  63. 123 133
      src/artis-star/kernel/pdevs/mpi/ModelProxy.hpp
  64. 198 202
      src/artis-star/kernel/pdevs/multithreading/Coordinator.hpp
  65. 12 12
      src/artis-star/kernel/qss/Data.hpp
  66. 158 175
      src/artis-star/kernel/qss/Derivative.hpp
  67. 242 258
      src/artis-star/kernel/qss/Integrator.hpp
  68. 317 343
      src/artis-star/kernel/qss/Quantifier.hpp
  69. 130 136
      src/artis-star/kernel/sss/Coordinator.hpp
  70. 33 35
      src/artis-star/kernel/sss/Dynamics.hpp
  71. 82 85
      src/artis-star/kernel/sss/GraphManager.hpp
  72. 86 91
      src/artis-star/kernel/sss/Model.hpp
  73. 131 139
      src/artis-star/kernel/sss/Simulator.hpp

+ 2 - 3
src/apps/main.cpp

@@ -24,7 +24,6 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
  */
 
 
-int main()
-{
-    return 0;
+int main() {
+  return 0;
 }
 }

+ 200 - 201
src/artis-star/common/Any.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Any.hpp
+ * @file common/Any.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -35,230 +35,229 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        class Any {
-        private:
-            struct base {
-                virtual ~base() { }
+class Any {
+private:
+  struct base {
+    virtual ~base() {}
 
 
-                virtual base* clone() const = 0;
-            };
+    virtual base *clone() const = 0;
+  };
 
 
-            template<typename T, typename V>
-            struct data : base {
-                data(V T::* const& value)
-                        :value_(value) { }
+  template<typename T, typename V>
+  struct data : base {
+    data(V T::* const &value)
+        : value_(value) {}
 
 
-                base* clone() const { return new data<T, V>(*this); }
+    base *clone() const { return new data<T, V>(*this); }
 
 
-                V T::* value_;
-            };
+    V T::* value_;
+  };
 
 
-            base* ptr_;
+  base *ptr_;
 
 
-        public:
-            Any()
-                    :ptr_(nullptr) { }
+public:
+  Any()
+      : ptr_(nullptr) {}
 
 
-            template<typename T, typename V>
-            Any(V T::* const& value)
-                    : ptr_(new data<T, V>(value)) { }
+  template<typename T, typename V>
+  Any(V T::* const &value)
+      : ptr_(new data<T, V>(value)) {}
 
 
-            Any(Any const& other)
-                    :ptr_(other.ptr_ ? other.ptr_->clone() : nullptr) { }
+  Any(Any const &other)
+      : ptr_(other.ptr_ ? other.ptr_->clone() : nullptr) {}
 
 
-            virtual ~Any() { if (ptr_) delete ptr_; }
+  virtual ~Any() {
+    if (ptr_)
+      delete ptr_;
+  }
 
 
-            void operator=(Any const& other) { Any(other).swap(*this); }
+  void operator=(Any const &other) { Any(other).swap(*this); }
 
 
-            void swap(Any& other) { std::swap(ptr_, other.ptr_); }
+  void swap(Any &other) { std::swap(ptr_, other.ptr_); }
 
 
-            template<typename T, typename V>
-            V T::* get() const { return dynamic_cast < data<T, V>* >(ptr_)->value_; }
+  template<typename T, typename V>
+  V T::* get() const { return dynamic_cast < data<T, V> * >(ptr_)->value_; }
 
 
-            bool is_null() const { return ptr_ == nullptr; }
+  bool is_null() const { return ptr_ == nullptr; }
 
 
-            template<typename T, typename V>
-            void put(T* o, const V& value)
-            {
-                V T::* p = dynamic_cast <data<T, V>* >(ptr_)->value_;
-                o->*(p) = value;
-            }
+  template<typename T, typename V>
+  void put(T *o, const V &value) {
+    V T::* p = dynamic_cast <data<T, V> * >(ptr_)->value_;
+    o->*(p) = value;
+  }
 
 
-            template<typename T>
-            void restore(T* o, const common::Value& value)
-            {
-                if (value.is_type<double>()) {
-                    double v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<unsigned int>()) {
-                    unsigned int v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<int>()) {
-                    int v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<bool>()) {
-                    bool v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<std::vector<double> >()) {
-                    std::vector<double> v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<std::vector<unsigned int> >()) {
-                    std::vector<unsigned int> v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<std::vector<int> >()) {
-                    std::vector<int> v;
-
-                    value(v);
-                    put(o, v);
-                } else if (value.is_type<std::vector<bool> >()) {
-                    std::vector<bool> v;
-
-                    value(v);
-                    put(o, v);
-                } else {
-                    assert(false);
-                }
-            }
+  template<typename T>
+  void restore(T *o, const common::Value &value) {
+    if (value.is_type<double>()) {
+      double v;
+
+      value(v);
+      put(o, v);
+    } else if (value.is_type<unsigned int>()) {
+      unsigned int v;
+
+      value(v);
+      put(o, v);
+    } else if (value.is_type<int>()) {
+      int v;
+
+      value(v);
+      put(o, v);
+    } else if (value.is_type<bool>()) {
+      bool v;
+
+      value(v);
+      put(o, v);
+    } else if (value.is_type<std::vector<double> >()) {
+      std::vector<double> v;
+
+      value(v);
+      put(o, v);
+    } else if (value.is_type<std::vector<unsigned int> >()) {
+      std::vector<unsigned int> v;
+
+      value(v);
+      put(o, v);
+    } else if (value.is_type<std::vector<int> >()) {
+      std::vector<int> v;
 
 
-            template<typename T>
-            common::Value save(const T* o) const
-            {
-                if (ptr_) {
-                    data<T, double>* q_double =
-                            dynamic_cast < data<T, double>* >(ptr_);
-
-                    if (q_double) {
-                        return common::Value(o->*(q_double->value_));
-                    } else {
-                        data<T, unsigned int>* q_uint =
-                                dynamic_cast < data<T, unsigned int>* >(ptr_);
-
-                        if (q_uint) {
-                            return common::Value(o->*(q_uint->value_));
-                        } else {
-                            data<T, int>* q_int =
-                                    dynamic_cast < data<T, int>* >(ptr_);
-
-                            if (q_int) {
-                                return common::Value(o->*(q_int->value_));
-                            } else {
-                                data<T, bool>* q_bool =
-                                        dynamic_cast < data<T, bool>* >(ptr_);
-
-                                if (q_bool) {
-                                    return common::Value(o->*(q_bool->value_));
-                                } else {
-                                    data<T, std::vector<double> >* q_double_v =
-                                            dynamic_cast < data<T, std::vector<
-                                                    double> >* >(ptr_);
-
-                                    if (q_double_v) {
-                                        return common::Value(o->*(q_double_v->value_));
-                                    } else {
-                                        data<T, std::vector<int> >* q_int_v =
-                                                dynamic_cast < data<T, std::vector<
-                                                        int> >* >(ptr_);
-
-                                        if (q_int_v) {
-                                            return common::Value(o->*(q_int_v->value_));
-                                        } else {
-                                            data<T, std::vector<bool> >* q_bool_v =
-                                                    dynamic_cast < data<T, std::vector<
-                                                            bool> >* >(ptr_);
-
-                                            if (q_bool_v) {
-                                                return common::Value(
-                                                        o->*(q_bool_v->value_));
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
+      value(v);
+      put(o, v);
+    } else if (value.is_type<std::vector<bool> >()) {
+      std::vector<bool> v;
+
+      value(v);
+      put(o, v);
+    } else {
+      assert(false);
+    }
+  }
+
+  template<typename T>
+  common::Value save(const T *o) const {
+    if (ptr_) {
+      data<T, double> *q_double =
+          dynamic_cast < data<T, double> * >(ptr_);
+
+      if (q_double) {
+        return common::Value(o->*(q_double->value_));
+      } else {
+        data<T, unsigned int> *q_uint =
+            dynamic_cast < data<T, unsigned int> * >(ptr_);
+
+        if (q_uint) {
+          return common::Value(o->*(q_uint->value_));
+        } else {
+          data<T, int> *q_int =
+              dynamic_cast < data<T, int> * >(ptr_);
+
+          if (q_int) {
+            return common::Value(o->*(q_int->value_));
+          } else {
+            data<T, bool> *q_bool =
+                dynamic_cast < data<T, bool> * >(ptr_);
+
+            if (q_bool) {
+              return common::Value(o->*(q_bool->value_));
+            } else {
+              data<T, std::vector<double> > *q_double_v =
+                  dynamic_cast < data<T, std::vector<
+                      double> > * >(ptr_);
+
+              if (q_double_v) {
+                return common::Value(o->*(q_double_v->value_));
+              } else {
+                data<T, std::vector<int> > *q_int_v =
+                    dynamic_cast < data<T, std::vector<
+                        int> > * >(ptr_);
+
+                if (q_int_v) {
+                  return common::Value(o->*(q_int_v->value_));
+                } else {
+                  data<T, std::vector<bool> > *q_bool_v =
+                      dynamic_cast < data<T, std::vector<
+                          bool> > * >(ptr_);
+
+                  if (q_bool_v) {
+                    return common::Value(
+                        o->*(q_bool_v->value_));
+                  }
                 }
                 }
-                assert(false);
-                return common::Value();
+              }
             }
             }
-
-            template<typename T>
-            std::string to_string(const T* o) const
-            {
-                if (ptr_) {
-                    data<T, double>* q_double =
-                            dynamic_cast < data<T, double>* >(ptr_);
-
-                    if (q_double) {
-                        return std::to_string(o->*(q_double->value_));
-                    } else {
-                        data<T, unsigned int>* q_uint =
-                                dynamic_cast < data<T, unsigned int>* >(ptr_);
-
-                        if (q_uint) {
-                            return std::to_string(o->*(q_uint->value_));
-                        } else {
-                            data<T, int>* q_int =
-                                    dynamic_cast < data<T, int>* >(ptr_);
-
-                            if (q_int) {
-                                return std::to_string(o->*(q_int->value_));
-                            } else {
-                                data<T, bool>* q_bool =
-                                        dynamic_cast < data<T, bool>* >(ptr_);
-
-                                if (q_bool) {
-                                    return o->*(q_bool->value_) ? "true" : "false";
-                                } else {
-                                    data<T, std::vector<double> >* q_double_v =
-                                            dynamic_cast < data<T, std::vector<
-                                                    double> >* >(ptr_);
-
-                                    if (q_double_v) {
-                                        return "";
-                                    } else {
-                                        data<T, std::vector<int> >* q_int_v =
-                                                dynamic_cast < data<T, std::vector<
-                                                        int> >* >(ptr_);
-
-                                        if (q_int_v) {
-                                            return "";
-                                        } else {
-                                            data<T, std::vector<bool> >* q_bool_v =
-                                                    dynamic_cast < data<T, std::vector<
-                                                            bool> >* >(ptr_);
-
-                                            if (q_bool_v) {
-                                                return "";
-                                            } else {
-                                                return "NA";
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-                        }
-                    }
+          }
+        }
+      }
+    }
+    assert(false);
+    return common::Value();
+  }
+
+  template<typename T>
+  std::string to_string(const T *o) const {
+    if (ptr_) {
+      data<T, double> *q_double =
+          dynamic_cast < data<T, double> * >(ptr_);
+
+      if (q_double) {
+        return std::to_string(o->*(q_double->value_));
+      } else {
+        data<T, unsigned int> *q_uint =
+            dynamic_cast < data<T, unsigned int> * >(ptr_);
+
+        if (q_uint) {
+          return std::to_string(o->*(q_uint->value_));
+        } else {
+          data<T, int> *q_int =
+              dynamic_cast < data<T, int> * >(ptr_);
+
+          if (q_int) {
+            return std::to_string(o->*(q_int->value_));
+          } else {
+            data<T, bool> *q_bool =
+                dynamic_cast < data<T, bool> * >(ptr_);
+
+            if (q_bool) {
+              return o->*(q_bool->value_) ? "true" : "false";
+            } else {
+              data<T, std::vector<double> > *q_double_v =
+                  dynamic_cast < data<T, std::vector<
+                      double> > * >(ptr_);
+
+              if (q_double_v) {
+                return "";
+              } else {
+                data<T, std::vector<int> > *q_int_v =
+                    dynamic_cast < data<T, std::vector<
+                        int> > * >(ptr_);
+
+                if (q_int_v) {
+                  return "";
                 } else {
                 } else {
+                  data<T, std::vector<bool> > *q_bool_v =
+                      dynamic_cast < data<T, std::vector<
+                          bool> > * >(ptr_);
+
+                  if (q_bool_v) {
+                    return "";
+                  } else {
                     return "NA";
                     return "NA";
+                  }
                 }
                 }
+              }
             }
             }
-        };
-
+          }
+        }
+      }
+    } else {
+      return "NA";
     }
     }
+  }
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 38 - 41
src/artis-star/common/Bag.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Bag.hpp
+ * @file common/Bag.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef COMMON_BAG
 #ifndef COMMON_BAG
-#define COMMON_BAG 1
+#define COMMON_BAG
 
 
 #include <artis-star/common/ExternalEvent.hpp>
 #include <artis-star/common/ExternalEvent.hpp>
 
 
@@ -36,58 +36,55 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<class Time>
-        class ExternalEvent;
+template<class Time>
+class ExternalEvent;
 
 
-        template<class Time>
-        class Bag : public std::vector<ExternalEvent<Time> > {
-        public:
-            Bag() = default;
+template<class Time>
+class Bag : public std::vector<ExternalEvent<Time> > {
+public:
+  Bag() = default;
 
 
-            Bag(const ExternalEvent<Time>& event) { this->push_back(event); }
+  Bag(const ExternalEvent<Time> &event) { this->push_back(event); }
 
 
-            virtual ~Bag() = default;
+  virtual ~Bag() = default;
 
 
-            std::string to_string() const
-            {
-                std::ostringstream ss;
+  std::string to_string() const {
+    std::ostringstream ss;
 
 
-                ss << "{ ";
-                for (typename Bag<Time>::const_iterator it =
-                        Bag<Time>::begin();
-                     it != Bag<Time>::end(); ++it) {
-                    ss << it->to_string() << " ";
-                }
-                ss << "}";
-                return ss.str();
-            }
+    ss << "{ ";
+    for (typename Bag<Time>::const_iterator it =
+        Bag<Time>::begin();
+         it != Bag<Time>::end(); ++it) {
+      ss << it->to_string() << " ";
+    }
+    ss << "}";
+    return ss.str();
+  }
 
 
-        private:
-            friend class boost::serialization::access;
+private:
+  friend class boost::serialization::access;
 
 
-            template<class Archive>
-            void save(Archive& ar, const unsigned int version) const
-            {
-                (void) version;
+  template<class Archive>
+  void save(Archive &ar, const unsigned int version) const {
+    (void) version;
 
 
-                ar & *dynamic_cast < const std::vector<ExternalEvent<Time> >* >(
-                        this);
-            }
+    ar & *dynamic_cast < const std::vector<ExternalEvent<Time> > * >(
+        this);
+  }
 
 
-            template<class Archive>
-            void load(Archive& ar, const unsigned int version)
-            {
-                (void) version;
+  template<class Archive>
+  void load(Archive &ar, const unsigned int version) {
+    (void) version;
 
 
-                ar & *dynamic_cast < std::vector<ExternalEvent<Time> >* >(this);
-            }
+    ar & *dynamic_cast < std::vector<ExternalEvent<Time> > * >(this);
+  }
 
 
-            BOOST_SERIALIZATION_SPLIT_MEMBER()
-        };
+  BOOST_SERIALIZATION_SPLIT_MEMBER()
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 111 - 120
src/artis-star/common/Coordinator.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Coordinator.hpp
+ * @file common/Coordinator.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -36,134 +36,125 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<class Time>
-        class Model;
-
-        template<class Time>
-        class GraphManager;
-
-        template<class Time>
-        class Coordinator : public virtual Model<Time> {
-        public :
-            Coordinator(const std::string& name)
-                    :Model<Time>(name) { }
-
-            virtual ~Coordinator() { }
-
-            virtual GraphManager<Time>& get_graph_manager() = 0;
-
-            virtual const GraphManager<Time>& get_graph_manager() const = 0;
-
-            virtual const Model<Time>* get_submodel(unsigned int index) const
-            {
-                const GraphManager<Time>& graph_manager = get_graph_manager();
-                typename common::ModelMap<Time>::const_iterator it = graph_manager.child_map().find(
-                        index);
-
-                if (it != graph_manager.child_map().end()) {
-                    return it->second;
-                } else {
-                    return nullptr;
-                }
-            }
-
-            virtual const Model<Time>* get_submodel(unsigned int index, unsigned int rank) const
-            {
-                const GraphManager<Time>& graph_manager = get_graph_manager();
-                typename common::ModelsMap<Time>::const_iterator it = graph_manager.children_map().find(
-                        index);
-
-                if (it != graph_manager.children_map().end() and it->second.size() > rank) {
-                    return it->second.at(rank);
-                } else {
-                    return nullptr;
-                }
-            }
-
-            virtual unsigned int get_submodel_number(unsigned int index) const
-            {
-                const GraphManager<Time>& graph_manager = get_graph_manager();
-                typename common::ModelsMap<Time>::const_iterator it = graph_manager.children_map().find(
-                        index);
-
-                if (it != graph_manager.children_map().end()) {
-                    return it->second.size();
-                } else {
-                    return 0;
-                }
-            }
-
-            void input_port(common::Port p) { Coordinator<Time>::add_in_port(p); }
-
-            void input_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    Coordinator<Time>::add_in_port(*it);
-                }
-            }
-
-            virtual bool is_atomic() const { return false; }
-
-            void output_port(common::Port p) { Coordinator<Time>::add_out_port(p); }
-
-            void output_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    Coordinator<Time>::add_out_port(*it);
-                }
-            }
-
-            virtual void remove_model(const typename Time::type& t, common::Model<Time>* model)
-            {
-                model->finish(t);
-            }
-
-            void restore(const common::context::State<Time>& state)
-            {
-                Model<Time>::restore(state);
-                get_graph_manager().restore(state);
-            }
-
-            void save(common::context::State<Time>& state) const
-            {
-                Model<Time>::save(state);
-                get_graph_manager().save(state);
-            }
-
-            virtual std::string to_string(int /* level */) const
-            {
-                std::ostringstream ss;
-
-                ss << "Coordinator " << Coordinator<Time>::get_name();
-                return ss.str();
-            }
+namespace common {
 
 
-// DEVS methods
-            virtual void finish(const typename Time::type& t) = 0;
+template<class Time>
+class Model;
+
+template<class Time>
+class GraphManager;
+
+template<class Time>
+class Coordinator : public virtual Model<Time> {
+public :
+  Coordinator(const std::string &name)
+      : Model<Time>(name) {}
+
+  virtual ~Coordinator() {}
+
+  virtual GraphManager<Time> &get_graph_manager() = 0;
+
+  virtual const GraphManager<Time> &get_graph_manager() const = 0;
+
+  virtual const Model<Time> *get_submodel(unsigned int index) const {
+    const GraphManager<Time> &graph_manager = get_graph_manager();
+    typename common::ModelMap<Time>::const_iterator it = graph_manager.child_map().find(
+        index);
 
 
-            virtual common::Value
-            observe(const typename Time::type& t, unsigned int index) const = 0;
+    if (it != graph_manager.child_map().end()) {
+      return it->second;
+    } else {
+      return nullptr;
+    }
+  }
+
+  virtual const Model<Time> *get_submodel(unsigned int index, unsigned int rank) const {
+    const GraphManager<Time> &graph_manager = get_graph_manager();
+    typename common::ModelsMap<Time>::const_iterator it = graph_manager.children_map().find(
+        index);
 
 
-            virtual void output(const typename Time::type& t) = 0;
+    if (it != graph_manager.children_map().end() and it->second.size() > rank) {
+      return it->second.at(rank);
+    } else {
+      return nullptr;
+    }
+  }
 
 
-            virtual void
-            post_event(const typename Time::type& t, const common::ExternalEvent<Time>& event) = 0;
+  virtual unsigned int get_submodel_number(unsigned int index) const {
+    const GraphManager<Time> &graph_manager = get_graph_manager();
+    typename common::ModelsMap<Time>::const_iterator it = graph_manager.children_map().find(
+        index);
 
 
-            virtual typename Time::type dispatch_events(const common::Bag<Time>& bag,
-                    const typename Time::type& t) = 0;
+    if (it != graph_manager.children_map().end()) {
+      return it->second.size();
+    } else {
+      return 0;
+    }
+  }
+
+  void input_port(common::Port p) { Coordinator<Time>::add_in_port(p); }
+
+  void input_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      Coordinator<Time>::add_in_port(*it);
+    }
+  }
 
 
-            virtual typename Time::type start(const typename Time::type& t) = 0;
+  virtual bool is_atomic() const { return false; }
 
 
-            virtual typename Time::type transition(const typename Time::type& t) = 0;
-        };
+  void output_port(common::Port p) { Coordinator<Time>::add_out_port(p); }
 
 
+  void output_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      Coordinator<Time>::add_out_port(*it);
     }
     }
+  }
+
+  virtual void remove_model(const typename Time::type &t, common::Model<Time> *model) {
+    model->finish(t);
+  }
+
+  void restore(const common::context::State<Time> &state) {
+    Model<Time>::restore(state);
+    get_graph_manager().restore(state);
+  }
+
+  void save(common::context::State<Time> &state) const {
+    Model<Time>::save(state);
+    get_graph_manager().save(state);
+  }
+
+  virtual std::string to_string(int /* level */) const {
+    std::ostringstream ss;
+
+    ss << "Coordinator " << Coordinator<Time>::get_name();
+    return ss.str();
+  }
+
+// DEVS methods
+  virtual void finish(const typename Time::type &t) = 0;
+
+  virtual common::Value
+  observe(const typename Time::type &t, unsigned int index) const = 0;
+
+  virtual void output(const typename Time::type &t) = 0;
+
+  virtual void
+  post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event) = 0;
+
+  virtual typename Time::type dispatch_events(const common::Bag<Time> &bag,
+                                              const typename Time::type &t) = 0;
+
+  virtual typename Time::type start(const typename Time::type &t) = 0;
+
+  virtual typename Time::type transition(const typename Time::type &t) = 0;
+};
+
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 85 - 90
src/artis-star/common/ExternalEvent.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file ExternalEvent.hpp
+ * @file common/ExternalEvent.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef COMMON_EXTERNAL_EVENT
 #ifndef COMMON_EXTERNAL_EVENT
-#define COMMON_EXTERNAL_EVENT 1
+#define COMMON_EXTERNAL_EVENT
 
 
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Node.hpp>
 #include <artis-star/common/Node.hpp>
@@ -39,124 +39,119 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<class Time>
-        class Node;
+template<class Time>
+class Node;
 
 
-        template<class Time>
-        class Model;
+template<class Time>
+class Model;
 
 
-        template<class Time>
-        class ExternalEvent {
-        public:
-            ExternalEvent(const Value& data)
-                    :
-                    _port_index(-1), _model(nullptr), _data(data) { }
+template<class Time>
+class ExternalEvent {
+public:
+  ExternalEvent(const Value &data)
+      :
+      _port_index(-1), _model(nullptr), _data(data) {}
 
 
-            ExternalEvent(int port_index)
-                    :
-                    _port_index(port_index), _model(nullptr), _data(Value()) { }
+  ExternalEvent(int port_index)
+      :
+      _port_index(port_index), _model(nullptr), _data(Value()) {}
 
 
-            ExternalEvent(int port_index, const Value& data)
-                    :
-                    _port_index(port_index), _model(nullptr), _data(data) { }
+  ExternalEvent(int port_index, const Value &data)
+      :
+      _port_index(port_index), _model(nullptr), _data(data) {}
 
 
-            ExternalEvent(const Node<Time>& node, const Value& data)
-                    :
-                    _port_index(node.get_port_index()),
-                    _model(node.get_model()),
-                    _data(data) { }
+  ExternalEvent(const Node<Time> &node, const Value &data)
+      :
+      _port_index(node.get_port_index()),
+      _model(node.get_model()),
+      _data(data) {}
 
 
-            ExternalEvent(const ExternalEvent& event)
-                    :
-                    _port_index(event._port_index), _model(event._model),
-                    _data(event._data) { }
+  ExternalEvent(const ExternalEvent &event)
+      :
+      _port_index(event._port_index), _model(event._model),
+      _data(event._data) {}
 
 
-            ExternalEvent()
-                    :_port_index(-2), _model(nullptr) { }
+  ExternalEvent()
+      : _port_index(-2), _model(nullptr) {}
 
 
-            virtual ~ExternalEvent() = default;
+  virtual ~ExternalEvent() = default;
 
 
-            const Value& data() const { return _data; }
+  const Value &data() const { return _data; }
 
 
-            void data(const Value& data) { _data = data; }
+  void data(const Value &data) { _data = data; }
 
 
-            Model<Time>* get_model() const { return _model; }
+  Model<Time> *get_model() const { return _model; }
 
 
-            bool is_void() const { return _port_index == -2; }
+  bool is_void() const { return _port_index == -2; }
 
 
-            bool on_port(int port_index) const
-            {
+  bool on_port(int port_index) const {
 
 
-                assert(_port_index != -1);
+    assert(_port_index != -1);
 
 
-                return _port_index == port_index;
-            }
+    return _port_index == port_index;
+  }
 
 
-            ExternalEvent& operator=(const ExternalEvent& e)
-            {
-                _port_index = e._port_index;
-                _model = e._model;
-                _data = e._data;
-                return *this;
-            }
+  ExternalEvent &operator=(const ExternalEvent &e) {
+    _port_index = e._port_index;
+    _model = e._model;
+    _data = e._data;
+    return *this;
+  }
 
 
-            int port_index() const
-            {
+  int port_index() const {
 
 
-                assert(_port_index != -1);
+    assert(_port_index != -1);
 
 
-                return _port_index;
-            }
+    return _port_index;
+  }
 
 
-            void set_model(Model<Time>* model) { _model = model; }
+  void set_model(Model<Time> *model) { _model = model; }
 
 
-            std::string to_string() const
-            {
-                std::ostringstream ss;
+  std::string to_string() const {
+    std::ostringstream ss;
 
 
-                ss << "( ";
-                if (_port_index != -1) {
-                    ss << _port_index << " , ";
-                }
-                ss << (_model ? _model->get_name() : "<>")
-                   << " , ";
-                if (not _data.empty()) {
-                    ss << _data.to_string();
-                } else {
-                    ss << "null";
-                }
-                ss << " )";
-                return ss.str();
-            }
+    ss << "( ";
+    if (_port_index != -1) {
+      ss << _port_index << " , ";
+    }
+    ss << (_model ? _model->get_name() : "<>")
+       << " , ";
+    if (not _data.empty()) {
+      ss << _data.to_string();
+    } else {
+      ss << "null";
+    }
+    ss << " )";
+    return ss.str();
+  }
 
 
-            static ExternalEvent Void;
+  static ExternalEvent Void;
 
 
-        private:
-            friend class boost::serialization::access;
+private:
+  friend class boost::serialization::access;
 
 
-            template<class Archive>
-            void serialize(Archive& ar, const unsigned int version)
-            {
-                (void) version;
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version) {
+    (void) version;
 
 
-                ar & _port_index;
-                _model = 0;
-                // ar & _model;
-                ar & _data;
-                // ar & _model->get_name();
-            }
+    ar & _port_index;
+    _model = 0;
+    // ar & _model;
+    ar & _data;
+    // ar & _model->get_name();
+  }
 
 
-            int _port_index;
-            Model<Time>* _model;
-            Value _data;
-        };
+  int _port_index;
+  Model<Time> *_model;
+  Value _data;
+};
 
 
-        template<class Time>
-        ExternalEvent<Time> ExternalEvent<Time>::Void;
+template<class Time>
+ExternalEvent<Time> ExternalEvent<Time>::Void;
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 67 - 70
src/artis-star/common/GraphManager.hpp

@@ -36,78 +36,75 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<class Time>
-        class GraphManager {
-        public:
-            GraphManager(common::Coordinator<Time>* coordinator)
-                    :
-                    _coordinator(coordinator) { }
-
-            virtual ~GraphManager() { }
-
-            virtual void add_child(unsigned int index, common::Model<Time>* child)
-            {
-                _children.push_back(child);
-                _child_map[index] = child;
-                child->set_parent(_coordinator);
-            }
-
-            virtual void add_children(unsigned int index, common::Model<Time>* child)
-            {
-                _children.push_back(child);
-                if (_children_map.find(index) == _children_map.end()) {
-                    _children_map[index] = Models<Time>();
-                }
-                _children_map[index].push_back(child);
-                child->set_parent(_coordinator);
-            }
-
-            const common::Models<Time>& children() const { return _children; }
-
-            const common::ModelMap<Time>& child_map() const { return _child_map; }
-
-            common::Model<Time>* child_map(size_t index) const { return _child_map.at(index); }
-
-            const common::ModelsMap<Time>& children_map() const { return _children_map; }
-
-            common::Coordinator<Time>* coordinator() const { return _coordinator; }
-
-            virtual void remove_child(unsigned int index)
-            {
-                common::Model<Time>* child = _child_map[index];
-
-                _children.erase(std::find(_children.begin(), _children.end(), child));
-                _child_map[index] = nullptr;
-                _child_map.erase(index);
-            }
-
-            void restore(const common::context::State<Time>& state)
-            {
-                for(typename common::ModelMap<Time>::iterator it = _child_map.begin(); it != _child_map.end(); ++it) {
-                    it->second->restore(state.get_substate(it->first));
-                }
-            }
-
-            void save(common::context::State<Time>& state) const
-            {
-                for(typename common::ModelMap<Time>::const_iterator it = _child_map.begin(); it != _child_map.end(); ++it) {
-                    context::State<Time> substate;
-
-                    it->second->save(substate);
-                    state.add_substate(it->first, substate);
-                }
-            }
-
-        protected:
-            common::Models<Time> _children;
-            common::ModelMap<Time> _child_map;
-            common::ModelsMap<Time> _children_map;
-            common::Coordinator<Time>* _coordinator;
-        };
+namespace common {
+
+template<class Time>
+class GraphManager {
+public:
+  GraphManager(common::Coordinator<Time> *coordinator)
+      :
+      _coordinator(coordinator) {}
+
+  virtual ~GraphManager() {}
+
+  virtual void add_child(unsigned int index, common::Model<Time> *child) {
+    _children.push_back(child);
+    _child_map[index] = child;
+    child->set_parent(_coordinator);
+  }
+
+  virtual void add_children(unsigned int index, common::Model<Time> *child) {
+    _children.push_back(child);
+    if (_children_map.find(index) == _children_map.end()) {
+      _children_map[index] = Models<Time>();
+    }
+    _children_map[index].push_back(child);
+    child->set_parent(_coordinator);
+  }
+
+  const common::Models<Time> &children() const { return _children; }
+
+  const common::ModelMap<Time> &child_map() const { return _child_map; }
+
+  common::Model<Time> *child_map(size_t index) const { return _child_map.at(index); }
+
+  const common::ModelsMap<Time> &children_map() const { return _children_map; }
+
+  common::Coordinator<Time> *coordinator() const { return _coordinator; }
+
+  virtual void remove_child(unsigned int index) {
+    common::Model<Time> *child = _child_map[index];
 
 
+    _children.erase(std::find(_children.begin(), _children.end(), child));
+    _child_map[index] = nullptr;
+    _child_map.erase(index);
+  }
+
+  void restore(const common::context::State<Time> &state) {
+    for (typename common::ModelMap<Time>::iterator it = _child_map.begin(); it != _child_map.end();
+         ++it) {
+      it->second->restore(state.get_substate(it->first));
+    }
+  }
+
+  void save(common::context::State<Time> &state) const {
+    for (typename common::ModelMap<Time>::const_iterator it = _child_map.begin();
+         it != _child_map.end(); ++it) {
+      context::State<Time> substate;
+
+      it->second->save(substate);
+      state.add_substate(it->first, substate);
     }
     }
+  }
+
+protected:
+  common::Models<Time> _children;
+  common::ModelMap<Time> _child_map;
+  common::ModelsMap<Time> _children_map;
+  common::Coordinator<Time> *_coordinator;
+};
+
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 36 - 40
src/artis-star/common/InternalEvent.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file InternalEvent.hpp
+ * @file common/InternalEvent.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,64 +25,60 @@
  */
  */
 
 
 #ifndef COMMON_INTERNAL_EVENT
 #ifndef COMMON_INTERNAL_EVENT
-#define COMMON_INTERNAL_EVENT 1
+#define COMMON_INTERNAL_EVENT
 
 
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Model.hpp>
 
 
 #include <functional>
 #include <functional>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<class Time>
-        class Model;
+template<class Time>
+class Model;
 
 
-        template<class Time>
-        class InternalEvent {
-        public:
-            InternalEvent(const typename Time::type& time, Model<Time>* model)
-                    :_time(time), _model(model) { }
+template<class Time>
+class InternalEvent {
+public:
+  InternalEvent(const typename Time::type &time, Model<Time> *model)
+      : _time(time), _model(model) {}
 
 
-            virtual ~InternalEvent() { }
+  virtual ~InternalEvent() {}
 
 
-            Model<Time>* get_model() const { return _model; }
+  Model<Time> *get_model() const { return _model; }
 
 
-            typename Time::type get_time() const { return _time; }
+  typename Time::type get_time() const { return _time; }
 
 
-            bool operator<(InternalEvent const& e) const
-            {
-                return _time < e._time;
-            }
+  bool operator<(InternalEvent const &e) const {
+    return _time < e._time;
+  }
 
 
-            bool operator>(InternalEvent const& e) const
-            {
-                return _time > e._time;
-            }
+  bool operator>(InternalEvent const &e) const {
+    return _time > e._time;
+  }
 
 
-            bool operator>=(InternalEvent const& e) const
-            {
-                return _time >= e._time;
-            }
+  bool operator>=(InternalEvent const &e) const {
+    return _time >= e._time;
+  }
 
 
-            bool operator==(InternalEvent const& e) const
-            {
-                return _time == e._time;
-            }
+  bool operator==(InternalEvent const &e) const {
+    return _time == e._time;
+  }
 
 
-            void set_time(typename Time::type time) { _time = time; }
+  void set_time(typename Time::type time) { _time = time; }
 
 
-        private:
-            typename Time::type _time;
-            Model<Time>* _model;
-        };
+private:
+  typename Time::type _time;
+  Model<Time> *_model;
+};
 
 
-        template<typename Event>
-        struct EventCompare
-                : std::binary_function<Event, Event, bool> {
-            bool operator()(const Event& left, const Event& right) const { return left >= right; }
-        };
+template<typename Event>
+struct EventCompare
+    : std::binary_function<Event, Event, bool> {
+  bool operator()(const Event &left, const Event &right) const { return left >= right; }
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 109 - 116
src/artis-star/common/Links.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Links.hpp
+ * @file common/Links.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef COMMON_LINKS
 #ifndef COMMON_LINKS
-#define COMMON_LINKS 1
+#define COMMON_LINKS
 
 
 #include <artis-star/common/Node.hpp>
 #include <artis-star/common/Node.hpp>
 #include <artis-star/common/utils/String.hpp>
 #include <artis-star/common/utils/String.hpp>
@@ -34,121 +34,114 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<class Time>
-        class Node;
-
-        template<class Time>
-        class Links : public std::multimap<Node<Time>, Node<Time> > {
-            typedef std::multimap<Node<Time>, Node<Time> > type;
-
-        public:
-            typedef std::pair<
-                    typename Links<Time>::const_iterator,
-                    typename Links<Time>::const_iterator
-            > Result;
-
-            Links() { }
-
-            virtual ~Links() { }
-
-            void add(Model<Time>* out_model, unsigned int out_port_index,
-                    Model<Time>* in_model, unsigned int in_port_index)
-            {
-                type::insert(std::pair<Node<Time>, Node<Time> >(
-                        Node<Time>(out_model, out_port_index),
-                        Node<Time>(in_model, in_port_index)));
-            }
-
-            bool exist(Model<Time>* out_model,
-                    unsigned int out_port_index,
-                    Model<Time>* in_model,
-                    unsigned int in_port_index) const
-            {
-                std::pair<typename Links<Time>::const_iterator,
-                        typename Links<Time>::const_iterator> it =
-                        type::equal_range(Node<Time>(out_model, out_port_index));
-                typename Links<Time>::const_iterator it2 = it.first;
-                bool found = false;
-
-                while (not found and it2 != it.second) {
-                    found = it2->second == Node<Time>(
-                            in_model, in_port_index);
-                    ++it2;
-                }
-                return found;
-            }
-
-            typename Links<Time>::const_iterator
-            find(Model<Time>* out_model, unsigned int out_port_index,
-                    Model<Time>* in_model, unsigned int in_port_index) const
-            {
-                std::pair<typename Links<Time>::const_iterator,
-                        typename Links<Time>::const_iterator> it =
-                        type::equal_range(Node<Time>(out_model, out_port_index));
-                typename Links<Time>::const_iterator it2 = it.first;
-                bool found = false;
-
-                while (not found and it2 != it.second) {
-                    found = it2->second == Node<Time>(
-                            in_model, in_port_index);
-                    if (not found) {
-                        ++it2;
-                    }
-                }
-                return it2;
-            }
-
-            Links::Result find(Model<Time>* out_model, unsigned int out_port_index) const
-            {
-                return type::equal_range(common::Node<Time>(out_model, out_port_index));
-            }
-
-            void remove(common::Model<Time>* src_model, unsigned int src_port_index,
-                    common::Model<Time>* dst_model, unsigned int dst_port_index)
-            {
-                typename Links<Time>::const_iterator result = find(src_model, src_port_index,
-                        dst_model, dst_port_index);
-
-                this->erase(result);
-            }
-
-            void remove_links(common::Model<Time>* model)
-            {
-                typename Links<Time>::iterator it = this->begin();
-
-                while (it != this->end()) {
-                    if (it->first.get_model() == model or it->second.get_model() == model) {
-                        this->erase(it);
-                        it = this->begin();
-                    } else {
-                        ++it;
-                    }
-                }
-            }
-
-            std::string to_string(int level = 0) const
-            {
-                std::stringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "Links:" << std::endl;
-                for (typename Links<Time>::const_iterator it = Links<Time>::begin();
-                     it != Links<Time>::end(); ++it) {
-                    ss << common::String::make_spaces((level + 1) * 2)
-                       << it->first.get_model()->get_name() << "::"
-                       << it->first.get_model()->get_out_port_name(
-                               it->first.get_port_index())
-                       << " -> "
-                       << it->second.get_model()->get_name() << "::"
-                       << it->second.get_model()->get_out_port_name(
-                               it->second.get_port_index()) << std::endl;
-                }
-                return ss.str();
-            }
-        };
-
+namespace common {
+
+template<class Time>
+class Node;
+
+template<class Time>
+class Links : public std::multimap<Node<Time>, Node<Time> > {
+  typedef std::multimap<Node<Time>, Node<Time> > type;
+
+public:
+  typedef std::pair<
+      typename Links<Time>::const_iterator,
+      typename Links<Time>::const_iterator
+  > Result;
+
+  Links() {}
+
+  virtual ~Links() {}
+
+  void add(Model<Time> *out_model, unsigned int out_port_index,
+           Model<Time> *in_model, unsigned int in_port_index) {
+    type::insert(std::pair<Node<Time>, Node<Time> >(
+        Node<Time>(out_model, out_port_index),
+        Node<Time>(in_model, in_port_index)));
+  }
+
+  bool exist(Model<Time> *out_model,
+             unsigned int out_port_index,
+             Model<Time> *in_model,
+             unsigned int in_port_index) const {
+    std::pair<typename Links<Time>::const_iterator,
+              typename Links<Time>::const_iterator> it =
+        type::equal_range(Node<Time>(out_model, out_port_index));
+    typename Links<Time>::const_iterator it2 = it.first;
+    bool found = false;
+
+    while (not found and it2 != it.second) {
+      found = it2->second == Node<Time>(
+          in_model, in_port_index);
+      ++it2;
+    }
+    return found;
+  }
+
+  typename Links<Time>::const_iterator
+  find(Model<Time> *out_model, unsigned int out_port_index,
+       Model<Time> *in_model, unsigned int in_port_index) const {
+    std::pair<typename Links<Time>::const_iterator,
+              typename Links<Time>::const_iterator> it =
+        type::equal_range(Node<Time>(out_model, out_port_index));
+    typename Links<Time>::const_iterator it2 = it.first;
+    bool found = false;
+
+    while (not found and it2 != it.second) {
+      found = it2->second == Node<Time>(
+          in_model, in_port_index);
+      if (not found) {
+        ++it2;
+      }
+    }
+    return it2;
+  }
+
+  Links::Result find(Model<Time> *out_model, unsigned int out_port_index) const {
+    return type::equal_range(common::Node<Time>(out_model, out_port_index));
+  }
+
+  void remove(common::Model<Time> *src_model, unsigned int src_port_index,
+              common::Model<Time> *dst_model, unsigned int dst_port_index) {
+    typename Links<Time>::const_iterator result = find(src_model, src_port_index,
+                                                       dst_model, dst_port_index);
+
+    this->erase(result);
+  }
+
+  void remove_links(common::Model<Time> *model) {
+    typename Links<Time>::iterator it = this->begin();
+
+    while (it != this->end()) {
+      if (it->first.get_model() == model or it->second.get_model() == model) {
+        this->erase(it);
+        it = this->begin();
+      } else {
+        ++it;
+      }
     }
     }
+  }
+
+  std::string to_string(int level = 0) const {
+    std::stringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "Links:" << std::endl;
+    for (typename Links<Time>::const_iterator it = Links<Time>::begin();
+         it != Links<Time>::end(); ++it) {
+      ss << common::String::make_spaces((level + 1) * 2)
+         << it->first.get_model()->get_name() << "::"
+         << it->first.get_model()->get_out_port_name(
+             it->first.get_port_index())
+         << " -> "
+         << it->second.get_model()->get_name() << "::"
+         << it->second.get_model()->get_out_port_name(
+             it->second.get_port_index()) << std::endl;
+    }
+    return ss.str();
+  }
+};
+
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 1 - 1
src/artis-star/common/Macro.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Macro.hpp
+ * @file common/Macro.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */

+ 234 - 259
src/artis-star/common/Model.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Model.hpp
+ * @file common/Model.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -40,318 +40,293 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<class Time>
-        class ExternalEvent;
+template<class Time>
+class ExternalEvent;
 
 
-        template<class Time>
-        class InternalEvent;
+template<class Time>
+class InternalEvent;
 
 
-        template<class Time>
-        class Bag;
+template<class Time>
+class Bag;
 
 
-        struct Port {
-            unsigned int index;
-            std::string name;
-        };
+struct Port {
+  unsigned int index;
+  std::string name;
+};
 
 
-        typedef std::vector<unsigned int> Ports;
-        typedef std::map<unsigned int, std::string> PortMap;
+typedef std::vector<unsigned int> Ports;
+typedef std::map<unsigned int, std::string> PortMap;
 
 
-        template<class Time>
-        class Model {
-        public:
-            Model(const std::string& name)
-                    :
-                    _tl(0), _tn(0), _parent(0), _name(name), _inputs(0) { }
+template<class Time>
+class Model {
+public:
+  Model(const std::string &name)
+      :
+      _tl(0), _tn(0), _parent(0), _name(name), _inputs(0) {}
 
 
-            virtual ~Model()
-            {
-                if (_inputs) {
-                    delete _inputs;
-                }
-            }
+  virtual ~Model() {
+    if (_inputs) {
+      delete _inputs;
+    }
+  }
+
+  // structure
+  void add_in_port(const Port &port) {
+    assert(not exist_in_port(port.index));
+
+    _in_ports.push_back(port.index);
+    _in_port_map[port.index] = port.name;
+  }
+
+  void add_out_port(const Port &port) {
+    assert(not exist_out_port(port.index));
+
+    _out_ports.push_back(port.index);
+    _out_port_map[port.index] = port.name;
+  }
+
+  void delete_in_port(const Port &port) {
+    assert(not exist_in_port(port.index));
+
+    _in_ports.erase(std::find(_in_ports.begin(), _in_ports.end(),
+                              port.index));
+    _in_port_map.erase(port.index);
+  }
+
+  void delete_out_port(const Port &port) {
+    assert(not exist_out_port(port.index));
+
+    _out_ports.erase(std::find(_out_ports.begin(), _out_ports.end(),
+                               port.index));
+    _out_port_map.erase(port.index);
+  }
+
+  bool exist_in_port(unsigned int port_index) const {
+    return _in_port_map.find(port_index) != _in_port_map.end();
+  }
+
+  bool exist_out_port(unsigned int port_index) const {
+    return _out_port_map.find(port_index) != _out_port_map.end();
+  }
 
 
-            // structure
-            void add_in_port(const Port& port)
-            {
-                assert(not exist_in_port(port.index));
+  std::string get_in_port_name(unsigned int port_index) const {
+    assert(exist_in_port(port_index));
 
 
-                _in_ports.push_back(port.index);
-                _in_port_map[port.index] = port.name;
-            }
+    return _in_port_map.find(port_index)->second;
+  }
 
 
-            void add_out_port(const Port& port)
-            {
-                assert(not exist_out_port(port.index));
+  size_t get_in_port_number() const { return _in_port_map.size(); }
 
 
-                _out_ports.push_back(port.index);
-                _out_port_map[port.index] = port.name;
-            }
+  std::string get_out_port_name(unsigned int port_index) const {
+    assert(exist_out_port(port_index));
 
 
-            void delete_in_port(const Port& port)
-            {
-                assert(not exist_in_port(port.index));
+    return _out_port_map.find(port_index)->second;
+  }
 
 
-                _in_ports.erase(std::find(_in_ports.begin(), _in_ports.end(),
-                        port.index));
-                _in_port_map.erase(port.index);
-            }
+  size_t get_out_port_number() const { return _out_port_map.size(); }
 
 
-            void delete_out_port(const Port& port)
-            {
-                assert(not exist_out_port(port.index));
+  const std::string &get_name() const { return _name; }
 
 
-                _out_ports.erase(std::find(_out_ports.begin(), _out_ports.end(),
-                        port.index));
-                _out_port_map.erase(port.index);
-            }
+  Model<Time> *get_parent() const { return _parent; }
 
 
-            bool exist_in_port(unsigned int port_index) const
-            {
-                return _in_port_map.find(port_index) != _in_port_map.end();
-            }
+  // TODO: to remove
+  virtual int get_receiver_number(typename Time::type t) {
+    (void) t;
 
 
-            bool exist_out_port(unsigned int port_index) const
-            {
-                return _out_port_map.find(port_index) != _out_port_map.end();
-            }
+    return 0;
+  }
 
 
-            std::string get_in_port_name(unsigned int port_index) const
-            {
-                assert(exist_in_port(port_index));
+  virtual const Model<Time> *get_submodel(unsigned int index) const {
+    (void) index;
 
 
-                return _in_port_map.find(port_index)->second;
-            }
+    assert(false);
 
 
-            size_t get_in_port_number() const { return _in_port_map.size(); }
+    return nullptr;
+  }
 
 
-            std::string get_out_port_name(unsigned int port_index) const
-            {
-                assert(exist_out_port(port_index));
+  virtual const Model<Time> *get_submodel(unsigned int index,
+                                          unsigned int rank) const {
+    (void) index;
+    (void) rank;
 
 
-                return _out_port_map.find(port_index)->second;
-            }
+    assert(false);
 
 
-            size_t get_out_port_number() const { return _out_port_map.size(); }
+    return nullptr;
+  }
 
 
-            const std::string& get_name() const { return _name; }
+  virtual unsigned int get_submodel_number(unsigned int index) const {
+    (void) index;
 
 
-            Model<Time>* get_parent() const { return _parent; }
+    assert(false);
 
 
-            // TODO: to remove
-            virtual int get_receiver_number(typename Time::type t)
-            {
-                (void) t;
+    return 0;
+  }
 
 
-                return 0;
-            }
+  virtual bool is_atomic() const = 0;
 
 
-            virtual const Model<Time>* get_submodel(unsigned int index) const
-            {
-                (void) index;
+  virtual bool is_remote() const { return false; }
 
 
-                assert(false);
+  virtual std::string observable_name(unsigned int observable_index) const {
+    (void) observable_index;
 
 
-                return nullptr;
-            }
+    assert(false);
 
 
-            virtual const Model<Time>* get_submodel(unsigned int index,
-                    unsigned int rank) const
-            {
-                (void) index;
-                (void) rank;
+    return std::string();
+  }
 
 
-                assert(false);
+  std::string path() const {
+    return (_parent != nullptr ? _parent->path() : "") + ":" + get_name();
+  }
 
 
-                return nullptr;
-            }
+  virtual void restore(const common::context::State<Time> &state) {
+    _tl = state.last_time();
+    _tn = state.next_time();
+  }
 
 
-            virtual unsigned int get_submodel_number(unsigned int index) const
-            {
-                (void) index;
+  virtual void save(common::context::State<Time> &state) const {
+    state.last_time(_tl);
+    state.next_time(_tn);
+  }
 
 
-                assert(false);
+  void set_parent(Model<Time> *parent) { _parent = parent; }
 
 
-                return 0;
-            }
+  virtual std::string to_string(int /* level */) const = 0;
 
 
-            virtual bool is_atomic() const = 0;
+  // event
+  void add_event(const common::ExternalEvent<Time> &message) {
+    if (_inputs == 0) {
+      _inputs = new Bag<Time>;
+    }
+    _inputs->push_back(message);
+  }
+
+  void clear_bag() {
+    if (_inputs) {
+      delete _inputs;
+      _inputs = 0;
+    }
+  }
+
+  unsigned int event_number() const {
+    return _inputs ? _inputs->size() : 0;
+  }
+
+  const common::Bag<Time> &get_bag() {
+    if (_inputs == 0) {
+      _inputs = new Bag<Time>;
+    }
+    return *_inputs;
+  }
 
 
-            virtual bool is_remote() const { return false; }
+  // time
+  typename Time::type get_tl() const { return _tl; }
 
 
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                (void) observable_index;
+  typename Time::type get_tn() const { return _tn; }
 
 
-                assert(false);
+  // devs methods
+  virtual void finish(const typename Time::type &t) = 0;
 
 
-                return std::string();
-            }
+  virtual common::Value observe(const typename Time::type &t,
+                                unsigned int index) const = 0;
 
 
-            std::string path() const
-            {
-                return (_parent != nullptr ? _parent->path() : "") + ":" + get_name();
-            }
+  virtual void output(const typename Time::type &t) = 0;
 
 
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                _tl = state.last_time();
-                _tn = state.next_time();
-            }
+  virtual void post_event(const typename Time::type &t,
+                          const common::ExternalEvent<Time> &event) = 0;
 
 
-            virtual void save(common::context::State<Time>& state) const
-            {
-                state.last_time(_tl);
-                state.next_time(_tn);
-            }
+  virtual typename Time::type start(const typename Time::type &t) = 0;
 
 
-            void set_parent(Model<Time>* parent) { _parent = parent; }
+  virtual typename Time::type transition(const typename Time::type &t) = 0;
 
 
-            virtual std::string to_string(int /* level */) const = 0;
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
 
-            // event
-            void add_event(const common::ExternalEvent<Time>& message)
-            {
-                if (_inputs == 0) {
-                    _inputs = new Bag<Time>;
-                }
-                _inputs->push_back(message);
-            }
+  // scheduler
+  void handle(SchedulerHandle handle) { _handle.handle(handle); }
 
 
-            void clear_bag()
-            {
-                if (_inputs) {
-                    delete _inputs;
-                    _inputs = 0;
-                }
-            }
+  const SchedulerHandle &handle() const { return _handle.handle(); }
 
 
-            unsigned int event_number() const
-            {
-                return _inputs ? _inputs->size() : 0;
-            }
+protected:
+  typename Time::type _tl;
+  typename Time::type _tn;
 
 
-            const common::Bag<Time>& get_bag()
-            {
-                if (_inputs == 0) {
-                    _inputs = new Bag<Time>;
-                }
-                return *_inputs;
-            }
+private :
+  Model<Time> *_parent;
+  std::string _name;
+  Ports _in_ports;
+  PortMap _in_port_map;
+  Ports _out_ports;
+  PortMap _out_port_map;
 
 
-            // time
-            typename Time::type get_tl() const { return _tl; }
+  Bag<Time> *_inputs;
+  SchedulerHandle _handle;
+};
 
 
-            typename Time::type get_tn() const { return _tn; }
-
-            // devs methods
-            virtual void finish(const typename Time::type& t) = 0;
-
-            virtual common::Value observe(const typename Time::type& t,
-                    unsigned int index) const = 0;
-
-            virtual void output(const typename Time::type& t) = 0;
-
-            virtual void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event) = 0;
-
-            virtual typename Time::type start(const typename Time::type& t) = 0;
-
-            virtual typename Time::type transition(const typename Time::type& t) = 0;
-
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
-
-            // scheduler
-            void handle(SchedulerHandle handle) { _handle.handle(handle); }
-
-            const SchedulerHandle& handle() const { return _handle.handle(); }
-
-        protected:
-            typename Time::type _tl;
-            typename Time::type _tn;
-
-        private :
-            Model<Time>* _parent;
-            std::string _name;
-            Ports _in_ports;
-            PortMap _in_port_map;
-            Ports _out_ports;
-            PortMap _out_port_map;
-
-            Bag<Time>* _inputs;
-            SchedulerHandle _handle;
-        };
-
-        template<class Time>
-        class ModelMap : public std::map<unsigned int, Model<Time>*> {
-        public:
-            ModelMap() { }
-
-            virtual ~ModelMap() { }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                ss << "{ ";
-                for (typename ModelMap<Time>::const_iterator it =
-                        ModelMap<Time>::begin();
-                     it != ModelMap<Time>::end(); ++it) {
-                    ss << it->second->get_name() << " ";
-                }
-                ss << "}";
-                return ss.str();
-            }
-        };
-
-        template<class Time>
-        class Models : public std::vector<Model<Time>*> {
-        public:
-            Models() { }
-
-            virtual ~Models() { }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                ss << "{ ";
-                for (typename Models<Time>::const_iterator it =
-                        Models<Time>::begin();
-                     it != Models<Time>::end(); ++it) {
-                    ss << (*it)->get_name() << " ";
-                }
-                ss << "}";
-                return ss.str();
-            }
-        };
-
-        template<class Time>
-        class ModelsMap : public std::map<unsigned int, Models<Time> > {
-        public:
-            ModelsMap() { }
-
-            virtual ~ModelsMap() { }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                ss << "{ ";
-                for (typename ModelsMap<Time>::const_iterator it =
-                        ModelsMap<Time>::begin();
-                     it != ModelsMap<Time>::end(); ++it) {
-                    ss << it->second.to_string() << " ";
-                }
-                ss << "}";
-                return ss.str();
-            }
-        };
+template<class Time>
+class ModelMap : public std::map<unsigned int, Model<Time> *> {
+public:
+  ModelMap() {}
 
 
+  virtual ~ModelMap() {}
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    ss << "{ ";
+    for (typename ModelMap<Time>::const_iterator it =
+        ModelMap<Time>::begin();
+         it != ModelMap<Time>::end(); ++it) {
+      ss << it->second->get_name() << " ";
+    }
+    ss << "}";
+    return ss.str();
+  }
+};
+
+template<class Time>
+class Models : public std::vector<Model<Time> *> {
+public:
+  Models() {}
+
+  virtual ~Models() {}
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    ss << "{ ";
+    for (typename Models<Time>::const_iterator it =
+        Models<Time>::begin();
+         it != Models<Time>::end(); ++it) {
+      ss << (*it)->get_name() << " ";
     }
     }
+    ss << "}";
+    return ss.str();
+  }
+};
+
+template<class Time>
+class ModelsMap : public std::map<unsigned int, Models<Time> > {
+public:
+  ModelsMap() {}
+
+  virtual ~ModelsMap() {}
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    ss << "{ ";
+    for (typename ModelsMap<Time>::const_iterator it =
+        ModelsMap<Time>::begin();
+         it != ModelsMap<Time>::end(); ++it) {
+      ss << it->second.to_string() << " ";
+    }
+    ss << "}";
+    return ss.str();
+  }
+};
+
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 29 - 32
src/artis-star/common/Node.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Node.hpp
+ * @file common/Node.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -32,47 +32,44 @@
 #include <string>
 #include <string>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<class Time>
-        class Model;
+template<class Time>
+class Model;
 
 
-        template<class Time>
-        class Node {
-        public :
-            Node(Model<Time>* model, unsigned int port_index)
-                    :_model(model), _port_index(port_index)
-            {
-                _id = std::hash<std::string>()(model->get_name() +
-                        std::to_string(port_index));
-            }
+template<class Time>
+class Node {
+public :
+  Node(Model<Time> *model, unsigned int port_index)
+      : _model(model), _port_index(port_index) {
+    _id = std::hash<std::string>()(model->get_name() +
+        std::to_string(port_index));
+  }
 
 
-            Node(const Node<Time>& other)
-                    :_model(other._model), _port_index(other._port_index), _id(other._id) { }
+  Node(const Node<Time> &other)
+      : _model(other._model), _port_index(other._port_index), _id(other._id) {}
 
 
-            virtual ~Node() { }
+  virtual ~Node() {}
 
 
-            bool operator<(const Node<Time>& o) const
-            {
-                return _id < o._id;
-            }
+  bool operator<(const Node<Time> &o) const {
+    return _id < o._id;
+  }
 
 
-            bool operator==(const Node<Time>& o) const
-            {
-                return _id == o._id;
-            }
+  bool operator==(const Node<Time> &o) const {
+    return _id == o._id;
+  }
 
 
-            unsigned int get_port_index() const { return _port_index; }
+  unsigned int get_port_index() const { return _port_index; }
 
 
-            Model<Time>* get_model() const { return _model; }
+  Model<Time> *get_model() const { return _model; }
 
 
-        private :
-            Model<Time>* _model;
-            unsigned int _port_index;
-            int _id;
-        };
+private :
+  Model<Time> *_model;
+  unsigned int _port_index;
+  int _id;
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 7 - 7
src/artis-star/common/Parameters.hpp

@@ -25,17 +25,17 @@
  */
  */
 
 
 #ifndef COMMON_PARAMETERS
 #ifndef COMMON_PARAMETERS
-#define COMMON_PARAMETERS 1
+#define COMMON_PARAMETERS
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        class NoParameters {
-        public:
-            NoParameters() { }
-        };
+class NoParameters {
+public:
+  NoParameters() {}
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 73 - 77
src/artis-star/common/RootCoordinator.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file RootCoordinator.hpp
+ * @file common/RootCoordinator.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -36,43 +36,41 @@
 #include <string>
 #include <string>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<class Time, class Coordinator>
-        class RootCoordinator {
-        public :
-            RootCoordinator(const common::context::Context<Time>& context,
-                    const std::string& root_name,
-                    const typename Coordinator::parameters_type& parameters,
-                    const typename Coordinator::graph_parameters_type& graph_parameters)
-                    :
-                    _root(root_name, parameters, graph_parameters), _observer(&_root),
-                    _t_max(context.end()), _tn(context.begin()) { }
-
-            RootCoordinator(const common::context::Context<Time>& context,
-                    const std::string& root_name,
-                    const typename Coordinator::parameters_type& parameters)
-                    :
-                    _root(root_name, parameters, NoParameters()), _observer(&_root),
-                    _t_max(context.end()), _tn(context.begin()) { }
-
-            RootCoordinator(const common::context::Context<Time>& context,
-                    const std::string& root_name)
-                    :
-                    _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
-                    _t_max(context.end()), _tn(context.begin()) { }
-
-            virtual ~RootCoordinator() { }
-
-            void attachView(const std::string& name, observer::View<Time>* view)
-            {
-                _observer.attachView(name, view);
-            }
-
-            const observer::Observer<Time>& observer() const { return _observer; }
-
-            void run(const common::context::Context<Time>& context)
-            {
+namespace common {
+
+template<class Time, class Coordinator>
+class RootCoordinator {
+public :
+  RootCoordinator(const common::context::Context<Time> &context,
+                  const std::string &root_name,
+                  const typename Coordinator::parameters_type &parameters,
+                  const typename Coordinator::graph_parameters_type &graph_parameters)
+      :
+      _root(root_name, parameters, graph_parameters), _observer(&_root),
+      _t_max(context.end()), _tn(context.begin()) {}
+
+  RootCoordinator(const common::context::Context<Time> &context,
+                  const std::string &root_name,
+                  const typename Coordinator::parameters_type &parameters)
+      :
+      _root(root_name, parameters, NoParameters()), _observer(&_root),
+      _t_max(context.end()), _tn(context.begin()) {}
+
+  RootCoordinator(const common::context::Context<Time> &context,
+                  const std::string &root_name)
+      :
+      _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
+      _t_max(context.end()), _tn(context.begin()) {}
+
+  virtual ~RootCoordinator() {}
+
+  void attachView(const std::string &name, observer::View<Time> *view) {
+    _observer.attachView(name, view);
+  }
+
+  const observer::Observer<Time> &observer() const { return _observer; }
+
+  void run(const common::context::Context<Time> &context) {
 //             DSDE synchroniser
 //             DSDE synchroniser
 //               When receive (START,t)
 //               When receive (START,t)
 //                  send (START,0) to child
 //                  send (START,0) to child
@@ -84,47 +82,45 @@ namespace artis {
 //                  endWhile
 //                  endWhile
 //               end
 //               end
 
 
-                _observer.init();
-                if (context.valid()) {
-                    _root.restore(context.state());
-                    _tn = _root.get_tn();
-                } else {
-                    _tn = _root.start(_tn);
-                }
-                while (_tn <= _t_max) {
-                    typename Time::type next_tn;
-
-                    _root.output(_tn);
-                    next_tn = _root.transition(_tn);
-                    _observer.observe(_tn, _t_max < next_tn ? _t_max : next_tn);
-                    _tn = next_tn;
-                }
-            }
-
-            void save(common::context::Context<Time>& context) const
-            {
-                _root.save(context.state());
-                context.saved();
-            }
-
-            void switch_to_timed_observer(double step) { _observer.switch_to_timed_observer(step); }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                ss << _root.to_string(0);
-                return ss.str();
-            }
-
-        private :
-            Coordinator _root;
-            observer::Observer<Time> _observer;
-            typename Time::type _t_max;
-            typename Time::type _tn;
-        };
+    _observer.init();
+    if (context.valid()) {
+      _root.restore(context.state());
+      _tn = _root.get_tn();
+    } else {
+      _tn = _root.start(_tn);
+    }
+    while (_tn <= _t_max) {
+      typename Time::type next_tn;
 
 
+      _root.output(_tn);
+      next_tn = _root.transition(_tn);
+      _observer.observe(_tn, _t_max < next_tn ? _t_max : next_tn);
+      _tn = next_tn;
     }
     }
+  }
+
+  void save(common::context::Context<Time> &context) const {
+    _root.save(context.state());
+    context.saved();
+  }
+
+  void switch_to_timed_observer(double step) { _observer.switch_to_timed_observer(step); }
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    ss << _root.to_string(0);
+    return ss.str();
+  }
+
+private :
+  Coordinator _root;
+  observer::Observer<Time> _observer;
+  typename Time::type _t_max;
+  typename Time::type _tn;
+};
+
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 15 - 15
src/artis-star/common/Scheduler.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Scheduler.hpp
+ * @file common/Scheduler.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,33 +25,33 @@
  */
  */
 
 
 #ifndef COMMON_SCHEDULER
 #ifndef COMMON_SCHEDULER
-#define COMMON_SCHEDULER 1
+#define COMMON_SCHEDULER
 
 
 #include <artis-star/common/scheduler/HeapScheduler.hpp>
 #include <artis-star/common/scheduler/HeapScheduler.hpp>
 #include <artis-star/common/time/DoubleTime.hpp>
 #include <artis-star/common/time/DoubleTime.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        struct SchedulerHandle;
+struct SchedulerHandle;
 
 
-        typedef typename artis::common::scheduler::HeapScheduler<
-                common::DoubleTime, SchedulerHandle>::type SchedulerType;
+typedef typename artis::common::scheduler::HeapScheduler<
+    common::DoubleTime, SchedulerHandle>::type SchedulerType;
 
 
-        struct SchedulerHandle {
-            SchedulerHandle() { }
+struct SchedulerHandle {
+  SchedulerHandle() {}
 
 
-            SchedulerHandle(const SchedulerType::handle_type& handle)
-                    :_handle(handle) { }
+  SchedulerHandle(const SchedulerType::handle_type &handle)
+      : _handle(handle) {}
 
 
-            const SchedulerHandle& handle() const { return *this; }
+  const SchedulerHandle &handle() const { return *this; }
 
 
-            void handle(const SchedulerHandle& handle) { _handle = handle._handle; }
+  void handle(const SchedulerHandle &handle) { _handle = handle._handle; }
 
 
-            SchedulerType::handle_type _handle;
-        };
+  SchedulerType::handle_type _handle;
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 24 - 25
src/artis-star/common/Simulator.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Simulator.hpp
+ * @file common/Simulator.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -32,43 +32,42 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<class Time>
-        class Simulator : public virtual Model<Time> {
-        public :
-            Simulator(const std::string& name)
-                    :Model<Time>(name) { }
+template<class Time>
+class Simulator : public virtual Model<Time> {
+public :
+  Simulator(const std::string &name)
+      : Model<Time>(name) {}
 
 
-            virtual ~Simulator() { }
+  virtual ~Simulator() {}
 
 
-            virtual bool is_atomic() const { return true; }
+  virtual bool is_atomic() const { return true; }
 
 
-            virtual std::string to_string(int /* level */) const
-            {
-                std::ostringstream ss;
+  virtual std::string to_string(int /* level */) const {
+    std::ostringstream ss;
 
 
-                ss << "Simulator " << Simulator<Time>::get_name();
-                return ss.str();
-            }
+    ss << "Simulator " << Simulator<Time>::get_name();
+    return ss.str();
+  }
 
 
 // DEVS methods
 // DEVS methods
-            virtual void finish(const typename Time::type& t) = 0;
+  virtual void finish(const typename Time::type &t) = 0;
 
 
-            virtual common::Value observe(const typename Time::type& t,
-                    unsigned int index) const = 0;
+  virtual common::Value observe(const typename Time::type &t,
+                                unsigned int index) const = 0;
 
 
-            virtual void output(const typename Time::type& t) = 0;
+  virtual void output(const typename Time::type &t) = 0;
 
 
-            virtual void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event) = 0;
+  virtual void post_event(const typename Time::type &t,
+                          const common::ExternalEvent<Time> &event) = 0;
 
 
-            virtual typename Time::type start(const typename Time::type& t) = 0;
+  virtual typename Time::type start(const typename Time::type &t) = 0;
 
 
-            virtual typename Time::type transition(const typename Time::type& t) = 0;
-        };
+  virtual typename Time::type transition(const typename Time::type &t) = 0;
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 78 - 82
src/artis-star/common/States.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file States.hpp
+ * @file common/States.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -34,89 +34,85 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<typename Time, typename Dyn>
-        class States {
-        public:
-            template<class W>
-            struct element {
-                unsigned int index;
-                const std::string name;
-                W Dyn::* var;
-
-                element(unsigned int index, const std::string& name, W Dyn::* var)
-                        :
-                        index(index), name(name), var(var) { }
-            };
-
-            States() { }
-
-            virtual ~States() { }
-
-            common::Any& get(unsigned int index) { return states.at(index); }
-
-            const common::Any& get(unsigned int index) const { return states.at(index); }
-
-            unsigned int state_number() const { return states.size(); }
-
-            template<class W>
-            void S_(std::initializer_list<element<W> > list)
-            {
-                for (typename std::initializer_list<element<W> >::iterator it =
-                        list.begin(); it != list.end(); ++it) {
-                    if (states.size() <= it->index) {
-                        states.resize(it->index + 1, common::Any());
-                        state_names.resize(it->index + 1, std::string());
-                    }
-                    states[it->index] = it->var;
-                    state_names[it->index] = it->name;
-                }
-            }
-
-            virtual void restore(Dyn* model, const common::context::State<Time>& state)
-            {
-                unsigned int index = 0;
-
-                for (typename std::vector<common::Any>::iterator it = states.begin();
-                     it != states.end(); ++it) {
-                    if (not it->is_null()) {
-                        it->restore<Dyn>(model, state.get_state(index));
-                    }
-                    ++index;
-                }
-            }
-
-            virtual void save(const Dyn* model, common::context::State<Time>& state) const
-            {
-                unsigned int index = 0;
-
-                for (typename std::vector<common::Any>::const_iterator it =
-                        states.begin(); it != states.end(); ++it) {
-                    if (not it->is_null()) {
-                        state.add_state(index, it->save<Dyn>(model));
-                    }
-                    ++index;
-                }
-            }
-
-            template<class W>
-            void state_(unsigned int index, const std::string& name, W Dyn::* var)
-            {
-                if (states.size() <= index) {
-                    states.resize(index + 1, common::Any());
-                    state_names.resize(index + 1, std::string());
-                }
-                states[index] = common::Any(var);
-                state_names[index] = name;
-            }
-
-        private:
-            std::vector<common::Any> states;
-            std::vector<std::string> state_names;
-        };
+namespace common {
+
+template<typename Time, typename Dyn>
+class States {
+public:
+  template<class W>
+  struct element {
+    unsigned int index;
+    const std::string name;
+    W Dyn::* var;
+
+    element(unsigned int index, const std::string &name, W Dyn::* var)
+        :
+        index(index), name(name), var(var) {}
+  };
+
+  States() {}
+
+  virtual ~States() {}
+
+  common::Any &get(unsigned int index) { return states.at(index); }
+
+  const common::Any &get(unsigned int index) const { return states.at(index); }
+
+  unsigned int state_number() const { return states.size(); }
+
+  template<class W>
+  void S_(std::initializer_list<element<W> > list) {
+    for (typename std::initializer_list<element<W> >::iterator it =
+        list.begin(); it != list.end(); ++it) {
+      if (states.size() <= it->index) {
+        states.resize(it->index + 1, common::Any());
+        state_names.resize(it->index + 1, std::string());
+      }
+      states[it->index] = it->var;
+      state_names[it->index] = it->name;
+    }
+  }
+
+  virtual void restore(Dyn *model, const common::context::State<Time> &state) {
+    unsigned int index = 0;
+
+    for (typename std::vector<common::Any>::iterator it = states.begin();
+         it != states.end(); ++it) {
+      if (not it->is_null()) {
+        it->restore<Dyn>(model, state.get_state(index));
+      }
+      ++index;
+    }
+  }
+
+  virtual void save(const Dyn *model, common::context::State<Time> &state) const {
+    unsigned int index = 0;
 
 
+    for (typename std::vector<common::Any>::const_iterator it =
+        states.begin(); it != states.end(); ++it) {
+      if (not it->is_null()) {
+        state.add_state(index, it->save<Dyn>(model));
+      }
+      ++index;
     }
     }
+  }
+
+  template<class W>
+  void state_(unsigned int index, const std::string &name, W Dyn::* var) {
+    if (states.size() <= index) {
+      states.resize(index + 1, common::Any());
+      state_names.resize(index + 1, std::string());
+    }
+    states[index] = common::Any(var);
+    state_names[index] = name;
+  }
+
+private:
+  std::vector<common::Any> states;
+  std::vector<std::string> state_names;
+};
+
+}
 }
 }
 
 
 #define DECLARE_STATE(W, index, var)                                    \
 #define DECLARE_STATE(W, index, var)                                    \

+ 166 - 172
src/artis-star/common/Value.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Value.hpp
+ * @file common/Value.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef COMMON_VALUE
 #ifndef COMMON_VALUE
-#define COMMON_VALUE 1
+#define COMMON_VALUE
 
 
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/array.hpp>
 #include <boost/serialization/array.hpp>
@@ -37,178 +37,172 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        class Value {
-        public:
-            Value()
-                    :_content(nullptr), _size(0) { }
-
-            template<typename T>
-            Value(T value) { assign(&value, sizeof(T), typeid(T).hash_code()); }
-
-            template<typename T>
-            Value(T* value, size_t size)
-            {
-                assign(value, sizeof(T) * size, typeid(T*).hash_code());
-            }
-
-            Value(void* content, size_t size) { assign(content, size, typeid(void*).hash_code()); }
-
-            Value(const char* value, unsigned int size)
-            {
-                assign(value, size * sizeof(char), typeid(char*).hash_code());
-            }
-
-            Value(const Value& value)
-            {
-                if (value._content) {
-                    assign(value._content, value._size, value._type_id);
-                } else {
-                    _content = nullptr;
-                    _size = 0;
-                    _type_id = 0;
-                }
-            }
-
-            virtual ~Value() { if (_content != nullptr) delete[] _content; }
-
-            bool empty() const { return _content == nullptr; }
-
-            template<typename T>
-            void operator()(T& value) const
-            {
-                assert(_type_id == typeid(T).hash_code());
-
-                value = *(T*) (_content);
-            }
-
-            template<typename T>
-            void operator()(T*& value) const
-            {
-                assert(_type_id == typeid(T*).hash_code());
-
-                value = (T*) (_content);
-            }
-
-            template<typename Z>
-            bool is_type() const { return _type_id == typeid(Z).hash_code(); }
-
-            Value& operator=(const Value& value)
-            {
-                if (_content != nullptr) {
-                    delete _content;
-                }
-                if (value._content) {
-                    assign(value._content, value._size, value._type_id);
-                } else {
-                    _content = nullptr;
-                    _size = 0;
-                    _type_id = 0;
-                }
-                return *this;
-            }
-
-            std::string to_string() const
-            {
-                if (empty()) {
-                    return "<null>";
-                } else if (is_type<double>()) {
-                    double v;
-
-                    operator()(v);
-                    return std::to_string(v);
-                } else if (is_type<int>()) {
-                    int v;
-
-                    operator()(v);
-                    return std::to_string(v);
-                } else if (is_type<unsigned int>()) {
-                    unsigned int v;
-
-                    operator()(v);
-                    return std::to_string(v);
-                } else if (is_type<bool>()) {
-                    bool v;
-
-                    operator()(v);
-                    return v ? "true" : "false";
-                } else if (is_type<double*>()) {
-                    double* v;
-                    std::string str;
-                    size_t size = _size / sizeof(double);
-
-                    operator()(v);
-                    for (size_t i = 0; i < size; ++i) {
-                        str += std::to_string(v[i]) + std::string(" ");
-                    }
-                    return str;
-                } else if (is_type<int*>()) {
-                    int* v;
-                    std::string str;
-                    size_t size = _size / sizeof(int);
-
-                    operator()(v);
-                    for (size_t i = 0; i < size; ++i) {
-                        str += std::to_string(v[i]) + std::string(" ");
-                    }
-                    return str;
-                } else if (is_type<unsigned int*>()) {
-                    unsigned int* v;
-                    std::string str;
-                    size_t size = _size / sizeof(unsigned int);
-
-                    operator()(v);
-                    for (size_t i = 0; i < size; ++i) {
-                        str += std::to_string(v[i]) + std::string(" ");
-                    }
-                    return str;
-                } else if (is_type<bool*>()) {
-                    bool* v;
-                    std::string str;
-                    size_t size = _size / sizeof(bool);
-
-                    operator()(v);
-                    for (size_t i = 0; i < size; ++i) {
-                        str += std::to_string(v[i]) + std::string(" ");
-                    }
-                    return str;
-                } else {
-                    return "<unstringify>";
-                }
-            }
-
-        private:
-            void assign(const void* content, size_t size, size_t type_id)
-            {
-                _content = new char[size];
-                std::memcpy(_content, content, size);
-                _size = size;
-                _type_id = type_id;
-            }
-
-            friend class boost::serialization::access;
-
-            template<class Archive>
-            void serialize(Archive& ar, const unsigned int version)
-            {
-                (void) version;
-
-                ar & _size;
-                if (Archive::is_loading::value) {
-                    assert(_content == nullptr);
-                    _content = new char[_size];
-                }
-                ar & boost::serialization::make_array<char>(_content, _size);
-                ar & _type_id;
-            }
-
-            char* _content;
-            size_t _size;
-            size_t _type_id;
-        };
+namespace common {
+
+class Value {
+public:
+  Value()
+      : _content(nullptr), _size(0) {}
+
+  template<typename T>
+  Value(T value) { assign(&value, sizeof(T), typeid(T).hash_code()); }
+
+  template<typename T>
+  Value(T *value, size_t size) {
+    assign(value, sizeof(T) * size, typeid(T *).hash_code());
+  }
+
+  Value(void *content, size_t size) { assign(content, size, typeid(void *).hash_code()); }
+
+  Value(const char *value, unsigned int size) {
+    assign(value, size * sizeof(char), typeid(char *).hash_code());
+  }
+
+  Value(const Value &value) {
+    if (value._content) {
+      assign(value._content, value._size, value._type_id);
+    } else {
+      _content = nullptr;
+      _size = 0;
+      _type_id = 0;
+    }
+  }
+
+  virtual ~Value() {
+    if (_content != nullptr)
+      delete[] _content;
+  }
+
+  bool empty() const { return _content == nullptr; }
+
+  template<typename T>
+  void operator()(T &value) const {
+    assert(_type_id == typeid(T).hash_code());
+
+    value = *(T *) (_content);
+  }
+
+  template<typename T>
+  void operator()(T *&value) const {
+    assert(_type_id == typeid(T *).hash_code());
+
+    value = (T *) (_content);
+  }
 
 
+  template<typename Z>
+  bool is_type() const { return _type_id == typeid(Z).hash_code(); }
+
+  Value &operator=(const Value &value) {
+    if (_content != nullptr) {
+      delete _content;
+    }
+    if (value._content) {
+      assign(value._content, value._size, value._type_id);
+    } else {
+      _content = nullptr;
+      _size = 0;
+      _type_id = 0;
+    }
+    return *this;
+  }
+
+  std::string to_string() const {
+    if (empty()) {
+      return "<null>";
+    } else if (is_type<double>()) {
+      double v;
+
+      operator()(v);
+      return std::to_string(v);
+    } else if (is_type<int>()) {
+      int v;
+
+      operator()(v);
+      return std::to_string(v);
+    } else if (is_type<unsigned int>()) {
+      unsigned int v;
+
+      operator()(v);
+      return std::to_string(v);
+    } else if (is_type<bool>()) {
+      bool v;
+
+      operator()(v);
+      return v ? "true" : "false";
+    } else if (is_type<double *>()) {
+      double *v;
+      std::string str;
+      size_t size = _size / sizeof(double);
+
+      operator()(v);
+      for (size_t i = 0; i < size; ++i) {
+        str += std::to_string(v[i]) + std::string(" ");
+      }
+      return str;
+    } else if (is_type<int *>()) {
+      int *v;
+      std::string str;
+      size_t size = _size / sizeof(int);
+
+      operator()(v);
+      for (size_t i = 0; i < size; ++i) {
+        str += std::to_string(v[i]) + std::string(" ");
+      }
+      return str;
+    } else if (is_type<unsigned int *>()) {
+      unsigned int *v;
+      std::string str;
+      size_t size = _size / sizeof(unsigned int);
+
+      operator()(v);
+      for (size_t i = 0; i < size; ++i) {
+        str += std::to_string(v[i]) + std::string(" ");
+      }
+      return str;
+    } else if (is_type<bool *>()) {
+      bool *v;
+      std::string str;
+      size_t size = _size / sizeof(bool);
+
+      operator()(v);
+      for (size_t i = 0; i < size; ++i) {
+        str += std::to_string(v[i]) + std::string(" ");
+      }
+      return str;
+    } else {
+      return "<unstringify>";
     }
     }
+  }
+
+private:
+  void assign(const void *content, size_t size, size_t type_id) {
+    _content = new char[size];
+    std::memcpy(_content, content, size);
+    _size = size;
+    _type_id = type_id;
+  }
+
+  friend class boost::serialization::access;
+
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version) {
+    (void) version;
+
+    ar & _size;
+    if (Archive::is_loading::value) {
+      assert(_content == nullptr);
+      _content = new char[_size];
+    }
+    ar & boost::serialization::make_array<char>(_content, _size);
+    ar & _type_id;
+  }
+
+  char *_content;
+  size_t _size;
+  size_t _type_id;
+};
+
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 48 - 51
src/artis-star/common/context/Context.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/common/context/Context.hpp
+ * @file common/context/Context.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -32,73 +32,70 @@
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/serialization.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-        namespace context {
+namespace common {
+namespace context {
 
 
-            template<class Time>
-            class Context {
-            public:
-                Context()
-                        :_begin(-1), _end(-1), _valid(false) { }
+template<class Time>
+class Context {
+public:
+  Context()
+      : _begin(-1), _end(-1), _valid(false) {}
 
 
-                Context(const typename Time::type& begin, const typename Time::type& end)
-                        :_begin(begin), _end(end), _valid(false) { }
+  Context(const typename Time::type &begin, const typename Time::type &end)
+      : _begin(begin), _end(end), _valid(false) {}
 
 
-                virtual ~Context() { }
+  virtual ~Context() {}
 
 
-                const typename Time::type& begin() const { return _begin; }
+  const typename Time::type &begin() const { return _begin; }
 
 
-                const typename Time::type& end() const { return _end; }
+  const typename Time::type &end() const { return _end; }
 
 
-                void end(const typename Time::type& end) { _end = end; }
+  void end(const typename Time::type &end) { _end = end; }
 
 
-                const Context& operator=(const Context& context)
-                {
-                    _begin = context._begin;
-                    _end = context._end;
-                    _valid = context._valid;
-                    _state = context._state;
-                    return *this;
-                }
+  const Context &operator=(const Context &context) {
+    _begin = context._begin;
+    _end = context._end;
+    _valid = context._valid;
+    _state = context._state;
+    return *this;
+  }
 
 
-                void saved() { _valid = true; }
+  void saved() { _valid = true; }
 
 
-                const State<Time>& state() const { return _state; }
+  const State<Time> &state() const { return _state; }
 
 
-                State<Time>& state() { return _state; }
+  State<Time> &state() { return _state; }
 
 
-                std::string to_string() const
-                {
-                    return "begin: " + std::to_string(_begin) +
-                            "; end: " + std::to_string(_end) +
-                            "; valid: " + (_valid ? "true" : "false") +
-                            "; state: " + _state.to_string();
-                }
+  std::string to_string() const {
+    return "begin: " + std::to_string(_begin) +
+        "; end: " + std::to_string(_end) +
+        "; valid: " + (_valid ? "true" : "false") +
+        "; state: " + _state.to_string();
+  }
 
 
-                bool valid() const { return _valid; }
+  bool valid() const { return _valid; }
 
 
-            private:
-                friend class boost::serialization::access;
+private:
+  friend class boost::serialization::access;
 
 
-                template<class Archive>
-                void serialize(Archive& ar, const unsigned int version)
-                {
-                    (void) version;
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version) {
+    (void) version;
 
 
-                    ar & _begin;
-                    ar & _end;
-                    ar & _state;
-                    ar & _valid;
-                }
+    ar & _begin;
+    ar & _end;
+    ar & _state;
+    ar & _valid;
+  }
 
 
-                typename Time::type _begin;
-                typename Time::type  _end;
-                State<Time> _state;
-                bool _valid;
-            };
+  typename Time::type _begin;
+  typename Time::type _end;
+  State<Time> _state;
+  bool _valid;
+};
 
 
-        }
-    }
+}
+}
 }
 }
 
 
 #endif
 #endif

+ 71 - 77
src/artis-star/common/context/State.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/common/context/State.hpp
+ * @file common/context/State.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -36,83 +36,77 @@
 #include <boost/serialization/vector.hpp>
 #include <boost/serialization/vector.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-        namespace context {
-
-            template<class Time>
-            class State {
-                typedef std::map<unsigned int, State<Time> > Substates;
-
-            public:
-                State()
-                        :_last_time(-1), _next_time(-1) { }
-
-                virtual ~State() { }
-
-                void add_state(unsigned int variable_key, const Value& value)
-                {
-                    _values.add_state(variable_key, value);
-                }
-
-                void add_substate(unsigned int model_key, State& state)
-                {
-                    _substates.insert(std::make_pair(model_key, state));
-                }
-
-                const Value& get_state(unsigned int variable_key) const
-                {
-                    return _values.get_state(variable_key);
-                }
-
-                const State<Time>& get_substate(unsigned int model_key) const
-                {
-                    return _substates.find(model_key)->second;
-                }
-
-                typename Time::type last_time() const { return _last_time; }
-
-                void last_time(typename Time::type t) { _last_time = t; }
-
-                typename Time::type next_time() const { return _next_time; }
-
-                void next_time(typename Time::type t) { _next_time = t; }
-
-                std::string to_string() const
-                {
-                    std::string str = "last_time: " + std::to_string(_last_time) +
-                            "; next_time: " + std::to_string(_next_time) +
-                            "; values: " + _values.to_string() + "; sub_states: [ ";
-
-                    for (typename Substates::const_iterator it = _substates.begin();
-                         it != _substates.end(); ++it) {
-                        str += it->second.to_string() + " ";
-                    }
-                    str += "]";
-                    return str;
-                }
-
-            private:
-                friend class boost::serialization::access;
-
-                template<class Archive>
-                void serialize(Archive& ar, const unsigned int version)
-                {
-                    (void) version;
-
-                    ar & _values;
-                    ar & _substates;
-                    ar & _last_time;
-                    ar & _next_time;
-                }
-
-                StateValues _values;
-                Substates _substates;
-                typename Time::type _last_time;
-                typename Time::type _next_time;
-            };
-
-        }
+namespace common {
+namespace context {
+
+template<class Time>
+class State {
+  typedef std::map<unsigned int, State<Time> > Substates;
+
+public:
+  State()
+      : _last_time(-1), _next_time(-1) {}
+
+  virtual ~State() {}
+
+  void add_state(unsigned int variable_key, const Value &value) {
+    _values.add_state(variable_key, value);
+  }
+
+  void add_substate(unsigned int model_key, State &state) {
+    _substates.insert(std::make_pair(model_key, state));
+  }
+
+  const Value &get_state(unsigned int variable_key) const {
+    return _values.get_state(variable_key);
+  }
+
+  const State<Time> &get_substate(unsigned int model_key) const {
+    return _substates.find(model_key)->second;
+  }
+
+  typename Time::type last_time() const { return _last_time; }
+
+  void last_time(typename Time::type t) { _last_time = t; }
+
+  typename Time::type next_time() const { return _next_time; }
+
+  void next_time(typename Time::type t) { _next_time = t; }
+
+  std::string to_string() const {
+    std::string str = "last_time: " + std::to_string(_last_time) +
+        "; next_time: " + std::to_string(_next_time) +
+        "; values: " + _values.to_string() + "; sub_states: [ ";
+
+    for (typename Substates::const_iterator it = _substates.begin();
+         it != _substates.end(); ++it) {
+      str += it->second.to_string() + " ";
     }
     }
+    str += "]";
+    return str;
+  }
+
+private:
+  friend class boost::serialization::access;
+
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version) {
+    (void) version;
+
+    ar & _values;
+    ar & _substates;
+    ar & _last_time;
+    ar & _next_time;
+  }
+
+  StateValues _values;
+  Substates _substates;
+  typename Time::type _last_time;
+  typename Time::type _next_time;
+};
+
+}
+}
 }
 }
 
 
 #endif
 #endif

+ 48 - 51
src/artis-star/common/context/StateValues.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/common/context/StateValues.hpp
+ * @file common/context/StateValues.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -35,57 +35,54 @@
 #include <boost/serialization/map.hpp>
 #include <boost/serialization/map.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-        namespace context {
-
-            class StateValues {
-            public:
-                StateValues() { }
-
-                virtual ~StateValues() { }
-
-                void add_state(unsigned int key, const Value& value) { _states[key] = value; }
-
-                const Value& get_state(unsigned int key) const
-                {
-                    std::map<unsigned int, Value>::const_iterator it =
-                            _states.find(key);
-
-                    if (it != _states.end()) {
-                        return it->second;
-                    } else {
-                        assert(false);
-                        return it->second;
-                    }
-                }
-
-                std::string to_string() const
-                {
-                    std::string str = "states: [ ";
-                    for (std::map<unsigned int, Value>::const_iterator it =
-                            _states.begin(); it != _states.end(); ++it) {
-                        str += it->second.to_string() + " ";
-                    }
-                    str += "]";
-                    return str;
-                }
-
-            private:
-                friend class boost::serialization::access;
-
-                template<class Archive>
-                void serialize(Archive& ar, const unsigned int version)
-                {
-                    (void) version;
-
-                    ar & _states;
-                }
-
-                std::map<unsigned int, Value> _states;
-            };
-
-        }
+namespace common {
+namespace context {
+
+class StateValues {
+public:
+  StateValues() {}
+
+  virtual ~StateValues() {}
+
+  void add_state(unsigned int key, const Value &value) { _states[key] = value; }
+
+  const Value &get_state(unsigned int key) const {
+    std::map<unsigned int, Value>::const_iterator it =
+        _states.find(key);
+
+    if (it != _states.end()) {
+      return it->second;
+    } else {
+      assert(false);
+      return it->second;
+    }
+  }
+
+  std::string to_string() const {
+    std::string str = "states: [ ";
+    for (std::map<unsigned int, Value>::const_iterator it =
+        _states.begin(); it != _states.end(); ++it) {
+      str += it->second.to_string() + " ";
     }
     }
+    str += "]";
+    return str;
+  }
+
+private:
+  friend class boost::serialization::access;
+
+  template<class Archive>
+  void serialize(Archive &ar, const unsigned int version) {
+    (void) version;
+
+    ar & _states;
+  }
+
+  std::map<unsigned int, Value> _states;
+};
+
+}
+}
 }
 }
 
 
 #endif
 #endif

+ 59 - 61
src/artis-star/common/observer/Iterator.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/common/observer/View.hpp
+ * @file common/observer/View.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -30,67 +30,65 @@
 #include <artis-star/common/observer/View.hpp>
 #include <artis-star/common/observer/View.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace observer {
-
-        template<typename Time>
-        class Iterator {
-        public:
-            Iterator(const typename View<Time>::Values& view)
-                    :_view(view), _iterator(view.begin()) { }
-
-            virtual ~Iterator() = default;
-
-            bool has_next() const { return _iterator != _view.end(); }
-
-            virtual void operator++() { _iterator++; }
-
-            virtual const std::pair<double, common::Value>& operator*() const { return *_iterator; }
-
-        private:
-            const typename View<Time>::Values& _view;
-            typename View<Time>::Values::const_iterator _iterator;
-        };
-
-        template<typename Time>
-        class DiscreteTimeIterator : public Iterator<Time> {
-        public:
-            DiscreteTimeIterator(const typename View<Time>::Values& view,
-                    const typename Time::type& start, const typename Time::type& step)
-                    :Iterator<Time>(view), _step(step), _time(start)
-            {
-                _last_value = &Iterator<Time>::operator*();
-                while (Iterator<Time>::operator*().first <= start
-                        and Iterator<Time>::has_next()) {
-                    Iterator<Time>::operator++();
-                    if (Iterator<Time>::operator*().first == start) {
-                        _last_value = &Iterator<Time>::operator*();
-                    }
-                }
-            }
-
-            virtual ~DiscreteTimeIterator() = default;
-
-            void operator++() override
-            {
-                _time += _step;
-                _last_value = &Iterator<Time>::operator*();
-                while (Iterator<Time>::operator*().first <= _time and Iterator<Time>::has_next()) {
-                    Iterator<Time>::operator++();
-                    if (Iterator<Time>::operator*().first == _time) {
-                        _last_value = &Iterator<Time>::operator*();
-                    }
-                }
-            }
-
-            const std::pair<double, common::Value>& operator*() const override { return *_last_value; }
-
-        private:
-            typename Time::type _step;
-            typename Time::type _time;
-            const std::pair<double, common::Value>* _last_value;
-        };
-
+namespace observer {
+
+template<typename Time>
+class Iterator {
+public:
+  Iterator(const typename View<Time>::Values &view)
+      : _view(view), _iterator(view.begin()) {}
+
+  virtual ~Iterator() = default;
+
+  bool has_next() const { return _iterator != _view.end(); }
+
+  virtual void operator++() { _iterator++; }
+
+  virtual const std::pair<double, common::Value> &operator*() const { return *_iterator; }
+
+private:
+  const typename View<Time>::Values &_view;
+  typename View<Time>::Values::const_iterator _iterator;
+};
+
+template<typename Time>
+class DiscreteTimeIterator : public Iterator<Time> {
+public:
+  DiscreteTimeIterator(const typename View<Time>::Values &view,
+                       const typename Time::type &start, const typename Time::type &step)
+      : Iterator<Time>(view), _step(step), _time(start) {
+    _last_value = &Iterator<Time>::operator*();
+    while (Iterator<Time>::operator*().first <= start
+        and Iterator<Time>::has_next()) {
+      Iterator<Time>::operator++();
+      if (Iterator<Time>::operator*().first == start) {
+        _last_value = &Iterator<Time>::operator*();
+      }
+    }
+  }
+
+  virtual ~DiscreteTimeIterator() = default;
+
+  void operator++() override {
+    _time += _step;
+    _last_value = &Iterator<Time>::operator*();
+    while (Iterator<Time>::operator*().first <= _time and Iterator<Time>::has_next()) {
+      Iterator<Time>::operator++();
+      if (Iterator<Time>::operator*().first == _time) {
+        _last_value = &Iterator<Time>::operator*();
+      }
     }
     }
+  }
+
+  const std::pair<double, common::Value> &operator*() const override { return *_last_value; }
+
+private:
+  typename Time::type _step;
+  typename Time::type _time;
+  const std::pair<double, common::Value> *_last_value;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 75 - 82
src/artis-star/common/observer/Observer.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/common/observer/Observer.hpp
+ * @file common/observer/Observer.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -33,89 +33,82 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace observer {
-
-        template<typename Time>
-        class Observer {
-        public:
-            typedef std::map<std::string, View<Time>*> Views;
-
-            Observer(const common::Model<Time>* model)
-                    :
-                    _step(0),
-                    _model(model) { }
-
-            virtual ~Observer()
-            {
-                for (typename Views::iterator it = _views.begin(); it != _views.end();
-                     ++it) {
-                    delete it->second;
-                }
-            }
-
-            void attachView(const std::string& name, View<Time>* view)
-            {
-                _views[name] = view;
-                view->attachModel(_model);
-            }
-
-            Views* cloneViews() const
-            {
-                Views* v = new Views();
-
-                for (typename Views::const_iterator it = _views.begin();
-                     it != _views.end(); ++it) {
-                    (*v)[it->first] = it->second->clone();
-                }
-                return v;
-            }
-
-            const View<Time>& view(const std::string& name) const
-            {
-                return *_views.find(name)->second;
-            }
-
-            const Views& views() const { return _views; }
-
-            void init() { }
-
-            void observe(double t, double next_t)
-            {
-                if (_step == 0) {
-                    observe(t);
-                } else {
-                    double time = std::ceil(t / _step) * _step;
-
-                    while (time < next_t) {
-                        observe(time);
-                        time += _step;
-                    }
-                }
-            }
-
-            void switch_to_timed_observer(double step)
-            {
-
-                assert(step > 0);
-
-                _step = step;
-            }
-
-        private:
-            void observe(double t)
-            {
-                for (typename Views::iterator it = _views.begin(); it != _views.end();
-                     ++it) {
-                    it->second->observe(t);
-                }
-            }
-
-            double _step;
-            const common::Model<Time>* _model;
-            Views _views;
-        };
+namespace observer {
+
+template<typename Time>
+class Observer {
+public:
+  typedef std::map<std::string, View<Time> *> Views;
+
+  Observer(const common::Model<Time> *model)
+      :
+      _step(0),
+      _model(model) {}
+
+  virtual ~Observer() {
+    for (typename Views::iterator it = _views.begin(); it != _views.end();
+         ++it) {
+      delete it->second;
+    }
+  }
+
+  void attachView(const std::string &name, View<Time> *view) {
+    _views[name] = view;
+    view->attachModel(_model);
+  }
+
+  Views *cloneViews() const {
+    Views *v = new Views();
+
+    for (typename Views::const_iterator it = _views.begin();
+         it != _views.end(); ++it) {
+      (*v)[it->first] = it->second->clone();
+    }
+    return v;
+  }
+
+  const View<Time> &view(const std::string &name) const {
+    return *_views.find(name)->second;
+  }
+
+  const Views &views() const { return _views; }
+
+  void init() {}
+
+  void observe(double t, double next_t) {
+    if (_step == 0) {
+      observe(t);
+    } else {
+      double time = std::ceil(t / _step) * _step;
 
 
+      while (time < next_t) {
+        observe(time);
+        time += _step;
+      }
     }
     }
+  }
+
+  void switch_to_timed_observer(double step) {
+
+    assert(step > 0);
+
+    _step = step;
+  }
+
+private:
+  void observe(double t) {
+    for (typename Views::iterator it = _views.begin(); it != _views.end();
+         ++it) {
+      it->second->observe(t);
+    }
+  }
+
+  double _step;
+  const common::Model<Time> *_model;
+  Views _views;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 63 - 64
src/artis-star/common/observer/Output.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/observer/Output.hpp
+ * @file observer/Output.hpp
  * @author See the AUTHORS file
  * @author See the AUTHORS file
  */
  */
 
 
@@ -31,70 +31,69 @@
 #include <fstream>
 #include <fstream>
 
 
 namespace artis {
 namespace artis {
-    namespace observer {
-
-        template<typename Time>
-        class Output {
-        public:
-            Output(const Observer<Time>& observer)
-                    :_observer(observer) { }
-
-            virtual ~Output() { }
-
-            void operator()(double begin, double end, double step) const
-            {
-                const typename Observer<Time>::Views& views = _observer.views();
-
-                for (typename Observer<Time>::Views::const_iterator it =
-                        views.begin(); it != views.end(); ++it) {
-                    std::ofstream o((boost::format("%1%.csv") % it->first).str());
-                    const typename View<Time>::SelectorValues& values = it->second->values();
-                    std::vector<artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>> its;
-
-                    o.precision(10);
-                    // write header
-                    o << "time";
-                    for (typename View<Time>::SelectorValues::const_iterator itv = values.begin();
-                         itv != values.end(); ++itv) {
-                        const typename View<Time>::VariableValues& vv = itv->second;
-
-                        for (typename View<Time>::VariableValues::const_iterator itvv = vv.begin();
-                             itvv != vv.end(); ++itvv) {
-                            o << ";" << itvv->first;
-                            its.push_back(
-                                    artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>(
-                                            itvv->second, begin, step));
-                        }
-                    }
-                    o << std::endl;
-
-                    // write values
-                    bool more = true;
-                    double t = begin;
-
-                    while (more and t <= end) {
-                        more = false;
-                        o << t;
-                        for (auto& dtt: its) {
-                            if (dtt.has_next()) {
-                                o << ";" << (*dtt).second.to_string();
-                                ++dtt;
-                                more = true;
-                            } else {
-                                o << ";";
-                            }
-                        }
-                        o << std::endl;
-                        t += step;
-                    }
-                }
-            }
-
-        private:
-            const Observer<Time>& _observer;
-        };
-
+namespace observer {
+
+template<typename Time>
+class Output {
+public:
+  Output(const Observer<Time> &observer)
+      : _observer(observer) {}
+
+  virtual ~Output() {}
+
+  void operator()(double begin, double end, double step) const {
+    const typename Observer<Time>::Views &views = _observer.views();
+
+    for (typename Observer<Time>::Views::const_iterator it =
+        views.begin(); it != views.end(); ++it) {
+      std::ofstream o((boost::format("%1%.csv") % it->first).str());
+      const typename View<Time>::SelectorValues &values = it->second->values();
+      std::vector<artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>> its;
+
+      o.precision(10);
+      // write header
+      o << "time";
+      for (typename View<Time>::SelectorValues::const_iterator itv = values.begin();
+           itv != values.end(); ++itv) {
+        const typename View<Time>::VariableValues &vv = itv->second;
+
+        for (typename View<Time>::VariableValues::const_iterator itvv = vv.begin();
+             itvv != vv.end(); ++itvv) {
+          o << ";" << itvv->first;
+          its.push_back(
+              artis::observer::DiscreteTimeIterator<artis::common::DoubleTime>(
+                  itvv->second, begin, step));
+        }
+      }
+      o << std::endl;
+
+      // write values
+      bool more = true;
+      double t = begin;
+
+      while (more and t <= end) {
+        more = false;
+        o << t;
+        for (auto &dtt: its) {
+          if (dtt.has_next()) {
+            o << ";" << (*dtt).second.to_string();
+            ++dtt;
+            more = true;
+          } else {
+            o << ";";
+          }
+        }
+        o << std::endl;
+        t += step;
+      }
     }
     }
+  }
+
+private:
+  const Observer<Time> &_observer;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 138 - 145
src/artis-star/common/observer/View.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file artis-star/common/observer/View.hpp
+ * @file common/observer/View.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -35,47 +35,46 @@
 #include <boost/lexical_cast.hpp>
 #include <boost/lexical_cast.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace observer {
+namespace observer {
 
 
-        template<typename Time>
-        class View {
-            typedef std::vector<int> Selector;
+template<typename Time>
+class View {
+  typedef std::vector<int> Selector;
 
 
-        public:
-            typedef std::vector<std::pair<double, common::Value> > Values;
-            typedef std::map<std::string, Values> VariableValues;
-            typedef std::map<std::string, VariableValues> SelectorValues;
+public:
+  typedef std::vector<std::pair<double, common::Value> > Values;
+  typedef std::map<std::string, Values> VariableValues;
+  typedef std::map<std::string, VariableValues> SelectorValues;
 
 
-            enum vars {
-                ALL = -1
-            };
+  enum vars {
+    ALL = -1
+  };
 
 
-            View()
-                    :_model(0) { }
+  View()
+      : _model(0) {}
 
 
-            virtual ~View() { }
+  virtual ~View() {}
 
 
-            void attachModel(const artis::common::Model<Time>* m) { _model = m; }
+  void attachModel(const artis::common::Model<Time> *m) { _model = m; }
 
 
-            View* clone() const
-            {
-                View* v = new View();
+  View *clone() const {
+    View *v = new View();
 
 
-                // v->_selectors = _selectors;
-                // for (Values::const_iterator it = _values.begin(); it!= _values.end();
-                //      ++it) {
+    // v->_selectors = _selectors;
+    // for (Values::const_iterator it = _values.begin(); it!= _values.end();
+    //      ++it) {
 
 
-                //     v->_values[it->first] = Value();
-                //     Value::const_iterator itp = it->second.begin();
+    //     v->_values[it->first] = Value();
+    //     Value::const_iterator itp = it->second.begin();
 
 
-                //     while (itp != it->second.end()) {
-                //         v->_values[it->first].push_back(*itp);
-                //         ++itp;
-                //     }
-                // }
-                // v->_model = 0;
-                return v;
-            }
+    //     while (itp != it->second.end()) {
+    //         v->_values[it->first].push_back(*itp);
+    //         ++itp;
+    //     }
+    // }
+    // v->_model = 0;
+    return v;
+  }
 
 
 //            double
 //            double
 //            get(double t, const std::string& selector_name, const std::string& variable_name) const
 //            get(double t, const std::string& selector_name, const std::string& variable_name) const
@@ -104,121 +103,115 @@ namespace artis {
 //                return 0;
 //                return 0;
 //            }
 //            }
 
 
-            const Values&
-            get(const std::string& selector_name, const std::string& variable_name) const
-            {
-                SelectorValues::const_iterator it = _values.find(selector_name);
-
-                if (it != _values.end()) {
-                    VariableValues::const_iterator itv = it->second.find(variable_name);
-
-                    if (itv != it->second.end()) {
-                        return itv->second;
-                    } else {
-                        assert(false);
-                    }
-                } else {
-                    assert(false);
-                }
-            }
-
-            const Values& get(const std::string& selector_name) const
-            {
-                SelectorValues::const_iterator it = _values.find(selector_name);
-
-                if (it != _values.end()) {
-                    assert(it->second.size() == 1);
-
-                    return it->second.begin()->second;
-                } else {
-                    assert(false);
-                }
-            }
-
-            void observe(double time, const common::Model<common::DoubleTime>* model,
-                    const std::string& selector_name, unsigned int variable_index)
-            {
-                std::string path = (boost::format("%1%:%2%") % model->path() %
-                        model->observable_name(variable_index)).str();
-                VariableValues& values = _values[selector_name];
-
-                if (values.find(path) == values.end()) {
-                    values[path] = Values();
-                }
-                values[path].push_back(
-                        std::make_pair(time, model->observe(time, variable_index)));
-            }
-
-            void observe(const Selector& chain, unsigned int i,
-                    double time, const common::Model<common::DoubleTime>* model,
-                    const std::string& selector_name, unsigned int variable_index)
-            {
-                assert(model != nullptr);
-
-                while (i < chain.size() - 1 and chain[i + 1] != ALL and model) {
-
-                    assert(chain[i] >= 0);
-
-                    model = model->get_submodel((unsigned int) chain[i]);
-                    ++i;
-                }
-                if (i < chain.size() - 1 and chain[i + 1] == ALL) {
-
-                    assert(model != nullptr);
-
-                    for (size_t model_index = 0;
-                         model_index < model->get_submodel_number(chain[i]);
-                         ++model_index) {
-
-                        assert(chain[i] >= 0);
-
-                        observe(chain, i + 2, time,
-                                model->get_submodel((unsigned int) chain[i],
-                                        model_index),
-                                selector_name, variable_index);
-                    }
-                } else {
-                    if (model) {
-                        observe(time, model, selector_name, variable_index);
-                    }
-                }
-            }
-
-            virtual void observe(double time)
-            {
-                for (typename Selectors::const_iterator it = _selectors.begin();
-                     it != _selectors.end(); ++it) {
-                    const common::Model<common::DoubleTime>* model = _model;
-
-                    if (it->second.size() > 1) {
-                        size_t i = 0;
-
-                        observe(it->second, i, time, model, it->first,
-                                it->second.back());
-                    } else {
-                        if (model) {
-                            observe(time, model, it->first, it->second.back());
-                        }
-                    }
-                }
-            }
-
-            void selector(const std::string& name, const Selector& chain)
-            {
-                _selectors[name] = chain;
-            }
-
-            const SelectorValues& values() const { return _values; }
-
-        private:
-            typedef std::map<std::string, Selector> Selectors;
-
-            Selectors _selectors;
-            SelectorValues _values;
-            const artis::common::Model<Time>* _model;
-        };
+  const Values &
+  get(const std::string &selector_name, const std::string &variable_name) const {
+    SelectorValues::const_iterator it = _values.find(selector_name);
 
 
+    if (it != _values.end()) {
+      VariableValues::const_iterator itv = it->second.find(variable_name);
+
+      if (itv != it->second.end()) {
+        return itv->second;
+      } else {
+        assert(false);
+      }
+    } else {
+      assert(false);
+    }
+  }
+
+  const Values &get(const std::string &selector_name) const {
+    SelectorValues::const_iterator it = _values.find(selector_name);
+
+    if (it != _values.end()) {
+      assert(it->second.size() == 1);
+
+      return it->second.begin()->second;
+    } else {
+      assert(false);
+    }
+  }
+
+  void observe(double time, const common::Model<common::DoubleTime> *model,
+               const std::string &selector_name, unsigned int variable_index) {
+    std::string path = (boost::format("%1%:%2%") % model->path() %
+        model->observable_name(variable_index)).str();
+    VariableValues &values = _values[selector_name];
+
+    if (values.find(path) == values.end()) {
+      values[path] = Values();
+    }
+    values[path].push_back(
+        std::make_pair(time, model->observe(time, variable_index)));
+  }
+
+  void observe(const Selector &chain, unsigned int i,
+               double time, const common::Model<common::DoubleTime> *model,
+               const std::string &selector_name, unsigned int variable_index) {
+    assert(model != nullptr);
+
+    while (i < chain.size() - 1 and chain[i + 1] != ALL and model) {
+
+      assert(chain[i] >= 0);
+
+      model = model->get_submodel((unsigned int) chain[i]);
+      ++i;
     }
     }
+    if (i < chain.size() - 1 and chain[i + 1] == ALL) {
+
+      assert(model != nullptr);
+
+      for (size_t model_index = 0;
+           model_index < model->get_submodel_number(chain[i]);
+           ++model_index) {
+
+        assert(chain[i] >= 0);
+
+        observe(chain, i + 2, time,
+                model->get_submodel((unsigned int) chain[i],
+                                    model_index),
+                selector_name, variable_index);
+      }
+    } else {
+      if (model) {
+        observe(time, model, selector_name, variable_index);
+      }
+    }
+  }
+
+  virtual void observe(double time) {
+    for (typename Selectors::const_iterator it = _selectors.begin();
+         it != _selectors.end(); ++it) {
+      const common::Model<common::DoubleTime> *model = _model;
+
+      if (it->second.size() > 1) {
+        size_t i = 0;
+
+        observe(it->second, i, time, model, it->first,
+                it->second.back());
+      } else {
+        if (model) {
+          observe(time, model, it->first, it->second.back());
+        }
+      }
+    }
+  }
+
+  void selector(const std::string &name, const Selector &chain) {
+    _selectors[name] = chain;
+  }
+
+  const SelectorValues &values() const { return _values; }
+
+private:
+  typedef std::map<std::string, Selector> Selectors;
+
+  Selectors _selectors;
+  SelectorValues _values;
+  const artis::common::Model<Time> *_model;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 112 - 120
src/artis-star/common/scheduler/HeapScheduler.hpp

@@ -34,127 +34,119 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<class Time>
-        class Model;
-
-        template<class Time>
-        class Models;
-
-        namespace scheduler {
-
-            template<class Time, class T>
-            class HeapScheduler :
-                    public boost::heap::fibonacci_heap<
-                            InternalEvent<Time>,
-                            boost::heap::compare<
-                                    EventCompare<InternalEvent<Time> > > > {
-            public:
-                typedef HeapScheduler<Time, T> type;
-                typedef Model<Time> model_type;
-                typedef Models<Time> models_type;
-                typedef InternalEvent<Time> internal_event_type;
-
-                HeapScheduler() { }
-
-                virtual ~HeapScheduler() { }
-
-                model_type* get_current_model()
-                {
-                    return type::top().get_model();
-                }
-
-                models_type get_current_models(const typename Time::type& time) const
-                {
-                    models_type models;
-                    typename models_type::iterator it;
-
-                    for (typename type::ordered_iterator it = type::ordered_begin();
-                         it != type::ordered_end() and it->get_time() == time; ++it) {
-                        std::string str = it->get_model()->get_name();
-                        auto it2 = find_if(models.begin(), models.end(),
-                                [&str](const model_type* obj) {
-                                    return obj->get_name() == str;
-                                });
-
-                        if (it2 == models.end()) {
-                            models.push_back(it->get_model());
-                        }
-                    }
-                    return models;
-                }
-
-                models_type get_current_models(const typename Time::type& begin,
-                        const typename Time::type& end) const
-                {
-                    models_type models;
-                    typename models_type::iterator it;
-
-                    for (typename type::ordered_iterator it = type::ordered_begin();
-                         it != type::ordered_end() and (std::abs(it->get_time() - begin) < 1e-6
-                                 or (it->get_time() > begin
-                                         and it->get_time() < end)); ++it) {
-                        std::string str = it->get_model()->get_name();
-                        auto it2 = find_if(models.begin(), models.end(),
-                                [&str](const model_type* obj) {
-                                    return obj->get_name() == str;
-                                });
-
-                        if (it2 == models.end()) {
-                            models.push_back(it->get_model());
-                        }
-                    }
-                    return models;
-                }
-
-                typename Time::type get_current_time() const
-                {
-                    return type::top().get_time();
-                }
-
-                void init(typename Time::type time, model_type* model)
-                {
-                    model->handle(T(type::push(internal_event_type(time, model))));
-                }
-
-                void put(typename Time::type time, const model_type* model)
-                {
-                    typename Time::type previous_time =
-                            (*model->handle()._handle).get_time();
-
-                    if (previous_time != time) {
-                        (*model->handle()._handle).set_time(time);
-                        if (previous_time < time) {
-                            type::decrease(model->handle()._handle);
-                        } else if (previous_time > time) {
-                            type::increase(model->handle()._handle);
-                        }
-                    }
-                }
-
-                void remove_model(model_type* model)
-                {
-                    type::erase(model->handle()._handle);
-                }
-
-                std::string to_string() const
-                {
-                    std::stringstream ss;
-
-                    ss << "Scheduler = { ";
-                    for (typename type::ordered_iterator it = type::ordered_begin();
-                         it != type::ordered_end(); ++it) {
-                        ss << "(" << it->get_time() << " -> " << it->get_model()->get_name()
-                           << ") ";
-                    }
-                    ss << "} [" << type::size() << "]";
-                    return ss.str();
-                }
-            };
-
-        }
+namespace common {
+
+template<class Time>
+class Model;
+
+template<class Time>
+class Models;
+
+namespace scheduler {
+
+template<class Time, class T>
+class HeapScheduler :
+    public boost::heap::fibonacci_heap<
+        InternalEvent<Time>,
+        boost::heap::compare<
+            EventCompare<InternalEvent<Time> > > > {
+public:
+  typedef HeapScheduler<Time, T> type;
+  typedef Model<Time> model_type;
+  typedef Models<Time> models_type;
+  typedef InternalEvent<Time> internal_event_type;
+
+  HeapScheduler() {}
+
+  virtual ~HeapScheduler() {}
+
+  model_type *get_current_model() {
+    return type::top().get_model();
+  }
+
+  models_type get_current_models(const typename Time::type &time) const {
+    models_type models;
+    typename models_type::iterator it;
+
+    for (typename type::ordered_iterator it = type::ordered_begin();
+         it != type::ordered_end() and it->get_time() == time; ++it) {
+      std::string str = it->get_model()->get_name();
+      auto it2 = find_if(models.begin(), models.end(),
+                         [&str](const model_type *obj) {
+                           return obj->get_name() == str;
+                         });
+
+      if (it2 == models.end()) {
+        models.push_back(it->get_model());
+      }
     }
     }
+    return models;
+  }
+
+  models_type get_current_models(const typename Time::type &begin,
+                                 const typename Time::type &end) const {
+    models_type models;
+    typename models_type::iterator it;
+
+    for (typename type::ordered_iterator it = type::ordered_begin();
+         it != type::ordered_end() and (std::abs(it->get_time() - begin) < 1e-6
+             or (it->get_time() > begin
+                 and it->get_time() < end)); ++it) {
+      std::string str = it->get_model()->get_name();
+      auto it2 = find_if(models.begin(), models.end(),
+                         [&str](const model_type *obj) {
+                           return obj->get_name() == str;
+                         });
+
+      if (it2 == models.end()) {
+        models.push_back(it->get_model());
+      }
+    }
+    return models;
+  }
+
+  typename Time::type get_current_time() const {
+    return type::top().get_time();
+  }
+
+  void init(typename Time::type time, model_type *model) {
+    model->handle(T(type::push(internal_event_type(time, model))));
+  }
+
+  void put(typename Time::type time, const model_type *model) {
+    typename Time::type previous_time =
+        (*model->handle()._handle).get_time();
+
+    if (previous_time != time) {
+      (*model->handle()._handle).set_time(time);
+      if (previous_time < time) {
+        type::decrease(model->handle()._handle);
+      } else if (previous_time > time) {
+        type::increase(model->handle()._handle);
+      }
+    }
+  }
+
+  void remove_model(model_type *model) {
+    type::erase(model->handle()._handle);
+  }
+
+  std::string to_string() const {
+    std::stringstream ss;
+
+    ss << "Scheduler = { ";
+    for (typename type::ordered_iterator it = type::ordered_begin();
+         it != type::ordered_end(); ++it) {
+      ss << "(" << it->get_time() << " -> " << it->get_model()->get_name()
+         << ") ";
+    }
+    ss << "} [" << type::size() << "]";
+    return ss.str();
+  }
+};
+
+}
+}
 } // namespace artis common scheduler
 } // namespace artis common scheduler
 
 
 #endif
 #endif

+ 10 - 10
src/artis-star/common/scheduler/SchedulerHandle.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file SchedulerHandle.hpp
+ * @file common/scheduler/SchedulerHandle.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -28,19 +28,19 @@
 #define COMMON_SCHEDULER_SCHEDULER_HANDLE_HPP
 #define COMMON_SCHEDULER_SCHEDULER_HANDLE_HPP
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-        namespace scheduler {
+namespace common {
+namespace scheduler {
 
 
-            struct NoSchedulerHandle {
-                NoSchedulerHandle() { }
+struct NoSchedulerHandle {
+  NoSchedulerHandle() {}
 
 
-                const NoSchedulerHandle& handle() const { return *this; }
+  const NoSchedulerHandle &handle() const { return *this; }
 
 
-                void handle(const NoSchedulerHandle& /* handle */) { }
-            };
+  void handle(const NoSchedulerHandle & /* handle */) {}
+};
 
 
-        }
-    }
+}
+}
 } // namespace artis common scheduler
 } // namespace artis common scheduler
 
 
 #endif
 #endif

+ 77 - 83
src/artis-star/common/scheduler/VectorScheduler.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file VectorScheduler.hpp
+ * @file common/scheduler/VectorScheduler.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -34,89 +34,83 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-        namespace scheduler {
-
-            template<class Time>
-            class VectorScheduler :
-                    protected std::vector<InternalEvent<Time, NoSchedulerHandle> > {
-            public:
-                VectorScheduler() { }
-
-                virtual ~VectorScheduler() { }
-
-                Model<Time, NoSchedulerHandle>* get_current_model()
-                {
-                    return VectorScheduler<Time>::front().get_model();
-                }
-
-                Models<Time, NoSchedulerHandle> get_current_models(
-                        typename Time::type time) const
-                {
-                    Models<Time, NoSchedulerHandle> models;
-
-                    for (typename VectorScheduler<Time>::const_iterator it =
-                            VectorScheduler<Time>::begin();
-                         it != VectorScheduler<Time>::end() and it->get_time() == time;
-                         ++it) {
-                        models.push_back(it->get_model());
-                    }
-                    return models;
-                }
-
-                typename Time::type get_current_time() const { return VectorScheduler<Time>::front().get_time(); }
-
-                void init(typename Time::type time,
-                        Model<Time, NoSchedulerHandle>* model)
-                {
-                    VectorScheduler<Time>::push_back(
-                            InternalEvent<Time, NoSchedulerHandle>(time, model));
-                    std::sort(VectorScheduler<Time>::begin(),
-                            VectorScheduler<Time>::end());
-                }
-
-                void put(typename Time::type time, Model<Time, NoSchedulerHandle>* model)
-                {
-                    remove(model);
-                    VectorScheduler<Time>::push_back(
-                            InternalEvent<Time, NoSchedulerHandle>(time, model));
-                    std::sort(VectorScheduler<Time>::begin(),
-                            VectorScheduler<Time>::end());
-                }
-
-                std::string to_string() const
-                {
-                    std::stringstream ss;
-
-                    ss << "Scheduler = { ";
-                    for (typename VectorScheduler<Time>::const_iterator it =
-                            VectorScheduler<Time>::begin();
-                         it != VectorScheduler<Time>::end(); ++it) {
-                        ss << "(" << it->get_time() << " -> " << it->get_model()->get_name()
-                           << ") ";
-                    }
-                    ss << "}";
-                    return ss.str();
-                }
-
-            private:
-                void remove(Model<Time, NoSchedulerHandle>* model)
-                {
-                    typename VectorScheduler<Time>::iterator jt =
-                            VectorScheduler<Time>::begin();
-
-                    while (jt != VectorScheduler<Time>::end()) {
-                        if (jt->get_model() == model) {
-                            jt = VectorScheduler<Time>::erase(jt);
-                        } else {
-                            ++jt;
-                        }
-                    }
-                }
-            };
-
-        }
+namespace common {
+namespace scheduler {
+
+template<class Time>
+class VectorScheduler :
+    protected std::vector<InternalEvent<Time, NoSchedulerHandle> > {
+public:
+  VectorScheduler() {}
+
+  virtual ~VectorScheduler() {}
+
+  Model<Time, NoSchedulerHandle> *get_current_model() {
+    return VectorScheduler<Time>::front().get_model();
+  }
+
+  Models<Time, NoSchedulerHandle> get_current_models(
+      typename Time::type time) const {
+    Models<Time, NoSchedulerHandle> models;
+
+    for (typename VectorScheduler<Time>::const_iterator it =
+        VectorScheduler<Time>::begin();
+         it != VectorScheduler<Time>::end() and it->get_time() == time;
+         ++it) {
+      models.push_back(it->get_model());
     }
     }
+    return models;
+  }
+
+  typename Time::type get_current_time() const { return VectorScheduler<Time>::front().get_time(); }
+
+  void init(typename Time::type time,
+            Model<Time, NoSchedulerHandle> *model) {
+    VectorScheduler<Time>::push_back(
+        InternalEvent<Time, NoSchedulerHandle>(time, model));
+    std::sort(VectorScheduler<Time>::begin(),
+              VectorScheduler<Time>::end());
+  }
+
+  void put(typename Time::type time, Model<Time, NoSchedulerHandle> *model) {
+    remove(model);
+    VectorScheduler<Time>::push_back(
+        InternalEvent<Time, NoSchedulerHandle>(time, model));
+    std::sort(VectorScheduler<Time>::begin(),
+              VectorScheduler<Time>::end());
+  }
+
+  std::string to_string() const {
+    std::stringstream ss;
+
+    ss << "Scheduler = { ";
+    for (typename VectorScheduler<Time>::const_iterator it =
+        VectorScheduler<Time>::begin();
+         it != VectorScheduler<Time>::end(); ++it) {
+      ss << "(" << it->get_time() << " -> " << it->get_model()->get_name()
+         << ") ";
+    }
+    ss << "}";
+    return ss.str();
+  }
+
+private:
+  void remove(Model<Time, NoSchedulerHandle> *model) {
+    typename VectorScheduler<Time>::iterator jt =
+        VectorScheduler<Time>::begin();
+
+    while (jt != VectorScheduler<Time>::end()) {
+      if (jt->get_model() == model) {
+        jt = VectorScheduler<Time>::erase(jt);
+      } else {
+        ++jt;
+      }
+    }
+  }
+};
+
+}
+}
 } // namespace artis common scheduler
 } // namespace artis common scheduler
 
 
 #endif
 #endif

+ 4 - 4
src/artis-star/common/time/DoubleTime.hpp

@@ -25,17 +25,17 @@
  */
  */
 
 
 #ifndef COMMON_TIME_DOUBLE_TIME
 #ifndef COMMON_TIME_DOUBLE_TIME
-#define COMMON_TIME_DOUBLE_TIME 1
+#define COMMON_TIME_DOUBLE_TIME
 
 
 #include <artis-star/common/time/Limits.hpp>
 #include <artis-star/common/time/Limits.hpp>
 #include <artis-star/common/time/Time.hpp>
 #include <artis-star/common/time/Time.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        typedef Time<double, Limits<double> > DoubleTime;
+typedef Time<double, Limits<double> > DoubleTime;
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 4 - 4
src/artis-star/common/time/IntegerTime.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef COMMON_TIME_INTEGER_TIME
 #ifndef COMMON_TIME_INTEGER_TIME
-#define COMMON_TIME_INTEGER_TIME 1
+#define COMMON_TIME_INTEGER_TIME
 
 
 #include <artis-star/common/time/Limits.hpp>
 #include <artis-star/common/time/Limits.hpp>
 #include <artis-star/common/time/Time.hpp>
 #include <artis-star/common/time/Time.hpp>
@@ -33,11 +33,11 @@
 #include <limits>
 #include <limits>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        typedef Time<int, Limits<int> > IntegerTime;
+typedef Time<int, Limits<int> > IntegerTime;
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 9 - 9
src/artis-star/common/time/Limits.hpp

@@ -25,21 +25,21 @@
  */
  */
 
 
 #ifndef COMMON_TIME_LIMITS
 #ifndef COMMON_TIME_LIMITS
-#define COMMON_TIME_LIMITS 1
+#define COMMON_TIME_LIMITS
 
 
 #include <limits>
 #include <limits>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<typename T>
-        struct Limits {
-            static constexpr T negative_infinity = std::numeric_limits<T>::lowest();
-            static constexpr T positive_infinity = std::numeric_limits<T>::max();
-            static constexpr T null = 0;
-        };
+template<typename T>
+struct Limits {
+  static constexpr T negative_infinity = std::numeric_limits<T>::lowest();
+  static constexpr T positive_infinity = std::numeric_limits<T>::max();
+  static constexpr T null = 0;
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 11 - 9
src/artis-star/common/time/RationalTime.hpp

@@ -25,24 +25,26 @@
  */
  */
 
 
 #ifndef COMMON_TIME_RATIONAL_TIME
 #ifndef COMMON_TIME_RATIONAL_TIME
-#define COMMON_TIME_RATIONAL_TIME 1
+#define COMMON_TIME_RATIONAL_TIME
 
 
 #include <artis-star/common/time/Time.hpp>
 #include <artis-star/common/time/Time.hpp>
 
 
 #include <boost/rational.hpp>
 #include <boost/rational.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        struct RationalLimits {
-            static constexpr boost::rational<int> negative_infinity = boost::rational<int>(std::numeric_limits<int>::lowest());
-            static constexpr boost::rational<int> positive_infinity = boost::rational<int>(std::numeric_limits<int>::max());
-            static constexpr boost::rational<int> null = boost::rational<int>();
-        };
+struct RationalLimits {
+  static constexpr boost::rational<int>
+      negative_infinity = boost::rational<int>(std::numeric_limits<int>::lowest());
+  static constexpr boost::rational<int>
+      positive_infinity = boost::rational<int>(std::numeric_limits<int>::max());
+  static constexpr boost::rational<int> null = boost::rational<int>();
+};
 
 
-        typedef Time<boost::rational<int>, RationalLimits> RationalTime;
+typedef Time<boost::rational<int>, RationalLimits> RationalTime;
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 16 - 16
src/artis-star/common/time/Time.hpp

@@ -25,29 +25,29 @@
  */
  */
 
 
 #ifndef COMMON_TIME_TIME
 #ifndef COMMON_TIME_TIME
-#define COMMON_TIME_TIME 1
+#define COMMON_TIME_TIME
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        template<typename Type, typename Limits>
-        struct Time {
-            static Type negative_infinity;
-            static Type infinity;
-            static Type null;
-            typedef Type type;
-        };
+template<typename Type, typename Limits>
+struct Time {
+  static Type negative_infinity;
+  static Type infinity;
+  static Type null;
+  typedef Type type;
+};
 
 
-        template<typename Type, typename Limits>
-        Type Time<Type, Limits>::negative_infinity = Limits::negative_infinity;
+template<typename Type, typename Limits>
+Type Time<Type, Limits>::negative_infinity = Limits::negative_infinity;
 
 
-        template<typename Type, typename Limits>
-        Type Time<Type, Limits>::infinity = Limits::positive_infinity;
+template<typename Type, typename Limits>
+Type Time<Type, Limits>::infinity = Limits::positive_infinity;
 
 
-        template<typename Type, typename Limits>
-        Type Time<Type, Limits>::null = Limits::null;
+template<typename Type, typename Limits>
+Type Time<Type, Limits>::null = Limits::null;
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 #endif
 #endif

+ 28 - 40
src/artis-star/common/utils/FormalismType.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file FormalismType.hpp
+ * @file common/utils/FormalismType.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,50 +25,38 @@
  */
  */
 
 
 #ifndef COMMON_UTILS_FORMALISM_TYPE
 #ifndef COMMON_UTILS_FORMALISM_TYPE
-#define COMMON_UTILS_FORMALISM_TYPE 1
+#define COMMON_UTILS_FORMALISM_TYPE
 
 
 #include <string>
 #include <string>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
+
+class FormalismType {
+public:
+  enum Values {
+    NONE = 0, DEVS, DSDE, PDEVS, QSS, DTSS, GDEVS, CELLDEVS, FDDEVS, DESS, SSS
+  };
+
+  static std::string to_string(const FormalismType::Values &s) {
+    switch (s) {
+    case NONE:return "none";
+    case DEVS:return "devs";
+    case DSDE:return "dsde";
+    case PDEVS:return "pdevs";
+    case QSS:return "qss";
+    case DTSS:return "dtss";
+    case GDEVS:return "gdevs";
+    case CELLDEVS:return "celldevs";
+    case FDDEVS:return "fddevs";
+    case DESS:return "dess";
+    case SSS:return "sss";
+    };
+    return "";
+  }
+};
 
 
-        class FormalismType {
-        public:
-            enum Values {
-                NONE = 0, DEVS, DSDE, PDEVS, QSS, DTSS, GDEVS, CELLDEVS, FDDEVS, DESS, SSS
-            };
-
-            static std::string to_string(const FormalismType::Values& s)
-            {
-                switch (s) {
-                case NONE:
-                    return "none";
-                case DEVS:
-                    return "devs";
-                case DSDE:
-                    return "dsde";
-                case PDEVS:
-                    return "pdevs";
-                case QSS:
-                    return "qss";
-                case DTSS:
-                    return "dtss";
-                case GDEVS:
-                    return "gdevs";
-                case CELLDEVS:
-                    return "celldevs";
-                case FDDEVS:
-                    return "fddevs";
-                case DESS:
-                    return "dess";
-                case SSS:
-                    return "sss";
-                };
-                return "";
-            }
-        };
-
-    }
+}
 }
 }
 
 
 #endif
 #endif

+ 31 - 47
src/artis-star/common/utils/FunctionType.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file TraceType.hpp
+ * @file common/utils/TraceType.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,59 +25,43 @@
  */
  */
 
 
 #ifndef COMMON_UTILS_FUNCTION_TYPE
 #ifndef COMMON_UTILS_FUNCTION_TYPE
-#define COMMON_UTILS_FUNCTION_TYPE 1
+#define COMMON_UTILS_FUNCTION_TYPE
 
 
 #include <string>
 #include <string>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        class FunctionType {
-        public:
-            enum Values {
-                NONE = 0, CONSTRUCTOR, FINISH, I_MESSAGE, POST_EVENT, S_MESSAGE, Y_MESSAGE,
-                DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START, OUTPUT, TRANSITION
-            };
+class FunctionType {
+public:
+  enum Values {
+    NONE = 0, CONSTRUCTOR, FINISH, I_MESSAGE, POST_EVENT, S_MESSAGE, Y_MESSAGE,
+    DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START, OUTPUT, TRANSITION
+  };
 
 
-            static std::string to_string(const FunctionType::Values& s)
-            {
-                switch (s) {
-                case NONE:
-                    return "none";
-                case CONSTRUCTOR:
-                    return "constructor";
-                case FINISH:
-                    return "finish";
-                case I_MESSAGE:
-                    return "i_message";
-                case POST_EVENT:
-                    return "post_event";
-                case S_MESSAGE:
-                    return "s_message";
-                case Y_MESSAGE:
-                    return "y_message";
-                case DELTA_INT:
-                    return "delta_int";
-                case DELTA_EXT:
-                    return "delta_ext";
-                case DELTA_CONF:
-                    return "delta_conf";
-                case TA:
-                    return "ta";
-                case LAMBDA:
-                    return "lambda";
-                case START:
-                    return "start";
-                case OUTPUT:
-                    return "output";
-                case TRANSITION:
-                    return "transition";
-                };
-                return "";
-            }
-        };
+  static std::string to_string(const FunctionType::Values &s) {
+    switch (s) {
+    case NONE:return "none";
+    case CONSTRUCTOR:return "constructor";
+    case FINISH:return "finish";
+    case I_MESSAGE:return "i_message";
+    case POST_EVENT:return "post_event";
+    case S_MESSAGE:return "s_message";
+    case Y_MESSAGE:return "y_message";
+    case DELTA_INT:return "delta_int";
+    case DELTA_EXT:return "delta_ext";
+    case DELTA_CONF:return "delta_conf";
+    case TA:return "ta";
+    case LAMBDA:return "lambda";
+    case START:return "start";
+    case OUTPUT:return "output";
+    case TRANSITION:return "transition";
+    };
+    return "";
+  }
+};
 
 
-    }
+}
 }
 }
 
 
 #endif
 #endif

+ 22 - 27
src/artis-star/common/utils/LevelType.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file LevelType.hpp
+ * @file common/utils/LevelType.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,36 +25,31 @@
  */
  */
 
 
 #ifndef COMMON_UTILS_LEVEL_TYPE
 #ifndef COMMON_UTILS_LEVEL_TYPE
-#define COMMON_UTILS_LEVEL_TYPE 1
+#define COMMON_UTILS_LEVEL_TYPE
 
 
 #include <string>
 #include <string>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        class LevelType {
-        public:
-            enum Values {
-                NONE = 0, COMMON, FORMALISM, USER
-            };
-
-            static std::string to_string(const LevelType::Values& s)
-            {
-                switch (s) {
-                case NONE:
-                    return "none";
-                case COMMON:
-                    return "common";
-                case FORMALISM:
-                    return "formalism";
-                case USER:
-                    return "user";
-                };
-                return "";
-            }
-        };
-
-    }
+namespace common {
+
+class LevelType {
+public:
+  enum Values {
+    NONE = 0, COMMON, FORMALISM, USER
+  };
+
+  static std::string to_string(const LevelType::Values &s) {
+    switch (s) {
+    case NONE:return "none";
+    case COMMON:return "common";
+    case FORMALISM:return "formalism";
+    case USER:return "user";
+    };
+    return "";
+  }
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 199 - 210
src/artis-star/common/utils/Multithreading.hpp

@@ -25,224 +25,213 @@
  */
  */
 
 
 #ifndef COMMON_UTILS_MULTITHREADING
 #ifndef COMMON_UTILS_MULTITHREADING
-#define COMMON_UTILS_MULTITHREADING 1
+#define COMMON_UTILS_MULTITHREADING
 
 
 #include <condition_variable>
 #include <condition_variable>
 #include <queue>
 #include <queue>
 #include <mutex>
 #include <mutex>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        struct BaseMessage {
-            virtual ~BaseMessage() { }
-        };
-
-        template<typename Msg>
-        struct Message : BaseMessage {
-            explicit Message(Msg const& content)
-                    :_content(content) { }
-
-            Msg _content;
-        };
-
-        class Close {
-        };
-
-        class MessageQueue {
-        public:
-            MessageQueue() = default;
-
-            template<typename T>
-            void push(T const& msg)
-            {
-                std::lock_guard<std::mutex> lock(_mutex);
-
-                _queue.push(std::make_shared<Message<T> >(msg));
-                _condition.notify_all();
-            }
-
-            std::shared_ptr<BaseMessage> wait_and_pop()
-            {
-                std::unique_lock<std::mutex> lock(_mutex);
-
-                _condition.wait(lock, [&] { return not _queue.empty(); });
-                auto res = _queue.front();
-                _queue.pop();
-                return res;
-            }
-
-        private:
-            std::mutex _mutex;
-            std::condition_variable _condition;
-            std::queue<std::shared_ptr<BaseMessage> > _queue;
-        };
-
-        class Sender {
-        public:
-            Sender()
-                    :_queue(0) { }
-
-            explicit Sender(MessageQueue* queue)
-                    :_queue(queue) { }
-
-            template<typename Message>
-            void send(Message const& msg)
-            {
-                if (_queue) {
-                    _queue->push(msg);
-                }
-            }
-
-        private:
-            MessageQueue* _queue;
-        };
-
-        template<typename PreviousDispatcher, typename Msg, typename Func>
-        class TemplateDispatcher {
-            template<typename Dispatcher, typename OtherMsg, typename OtherFunc>
-            friend
-            class TemplateDispatcher;
-
-        public:
-            TemplateDispatcher(TemplateDispatcher&& other)
-                    :_queue(other._queue),
-                     _previous(other._previous),
-                     _function(
-                             std::move(
-                                     other._function)),
-                     _chained(other._chained) { other._chained = true; }
-
-            TemplateDispatcher(MessageQueue* queue,
-                    PreviousDispatcher* previous,
-                    Func&& function)
-                    :
-                    _queue(queue), _previous(previous),
-                    _function(std::forward<Func>(function)),
-                    _chained(false) { previous->_chained = true; }
-
-            bool dispatch(std::shared_ptr<BaseMessage> const& msg)
-            {
-                Message<Msg>* message =
-                        dynamic_cast < Message<Msg>* >(msg.get());
-
-                if (message) {
-                    _function(message->_content);
-                    return true;
-                } else {
-                    return _previous->dispatch(msg);
-                }
-            }
-
-            template<typename OtherMsg, typename OtherFunc>
-            TemplateDispatcher<TemplateDispatcher<PreviousDispatcher, Msg, Func>,
-                    OtherMsg, OtherFunc>
-            handle(OtherFunc&& of)
-            {
-                return TemplateDispatcher<TemplateDispatcher<PreviousDispatcher,
-                        Msg, Func>,
-                        OtherMsg, OtherFunc>(
-                        _queue, this, std::forward<OtherFunc>(of));
-            }
-
-            ~TemplateDispatcher() noexcept(false)
-            {
-                if (not _chained) {
-                    wait_and_dispatch();
-                }
-            }
-
-        private:
-            TemplateDispatcher(TemplateDispatcher const&) = delete;
-
-            TemplateDispatcher& operator=(TemplateDispatcher const&) = delete;
-
-            void wait_and_dispatch()
-            {
-                for (;;) {
-                    auto msg = _queue->wait_and_pop();
-
-                    if (dispatch(msg)) {
-                        break;
-                    }
-                }
-            }
-
-            MessageQueue* _queue;
-            PreviousDispatcher* _previous;
-            Func _function;
-            bool _chained;
-        };
-
-        class Dispatcher {
-            template<typename Dispatcher, typename Msg, typename Func>
-            friend
-            class TemplateDispatcher;
-
-        public:
-            Dispatcher(Dispatcher&& other)
-                    :_queue(other._queue),
-                     _chained(other._chained) { other._chained = true; }
-
-            explicit Dispatcher(MessageQueue* queue)
-                    :_queue(queue), _chained(false) { }
-
-            template<typename Message, typename Func>
-            TemplateDispatcher<Dispatcher, Message, Func>
-            handle(Func&& function)
-            {
-                return TemplateDispatcher<Dispatcher, Message, Func>(
-                        _queue, this, std::forward<Func>(function));
-            }
-
-            ~Dispatcher() noexcept(false)
-            {
-                if (not _chained) {
-                    wait_and_dispatch();
-                }
-            }
-
-        private:
-            Dispatcher(Dispatcher const&) = delete;
-
-            Dispatcher& operator=(Dispatcher const&) = delete;
-
-            void wait_and_dispatch()
-            {
-                for (;;) {
-                    auto msg = _queue->wait_and_pop();
-
-                    dispatch(msg);
-                }
-            }
-
-            bool dispatch(std::shared_ptr<BaseMessage> const& msg)
-            {
-                if (dynamic_cast < Message<Close>* >(msg.get())) {
-                    throw Close();
-                }
-                return false;
-            }
-
-            MessageQueue* _queue;
-            bool _chained;
-        };
-
-        class Receiver {
-        public:
-            Receiver() : _queue(new MessageQueue) { }
-
-            ~Receiver() { delete _queue; }
-
-            Sender get_sender() { return Sender(_queue); }
-
-            Dispatcher wait() { return Dispatcher(_queue); }
-
-        private:
-            MessageQueue* _queue;
-        };
+namespace common {
+
+struct BaseMessage {
+  virtual ~BaseMessage() {}
+};
+
+template<typename Msg>
+struct Message : BaseMessage {
+  explicit Message(Msg const &content)
+      : _content(content) {}
+
+  Msg _content;
+};
+
+class Close {
+};
+
+class MessageQueue {
+public:
+  MessageQueue() = default;
+
+  template<typename T>
+  void push(T const &msg) {
+    std::lock_guard<std::mutex> lock(_mutex);
+
+    _queue.push(std::make_shared<Message<T> >(msg));
+    _condition.notify_all();
+  }
+
+  std::shared_ptr<BaseMessage> wait_and_pop() {
+    std::unique_lock<std::mutex> lock(_mutex);
+
+    _condition.wait(lock, [&] { return not _queue.empty(); });
+    auto res = _queue.front();
+    _queue.pop();
+    return res;
+  }
+
+private:
+  std::mutex _mutex;
+  std::condition_variable _condition;
+  std::queue<std::shared_ptr<BaseMessage> > _queue;
+};
+
+class Sender {
+public:
+  Sender()
+      : _queue(0) {}
+
+  explicit Sender(MessageQueue *queue)
+      : _queue(queue) {}
+
+  template<typename Message>
+  void send(Message const &msg) {
+    if (_queue) {
+      _queue->push(msg);
+    }
+  }
+
+private:
+  MessageQueue *_queue;
+};
+
+template<typename PreviousDispatcher, typename Msg, typename Func>
+class TemplateDispatcher {
+  template<typename Dispatcher, typename OtherMsg, typename OtherFunc>
+  friend
+  class TemplateDispatcher;
+
+public:
+  TemplateDispatcher(TemplateDispatcher &&other)
+      : _queue(other._queue),
+        _previous(other._previous),
+        _function(
+            std::move(
+                other._function)),
+        _chained(other._chained) { other._chained = true; }
+
+  TemplateDispatcher(MessageQueue *queue,
+                     PreviousDispatcher *previous,
+                     Func &&function)
+      :
+      _queue(queue), _previous(previous),
+      _function(std::forward<Func>(function)),
+      _chained(false) { previous->_chained = true; }
+
+  bool dispatch(std::shared_ptr<BaseMessage> const &msg) {
+    Message<Msg> *message =
+        dynamic_cast < Message<Msg> * >(msg.get());
+
+    if (message) {
+      _function(message->_content);
+      return true;
+    } else {
+      return _previous->dispatch(msg);
+    }
+  }
+
+  template<typename OtherMsg, typename OtherFunc>
+  TemplateDispatcher<TemplateDispatcher<PreviousDispatcher, Msg, Func>,
+                     OtherMsg, OtherFunc>
+  handle(OtherFunc &&of) {
+    return TemplateDispatcher<TemplateDispatcher<PreviousDispatcher,
+                                                 Msg, Func>,
+                              OtherMsg, OtherFunc>(
+        _queue, this, std::forward<OtherFunc>(of));
+  }
+
+  ~TemplateDispatcher() noexcept(false) {
+    if (not _chained) {
+      wait_and_dispatch();
+    }
+  }
+
+private:
+  TemplateDispatcher(TemplateDispatcher const &) = delete;
+
+  TemplateDispatcher &operator=(TemplateDispatcher const &) = delete;
+
+  void wait_and_dispatch() {
+    for (;;) {
+      auto msg = _queue->wait_and_pop();
 
 
+      if (dispatch(msg)) {
+        break;
+      }
     }
     }
+  }
+
+  MessageQueue *_queue;
+  PreviousDispatcher *_previous;
+  Func _function;
+  bool _chained;
+};
+
+class Dispatcher {
+  template<typename Dispatcher, typename Msg, typename Func>
+  friend
+  class TemplateDispatcher;
+
+public:
+  Dispatcher(Dispatcher &&other)
+      : _queue(other._queue),
+        _chained(other._chained) { other._chained = true; }
+
+  explicit Dispatcher(MessageQueue *queue)
+      : _queue(queue), _chained(false) {}
+
+  template<typename Message, typename Func>
+  TemplateDispatcher<Dispatcher, Message, Func>
+  handle(Func &&function) {
+    return TemplateDispatcher<Dispatcher, Message, Func>(
+        _queue, this, std::forward<Func>(function));
+  }
+
+  ~Dispatcher() noexcept(false) {
+    if (not _chained) {
+      wait_and_dispatch();
+    }
+  }
+
+private:
+  Dispatcher(Dispatcher const &) = delete;
+
+  Dispatcher &operator=(Dispatcher const &) = delete;
+
+  void wait_and_dispatch() {
+    for (;;) {
+      auto msg = _queue->wait_and_pop();
+
+      dispatch(msg);
+    }
+  }
+
+  bool dispatch(std::shared_ptr<BaseMessage> const &msg) {
+    if (dynamic_cast < Message<Close> * >(msg.get())) {
+      throw Close();
+    }
+    return false;
+  }
+
+  MessageQueue *_queue;
+  bool _chained;
+};
+
+class Receiver {
+public:
+  Receiver() : _queue(new MessageQueue) {}
+
+  ~Receiver() { delete _queue; }
+
+  Sender get_sender() { return Sender(_queue); }
+
+  Dispatcher wait() { return Dispatcher(_queue); }
+
+private:
+  MessageQueue *_queue;
+};
+
+}
 }  // namespace artis common
 }  // namespace artis common
 
 
 #endif
 #endif

+ 12 - 13
src/artis-star/common/utils/String.hpp

@@ -30,22 +30,21 @@
 #include <string>
 #include <string>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
+namespace common {
 
 
-        class String {
-        public:
-            static std::string make_spaces(unsigned int number)
-            {
-                std::string str;
-
-                for (unsigned int i = 0; i < number; ++i) {
-                    str += " ";
-                }
-                return str;
-            }
-        };
+class String {
+public:
+  static std::string make_spaces(unsigned int number) {
+    std::string str;
 
 
+    for (unsigned int i = 0; i < number; ++i) {
+      str += " ";
     }
     }
+    return str;
+  }
+};
+
+}
 }  // namespace artis common
 }  // namespace artis common
 
 
 #endif
 #endif

+ 179 - 192
src/artis-star/common/utils/Trace.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Trace.hpp
+ * @file common/utils/Trace.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef COMMON_UTILS_TRACE
 #ifndef COMMON_UTILS_TRACE
-#define COMMON_UTILS_TRACE 1
+#define COMMON_UTILS_TRACE
 
 
 #include <artis-star/common/utils/FormalismType.hpp>
 #include <artis-star/common/utils/FormalismType.hpp>
 #include <artis-star/common/utils/FunctionType.hpp>
 #include <artis-star/common/utils/FunctionType.hpp>
@@ -39,221 +39,208 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace common {
-
-        template<class Time>
-        class TraceElement {
-        public:
-            TraceElement()
-                    :_time(Time::null), _formalism_type(FormalismType::NONE),
-                     _function_type(FunctionType::NONE), _level_type(LevelType::NONE) { }
-
-            TraceElement(const std::string& model_name, typename Time::type time,
-                    const FormalismType::Values& formalism_type,
-                    const FunctionType::Values& function_type, const LevelType::Values& level_type)
-                    :_model_name(model_name), _time(time), _formalism_type(formalism_type),
-                     _function_type(function_type), _level_type(level_type) { }
-
-            virtual ~TraceElement() { }
-
-            const std::string& get_comment() const { return _comment; }
-
-            const std::string& get_model_name() const { return _model_name; }
-
-            typename Time::type get_time() const { return _time; }
-
-            const FormalismType::Values& get_formalism_type() const { return _formalism_type; }
-
-            const FunctionType::Values& get_function_type() const { return _function_type; }
-
-            const LevelType::Values& get_level_type() const { return _level_type; }
-
-            void set_comment(const std::string& comment) { _comment = comment; }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                ss << "TRACE: " << get_model_name() << " at " << get_time() << " <";
-                ss << FormalismType::to_string(get_formalism_type()) << ", ";
-                ss << FunctionType::to_string(get_function_type()) << ", ";
-                ss << LevelType::to_string(get_level_type()) << ">";
-                if (not get_comment().empty()) {
-                    ss << " => " << get_comment();
-                }
-                return ss.str();
-            }
-
-        private:
-            std::string _model_name;
-            typename Time::type _time;
-            FormalismType::Values _formalism_type;
-            FunctionType::Values _function_type;
-            LevelType::Values _level_type;
-            std::string _comment;
-        };
-
-        template<class Time>
-        class TraceElements : public std::vector<TraceElement<Time> > {
-        public:
-            TraceElements() { }
-
-            virtual ~TraceElements() { }
-
-            TraceElements filter_model_name(const std::string& model_name) const
-            {
-                TraceElements<Time> result;
-
-                std::copy_if(TraceElements<Time>::begin(),
-                        TraceElements<Time>::end(), std::back_inserter(result),
-                        [model_name](TraceElement<Time> const& x) {
-                            return x.get_model_name() == model_name;
-                        });
-                return result;
-            }
-
-            TraceElements filter_time(typename Time::type time) const
-            {
-                TraceElements result;
-
-                std::copy_if(TraceElements<Time>::begin(),
-                        TraceElements<Time>::end(), std::back_inserter(result),
-                        [time](TraceElement<Time> const& x) { return x.get_time() == time; });
-                return result;
-            }
-
-            TraceElements filter_formalism_type(const FormalismType::Values& type) const
-            {
-                TraceElements result;
-
-                std::copy_if(TraceElements<Time>::begin(),
-                        TraceElements<Time>::end(), std::back_inserter(result),
-                        [type](TraceElement<Time> const& x) { return x.get_formalism_type() == type; });
-                return result;
-            }
-
-            TraceElements filter_function_type(const FunctionType::Values& type) const
-            {
-                TraceElements result;
-
-                std::copy_if(TraceElements<Time>::begin(),
-                        TraceElements<Time>::end(), std::back_inserter(result),
-                        [type](TraceElement<Time> const& x) { return x.get_function_type() == type; });
-                return result;
-            }
-
-            TraceElements filter_level_type(const LevelType::Values& type) const
-            {
-                TraceElements result;
-
-                std::copy_if(TraceElements<Time>::begin(),
-                        TraceElements<Time>::end(), std::back_inserter(result),
-                        [type](TraceElement<Time> const& x) { return x.get_level_type() == type; });
-                return result;
-            }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                for (typename TraceElements<Time>::const_iterator it = TraceElements<Time>::begin();
-                     it != TraceElements<Time>::end(); ++it) {
-                    ss << "TRACE: " << it->get_model_name() << " at " << it->get_time() << " <";
-                    ss << FormalismType::to_string(it->get_formalism_type()) << ", ";
-                    ss << FunctionType::to_string(it->get_function_type()) << ", ";
-                    ss << LevelType::to_string(it->get_level_type()) << ">";
-                    if (not it->get_comment().empty()) {
-                        ss << " => " << it->get_comment();
-                    }
-                    ss << std::endl;
-                }
-                return ss.str();
-            }
-        };
-
-        template<class Time>
-        class Trace {
-        public:
-            virtual ~Trace() { }
-
-            static Trace& trace()
-            {
+namespace common {
+
+template<class Time>
+class TraceElement {
+public:
+  TraceElement()
+      : _time(Time::null), _formalism_type(FormalismType::NONE),
+        _function_type(FunctionType::NONE), _level_type(LevelType::NONE) {}
+
+  TraceElement(const std::string &model_name, typename Time::type time,
+               const FormalismType::Values &formalism_type,
+               const FunctionType::Values &function_type, const LevelType::Values &level_type)
+      : _model_name(model_name), _time(time), _formalism_type(formalism_type),
+        _function_type(function_type), _level_type(level_type) {}
+
+  virtual ~TraceElement() {}
+
+  const std::string &get_comment() const { return _comment; }
+
+  const std::string &get_model_name() const { return _model_name; }
+
+  typename Time::type get_time() const { return _time; }
+
+  const FormalismType::Values &get_formalism_type() const { return _formalism_type; }
+
+  const FunctionType::Values &get_function_type() const { return _function_type; }
+
+  const LevelType::Values &get_level_type() const { return _level_type; }
+
+  void set_comment(const std::string &comment) { _comment = comment; }
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    ss << "TRACE: " << get_model_name() << " at " << get_time() << " <";
+    ss << FormalismType::to_string(get_formalism_type()) << ", ";
+    ss << FunctionType::to_string(get_function_type()) << ", ";
+    ss << LevelType::to_string(get_level_type()) << ">";
+    if (not get_comment().empty()) {
+      ss << " => " << get_comment();
+    }
+    return ss.str();
+  }
+
+private:
+  std::string _model_name;
+  typename Time::type _time;
+  FormalismType::Values _formalism_type;
+  FunctionType::Values _function_type;
+  LevelType::Values _level_type;
+  std::string _comment;
+};
+
+template<class Time>
+class TraceElements : public std::vector<TraceElement<Time> > {
+public:
+  TraceElements() {}
+
+  virtual ~TraceElements() {}
+
+  TraceElements filter_model_name(const std::string &model_name) const {
+    TraceElements<Time> result;
+
+    std::copy_if(TraceElements<Time>::begin(),
+                 TraceElements<Time>::end(), std::back_inserter(result),
+                 [model_name](TraceElement<Time> const &x) {
+                   return x.get_model_name() == model_name;
+                 });
+    return result;
+  }
+
+  TraceElements filter_time(typename Time::type time) const {
+    TraceElements result;
+
+    std::copy_if(TraceElements<Time>::begin(),
+                 TraceElements<Time>::end(), std::back_inserter(result),
+                 [time](TraceElement<Time> const &x) { return x.get_time() == time; });
+    return result;
+  }
+
+  TraceElements filter_formalism_type(const FormalismType::Values &type) const {
+    TraceElements result;
+
+    std::copy_if(TraceElements<Time>::begin(),
+                 TraceElements<Time>::end(), std::back_inserter(result),
+                 [type](TraceElement<Time> const &x) { return x.get_formalism_type() == type; });
+    return result;
+  }
+
+  TraceElements filter_function_type(const FunctionType::Values &type) const {
+    TraceElements result;
+
+    std::copy_if(TraceElements<Time>::begin(),
+                 TraceElements<Time>::end(), std::back_inserter(result),
+                 [type](TraceElement<Time> const &x) { return x.get_function_type() == type; });
+    return result;
+  }
+
+  TraceElements filter_level_type(const LevelType::Values &type) const {
+    TraceElements result;
+
+    std::copy_if(TraceElements<Time>::begin(),
+                 TraceElements<Time>::end(), std::back_inserter(result),
+                 [type](TraceElement<Time> const &x) { return x.get_level_type() == type; });
+    return result;
+  }
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    for (typename TraceElements<Time>::const_iterator it = TraceElements<Time>::begin();
+         it != TraceElements<Time>::end(); ++it) {
+      ss << "TRACE: " << it->get_model_name() << " at " << it->get_time() << " <";
+      ss << FormalismType::to_string(it->get_formalism_type()) << ", ";
+      ss << FunctionType::to_string(it->get_function_type()) << ", ";
+      ss << LevelType::to_string(it->get_level_type()) << ">";
+      if (not it->get_comment().empty()) {
+        ss << " => " << it->get_comment();
+      }
+      ss << std::endl;
+    }
+    return ss.str();
+  }
+};
+
+template<class Time>
+class Trace {
+public:
+  virtual ~Trace() {}
+
+  static Trace &trace() {
 //                std::call_once(_flag, []() { _instance.reset(new Trace()); });
 //                std::call_once(_flag, []() { _instance.reset(new Trace()); });
-                if (!_instance) {
-                    _instance.reset(new Trace());
-                }
-                return *_instance;
-            }
+    if (!_instance) {
+      _instance.reset(new Trace());
+    }
+    return *_instance;
+  }
 
 
-            void clear() { _trace.clear(); }
+  void clear() { _trace.clear(); }
 
 
-            const TraceElements<Time>& elements() const { return _trace; }
+  const TraceElements<Time> &elements() const { return _trace; }
 
 
-            void flush()
-            {
-                std::lock_guard<std::mutex> lock(_mutex);
+  void flush() {
+    std::lock_guard<std::mutex> lock(_mutex);
 
 
-                if (_sstream) {
-                    _element.set_comment(_sstream->str());
-                    delete _sstream;
-                    _sstream = 0;
-                }
-                _trace.push_back(_element);
-            }
+    if (_sstream) {
+      _element.set_comment(_sstream->str());
+      delete _sstream;
+      _sstream = 0;
+    }
+    _trace.push_back(_element);
+  }
 
 
-            std::mutex& mutex() { return _mutex; }
+  std::mutex &mutex() { return _mutex; }
 
 
-            void set_element(const TraceElement<Time>& element) { _element = element; }
+  void set_element(const TraceElement<Time> &element) { _element = element; }
 
 
-            std::ostringstream& sstream()
-            {
-                if (_sstream == 0) {
-                    _sstream = new std::ostringstream();
-                }
-                return *_sstream;
-            }
+  std::ostringstream &sstream() {
+    if (_sstream == 0) {
+      _sstream = new std::ostringstream();
+    }
+    return *_sstream;
+  }
 
 
-        private:
-            Trace() { _sstream = 0; }
+private:
+  Trace() { _sstream = 0; }
 
 
-            static std::shared_ptr<Trace<Time> > _instance;
+  static std::shared_ptr<Trace<Time> > _instance;
 //            static std::once_flag _flag;
 //            static std::once_flag _flag;
 
 
-            TraceElements<Time> _trace;
-            TraceElement<Time> _element;
-            std::ostringstream* _sstream;
-            std::mutex _mutex;
-        };
+  TraceElements<Time> _trace;
+  TraceElement<Time> _element;
+  std::ostringstream *_sstream;
+  std::mutex _mutex;
+};
 
 
-    }
+}
 } // namespace artis common
 } // namespace artis common
 
 
 template<class Time>
 template<class Time>
-artis::common::Trace<Time>&
-operator<<(artis::common::Trace<Time>& trace, const artis::common::TraceElement<Time>& e)
-{
-    std::lock_guard<std::mutex> lock(trace.mutex());
+artis::common::Trace<Time> &
+operator<<(artis::common::Trace<Time> &trace, const artis::common::TraceElement<Time> &e) {
+  std::lock_guard<std::mutex> lock(trace.mutex());
 
 
-    trace.set_element(e);
-    return trace;
+  trace.set_element(e);
+  return trace;
 }
 }
 
 
 template<class Time>
 template<class Time>
-artis::common::Trace<Time>& operator<<(artis::common::Trace<Time>& trace, const std::string& str)
-{
-    std::lock_guard<std::mutex> lock(trace.mutex());
+artis::common::Trace<Time> &operator<<(artis::common::Trace<Time> &trace, const std::string &str) {
+  std::lock_guard<std::mutex> lock(trace.mutex());
 
 
-    trace.sstream() << str;
-    return trace;
+  trace.sstream() << str;
+  return trace;
 }
 }
 
 
 template<class Time>
 template<class Time>
-artis::common::Trace<Time>& operator<<(artis::common::Trace<Time>& trace, typename Time::type t)
-{
-    std::lock_guard<std::mutex> lock(trace.mutex());
+artis::common::Trace<Time> &operator<<(artis::common::Trace<Time> &trace, typename Time::type t) {
+  std::lock_guard<std::mutex> lock(trace.mutex());
 
 
-    trace.sstream() << t;
-    return trace;
+  trace.sstream() << t;
+  return trace;
 }
 }
 
 
 template<class Time>
 template<class Time>

+ 241 - 252
src/artis-star/kernel/devs/Coordinator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef DEVS_COORDINATOR
 #ifndef DEVS_COORDINATOR
-#define DEVS_COORDINATOR 1
+#define DEVS_COORDINATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -36,68 +36,64 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace devs {
-
-        template<class Time,
-                class GraphManager,
-                class Select,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class Coordinator : public common::Coordinator<Time> {
-            typedef Coordinator<Time, GraphManager, Parameters, GraphParameters> type;
-
-        public:
-            typedef Parameters parameters_type;
-            typedef GraphParameters graph_parameters_type;
-
-            Coordinator(const std::string& name, const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Coordinator<Time>(name),
-                    _graph_manager(this, parameters, graph_parameters),
-                    _d_star(nullptr) { }
-
-            virtual ~Coordinator() = default;
-
-            GraphManager& get_graph_manager() { return _graph_manager; }
-
-            const GraphManager& get_graph_manager() const { return _graph_manager; }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "p-devs coordinator \""
-                   << this->get_name() << "\":" << std::endl;
-                ss << _graph_manager.to_string(level + 1);
-                return ss.str();
-            }
-
-            void restore(const common::context::State<Time>& state)
-            {
-                common::Coordinator<Time>::restore(state);
-                for (auto& child : _graph_manager.children()) {
-                    _event_table.init(child->get_tn(), child);
-                }
-            }
-
-            virtual void finish(const typename Time::type& t)
-            {
+namespace devs {
+
+template<class Time,
+    class GraphManager,
+    class Select,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
+  typedef Coordinator<Time, GraphManager, Parameters, GraphParameters> type;
+
+public:
+  typedef Parameters parameters_type;
+  typedef GraphParameters graph_parameters_type;
+
+  Coordinator(const std::string &name, const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      common::Coordinator<Time>(name),
+      _graph_manager(this, parameters, graph_parameters),
+      _d_star(nullptr) {}
+
+  virtual ~Coordinator() = default;
+
+  GraphManager &get_graph_manager() { return _graph_manager; }
+
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "p-devs coordinator \""
+       << this->get_name() << "\":" << std::endl;
+    ss << _graph_manager.to_string(level + 1);
+    return ss.str();
+  }
+
+  void restore(const common::context::State<Time> &state) {
+    common::Coordinator<Time>::restore(state);
+    for (auto &child : _graph_manager.children()) {
+      _event_table.init(child->get_tn(), child);
+    }
+  }
+
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #else
 #else
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message (i, t) at time t
 //                When i-message (i, t) at time t
 //                  for-each d ∈ D do
 //                  for-each d ∈ D do
 //                    send i-message (i, t) to child d
 //                    send i-message (i, t) to child d
@@ -107,40 +103,39 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
-                        << this->_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
+            << this->_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(_graph_manager.children().size() > 0);
+    assert(_graph_manager.children().size() > 0);
 
 
-                for (auto& child : _graph_manager.children()) {
-                    _event_table.init(child->start(t), child);
-                }
-                this->_tl = t;
-                this->_tn = _event_table.get_current_time();
+    for (auto &child : _graph_manager.children()) {
+      _event_table.init(child->start(t), child);
+    }
+    this->_tl = t;
+    this->_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << this->_tl
-                        << " ; tn = " << this->_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << this->_tl
+            << " ; tn = " << this->_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return this->_tn;
-            }
+    return this->_tn;
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //                When *-message (*, t)
 //                When *-message (*, t)
 //                  if t != tn then Error
 //                  if t != tn then Error
 //                  d* = first({d | (d, th,d) ∈ (event-list & tn,d = tn) })
 //                  d* = first({d | (d, th,d) ∈ (event-list & tn,d = tn) })
@@ -148,49 +143,48 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
-                        << this->_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
+            << this->_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t == this->_tn);
+    assert(t == this->_tn);
 
 
-                _d_star = Select()(_event_table.get_current_models(t));
+    _d_star = Select()(_event_table.get_current_models(t));
 
 
-                assert(_d_star);
+    assert(_d_star);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": d* = " << _d_star->get_name();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": d* = " << _d_star->get_name();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _d_star->output(t);
+    _d_star->output(t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << this->_tl << " ; tn = "
-                        << this->_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << this->_tl << " ; tn = "
+            << this->_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message (x, t)
 //                When x-message (x, t)
 //                  if not (tl <= t <= tn) then Error
 //                  if not (tl <= t <= tn) then Error
 //                  receivers = { r | r ∈ D, N ∈ Ir, Z(N,r)(x) isn't empty }
 //                  receivers = { r | r ∈ D, N ∈ Ir, Z(N,r)(x) isn't empty }
@@ -204,175 +198,170 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
-                        << this->_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
+            << this->_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t >= this->_tl and t <= this->_tn);
+    assert(t >= this->_tl and t <= this->_tn);
 
 
-                common::Models<Time> receivers = get_receivers();
-                common::Models<Time> IMM = _event_table.get_current_models(t);
+    common::Models<Time> receivers = get_receivers();
+    common::Models<Time> IMM = _event_table.get_current_models(t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": receivers = " << receivers.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": receivers = " << receivers.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                for (auto& model : receivers) {
-                    _event_table.put(model->transition(t), model);
-                }
-                if (_d_star) {
-                    _event_table.put(_d_star->transition(t), _d_star);
-                    _d_star = nullptr;
-                }
+    for (auto &model : receivers) {
+      _event_table.put(model->transition(t), model);
+    }
+    if (_d_star) {
+      _event_table.put(_d_star->transition(t), _d_star);
+      _d_star = nullptr;
+    }
 
 
-                update_event_table(t);
-                this->_tl = t;
-                this->_tn = _event_table.get_current_time();
-                this->clear_bag();
+    update_event_table(t);
+    this->_tl = t;
+    this->_tn = _event_table.get_current_time();
+    this->clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << this->_tl << " ; tn = "
-                        << this->_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << this->_tl << " ; tn = "
+            << this->_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return this->_tn;
-            }
+    return this->_tn;
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                this->add_event(event);
-                _graph_manager.post_event(t, event);
-                update_event_table(t);
-                this->_tn = _event_table.get_current_time();
+    this->add_event(event);
+    _graph_manager.post_event(t, event);
+    update_event_table(t);
+    this->_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type dispatch_events(const common::Bag<Time>& bag,
-                    const typename Time::type& t)
-            {
+  typename Time::type dispatch_events(const common::Bag<Time> &bag,
+                                      const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::Y_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
-                        << this->_tn << " ; bag = " << bag.to_string()
-                        << " ; " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::Y_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << this->_tl << " ; tn = "
+            << this->_tn << " ; bag = " << bag.to_string()
+            << " ; " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _graph_manager.dispatch_events(bag, t);
-                update_event_table(t);
-                this->_tn = _event_table.get_current_time();
+    _graph_manager.dispatch_events(bag, t);
+    update_event_table(t);
+    this->_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(this->get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::Y_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << this->_tl << " ; tn = " << this->_tn
-                        << " ; " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(this->get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::Y_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << this->_tl << " ; tn = " << this->_tn
+            << " ; " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return this->_tn;
-            }
-
-            common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const
-            {
-                assert(false);
-                return common::Value();
-            }
-
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _graph_manager.lookahead(t); }
-
-            common::Models<Time> get_imm_without_receivers(const common::Models<Time>& IMM,
-                    const common::Models<Time>& receivers) const
-            {
-                common::Models<Time> imm;
-
-                for (auto& model : IMM) {
-                    if (std::find(receivers.begin(), receivers.end(),
-                            model) == receivers.end()) {
-                        imm.push_back(model);
-                    }
-                }
-                return imm;
-            }
-
-            common::Models<Time> get_receivers() const
-            {
-                common::Models<Time> receivers;
-
-                for (auto& model : _graph_manager.children()) {
-                    if (model->event_number() > 0) {
-                        receivers.push_back(model);
-                    }
-                }
-                return receivers;
-            }
-
-            void update_event_table(typename Time::type t)
-            {
-                for (auto& model : _graph_manager.children()) {
-                    if (model->event_number() > 0) {
-                        _event_table.put(t, model);
-                    }
-                }
-            }
-
-        protected:
-            GraphManager _graph_manager;
-            common::SchedulerType _event_table;
-            common::Model<Time>* _d_star;
-        };
+    return this->_tn;
+  }
+
+  common::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
+    assert(false);
+    return common::Value();
+  }
+
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _graph_manager.lookahead(t);
+  }
 
 
+  common::Models<Time> get_imm_without_receivers(const common::Models<Time> &IMM,
+                                                 const common::Models<Time> &receivers) const {
+    common::Models<Time> imm;
+
+    for (auto &model : IMM) {
+      if (std::find(receivers.begin(), receivers.end(),
+                    model) == receivers.end()) {
+        imm.push_back(model);
+      }
+    }
+    return imm;
+  }
+
+  common::Models<Time> get_receivers() const {
+    common::Models<Time> receivers;
+
+    for (auto &model : _graph_manager.children()) {
+      if (model->event_number() > 0) {
+        receivers.push_back(model);
+      }
     }
     }
+    return receivers;
+  }
+
+  void update_event_table(typename Time::type t) {
+    for (auto &model : _graph_manager.children()) {
+      if (model->event_number() > 0) {
+        _event_table.put(t, model);
+      }
+    }
+  }
+
+protected:
+  GraphManager _graph_manager;
+  common::SchedulerType _event_table;
+  common::Model<Time> *_d_star;
+};
+
+}
 } // namespace artis devs
 } // namespace artis devs
 
 
 #endif
 #endif

+ 52 - 58
src/artis-star/kernel/devs/Dynamics.hpp

@@ -34,85 +34,79 @@
 #include <artis-star/kernel/devs/Simulator.hpp>
 #include <artis-star/kernel/devs/Simulator.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace devs {
+namespace devs {
 
 
-        template<class Time, class Dyn, class Parameters = common::NoParameters>
-        class Dynamics : public common::States<Time, Dyn> {
-            typedef devs::Simulator<Time, Dyn, Parameters> Simulator;
+template<class Time, class Dyn, class Parameters = common::NoParameters>
+class Dynamics : public common::States<Time, Dyn> {
+  typedef devs::Simulator<Time, Dyn, Parameters> Simulator;
 
 
-        public:
-            struct Observable {
-                unsigned int index;
-                std::string name;
-            };
+public:
+  struct Observable {
+    unsigned int index;
+    std::string name;
+  };
 
 
-            typedef std::map<unsigned int, std::string> Observables;
+  typedef std::map<unsigned int, std::string> Observables;
 
 
-            Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
-                    :
-                    _name(name), _simulator(context.simulator()) { }
+  Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
+      :
+      _name(name), _simulator(context.simulator()) {}
 
 
-            virtual ~Dynamics() { }
+  virtual ~Dynamics() {}
 
 
-            virtual void dint(typename Time::type /* t */) { }
+  virtual void dint(typename Time::type /* t */) {}
 
 
-            virtual void dext(typename Time::type /* t */, typename Time::type /* e */,
-                    const common::ExternalEvent<Time>& /* event */) { }
+  virtual void dext(typename Time::type /* t */, typename Time::type /* e */,
+                    const common::ExternalEvent<Time> & /* event */) {}
 
 
-            virtual void start(typename Time::type /* time */) { }
+  virtual void start(typename Time::type /* time */) {}
 
 
-            virtual typename Time::type
-            ta(typename Time::type /* time */) const { return Time::infinity; }
+  virtual typename Time::type
+  ta(typename Time::type /* time */) const { return Time::infinity; }
 
 
-            virtual common::ExternalEvent<Time>
-            lambda(typename Time::type /* time */) const { return common::ExternalEvent<Time>(); }
+  virtual common::ExternalEvent<Time>
+  lambda(typename Time::type /* time */) const { return common::ExternalEvent<Time>(); }
 
 
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const { return common::Value(); }
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const { return common::Value(); }
 
 
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
 
-            const std::string& get_name() const { return _name; }
+  const std::string &get_name() const { return _name; }
 
 
-            void observable(Observable observable)
-            {
-                _observables[observable.index] = observable.name;
-            }
+  void observable(Observable observable) {
+    _observables[observable.index] = observable.name;
+  }
 
 
-            void observables(std::initializer_list<Observable> list)
-            {
-                for (typename std::initializer_list<Observable>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    _observables[it->index] = it->name;
-                }
-            }
+  void observables(std::initializer_list<Observable> list) {
+    for (typename std::initializer_list<Observable>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      _observables[it->index] = it->name;
+    }
+  }
 
 
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                assert(_observables.find(observable_index) != _observables.end());
+  virtual std::string observable_name(unsigned int observable_index) const {
+    assert(_observables.find(observable_index) != _observables.end());
 
 
-                return _observables.find(observable_index)->second;
-            }
+    return _observables.find(observable_index)->second;
+  }
 
 
-            void restore(const common::context::State<Time>& state)
-            {
-                common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
-            }
+  void restore(const common::context::State<Time> &state) {
+    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  }
 
 
-            void save(common::context::State<Time>& state) const
-            {
-                common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
-            }
+  void save(common::context::State<Time> &state) const {
+    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  }
 
 
-        private:
-            std::string _name;
-            Simulator* _simulator;
-            Observables _observables;
-        };
+private:
+  std::string _name;
+  Simulator *_simulator;
+  Observables _observables;
+};
 
 
-    }
+}
 } // namespace artis devs
 } // namespace artis devs
 
 
 #endif
 #endif

+ 96 - 102
src/artis-star/kernel/devs/GraphManager.hpp

@@ -36,110 +36,104 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace devs {
-
-        template<class Time,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class GraphManager : public common::GraphManager<Time> {
-        public:
-            typedef GraphManager<Time, Parameters, GraphParameters> type;
-            typedef std::pair<common::Model<Time>*, common::Model<Time>*> Link;
-            typedef std::vector<Link> Links;
-
-            GraphManager(common::Coordinator<Time>* coordinator,
-                    const Parameters& /* parameters */,
-                    const GraphParameters& /* graph_parameters */)
-                    :
-                    common::GraphManager<Time>(coordinator) { }
-
-            ~GraphManager() override = default;
-
-            void dispatch_events(common::Bag<Time> bag, typename Time::type t)
-            {
-                for (auto& ymsg : bag) {
-                    auto it = std::find_if(_links.begin(), _links.end(),
-                            [&ymsg](const Link& link) { return link.first == ymsg.get_model(); });
-
-                    if (it != _links.end()) {
-                        // event on output port of coupled Model
-                        if (it->second == common::GraphManager<Time>::_coordinator) {
-                            dispatch_events_to_parent(ymsg.data(), t);
-                        } else { // event on input port of internal model
-                            it->second->post_event(t, common::ExternalEvent<Time>(ymsg.data()));
-                        }
-                    }
-                }
-            }
-
-            virtual void
-            dispatch_events_to_parent(const common::Value& content, typename Time::type t)
-            {
-                common::Bag<Time> ymessages;
-
-                ymessages.push_back(common::ExternalEvent<Time>(content));
-                if (common::GraphManager<Time>::_coordinator->get_parent()) {
-                    dynamic_cast < common::Coordinator<Time>* >(common::GraphManager<Time>::_coordinator->get_parent())
-                            ->dispatch_events(ymessages, t);
-                }
-            }
-
-            bool exist_link(common::Model<Time>* src_model, common::Model<Time>* dst_model) const
-            {
-                return _links.find(std::make_pair(src_model, dst_model));
-            }
-
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
-
-            void post_event(typename Time::type t, const common::ExternalEvent<Time>& event)
-            {
-                auto it = std::find_if(_links.begin(), _links.end(),
-                        [this](const Link& link) {
-                            return link.first == common::GraphManager<Time>::_coordinator;
-                        });
-
-                if (it != _links.end()) {
-                    it->second->post_event(t,
-                            common::ExternalEvent<Time>(event.data()));
-                }
-            }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
-                for (auto& child : common::GraphManager<Time>::_children) {
-                    ss << child->to_string(level + 1);
-                }
-                ss << common::String::make_spaces(level * 2) << "Links:" << std::endl;
-                for (typename Links::const_iterator it = _links.begin(); it != _links.end(); ++it) {
-                    ss << common::String::make_spaces((level + 1) * 2)
-                       << it->first->get_name() << " -> "
-                       << it->second->get_name() << std::endl;
-                }
-                return ss.str();
-            }
-
-            void add_link(common::Model<Time>* src_model, common::Model<Time>* dst_model)
-            {
-                assert((src_model != common::GraphManager<Time>::_coordinator and
-                        dst_model != common::GraphManager<Time>::_coordinator and
-                        src_model != dst_model) or
-                        (src_model == common::GraphManager<Time>::_coordinator and
-                                dst_model != common::GraphManager<Time>::_coordinator) or
-                        (src_model != common::GraphManager<Time>::_coordinator and
-                                dst_model == common::GraphManager<Time>::_coordinator));
-
-                _links.push_back(std::make_pair(src_model, dst_model));
-            }
-
-        private:
-            Links _links;
-        };
+namespace devs {
+
+template<class Time,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
+public:
+  typedef GraphManager<Time, Parameters, GraphParameters> type;
+  typedef std::pair<common::Model<Time> *, common::Model<Time> *> Link;
+  typedef std::vector<Link> Links;
+
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const Parameters & /* parameters */,
+               const GraphParameters & /* graph_parameters */)
+      :
+      common::GraphManager<Time>(coordinator) {}
+
+  ~GraphManager() override = default;
+
+  void dispatch_events(common::Bag<Time> bag, typename Time::type t) {
+    for (auto &ymsg : bag) {
+      auto it = std::find_if(_links.begin(), _links.end(),
+                             [&ymsg](const Link &link) { return link.first == ymsg.get_model(); });
+
+      if (it != _links.end()) {
+        // event on output port of coupled Model
+        if (it->second == common::GraphManager<Time>::_coordinator) {
+          dispatch_events_to_parent(ymsg.data(), t);
+        } else { // event on input port of internal model
+          it->second->post_event(t, common::ExternalEvent<Time>(ymsg.data()));
+        }
+      }
+    }
+  }
+
+  virtual void
+  dispatch_events_to_parent(const common::Value &content, typename Time::type t) {
+    common::Bag<Time> ymessages;
+
+    ymessages.push_back(common::ExternalEvent<Time>(content));
+    if (common::GraphManager<Time>::_coordinator->get_parent()) {
+      dynamic_cast < common::Coordinator<Time> * >(common::GraphManager<Time>::_coordinator
+          ->get_parent())
+          ->dispatch_events(ymessages, t);
+    }
+  }
+
+  bool exist_link(common::Model<Time> *src_model, common::Model<Time> *dst_model) const {
+    return _links.find(std::make_pair(src_model, dst_model));
+  }
+
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
 
+  void post_event(typename Time::type t, const common::ExternalEvent<Time> &event) {
+    auto it = std::find_if(_links.begin(), _links.end(),
+                           [this](const Link &link) {
+                             return link.first == common::GraphManager<Time>::_coordinator;
+                           });
+
+    if (it != _links.end()) {
+      it->second->post_event(t,
+                             common::ExternalEvent<Time>(event.data()));
+    }
+  }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
+    for (auto &child : common::GraphManager<Time>::_children) {
+      ss << child->to_string(level + 1);
+    }
+    ss << common::String::make_spaces(level * 2) << "Links:" << std::endl;
+    for (typename Links::const_iterator it = _links.begin(); it != _links.end(); ++it) {
+      ss << common::String::make_spaces((level + 1) * 2)
+         << it->first->get_name() << " -> "
+         << it->second->get_name() << std::endl;
     }
     }
+    return ss.str();
+  }
+
+  void add_link(common::Model<Time> *src_model, common::Model<Time> *dst_model) {
+    assert((src_model != common::GraphManager<Time>::_coordinator and
+        dst_model != common::GraphManager<Time>::_coordinator and
+        src_model != dst_model) or
+        (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator) or
+        (src_model != common::GraphManager<Time>::_coordinator and
+            dst_model == common::GraphManager<Time>::_coordinator));
+
+    _links.push_back(std::make_pair(src_model, dst_model));
+  }
+
+private:
+  Links _links;
+};
+
+}
 } // namespace artis devs
 } // namespace artis devs
 
 
 #endif
 #endif

+ 157 - 165
src/artis-star/kernel/devs/Simulator.hpp

@@ -34,134 +34,127 @@
 #include <artis-star/common/utils/Trace.hpp>
 #include <artis-star/common/utils/Trace.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace devs {
+namespace devs {
 
 
-        template<class Time, class Dynamics, class Parameters>
-        class Simulator;
+template<class Time, class Dynamics, class Parameters>
+class Simulator;
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Context {
-            typedef devs::Simulator<Time, Dynamics, Parameters> Simulator;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Context {
+  typedef devs::Simulator<Time, Dynamics, Parameters> Simulator;
 
 
-        public:
-            Context(const Parameters& parameters, Simulator* simulator)
-                    :
-                    _parameters(parameters), _simulator(simulator) { }
+public:
+  Context(const Parameters &parameters, Simulator *simulator)
+      :
+      _parameters(parameters), _simulator(simulator) {}
 
 
-            virtual ~Context() { }
+  virtual ~Context() {}
 
 
-            const Parameters& parameters() const { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
 
-            Simulator* simulator() const { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 
-        private:
-            const Parameters& _parameters;
-            Simulator* _simulator;
-        };
+private:
+  const Parameters &_parameters;
+  Simulator *_simulator;
+};
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Simulator : public common::Simulator<Time> {
-            typedef Simulator<Time, Dynamics, Parameters> type;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
+  typedef Simulator<Time, Dynamics, Parameters> type;
 
 
-        public :
-            Simulator(const std::string& name, const Parameters& parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Simulator<Time>(name),
-                    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) { }
+public :
+  Simulator(const std::string &name, const Parameters &parameters)
+      :
+      common::Model<Time>(name),
+      common::Simulator<Time>(name),
+      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) {}
 
 
-            ~Simulator() override { }
+  ~Simulator() override {}
 
 
-            const Dynamics& dynamics() const { return _dynamics; }
+  const Dynamics &dynamics() const { return _dynamics; }
 
 
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                common::Simulator<Time>::restore(state);
-                _dynamics.restore(state);
-            }
+  virtual void restore(const common::context::State<Time> &state) {
+    common::Simulator<Time>::restore(state);
+    _dynamics.restore(state);
+  }
 
 
-            virtual void save(common::context::State<Time>& state) const
-            {
-                common::Simulator<Time>::save(state);
-                _dynamics.save(state);
-            }
+  virtual void save(common::context::State<Time> &state) const {
+    common::Simulator<Time>::save(state);
+    _dynamics.save(state);
+  }
 
 
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
 
 
-                ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
-                   << type::get_name() << "\"" << std::endl;
-                return ss.str();
-            }
+    ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
+       << type::get_name() << "\"" << std::endl;
+    return ss.str();
+  }
 
 
-            virtual void finish(const typename Time::type& t)
-            {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #else
 #else
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                When i-message(t)
 //                  tl = t - e
 //                  tl = t - e
 //                  tn = tl + ta(s)
 //                  tn = tl + ta(s)
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _dynamics.start(t);
-                type::_tl = t;
+    _dynamics.start(t);
+    type::_tl = t;
 
 
-                typename Time::type duration = _dynamics.ta(t);
+    typename Time::type duration = _dynamics.ta(t);
 
 
-                assert(duration >= 0);
+    assert(duration >= 0);
 
 
-                type::_tn = type::_tl + duration;
+    type::_tn = type::_tl + duration;
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            common::Value observe(const typename Time::type& t,
-                    unsigned int index) const { return _dynamics.observe(t, index); }
+  common::Value observe(const typename Time::type &t,
+                        unsigned int index) const { return _dynamics.observe(t, index); }
 
 
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                return _dynamics.observable_name(observable_index);
-            }
+  virtual std::string observable_name(unsigned int observable_index) const {
+    return _dynamics.observable_name(observable_index);
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                When *-message(t)
 //                  if (t != tn) then Error
 //                  if (t != tn) then Error
 //                  y = lambda(s)
 //                  y = lambda(s)
@@ -169,57 +162,55 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": BEFORE";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": BEFORE";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t == type::_tn);
+    assert(t == type::_tn);
 
 
-                common::ExternalEvent<Time> event(_dynamics.lambda(t));
+    common::ExternalEvent<Time> event(_dynamics.lambda(t));
 
 
-                if (not event.is_void()) {
-                    event.set_model(this);
-                    dynamic_cast < common::Coordinator<Time>* >(
-                            type::get_parent())->dispatch_events(common::Bag<Time>(event), t);
-                }
+    if (not event.is_void()) {
+      event.set_model(this);
+      dynamic_cast < common::Coordinator<Time> * >(
+          type::get_parent())->dispatch_events(common::Bag<Time>(event), t);
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": AFTER";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": AFTER";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            void post_event(const typename Time::type& t, const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event) {
 
 
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #else
 #else
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": event = " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": event = " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
-            }
+    type::add_event(event);
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                When x-message(t)
 //                  if not (tl <= t <= tn) then Error
 //                  if not (tl <= t <= tn) then Error
 //                  if (x is empty and t = tn) then
 //                  if (x is empty and t = tn) then
@@ -232,60 +223,61 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(type::_tl <= t and t <= type::_tn);
+    assert(type::_tl <= t and t <= type::_tn);
 
 
-                if (t == type::_tn) {
-                    if (type::event_number() == 0) {
-                        _dynamics.dint(t);
-                    } else {
-                        assert(false);
-                    }
-                } else {
+    if (t == type::_tn) {
+      if (type::event_number() == 0) {
+        _dynamics.dint(t);
+      } else {
+        assert(false);
+      }
+    } else {
 
 
-                    assert(type::get_bag().size() == 1);
+      assert(type::get_bag().size() == 1);
 
 
-                    _dynamics.dext(t, t - type::_tl, type::get_bag().at(0));
-                }
-                type::_tl = t;
+      _dynamics.dext(t, t - type::_tl, type::get_bag().at(0));
+    }
+    type::_tl = t;
 
 
-                typename Time::type duration = _dynamics.ta(t);
+    typename Time::type duration = _dynamics.ta(t);
 
 
-                assert(duration >= 0);
+    assert(duration >= 0);
 
 
-                type::_tn = type::_tl + duration;
-                type::clear_bag();
+    type::_tn = type::_tl + duration;
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _dynamics.lookahead(t); }
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _dynamics.lookahead(t);
+  }
 
 
-        private :
-            Dynamics _dynamics;
-        };
+private :
+  Dynamics _dynamics;
+};
 
 
-    }
+}
 } // namespace artis devs
 } // namespace artis devs
 
 
 #endif
 #endif

+ 247 - 260
src/artis-star/kernel/dsde/Coordinator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef DSDE_COORDINATOR
 #ifndef DSDE_COORDINATOR
-#define DSDE_COORDINATOR 1
+#define DSDE_COORDINATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -39,73 +39,68 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace dsde {
-
-        template<class Time,
-                class GraphManager,
-                class Executive,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class Coordinator : public common::Coordinator<Time> {
-            typedef Coordinator<Time, GraphManager, Executive, Parameters, GraphParameters> type;
-
-        public:
-            typedef Parameters parameters_type;
-            typedef GraphParameters graph_parameters_type;
-
-            Coordinator(const std::string& name, const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Coordinator<Time>(name),
-                    _graph_manager(this, parameters, graph_parameters),
-                    _executive(parameters, graph_parameters, _graph_manager)
-            {
-                _graph_manager.add_child(0, &_executive);
-            }
-
-            virtual ~Coordinator() { }
-
-            GraphManager& get_graph_manager() { return _graph_manager; }
-
-            const GraphManager& get_graph_manager() const { return _graph_manager; }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "dsde coordinator \""
-                   << type::get_name() << "\":" << std::endl;
-                ss << _graph_manager.to_string(level + 1);
-                return ss.str();
-            }
-
-            void restore(const common::context::State<Time>& state)
-            {
-                common::Coordinator<Time>::restore(state);
-                for (auto& child : _graph_manager.children()) {
-                    _event_table.init(child->get_tn(), child);
-                }
-            }
-
-            virtual void finish(const typename Time::type& t)
-            {
+namespace dsde {
+
+template<class Time,
+    class GraphManager,
+    class Executive,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
+  typedef Coordinator<Time, GraphManager, Executive, Parameters, GraphParameters> type;
+
+public:
+  typedef Parameters parameters_type;
+  typedef GraphParameters graph_parameters_type;
+
+  Coordinator(const std::string &name, const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      common::Coordinator<Time>(name),
+      _graph_manager(this, parameters, graph_parameters),
+      _executive(parameters, graph_parameters, _graph_manager) {
+    _graph_manager.add_child(0, &_executive);
+  }
+
+  virtual ~Coordinator() {}
+
+  GraphManager &get_graph_manager() { return _graph_manager; }
+
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "dsde coordinator \""
+       << type::get_name() << "\":" << std::endl;
+    ss << _graph_manager.to_string(level + 1);
+    return ss.str();
+  }
+
+  void restore(const common::context::State<Time> &state) {
+    common::Coordinator<Time>::restore(state);
+    for (auto &child : _graph_manager.children()) {
+      _event_table.init(child->get_tn(), child);
+    }
+  }
+
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //             Network Simulator Start Message
 //             Network Simulator Start Message
 //                When receive (START,t)
 //                When receive (START,t)
 //                  send (START,t) to {I | I ∈ C}
 //                  send (START,t) to {I | I ∈ C}
@@ -114,40 +109,39 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(_graph_manager.children().size() > 0);
+    assert(_graph_manager.children().size() > 0);
 
 
-                for (auto& child : _graph_manager.children()) {
-                    _event_table.init(child->start(t), child);
-                }
-                type::_tl = t;
-                type::_tn = _event_table.get_current_time();
+    for (auto &child : _graph_manager.children()) {
+      _event_table.init(child->start(t), child);
+    }
+    type::_tl = t;
+    type::_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl
-                        << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl
+            << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //             Network Simulator Output Function
 //             Network Simulator Output Function
 //                When receive (OUTPUT,t)
 //                When receive (OUTPUT,t)
 //                  if t = tn then
 //                  if t = tn then
@@ -159,49 +153,48 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t == type::_tn);
+    assert(t == type::_tn);
 
 
-                common::Models<Time> I_N = _event_table.get_current_models(t);
+    common::Models<Time> I_N = _event_table.get_current_models(t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": I_N = " << I_N.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": I_N = " << I_N.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                for (auto& model : I_N) {
-                    model->output(t);
-                }
+    for (auto &model : I_N) {
+      model->output(t);
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //             Network Simulator Transition
 //             Network Simulator Transition
 //                When receive (TRANSITION,t,x)
 //                When receive (TRANSITION,t,x)
 //                  if t ∉ [tl ,tn ] then ERROR endIf
 //                  if t ∉ [tl ,tn ] then ERROR endIf
@@ -215,178 +208,172 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t >= type::_tl and t <= type::_tn);
+    assert(t >= type::_tl and t <= type::_tn);
 
 
-                common::Models<Time> receivers = _event_table.get_current_models(t);
+    common::Models<Time> receivers = _event_table.get_current_models(t);
 
 
-                add_models_with_inputs(receivers);
+    add_models_with_inputs(receivers);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": receivers = " << receivers.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": receivers = " << receivers.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                bool found = false;
-
-                for (auto& model : receivers) {
-                    if (model != &_executive) {
-                        _event_table.put(model->transition(t), model);
-                    } else {
-                        found = true;
-                    }
-                }
-                if (found) {
-                    _event_table.put(_executive.transition(t), &_executive);
-
-                    if (not _graph_manager.new_models().empty()) {
-                        for (auto& child : _graph_manager.new_models()) {
-                            _event_table.init(child->start(t), child);
-                        }
-                        _graph_manager.clear_new_models();
-                    }
-                }
-
-                update_event_table(t);
-                type::_tl = t;
-                type::_tn = _event_table.get_current_time();
-                type::clear_bag();
+    bool found = false;
+
+    for (auto &model : receivers) {
+      if (model != &_executive) {
+        _event_table.put(model->transition(t), model);
+      } else {
+        found = true;
+      }
+    }
+    if (found) {
+      _event_table.put(_executive.transition(t), &_executive);
+
+      if (not _graph_manager.new_models().empty()) {
+        for (auto &child : _graph_manager.new_models()) {
+          _event_table.init(child->start(t), child);
+        }
+        _graph_manager.clear_new_models();
+      }
+    }
+
+    update_event_table(t);
+    type::_tl = t;
+    type::_tn = _event_table.get_current_time();
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
-                _graph_manager.post_event(t, event);
-                update_event_table(t);
-                type::_tn = _event_table.get_current_time();
+    type::add_event(event);
+    _graph_manager.post_event(t, event);
+    update_event_table(t);
+    type::_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type dispatch_events(
-                    const common::Bag<Time>& bag,
-                    const typename Time::type& t)
-            {
+  typename Time::type dispatch_events(
+      const common::Bag<Time> &bag,
+      const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::Y_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; bag = " << bag.to_string()
-                        << " ; " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::Y_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; bag = " << bag.to_string()
+            << " ; " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _graph_manager.dispatch_events(bag, t);
-                update_event_table(t);
-                type::_tn = _event_table.get_current_time();
+    _graph_manager.dispatch_events(bag, t);
+    update_event_table(t);
+    type::_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::Y_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
-                        << " ; " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::Y_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
+            << " ; " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
-
-            common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const
-            {
-                assert(false);
-                return common::Value();
-            }
-
-            void add_models_with_inputs(common::Models<Time>& receivers)
-            {
-                for (auto& model : _graph_manager.children()) {
-                    if (model->event_number() > 0) {
-                        if (std::find(receivers.begin(), receivers.end(), model)
-                                == receivers.end()) {
-                            receivers.push_back(model);
-                        }
-                    }
-                }
-            }
-
-            void remove_model(const typename Time::type& t, common::Model<Time>* model) override
-            {
-                common::Coordinator<Time>::remove_model(t, model);
-                _event_table.remove_model(model);
-            }
-
-            void update_event_table(typename Time::type t)
-            {
-                for (auto& model : _graph_manager.children()) {
-                    if (model->event_number() > 0) {
-                        _event_table.put(t, model);
-                    }
-                }
-            }
-
-        protected:
-            GraphManager _graph_manager;
-            dsde::ExecutiveSimulator<Time, Executive, Parameters, GraphParameters> _executive;
-            common::SchedulerType _event_table;
-        };
-
+    return type::_tn;
+  }
+
+  common::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
+    assert(false);
+    return common::Value();
+  }
+
+  void add_models_with_inputs(common::Models<Time> &receivers) {
+    for (auto &model : _graph_manager.children()) {
+      if (model->event_number() > 0) {
+        if (std::find(receivers.begin(), receivers.end(), model)
+            == receivers.end()) {
+          receivers.push_back(model);
+        }
+      }
     }
     }
+  }
+
+  void remove_model(const typename Time::type &t, common::Model<Time> *model) override {
+    common::Coordinator<Time>::remove_model(t, model);
+    _event_table.remove_model(model);
+  }
+
+  void update_event_table(typename Time::type t) {
+    for (auto &model : _graph_manager.children()) {
+      if (model->event_number() > 0) {
+        _event_table.put(t, model);
+      }
+    }
+  }
+
+protected:
+  GraphManager _graph_manager;
+  dsde::ExecutiveSimulator<Time, Executive, Parameters, GraphParameters> _executive;
+  common::SchedulerType _event_table;
+};
+
+}
 } // namespace artis dsde
 } // namespace artis dsde
 
 
 #endif
 #endif

+ 230 - 241
src/artis-star/kernel/dsde/Executive.hpp

@@ -31,135 +31,129 @@
 #include <artis-star/kernel/pdevs/Dynamics.hpp>
 #include <artis-star/kernel/pdevs/Dynamics.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace dsde {
-
-        template<class Time, class Dynamics, class Parameters, class GraphParameters>
-        class ExecutiveSimulator;
-
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class ExecutiveContext {
-            typedef ExecutiveSimulator<Time, Dynamics, Parameters, GraphParameters> Simulator;
-
-        public:
-            ExecutiveContext(const Parameters& parameters, const GraphParameters& graph_parameters,
-                    Simulator* simulator)
-                    :
-                    _parameters(parameters), _graph_parameters(graph_parameters),
-                    _simulator(simulator) { }
-
-            virtual ~ExecutiveContext() { }
-
-            const GraphParameters& graph_parameters() const { return _graph_parameters; }
-
-            const Parameters& parameters() const { return _parameters; }
-
-            Simulator* simulator() const { return _simulator; }
-
-        private:
-            const Parameters& _parameters;
-            const GraphParameters& _graph_parameters;
-            Simulator* _simulator;
-        };
-
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class ExecutiveSimulator : public common::Simulator<Time> {
-            typedef ExecutiveSimulator<Time, Dynamics, Parameters, GraphParameters> type;
-
-        public :
-            ExecutiveSimulator(const Parameters& parameters,
-                    const GraphParameters& graph_parameters,
-                    GraphManager<Time, Parameters, GraphParameters>& graph_manager)
-                    :
-                    common::Model<Time>("executive"),
-                    common::Simulator<Time>("executive"),
-                    _dynamics(ExecutiveContext<Time, Dynamics, Parameters, GraphParameters>(
-                            parameters, graph_parameters, this), graph_manager) { }
-
-            ~ExecutiveSimulator() { }
-
-            const Dynamics& dynamics() const { return _dynamics; }
-
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                common::Simulator<Time>::restore(state);
-                _dynamics.restore(state);
-            }
-
-            virtual void save(common::context::State<Time>& state) const
-            {
-                common::Simulator<Time>::save(state);
-                _dynamics.save(state);
-            }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "executive simulator \""
-                   << type::get_name() << "\"" << std::endl;
-                return ss.str();
-            }
-
-            virtual void finish(const typename Time::type& t)
-            {
+namespace dsde {
+
+template<class Time, class Dynamics, class Parameters, class GraphParameters>
+class ExecutiveSimulator;
+
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class ExecutiveContext {
+  typedef ExecutiveSimulator<Time, Dynamics, Parameters, GraphParameters> Simulator;
+
+public:
+  ExecutiveContext(const Parameters &parameters, const GraphParameters &graph_parameters,
+                   Simulator *simulator)
+      :
+      _parameters(parameters), _graph_parameters(graph_parameters),
+      _simulator(simulator) {}
+
+  virtual ~ExecutiveContext() {}
+
+  const GraphParameters &graph_parameters() const { return _graph_parameters; }
+
+  const Parameters &parameters() const { return _parameters; }
+
+  Simulator *simulator() const { return _simulator; }
+
+private:
+  const Parameters &_parameters;
+  const GraphParameters &_graph_parameters;
+  Simulator *_simulator;
+};
+
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class ExecutiveSimulator : public common::Simulator<Time> {
+  typedef ExecutiveSimulator<Time, Dynamics, Parameters, GraphParameters> type;
+
+public :
+  ExecutiveSimulator(const Parameters &parameters,
+                     const GraphParameters &graph_parameters,
+                     GraphManager<Time, Parameters, GraphParameters> &graph_manager)
+      :
+      common::Model<Time>("executive"),
+      common::Simulator<Time>("executive"),
+      _dynamics(ExecutiveContext<Time, Dynamics, Parameters, GraphParameters>(
+          parameters, graph_parameters, this), graph_manager) {}
+
+  ~ExecutiveSimulator() {}
+
+  const Dynamics &dynamics() const { return _dynamics; }
+
+  virtual void restore(const common::context::State<Time> &state) {
+    common::Simulator<Time>::restore(state);
+    _dynamics.restore(state);
+  }
+
+  virtual void save(common::context::State<Time> &state) const {
+    common::Simulator<Time>::save(state);
+    _dynamics.save(state);
+  }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "executive simulator \""
+       << type::get_name() << "\"" << std::endl;
+    return ss.str();
+  }
+
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                When i-message(t)
 //                  tl = t - e
 //                  tl = t - e
 //                  tn = tl + ta(s)
 //                  tn = tl + ta(s)
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::_tl = t;
-                type::_tn = type::_tl + _dynamics.start(t);
+    type::_tl = t;
+    type::_tn = type::_tl + _dynamics.start(t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            common::Value observe(const typename Time::type& t,
-                    unsigned int index) const { return _dynamics.observe(t, index); }
+  common::Value observe(const typename Time::type &t,
+                        unsigned int index) const { return _dynamics.observe(t, index); }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                When *-message(t)
 //                  if (t = tn) then
 //                  if (t = tn) then
 //                    y = lambda(s)
 //                    y = lambda(s)
@@ -167,73 +161,71 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": BEFORE";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": BEFORE";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    common::Bag<Time> bag = _dynamics.lambda(t);
+    if (t == type::_tn) {
+      common::Bag<Time> bag = _dynamics.lambda(t);
 
 
-                    if (not bag.empty()) {
-                        for (auto& event : bag) {
-                            event.set_model(this);
-                        }
-                        dynamic_cast < common::Coordinator<Time>* >(
-                                type::get_parent())->dispatch_events(bag, t);
-                    }
-                }
+      if (not bag.empty()) {
+        for (auto &event : bag) {
+          event.set_model(this);
+        }
+        dynamic_cast < common::Coordinator<Time> * >(
+            type::get_parent())->dispatch_events(bag, t);
+      }
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": AFTER";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": AFTER";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
+    type::add_event(event);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                When x-message(t)
 //                  if (x is empty and t = tn) then
 //                  if (x is empty and t = tn) then
 //                    s = delta_int(s)
 //                    s = delta_int(s)
@@ -247,117 +239,114 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(type::_tl <= t and t <= type::_tn);
-
-                if (t == type::_tn) {
-                    if (type::event_number() == 0) {
-                        _dynamics.dint(t);
-                    } else {
-                        _dynamics.dconf(t, t - type::_tl, type::get_bag());
-                    }
-                } else {
-                    _dynamics.dext(t, t - type::_tl, type::get_bag());
-                }
-                type::_tn = t + _dynamics.ta(t);
-                type::_tl = t;
-                type::clear_bag();
+    assert(type::_tl <= t and t <= type::_tn);
+
+    if (t == type::_tn) {
+      if (type::event_number() == 0) {
+        _dynamics.dint(t);
+      } else {
+        _dynamics.dconf(t, t - type::_tl, type::get_bag());
+      }
+    } else {
+      _dynamics.dext(t, t - type::_tl, type::get_bag());
+    }
+    type::_tn = t + _dynamics.ta(t);
+    type::_tl = t;
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DSDE,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DSDE,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-        private :
-            Dynamics _dynamics;
-        };
+private :
+  Dynamics _dynamics;
+};
 
 
-        template<class Time, class Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
-        class ExecutiveDynamics : public common::States<Time, Dyn> {
-            typedef dsde::ExecutiveSimulator<Time, Dyn, Parameters, GraphParameters> Simulator;
+template<class Time, class Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
+class ExecutiveDynamics : public common::States<Time, Dyn> {
+  typedef dsde::ExecutiveSimulator<Time, Dyn, Parameters, GraphParameters> Simulator;
 
 
-        public:
-            ExecutiveDynamics(
-                    const ExecutiveContext<Time, Dyn, Parameters, GraphParameters>& context)
-                    :
-                    _simulator(context.simulator()), _name("executive") { }
+public:
+  ExecutiveDynamics(
+      const ExecutiveContext<Time, Dyn, Parameters, GraphParameters> &context)
+      :
+      _simulator(context.simulator()), _name("executive") {}
 
 
-            virtual ~ExecutiveDynamics() { }
+  virtual ~ExecutiveDynamics() {}
 
 
-            virtual void dconf(typename Time::type /* t */, typename Time::type /* e */,
-                    const common::Bag<Time>& /* bag */) { }
+  virtual void dconf(typename Time::type /* t */, typename Time::type /* e */,
+                     const common::Bag<Time> & /* bag */) {}
 
 
-            virtual void dint(typename Time::type /* t */) { }
+  virtual void dint(typename Time::type /* t */) {}
 
 
-            virtual void dext(typename Time::type /* t */, typename Time::type /* e */,
-                    const common::Bag<Time>& /* bag */) { }
+  virtual void dext(typename Time::type /* t */, typename Time::type /* e */,
+                    const common::Bag<Time> & /* bag */) {}
 
 
-            virtual typename Time::type
-            start(typename Time::type /* time */) { return Time::infinity; }
+  virtual typename Time::type
+  start(typename Time::type /* time */) { return Time::infinity; }
 
 
-            virtual typename Time::type
-            ta(typename Time::type /* time */) const { return Time::infinity; }
+  virtual typename Time::type
+  ta(typename Time::type /* time */) const { return Time::infinity; }
 
 
-            virtual common::Bag<Time>
-            lambda(typename Time::type /* time */) const { return common::Bag<Time>(); }
+  virtual common::Bag<Time>
+  lambda(typename Time::type /* time */) const { return common::Bag<Time>(); }
 
 
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const { return common::Value(); }
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const { return common::Value(); }
 
 
-            const std::string& get_name() const { return _name; }
+  const std::string &get_name() const { return _name; }
 
 
-            void restore(const common::context::State<Time>& state)
-            {
-                common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
-            }
+  void restore(const common::context::State<Time> &state) {
+    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  }
 
 
-            void save(common::context::State<Time>& state) const
-            {
-                common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
-            }
+  void save(common::context::State<Time> &state) const {
+    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  }
 
 
-        private:
-            Simulator* _simulator;
-            std::string _name;
-        };
+private:
+  Simulator *_simulator;
+  std::string _name;
+};
 
 
-        template<class Time, class Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
-        class Executive : public dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters> {
-        public:
-            Executive(const ExecutiveContext<Time, Dyn, Parameters, GraphParameters>& context,
-                    dsde::GraphManager<Time, Parameters, GraphParameters>& graph_manager)
-                    :
-                    dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters>(context),
-                    _graph_manager(graph_manager) { }
+template<class Time, class Dyn, class Parameters = common::NoParameters, class GraphParameters = common::NoParameters>
+class Executive : public dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters> {
+public:
+  Executive(const ExecutiveContext<Time, Dyn, Parameters, GraphParameters> &context,
+            dsde::GraphManager<Time, Parameters, GraphParameters> &graph_manager)
+      :
+      dsde::ExecutiveDynamics<Time, Dyn, Parameters, GraphParameters>(context),
+      _graph_manager(graph_manager) {}
 
 
-            ~Executive() override = default;
+  ~Executive() override = default;
 
 
-        protected:
-            dsde::GraphManager<Time, Parameters, GraphParameters>& graph_manager()
-            { return _graph_manager; }
+protected:
+  dsde::GraphManager<Time, Parameters, GraphParameters> &graph_manager() { return _graph_manager; }
 
 
-        private:
-            dsde::GraphManager<Time, Parameters, GraphParameters>& _graph_manager;
-        };
+private:
+  dsde::GraphManager<Time, Parameters, GraphParameters> &_graph_manager;
+};
 
 
-    }
+}
 }
 }
 
 
 #endif
 #endif

+ 80 - 86
src/artis-star/kernel/dsde/GraphManager.hpp

@@ -32,93 +32,87 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace dsde {
-
-        template<class Time,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
-        public:
-            typedef pdevs::GraphManager<Time, Parameters, GraphParameters> super;
-            typedef GraphManager<Time, Parameters, GraphParameters> type;
-
-            GraphManager(common::Coordinator<Time>* coordinator,
-                    const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
-                            graph_parameters) { }
-
-            ~GraphManager() override
-            {
-                for (auto m: _models) {
-                    delete m;
-                }
-            }
-
-            virtual void add_dynamic_child(unsigned int index, common::Model<Time>* child)
-            {
-                super::add_child(index, child);
-                _models.push_back(child);
-                _new_models.push_back(child);
-            }
-
-            virtual void add_dynamic_children(unsigned int index, common::Model<Time>* child)
-            {
-                super::add_children(index, child);
-                _models.push_back(child);
-                _new_models.push_back(child);
-            }
-
-            void add_link(unsigned int source_model_index, unsigned int source_port_index,
-                    unsigned int destination_model_index, unsigned int destination_port_index)
-            {
-                common::Model<Time>* source_model = super::child_map(source_model_index);
-                common::Model<Time>* destination_model = super::child_map(destination_model_index);
-
-                assert(source_model and destination_model);
-
-                this->out({source_model, source_port_index})
-                        >> this->in({destination_model, destination_port_index});
-            }
-
-            void clear_new_models() { _new_models.clear(); }
-
-            std::vector<common::Model<Time>*>& new_models() { return _new_models; }
-
-            void remove_dynamic_child(const typename Time::type& t, unsigned int index)
-            {
-                size_t new_index = index
-                        - (pdevs::GraphManager<Time, Parameters, GraphParameters>::_children.size()
-                                - _models.size());
-
-                new_index -= std::count_if(_models.begin(), _models.end(),
-                        [](common::Model<Time>* model) { return model == nullptr; });
-                type::coordinator()->remove_model(t, _models[new_index]);
-                super::remove_child(index);
-                this->remove_links(_models[new_index]);
-                delete _models[new_index];
-                _models[new_index] = nullptr;
-            }
-
-            void remove_link(unsigned int source_model_index, unsigned int source_port_index,
-                    unsigned int destination_model_index, unsigned int destination_port_index)
-            {
-                common::Model<Time>* source_model = super::child_map(source_model_index);
-                common::Model<Time>* destination_model = super::child_map(destination_model_index);
-
-                assert(source_model and destination_model);
-
-                super::remove_link(source_model, source_port_index, destination_model,
-                        destination_port_index);
-            }
-
-        private:
-            std::vector<common::Model<Time>*> _models;
-            std::vector<common::Model<Time>*> _new_models;
-        };
-
+namespace dsde {
+
+template<class Time,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
+public:
+  typedef pdevs::GraphManager<Time, Parameters, GraphParameters> super;
+  typedef GraphManager<Time, Parameters, GraphParameters> type;
+
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const Parameters &parameters,
+               const GraphParameters &graph_parameters)
+      :
+      pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
+                                                             graph_parameters) {}
+
+  ~GraphManager() override {
+    for (auto m: _models) {
+      delete m;
     }
     }
+  }
+
+  virtual void add_dynamic_child(unsigned int index, common::Model<Time> *child) {
+    super::add_child(index, child);
+    _models.push_back(child);
+    _new_models.push_back(child);
+  }
+
+  virtual void add_dynamic_children(unsigned int index, common::Model<Time> *child) {
+    super::add_children(index, child);
+    _models.push_back(child);
+    _new_models.push_back(child);
+  }
+
+  void add_link(unsigned int source_model_index, unsigned int source_port_index,
+                unsigned int destination_model_index, unsigned int destination_port_index) {
+    common::Model<Time> *source_model = super::child_map(source_model_index);
+    common::Model<Time> *destination_model = super::child_map(destination_model_index);
+
+    assert(source_model and destination_model);
+
+    this->out({source_model, source_port_index})
+        >> this->in({destination_model, destination_port_index});
+  }
+
+  void clear_new_models() { _new_models.clear(); }
+
+  std::vector<common::Model<Time> *> &new_models() { return _new_models; }
+
+  void remove_dynamic_child(const typename Time::type &t, unsigned int index) {
+    size_t new_index = index
+        - (pdevs::GraphManager<Time, Parameters, GraphParameters>::_children.size()
+            - _models.size());
+
+    new_index -= std::count_if(_models.begin(), _models.end(),
+                               [](common::Model<Time> *model) { return model == nullptr; });
+    type::coordinator()->remove_model(t, _models[new_index]);
+    super::remove_child(index);
+    this->remove_links(_models[new_index]);
+    delete _models[new_index];
+    _models[new_index] = nullptr;
+  }
+
+  void remove_link(unsigned int source_model_index, unsigned int source_port_index,
+                   unsigned int destination_model_index, unsigned int destination_port_index) {
+    common::Model<Time> *source_model = super::child_map(source_model_index);
+    common::Model<Time> *destination_model = super::child_map(destination_model_index);
+
+    assert(source_model and destination_model);
+
+    super::remove_link(source_model, source_port_index, destination_model,
+                       destination_port_index);
+  }
+
+private:
+  std::vector<common::Model<Time> *> _models;
+  std::vector<common::Model<Time> *> _new_models;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 167 - 173
src/artis-star/kernel/dtss/Coordinator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef DTSS_COORDINATOR
 #ifndef DTSS_COORDINATOR
-#define DTSS_COORDINATOR 1
+#define DTSS_COORDINATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -34,241 +34,235 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace dtss {
+namespace dtss {
 
 
-        template<class Time>
-        struct Parameters {
-            typename Time::type time_step;
-        };
+template<class Time>
+struct Parameters {
+  typename Time::type time_step;
+};
 
 
-        template<class Time, class Policy, class GraphManager,
-                class Parameters = Parameters<Time>,
-                class GraphParameters = common::NoParameters>
-        class Coordinator : public common::Coordinator<Time> {
-            typedef Coordinator<Time, Policy, GraphManager, Parameters, GraphParameters> type;
+template<class Time, class Policy, class GraphManager,
+    class Parameters = Parameters<Time>,
+    class GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
+  typedef Coordinator<Time, Policy, GraphManager, Parameters, GraphParameters> type;
 
 
-        public:
-            typedef Parameters parameters_type;
-            typedef GraphParameters graph_parameters_type;
+public:
+  typedef Parameters parameters_type;
+  typedef GraphParameters graph_parameters_type;
 
 
-            Coordinator(const std::string& name, const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Coordinator<Time>(name),
-                    _graph_manager(this, parameters, graph_parameters),
-                    _time_step(parameters.time_step) { }
+  Coordinator(const std::string &name, const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      common::Coordinator<Time>(name),
+      _graph_manager(this, parameters, graph_parameters),
+      _time_step(parameters.time_step) {}
 
 
-            virtual ~Coordinator() { }
+  virtual ~Coordinator() {}
 
 
-            GraphManager& get_graph_manager() { return _graph_manager; }
+  GraphManager &get_graph_manager() { return _graph_manager; }
 
 
-            const GraphManager& get_graph_manager() const { return _graph_manager; }
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
 
-            virtual void finish(const typename Time::type& t)
-            {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DTSS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DTSS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::I_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::I_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(_graph_manager.children().size() > 0);
+    assert(_graph_manager.children().size() > 0);
 
 
-                for (auto& child : _graph_manager.children()) {
-                    child->start(t);
-                }
-                type::_tl = t;
-                type::_tn = t;
+    for (auto &child : _graph_manager.children()) {
+      child->start(t);
+    }
+    type::_tl = t;
+    type::_tn = t;
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::I_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::I_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            typename Time::type dispatch_events(const common::Bag<Time>& bag,
-                    const typename Time::type& t)
-            {
+  typename Time::type dispatch_events(const common::Bag<Time> &bag,
+                                      const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::Y_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; bag = " << bag.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::Y_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; bag = " << bag.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _graph_manager.dispatch_events(bag, t);
+    _graph_manager.dispatch_events(bag, t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::Y_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::Y_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const
-            {
-                assert(false);
-                return common::Value();
-            }
+  common::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
+    assert(false);
+    return common::Value();
+  }
 
 
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _graph_manager.lookahead(t); }
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _graph_manager.lookahead(t);
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::LAMBDA,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::LAMBDA,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    for (auto& model : _graph_manager.children()) {
-                        model->output(t);
-                    }
-                }
+    if (t == type::_tn) {
+      for (auto &model : _graph_manager.children()) {
+        model->output(t);
+      }
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::LAMBDA,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::LAMBDA,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::POST_EVENT,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::POST_EVENT,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    _graph_manager.post_event(t, event);
-                } else {
-                    _policy(t, event, type::_tl, type::_tn);
-                }
+    if (t == type::_tn) {
+      _graph_manager.post_event(t, event);
+    } else {
+      _policy(t, event, type::_tl, type::_tn);
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::POST_EVENT,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::POST_EVENT,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::S_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::S_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    for (auto& event : _policy.bag()) {
-                        post_event(t, event);
-                    }
-                    _policy.clear();
-                    for (auto& model : _graph_manager.children()) {
-                        model->transition(t);
-                    }
-                    type::_tl = t;
-                    type::_tn = t + _time_step;
-                }
-                type::clear_bag();
+    if (t == type::_tn) {
+      for (auto &event : _policy.bag()) {
+        post_event(t, event);
+      }
+      _policy.clear();
+      for (auto &model : _graph_manager.children()) {
+        model->transition(t);
+      }
+      type::_tl = t;
+      type::_tn = t + _time_step;
+    }
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::S_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::S_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-        private:
-            GraphManager _graph_manager;
-            typename Time::type _time_step;
-            Policy _policy;
-        };
+private:
+  GraphManager _graph_manager;
+  typename Time::type _time_step;
+  Policy _policy;
+};
 
 
-    }
+}
 } // namespace artis dtss
 } // namespace artis dtss
 
 
 #endif
 #endif

+ 93 - 104
src/artis-star/kernel/dtss/Dynamics.hpp

@@ -1,5 +1,5 @@
 /**
 /**
- * @file Dynamics.hpp
+ * @file dtss/Dynamics.hpp
  * @author The ARTIS Development Team
  * @author The ARTIS Development Team
  * See the AUTHORS or Authors.txt file
  * See the AUTHORS or Authors.txt file
  */
  */
@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef DTSS_DYNAMICS
 #ifndef DTSS_DYNAMICS
-#define DTSS_DYNAMICS 1
+#define DTSS_DYNAMICS
 
 
 #include <artis-star/common/Bag.hpp>
 #include <artis-star/common/Bag.hpp>
 #include <artis-star/common/ExternalEvent.hpp>
 #include <artis-star/common/ExternalEvent.hpp>
@@ -34,110 +34,99 @@
 #include <artis-star/kernel/dtss/Simulator.hpp>
 #include <artis-star/kernel/dtss/Simulator.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace dtss {
-
-        template<class Time, class Dyn,
-                class Parameters = common::NoParameters>
-        class Dynamics : public common::States<Time, Dyn> {
-            typedef dtss::Simulator<Time, Dyn, Parameters> Simulator;
-
-        public:
-            struct Observable {
-                unsigned int index;
-                std::string name;
-            };
-
-            typedef std::map<unsigned int, std::string> Observables;
-
-            Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
-                    :
-                    _name(name), _simulator(context.simulator()) { }
-
-            virtual ~Dynamics() { }
-
-            virtual void transition(const common::Bag<Time>& /* x */,
-                    const typename Time::type& /* t */) { }
-
-            virtual void start(const typename Time::type& /* time */) { }
-
-            virtual common::Bag<Time> lambda(
-                    const typename Time::type& /* time */) const { return common::Bag<Time>(); }
-
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const { return common::Value(); }
-
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
-
-            const std::string& get_name() const { return _name; }
-
-            void input_port(common::Port p)
-            {
-                _simulator->add_in_port(p);
-            }
-
-            void input_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it =
-                        list.begin(); it != list.end(); ++it) {
-                    _simulator->add_in_port(*it);
-                }
-            }
-
-            void observable(Observable observable)
-            {
-                _observables[observable.index] = observable.name;
-            }
-
-            void observables(std::initializer_list<Observable> list)
-            {
-                for (typename std::initializer_list<Observable>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    _observables[it->index] = it->name;
-                }
-            }
-
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                assert(_observables.find(observable_index) != _observables.end());
-
-                return _observables.find(observable_index)->second;
-            }
-
-            void output_port(common::Port p)
-            {
-                _simulator->add_out_port(p);
-            }
-
-            void output_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it =
-                        list.begin(); it != list.end(); ++it) {
-                    _simulator->add_out_port(*it);
-                }
-            }
-
-            void restore(const common::context::State<Time>& state)
-            {
-                common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
-            }
-
-            void save(common::context::State<Time>& state) const
-            {
-                common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
-            }
-
-            const typename Time::type& time_step() const
-            { return _simulator->time_step(); }
-
-        private:
-            std::string _name;
-            Simulator* _simulator;
-            Observables _observables;
-        };
+namespace dtss {
 
 
+template<class Time, class Dyn,
+    class Parameters = common::NoParameters>
+class Dynamics : public common::States<Time, Dyn> {
+  typedef dtss::Simulator<Time, Dyn, Parameters> Simulator;
+
+public:
+  struct Observable {
+    unsigned int index;
+    std::string name;
+  };
+
+  typedef std::map<unsigned int, std::string> Observables;
+
+  Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
+      :
+      _name(name), _simulator(context.simulator()) {}
+
+  virtual ~Dynamics() {}
+
+  virtual void transition(const common::Bag<Time> & /* x */,
+                          const typename Time::type & /* t */) {}
+
+  virtual void start(const typename Time::type & /* time */) {}
+
+  virtual common::Bag<Time> lambda(
+      const typename Time::type & /* time */) const { return common::Bag<Time>(); }
+
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const { return common::Value(); }
+
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
+
+  const std::string &get_name() const { return _name; }
+
+  void input_port(common::Port p) {
+    _simulator->add_in_port(p);
+  }
+
+  void input_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it =
+        list.begin(); it != list.end(); ++it) {
+      _simulator->add_in_port(*it);
     }
     }
+  }
+
+  void observable(Observable observable) {
+    _observables[observable.index] = observable.name;
+  }
+
+  void observables(std::initializer_list<Observable> list) {
+    for (typename std::initializer_list<Observable>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      _observables[it->index] = it->name;
+    }
+  }
+
+  virtual std::string observable_name(unsigned int observable_index) const {
+    assert(_observables.find(observable_index) != _observables.end());
+
+    return _observables.find(observable_index)->second;
+  }
+
+  void output_port(common::Port p) {
+    _simulator->add_out_port(p);
+  }
+
+  void output_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it =
+        list.begin(); it != list.end(); ++it) {
+      _simulator->add_out_port(*it);
+    }
+  }
+
+  void restore(const common::context::State<Time> &state) {
+    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  }
+
+  void save(common::context::State<Time> &state) const {
+    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  }
+
+  const typename Time::type &time_step() const { return _simulator->time_step(); }
+
+private:
+  std::string _name;
+  Simulator *_simulator;
+  Observables _observables;
+};
+
+}
 } // namespace artis dtss
 } // namespace artis dtss
 
 
 #endif
 #endif

+ 122 - 130
src/artis-star/kernel/dtss/GraphManager.hpp

@@ -34,138 +34,130 @@
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace dtss {
-
-        template<class Time,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class GraphManager : public common::GraphManager<Time> {
-        public:
-            typedef GraphManager<Time, Parameters, GraphParameters> type;
-
-            struct ModelPort {
-                common::Model<Time>* model;
-                unsigned int port_index;
-                type* graph_manager;
-
-                ModelPort(common::Model<Time>* model, unsigned int port_index)
-                        :model(model),
-                         port_index(port_index),
-                         graph_manager(nullptr) { }
-
-                void operator>>(const ModelPort& dst)
-                {
-                    graph_manager->add_link(model, port_index, dst.model, dst.port_index);
-                }
-            };
-
-            GraphManager(common::Coordinator<Time>* coordinator,
-                    const Parameters& /* parameters */,
-                    const GraphParameters& /* graph_parameters */)
-                    :
-                    common::GraphManager<Time>(coordinator) { }
-
-            ~GraphManager() override = default;
-
-            ModelPort in(ModelPort p)
-            {
-                p.graph_manager = this;
-                return p;
-            }
-
-            ModelPort out(ModelPort p)
-            {
-                p.graph_manager = this;
-                return p;
-            }
-
-            void dispatch_events(common::Bag<Time> bag, typename Time::type t)
-            {
-                for (auto& ymsg : bag) {
-                    typename common::Links<Time>::Result result_model = _link_list.find(
-                            ymsg.get_model(),
-                            ymsg.port_index());
-
-                    for (typename common::Links<Time>::const_iterator it = result_model.first;
-                         it != result_model.second; ++it) {
-                        // event on output port of coupled Model
-                        if (it->second.get_model() == common::GraphManager<Time>::_coordinator) {
-                            dispatch_events_to_parent(it->second, ymsg.data(), t);
-                        } else { // event on input port of internal model
-                            it->second.get_model()->post_event(t,
-                                    common::ExternalEvent<Time>(it->second, ymsg.data()));
-                        }
-                    }
-                }
-            }
-
-            virtual void
-            dispatch_events_to_parent(common::Node<Time> node, const common::Value& content,
-                    typename Time::type t)
-            {
-                common::Bag<Time> ymessages;
-
-                ymessages.push_back(common::ExternalEvent<Time>(node, content));
-
-                if (common::GraphManager<Time>::_coordinator->get_parent()) {
-                    dynamic_cast < common::Coordinator<Time>* >(common::GraphManager<Time>::_coordinator->get_parent())
-                            ->dispatch_events(ymessages, t);
-                }
-            }
-
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
-
-            void post_event(typename Time::type t, const common::ExternalEvent<Time>& event)
-            {
-                typename common::Links<Time>::Result result =
-                        _link_list.find(common::GraphManager<Time>::_coordinator,
-                                event.port_index());
-
-                for (typename common::Links<Time>::const_iterator it_r = result.first;
-                     it_r != result.second;
-                     ++it_r) {
-                    it_r->second.get_model()->post_event(t,
-                            common::ExternalEvent<Time>(it_r->second, event.data()));
-                }
-            }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
-                for (auto& child : common::GraphManager<Time>::_children) {
-                    ss << child->to_string(level + 1);
-                }
-                ss << _link_list.to_string(level);
-                return ss.str();
-            }
-
-        private:
-            void add_link(common::Model<Time>* src_model, unsigned int src_port_index,
-                    common::Model<Time>* dst_model, unsigned int dst_port_index)
-            {
-                assert((src_model != common::GraphManager<Time>::_coordinator and
-                        dst_model != common::GraphManager<Time>::_coordinator and
-                        src_model->exist_out_port(src_port_index) and
-                        dst_model->exist_in_port(dst_port_index)) or
-                        (src_model == common::GraphManager<Time>::_coordinator and
-                                dst_model != common::GraphManager<Time>::_coordinator and
-                                src_model->exist_in_port(src_port_index) and
-                                dst_model->exist_in_port(dst_port_index)) or
-                        (src_model != common::GraphManager<Time>::_coordinator and
-                                dst_model == common::GraphManager<Time>::_coordinator and
-                                src_model->exist_out_port(src_port_index) and
-                                dst_model->exist_out_port(dst_port_index)));
-
-                _link_list.add(src_model, src_port_index, dst_model, dst_port_index);
-            }
-
-            common::Links<Time> _link_list;
-        };
+namespace dtss {
+
+template<class Time,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
+public:
+  typedef GraphManager<Time, Parameters, GraphParameters> type;
+
+  struct ModelPort {
+    common::Model<Time> *model;
+    unsigned int port_index;
+    type *graph_manager;
+
+    ModelPort(common::Model<Time> *model, unsigned int port_index)
+        : model(model),
+          port_index(port_index),
+          graph_manager(nullptr) {}
+
+    void operator>>(const ModelPort &dst) {
+      graph_manager->add_link(model, port_index, dst.model, dst.port_index);
+    }
+  };
+
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const Parameters & /* parameters */,
+               const GraphParameters & /* graph_parameters */)
+      :
+      common::GraphManager<Time>(coordinator) {}
+
+  ~GraphManager() override = default;
+
+  ModelPort in(ModelPort p) {
+    p.graph_manager = this;
+    return p;
+  }
+
+  ModelPort out(ModelPort p) {
+    p.graph_manager = this;
+    return p;
+  }
+
+  void dispatch_events(common::Bag<Time> bag, typename Time::type t) {
+    for (auto &ymsg : bag) {
+      typename common::Links<Time>::Result result_model = _link_list.find(
+          ymsg.get_model(),
+          ymsg.port_index());
+
+      for (typename common::Links<Time>::const_iterator it = result_model.first;
+           it != result_model.second; ++it) {
+        // event on output port of coupled Model
+        if (it->second.get_model() == common::GraphManager<Time>::_coordinator) {
+          dispatch_events_to_parent(it->second, ymsg.data(), t);
+        } else { // event on input port of internal model
+          it->second.get_model()->post_event(t,
+                                             common::ExternalEvent<Time>(it->second, ymsg.data()));
+        }
+      }
+    }
+  }
+
+  virtual void
+  dispatch_events_to_parent(common::Node<Time> node, const common::Value &content,
+                            typename Time::type t) {
+    common::Bag<Time> ymessages;
+
+    ymessages.push_back(common::ExternalEvent<Time>(node, content));
+
+    if (common::GraphManager<Time>::_coordinator->get_parent()) {
+      dynamic_cast < common::Coordinator<Time> * >(common::GraphManager<Time>::_coordinator
+          ->get_parent())
+          ->dispatch_events(ymessages, t);
+    }
+  }
+
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
+
+  void post_event(typename Time::type t, const common::ExternalEvent<Time> &event) {
+    typename common::Links<Time>::Result result =
+        _link_list.find(common::GraphManager<Time>::_coordinator,
+                        event.port_index());
+
+    for (typename common::Links<Time>::const_iterator it_r = result.first;
+         it_r != result.second;
+         ++it_r) {
+      it_r->second.get_model()->post_event(t,
+                                           common::ExternalEvent<Time>(it_r->second, event.data()));
+    }
+  }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
 
 
+    ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
+    for (auto &child : common::GraphManager<Time>::_children) {
+      ss << child->to_string(level + 1);
     }
     }
+    ss << _link_list.to_string(level);
+    return ss.str();
+  }
+
+private:
+  void add_link(common::Model<Time> *src_model, unsigned int src_port_index,
+                common::Model<Time> *dst_model, unsigned int dst_port_index) {
+    assert((src_model != common::GraphManager<Time>::_coordinator and
+        dst_model != common::GraphManager<Time>::_coordinator and
+        src_model->exist_out_port(src_port_index) and
+        dst_model->exist_in_port(dst_port_index)) or
+        (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
+            src_model->exist_in_port(src_port_index) and
+            dst_model->exist_in_port(dst_port_index)) or
+        (src_model != common::GraphManager<Time>::_coordinator and
+            dst_model == common::GraphManager<Time>::_coordinator and
+            src_model->exist_out_port(src_port_index) and
+            dst_model->exist_out_port(dst_port_index)));
+
+    _link_list.add(src_model, src_port_index, dst_model, dst_port_index);
+  }
+
+  common::Links<Time> _link_list;
+};
+
+}
 } // namespace artis dtss
 } // namespace artis dtss
 
 
 #endif
 #endif

+ 63 - 65
src/artis-star/kernel/dtss/Policy.hpp

@@ -25,77 +25,75 @@
  */
  */
 
 
 #ifndef DTSS_POLICY
 #ifndef DTSS_POLICY
-#define DTSS_POLICY 1
+#define DTSS_POLICY
 
 
 #include <artis-star/common/Bag.hpp>
 #include <artis-star/common/Bag.hpp>
 
 
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace dtss {
-
-        class Policy {
-        public:
-            Policy() = default;
-
-            virtual ~Policy() = default;
-
-            const common::Bag<common::DoubleTime>& bag() const { return _bag; }
-
-            void clear() { _bag.clear(); }
-
-            void push(const common::ExternalEvent<common::DoubleTime>& event) { _bag.push_back(event); }
-
-        private:
-            common::Bag<common::DoubleTime> _bag;
-        };
-
-        class AllEventsPolicy : public Policy {
-        public:
-            AllEventsPolicy() = default;
-
-            virtual ~AllEventsPolicy() = default;
-
-            virtual void operator()(
-                    typename common::DoubleTime::type /* t */,
-                    const common::ExternalEvent<common::DoubleTime>& event,
-                    typename common::DoubleTime::type /* tl */,
-                    typename common::DoubleTime::type /* tn */)
-            {
-                push(event);
-            }
-        };
-
-        class LastBagPolicy : public Policy {
-        public:
-            LastBagPolicy() = default;
-
-            virtual ~LastBagPolicy() = default;
-
-            virtual void operator()(
-                    typename common::DoubleTime::type /* t */,
-                    const common::ExternalEvent<common::DoubleTime>& event,
-                    typename common::DoubleTime::type /* tl */,
-                    typename common::DoubleTime::type /* tn */)
-            {
-                clear();
-                push(event);
-            }
-        };
-
-        class IgnorePolicy : public Policy {
-        public:
-            IgnorePolicy() = default;
-            virtual ~IgnorePolicy() = default;
-
-            virtual void operator()(
-                    typename common::DoubleTime::type /* t */,
-                    const common::ExternalEvent<common::DoubleTime>& /* event */,
-                    typename common::DoubleTime::type /* tl */,
-                    typename common::DoubleTime::type /* tn */) { }
-        };
-
-    }
+namespace dtss {
+
+class Policy {
+public:
+  Policy() = default;
+
+  virtual ~Policy() = default;
+
+  const common::Bag<common::DoubleTime> &bag() const { return _bag; }
+
+  void clear() { _bag.clear(); }
+
+  void push(const common::ExternalEvent<common::DoubleTime> &event) { _bag.push_back(event); }
+
+private:
+  common::Bag<common::DoubleTime> _bag;
+};
+
+class AllEventsPolicy : public Policy {
+public:
+  AllEventsPolicy() = default;
+
+  virtual ~AllEventsPolicy() = default;
+
+  virtual void operator()(
+      typename common::DoubleTime::type /* t */,
+      const common::ExternalEvent<common::DoubleTime> &event,
+      typename common::DoubleTime::type /* tl */,
+      typename common::DoubleTime::type /* tn */) {
+    push(event);
+  }
+};
+
+class LastBagPolicy : public Policy {
+public:
+  LastBagPolicy() = default;
+
+  virtual ~LastBagPolicy() = default;
+
+  virtual void operator()(
+      typename common::DoubleTime::type /* t */,
+      const common::ExternalEvent<common::DoubleTime> &event,
+      typename common::DoubleTime::type /* tl */,
+      typename common::DoubleTime::type /* tn */) {
+    clear();
+    push(event);
+  }
+};
+
+class IgnorePolicy : public Policy {
+public:
+  IgnorePolicy() = default;
+  virtual ~IgnorePolicy() = default;
+
+  virtual void operator()(
+      typename common::DoubleTime::type /* t */,
+      const common::ExternalEvent<common::DoubleTime> & /* event */,
+      typename common::DoubleTime::type /* tl */,
+      typename common::DoubleTime::type /* tn */) {}
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 151 - 159
src/artis-star/kernel/dtss/Simulator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef DTSS_SIMULATOR
 #ifndef DTSS_SIMULATOR
-#define DTSS_SIMULATOR 1
+#define DTSS_SIMULATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -35,229 +35,221 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace dtss {
+namespace dtss {
 
 
-        template<class Time, class Dynamics, class Parameters>
-        class Simulator;
+template<class Time, class Dynamics, class Parameters>
+class Simulator;
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Context {
-            typedef dtss::Simulator<Time, Dynamics, Parameters> Simulator;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Context {
+  typedef dtss::Simulator<Time, Dynamics, Parameters> Simulator;
 
 
-        public:
-            Context(const Parameters& parameters, Simulator* simulator)
-                    :
-                    _parameters(parameters), _simulator(simulator) { }
+public:
+  Context(const Parameters &parameters, Simulator *simulator)
+      :
+      _parameters(parameters), _simulator(simulator) {}
 
 
-            virtual ~Context() { }
+  virtual ~Context() {}
 
 
-            const Parameters& parameters() const { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
 
-            Simulator* simulator() const { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 
-        private:
-            const Parameters& _parameters;
-            Simulator* _simulator;
-        };
+private:
+  const Parameters &_parameters;
+  Simulator *_simulator;
+};
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Simulator : public common::Simulator<Time> {
-            typedef Simulator<Time, Dynamics, Parameters> type;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
+  typedef Simulator<Time, Dynamics, Parameters> type;
 
 
-        public:
-            Simulator(const std::string& name, const Parameters& parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Simulator<Time>(name),
-                    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)),
-                    _time_step(parameters.time_step) { }
+public:
+  Simulator(const std::string &name, const Parameters &parameters)
+      :
+      common::Model<Time>(name),
+      common::Simulator<Time>(name),
+      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)),
+      _time_step(parameters.time_step) {}
 
 
-            ~Simulator() { }
+  ~Simulator() {}
 
 
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                _dynamics.restore(state);
-            }
+  virtual void restore(const common::context::State<Time> &state) {
+    _dynamics.restore(state);
+  }
 
 
-            virtual void save(common::context::State<Time>& state) const
-            {
-                _dynamics.save(state);
-            }
+  virtual void save(common::context::State<Time> &state) const {
+    _dynamics.save(state);
+  }
 
 
-            virtual void finish(const typename Time::type& t)
-            {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::DTSS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::DTSS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::I_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::I_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _dynamics.start(t);
-                type::_tl = t;
-                type::_tn = t;
+    _dynamics.start(t);
+    type::_tl = t;
+    type::_tn = t;
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::I_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::I_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _dynamics.lookahead(t); }
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _dynamics.lookahead(t);
+  }
 
 
-            common::Value observe(const typename Time::type& t,
-                    unsigned int index) const { return _dynamics.observe(t, index); }
+  common::Value observe(const typename Time::type &t,
+                        unsigned int index) const { return _dynamics.observe(t, index); }
 
 
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                return _dynamics.observable_name(observable_index);
-            }
+  virtual std::string observable_name(unsigned int observable_index) const {
+    return _dynamics.observable_name(observable_index);
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::LAMBDA,
-                                    common::LevelType::FORMALISM)
-                                << ": BEFORE";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::LAMBDA,
+                        common::LevelType::FORMALISM)
+                    << ": BEFORE";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    common::Bag<Time> bag = _dynamics.lambda(t);
+    if (t == type::_tn) {
+      common::Bag<Time> bag = _dynamics.lambda(t);
 
 
-                    if (not bag.empty()) {
-                        for (auto& event : bag) {
-                            event.set_model(this);
-                        }
-                        dynamic_cast < common::Coordinator<Time>* >(
-                                type::get_parent())->dispatch_events(bag, t);
-                    }
-                }
+      if (not bag.empty()) {
+        for (auto &event : bag) {
+          event.set_model(this);
+        }
+        dynamic_cast < common::Coordinator<Time> * >(
+            type::get_parent())->dispatch_events(bag, t);
+      }
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::LAMBDA,
-                                    common::LevelType::FORMALISM)
-                                << ": AFTER";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::LAMBDA,
+                        common::LevelType::FORMALISM)
+                    << ": AFTER";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::POST_EVENT,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::POST_EVENT,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
+    type::add_event(event);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::POST_EVENT,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::POST_EVENT,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::S_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::S_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t == type::_tn);
+    assert(t == type::_tn);
 
 
-                _dynamics.transition(type::get_bag(), t);
-                type::_tl = t;
-                type::_tn = t + _time_step;
-                type::clear_bag();
+    _dynamics.transition(type::get_bag(), t);
+    type::_tl = t;
+    type::_tn = t + _time_step;
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                    common::FormalismType::DTSS,
-                                    common::FunctionType::S_MESSAGE,
-                                    common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                        common::FormalismType::DTSS,
+                        common::FunctionType::S_MESSAGE,
+                        common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            const typename Time::type& time_step() const
-            { return _time_step; }
+  const typename Time::type &time_step() const { return _time_step; }
 
 
-        private :
-            Dynamics _dynamics;
-            typename Time::type _time_step;
-        };
+private :
+  Dynamics _dynamics;
+  typename Time::type _time_step;
+};
 
 
-    }
+}
 } // namespace artis dtss
 } // namespace artis dtss
 
 
 #endif
 #endif

+ 26 - 26
src/artis-star/kernel/fddevs/Coordinator.hpp

@@ -25,41 +25,41 @@
  */
  */
 
 
 #ifndef FDDEVS_COORDINATOR
 #ifndef FDDEVS_COORDINATOR
-#define FDDEVS_COORDINATOR 1
+#define FDDEVS_COORDINATOR
 
 
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace fddevs {
+namespace fddevs {
 
 
-        template<class Time,
-                class GraphManager,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class Coordinator
-                : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters> {
-        public:
-            Coordinator(const std::string& name, const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    common::Model<Time>(name),
-                    pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(name,
-                            parameters, graph_parameters) { }
+template<class Time,
+    class GraphManager,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class Coordinator
+    : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters> {
+public:
+  Coordinator(const std::string &name, const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(name,
+                                                                          parameters,
+                                                                          graph_parameters) {}
 
 
-            virtual ~Coordinator() { }
+  virtual ~Coordinator() {}
 
 
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
 
 
-                ss << common::String::make_spaces(level * 2) << "fddevs coordinator \""
-                   << this->get_name() << "\":" << std::endl;
-                ss << this->get_graph_manager().to_string(level + 1);
-                return ss.str();
-            }
-        };
+    ss << common::String::make_spaces(level * 2) << "fddevs coordinator \""
+       << this->get_name() << "\":" << std::endl;
+    ss << this->get_graph_manager().to_string(level + 1);
+    return ss.str();
+  }
+};
 
 
-    }
+}
 } // namespace artis fddevs
 } // namespace artis fddevs
 
 
 #endif
 #endif

+ 69 - 79
src/artis-star/kernel/fddevs/Dynamics.hpp

@@ -37,112 +37,102 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace fddevs {
+namespace fddevs {
 
 
-        template<class Time, class Dyn, class StateValues, class Parameters = common::NoParameters>
-        class Dynamics : public common::States<Time, Dyn> {
-            typedef fddevs::Simulator<Time, Dyn, Parameters> Simulator;
+template<class Time, class Dyn, class StateValues, class Parameters = common::NoParameters>
+class Dynamics : public common::States<Time, Dyn> {
+  typedef fddevs::Simulator<Time, Dyn, Parameters> Simulator;
 
 
-        public:
-            Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
-                    :
-                    _name(name), _simulator(context.simulator()) { }
+public:
+  Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
+      :
+      _name(name), _simulator(context.simulator()) {}
 
 
-            virtual ~Dynamics() { }
+  virtual ~Dynamics() {}
 
 
-            // definition
-            void initial_state(const StateValues& state)
-            { _initial_state = state; }
+  // definition
+  void initial_state(const StateValues &state) { _initial_state = state; }
 
 
-            // < X, Y, S, s0, tau, delta_x, sigma, delta_tau, lambda >
-            virtual void delta_tau(typename Time::type /* t */) { }
+  // < X, Y, S, s0, tau, delta_x, sigma, delta_tau, lambda >
+  virtual void delta_tau(typename Time::type /* t */) {}
 
 
-            virtual void delta_x(typename Time::type /* t */, typename Time::type /* e */,
-                    const common::Bag<Time>& /* bag */) { }
+  virtual void delta_x(typename Time::type /* t */, typename Time::type /* e */,
+                       const common::Bag<Time> & /* bag */) {}
 
 
-            virtual void initial_state(typename Time::type /* time */)
-            { state(_initial_state); }
+  virtual void initial_state(typename Time::type /* time */) { state(_initial_state); }
 
 
-            virtual common::Bag<Time>
-            lambda(typename Time::type /* time */) const { return common::Bag<Time>(); }
+  virtual common::Bag<Time>
+  lambda(typename Time::type /* time */) const { return common::Bag<Time>(); }
 
 
-            virtual bool rho(typename Time::type /* time */,
-                    const common::Bag<common::DoubleTime>& /* bag */) const { return false; }
+  virtual bool rho(typename Time::type /* time */,
+                   const common::Bag<common::DoubleTime> & /* bag */) const { return false; }
 
 
-            virtual typename Time::type
-            tau(typename Time::type /* time */) const { return Time::infinity; }
+  virtual typename Time::type
+  tau(typename Time::type /* time */) const { return Time::infinity; }
 
 
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
 
-            // observation
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const { return common::Value(); }
+  // observation
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const { return common::Value(); }
 
 
-            // structure
-            const std::string& get_name() const { return _name; }
+  // structure
+  const std::string &get_name() const { return _name; }
 
 
-            void input_port(common::Port p)
-            {
-                _simulator->add_in_port(p);
-            }
+  void input_port(common::Port p) {
+    _simulator->add_in_port(p);
+  }
 
 
-            size_t input_port_number() const { return _simulator->get_in_port_number(); }
+  size_t input_port_number() const { return _simulator->get_in_port_number(); }
 
 
-            void input_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    _simulator->add_in_port(*it);
-                }
-            }
+  void input_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      _simulator->add_in_port(*it);
+    }
+  }
 
 
-            void output_port(common::Port p)
-            {
-                _simulator->add_out_port(p);
-            }
+  void output_port(common::Port p) {
+    _simulator->add_out_port(p);
+  }
 
 
-            size_t output_port_number() const { return _simulator->get_out_port_number(); }
+  size_t output_port_number() const { return _simulator->get_out_port_number(); }
 
 
-            void output_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it =
-                        list.begin(); it != list.end(); ++it) {
-                    _simulator->add_out_port(*it);
-                }
-            }
+  void output_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it =
+        list.begin(); it != list.end(); ++it) {
+      _simulator->add_out_port(*it);
+    }
+  }
 
 
-            // state
-            void restore(const common::context::State<Time>& state)
-            {
-                common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
-            }
+  // state
+  void restore(const common::context::State<Time> &state) {
+    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  }
 
 
-            void save(common::context::State<Time>& state) const
-            {
-                common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
-            }
+  void save(common::context::State<Time> &state) const {
+    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  }
 
 
-            void state(const StateValues& new_state)
-            {
-                _state = new_state;
-            }
+  void state(const StateValues &new_state) {
+    _state = new_state;
+  }
 
 
-            const StateValues& state() const { return _state; }
+  const StateValues &state() const { return _state; }
 
 
-        private:
-            std::string _name;
-            Simulator* _simulator;
+private:
+  std::string _name;
+  Simulator *_simulator;
 
 
-            // definition
-            StateValues _initial_state;
+  // definition
+  StateValues _initial_state;
 
 
-            // state
-            StateValues _state;
-        };
+  // state
+  StateValues _state;
+};
 
 
-    }
+}
 } // namespace artis fddevs
 } // namespace artis fddevs
 
 
 #endif
 #endif

+ 18 - 18
src/artis-star/kernel/fddevs/GraphManager.hpp

@@ -30,24 +30,24 @@
 #include <artis-star/kernel/pdevs/GraphManager.hpp>
 #include <artis-star/kernel/pdevs/GraphManager.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace fddevs {
-
-        template<class Time,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
-        public:
-            GraphManager(common::Coordinator<Time>* coordinator,
-                    const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
-                            graph_parameters) { }
-
-            ~GraphManager() override = default;
-        };
-
-    }
+namespace fddevs {
+
+template<class Time,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
+public:
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const Parameters &parameters,
+               const GraphParameters &graph_parameters)
+      :
+      pdevs::GraphManager<Time, Parameters, GraphParameters>(coordinator, parameters,
+                                                             graph_parameters) {}
+
+  ~GraphManager() override = default;
+};
+
+}
 } // namespace artis fddevs
 } // namespace artis fddevs
 
 
 #endif
 #endif

+ 170 - 177
src/artis-star/kernel/fddevs/Simulator.hpp

@@ -36,131 +36,125 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace fddevs {
+namespace fddevs {
 
 
-        template<class Time, class Dynamics, class Parameters>
-        class Simulator;
+template<class Time, class Dynamics, class Parameters>
+class Simulator;
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Context {
-            typedef fddevs::Simulator<Time, Dynamics, Parameters> Simulator;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Context {
+  typedef fddevs::Simulator<Time, Dynamics, Parameters> Simulator;
 
 
-        public:
-            Context(const Parameters& parameters, Simulator* simulator)
-                    :
-                    _parameters(parameters), _simulator(simulator) { }
+public:
+  Context(const Parameters &parameters, Simulator *simulator)
+      :
+      _parameters(parameters), _simulator(simulator) {}
 
 
-            virtual ~Context() { }
+  virtual ~Context() {}
 
 
-            const Parameters& parameters() const { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
 
-            Simulator* simulator() const { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 
-        private:
-            const Parameters& _parameters;
-            Simulator* _simulator;
-        };
+private:
+  const Parameters &_parameters;
+  Simulator *_simulator;
+};
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Simulator : public common::Simulator<Time> {
-            typedef Simulator<Time, Dynamics, Parameters> type;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
+  typedef Simulator<Time, Dynamics, Parameters> type;
 
 
-        public :
-            Simulator(const std::string& name, const Parameters& parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Simulator<Time>(name),
-                    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) { }
+public :
+  Simulator(const std::string &name, const Parameters &parameters)
+      :
+      common::Model<Time>(name),
+      common::Simulator<Time>(name),
+      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) {}
 
 
-            ~Simulator() { }
+  ~Simulator() {}
 
 
-            const Dynamics& dynamics() const { return _dynamics; }
+  const Dynamics &dynamics() const { return _dynamics; }
 
 
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                common::Simulator<Time>::restore(state);
-                _dynamics.restore(state);
-            }
+  virtual void restore(const common::context::State<Time> &state) {
+    common::Simulator<Time>::restore(state);
+    _dynamics.restore(state);
+  }
 
 
-            virtual void save(common::context::State<Time>& state) const
-            {
-                common::Simulator<Time>::save(state);
-                _dynamics.save(state);
-            }
+  virtual void save(common::context::State<Time> &state) const {
+    common::Simulator<Time>::save(state);
+    _dynamics.save(state);
+  }
 
 
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
 
 
-                ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
-                   << type::get_name() << "\"" << std::endl;
-                return ss.str();
-            }
+    ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
+       << type::get_name() << "\"" << std::endl;
+    return ss.str();
+  }
 
 
-            virtual void finish(const typename Time::type& t)
-            {
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                When i-message(t)
 //                  tl = t - e
 //                  tl = t - e
 //                  tn = tl + ta(s)
 //                  tn = tl + ta(s)
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _dynamics.initial_state(t);
-                type::_tl = t;
+    _dynamics.initial_state(t);
+    type::_tl = t;
 
 
-                typename Time::type duration = _dynamics.tau(t);
+    typename Time::type duration = _dynamics.tau(t);
 
 
-                assert(duration >= 0);
+    assert(duration >= 0);
 
 
-                type::_tn = type::_tl + duration;
+    type::_tn = type::_tl + duration;
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            common::Value observe(const typename Time::type& t,
-                    unsigned int index) const { return _dynamics.observe(t, index); }
+  common::Value observe(const typename Time::type &t,
+                        unsigned int index) const { return _dynamics.observe(t, index); }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                When *-message(t)
 //                  if (t = tn) then
 //                  if (t = tn) then
 //                    y = lambda(s)
 //                    y = lambda(s)
@@ -168,74 +162,72 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": BEFORE";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": BEFORE";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    common::Bag<Time> bag = _dynamics.lambda(t);
+    if (t == type::_tn) {
+      common::Bag<Time> bag = _dynamics.lambda(t);
 
 
-                    if (not bag.empty()) {
-                        for (auto& event : bag) {
-                            event.set_model(this);
-                        }
+      if (not bag.empty()) {
+        for (auto &event : bag) {
+          event.set_model(this);
+        }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                        common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": AFTER" << " => "
-                                << bag.to_string();
-                common::Trace<Time>::trace().flush();
+        common::Trace<Time>::trace()
+        << common::TraceElement<Time>(type::get_name(), t,
+                common::FormalismType::FDDEVS,
+                common::FunctionType::OUTPUT,
+                common::LevelType::FORMALISM)
+                << ": AFTER" << " => "
+                << bag.to_string();
+common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                        dynamic_cast < common::Coordinator<Time>* >(
-                                type::get_parent())->dispatch_events(bag, t);
-                    }
-                }
-            }
+        dynamic_cast < common::Coordinator<Time> * >(
+            type::get_parent())->dispatch_events(bag, t);
+      }
+    }
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
+    type::add_event(event);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                When x-message(t)
 //                  if (x is empty and t = tn) then
 //                  if (x is empty and t = tn) then
 //                    s = delta_int(s)
 //                    s = delta_int(s)
@@ -249,65 +241,66 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = " << type::_tn
-                        << " ; S = " << _dynamics.state();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = " << type::_tn
+            << " ; S = " << _dynamics.state();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(type::_tl <= t and t <= type::_tn);
+    assert(type::_tl <= t and t <= type::_tn);
 
 
-                if (t == type::_tn) {
-                    if (type::event_number() == 0) {
-                        _dynamics.delta_tau(t);
+    if (t == type::_tn) {
+      if (type::event_number() == 0) {
+        _dynamics.delta_tau(t);
 
 
-                        typename Time::type duration = _dynamics.tau(t);
+        typename Time::type duration = _dynamics.tau(t);
 
 
-                        assert(duration >= 0);
+        assert(duration >= 0);
 
 
-                        type::_tl = t;
-                        type::_tn = type::_tl + duration;
-                    }
-                } else {
-                    _dynamics.delta_x(t, t - type::_tl, type::get_bag());
-                    if (not _dynamics.rho(t, type::get_bag())) {
+        type::_tl = t;
+        type::_tn = type::_tl + duration;
+      }
+    } else {
+      _dynamics.delta_x(t, t - type::_tl, type::get_bag());
+      if (not _dynamics.rho(t, type::get_bag())) {
 
 
-                        typename Time::type duration = _dynamics.tau(t);
+        typename Time::type duration = _dynamics.tau(t);
 
 
-                        assert(duration >= 0);
+        assert(duration >= 0);
 
 
-                        type::_tl = t;
-                        type::_tn = type::_tl + duration;
-                    }
-                }
-                type::clear_bag();
+        type::_tl = t;
+        type::_tn = type::_tl + duration;
+      }
+    }
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::FDDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
-                        << " ; S = " << _dynamics.state();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::FDDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
+            << " ; S = " << _dynamics.state();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _dynamics.lookahead(t); }
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _dynamics.lookahead(t);
+  }
 
 
-        private :
-            Dynamics _dynamics;
-        };
+private :
+  Dynamics _dynamics;
+};
 
 
-    }
+}
 } // namespace artis fddevs
 } // namespace artis fddevs
 
 
 #endif
 #endif

+ 19 - 19
src/artis-star/kernel/pdevs/Context.hpp

@@ -28,33 +28,33 @@
 #define PDEVS_CONTEXT
 #define PDEVS_CONTEXT
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
+namespace pdevs {
 
 
-        template<class Time, class Dynamics, class Parameters>
-        class Simulator;
+template<class Time, class Dynamics, class Parameters>
+class Simulator;
 
 
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Context {
-            typedef pdevs::Simulator<Time, Dynamics, Parameters> Simulator;
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Context {
+  typedef pdevs::Simulator<Time, Dynamics, Parameters> Simulator;
 
 
-        public:
-            Context(const Parameters& parameters, Simulator* simulator)
-                    :
-                    _parameters(parameters), _simulator(simulator) { }
+public:
+  Context(const Parameters &parameters, Simulator *simulator)
+      :
+      _parameters(parameters), _simulator(simulator) {}
 
 
-            virtual ~Context() { }
+  virtual ~Context() {}
 
 
-            const Parameters& parameters() const { return _parameters; }
+  const Parameters &parameters() const { return _parameters; }
 
 
-            Simulator* simulator() const { return _simulator; }
+  Simulator *simulator() const { return _simulator; }
 
 
-        private:
-            const Parameters& _parameters;
-            Simulator* _simulator;
-        };
+private:
+  const Parameters &_parameters;
+  Simulator *_simulator;
+};
 
 
-    }
+}
 } // namespace artis pdevs
 } // namespace artis pdevs
 
 
 #endif
 #endif

+ 224 - 234
src/artis-star/kernel/pdevs/Coordinator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef PDEVS_COORDINATOR
 #ifndef PDEVS_COORDINATOR
-#define PDEVS_COORDINATOR 1
+#define PDEVS_COORDINATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -36,68 +36,64 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-
-        template<class Time,
-                class GraphManager,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class Coordinator : public common::Coordinator<Time> {
-            typedef Coordinator<Time, GraphManager, Parameters, GraphParameters> type;
-
-        public:
-            typedef Parameters parameters_type;
-            typedef GraphParameters graph_parameters_type;
-
-            Coordinator(const std::string& name, const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Coordinator<Time>(name),
-                    _graph_manager(this, parameters, graph_parameters) { }
-
-            virtual ~Coordinator() { }
-
-            GraphManager& get_graph_manager() { return _graph_manager; }
-
-            const GraphManager& get_graph_manager() const { return _graph_manager; }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "p-devs coordinator \""
-                   << type::get_name() << "\":" << std::endl;
-                ss << _graph_manager.to_string(level + 1);
-                return ss.str();
-            }
-
-            void restore(const common::context::State<Time>& state)
-            {
-                common::Coordinator<Time>::restore(state);
-                for (auto& child : _graph_manager.children()) {
-                    _event_table.init(child->get_tn(), child);
-                }
-            }
-
-            virtual void finish(const typename Time::type& t)
-            {
+namespace pdevs {
+
+template<class Time,
+    class GraphManager,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time> {
+  typedef Coordinator<Time, GraphManager, Parameters, GraphParameters> type;
+
+public:
+  typedef Parameters parameters_type;
+  typedef GraphParameters graph_parameters_type;
+
+  Coordinator(const std::string &name, const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      common::Coordinator<Time>(name),
+      _graph_manager(this, parameters, graph_parameters) {}
+
+  virtual ~Coordinator() {}
+
+  GraphManager &get_graph_manager() { return _graph_manager; }
+
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "p-devs coordinator \""
+       << type::get_name() << "\":" << std::endl;
+    ss << _graph_manager.to_string(level + 1);
+    return ss.str();
+  }
+
+  void restore(const common::context::State<Time> &state) {
+    common::Coordinator<Time>::restore(state);
+    for (auto &child : _graph_manager.children()) {
+      _event_table.init(child->get_tn(), child);
+    }
+  }
+
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message (i, t) at time t
 //                When i-message (i, t) at time t
 //                  for-each d ∈ D do
 //                  for-each d ∈ D do
 //                    send i-message to child d
 //                    send i-message to child d
@@ -107,40 +103,39 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(_graph_manager.children().size() > 0);
+    assert(_graph_manager.children().size() > 0);
 
 
-                for (auto& child : _graph_manager.children()) {
-                    _event_table.init(child->start(t), child);
-                }
-                type::_tl = t;
-                type::_tn = _event_table.get_current_time();
+    for (auto &child : _graph_manager.children()) {
+      _event_table.init(child->start(t), child);
+    }
+    type::_tl = t;
+    type::_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl
-                        << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl
+            << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //                When *-message (*, t)
 //                When *-message (*, t)
 //                  if t != tn then Error
 //                  if t != tn then Error
 //                  IMM = {d | (d, th,d) ∈ (event-list & tn,d = tn) }
 //                  IMM = {d | (d, th,d) ∈ (event-list & tn,d = tn) }
@@ -149,49 +144,48 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t == type::_tn);
+    assert(t == type::_tn);
 
 
-                common::Models<Time> IMM = _event_table.get_current_models(t);
+    common::Models<Time> IMM = _event_table.get_current_models(t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                        << ": IMM = " << IMM.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+            << ": IMM = " << IMM.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                for (auto& model : IMM) {
-                    model->output(t);
-                }
+    for (auto &model : IMM) {
+      model->output(t);
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message (x, t)
 //                When x-message (x, t)
 //                  if not (tl <= t <= tn) then Error
 //                  if not (tl <= t <= tn) then Error
 //                  receivers = { r | r ∈ children, N ∈ Ir, Z(N,r)(x) isn't empty }
 //                  receivers = { r | r ∈ children, N ∈ Ir, Z(N,r)(x) isn't empty }
@@ -205,160 +199,156 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t >= type::_tl and t <= type::_tn);
+    assert(t >= type::_tl and t <= type::_tn);
 
 
-                common::Models<Time> receivers = get_receivers();
-                common::Models<Time> IMM = _event_table.get_current_models(t);
+    common::Models<Time> receivers = get_receivers();
+    common::Models<Time> IMM = _event_table.get_current_models(t);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": receivers = " << receivers.to_string()
-                        << " ; IMM = " << IMM.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": receivers = " << receivers.to_string()
+            << " ; IMM = " << IMM.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                for (auto& model : receivers) {
-                    _event_table.put(model->transition(t), model);
-                }
-                for (auto& model : IMM) {
-                    if (std::find(receivers.begin(), receivers.end(), model) == receivers.end()) {
-                        _event_table.put(model->transition(t), model);
-                    }
-                }
+    for (auto &model : receivers) {
+      _event_table.put(model->transition(t), model);
+    }
+    for (auto &model : IMM) {
+      if (std::find(receivers.begin(), receivers.end(), model) == receivers.end()) {
+        _event_table.put(model->transition(t), model);
+      }
+    }
 //                update_event_table(t);
 //                update_event_table(t);
-                type::_tl = t;
-                type::_tn = _event_table.get_current_time();
-                type::clear_bag();
+    type::_tl = t;
+    type::_tn = _event_table.get_current_time();
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; scheduler = " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; scheduler = " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            void post_event(const typename Time::type& t, const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
-                _graph_manager.post_event(t, event);
+    type::add_event(event);
+    _graph_manager.post_event(t, event);
 //                update_event_table(t);
 //                update_event_table(t);
-                type::_tn = _event_table.get_current_time();
+    type::_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type dispatch_events(const common::Bag<Time>& bag,
-                    const typename Time::type& t)
-            {
+  typename Time::type dispatch_events(const common::Bag<Time> &bag,
+                                      const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::Y_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn << " ; bag = " << bag.to_string()
-                        << " ; " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::Y_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn << " ; bag = " << bag.to_string()
+            << " ; " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _graph_manager.dispatch_events(bag, t);
+    _graph_manager.dispatch_events(bag, t);
 //                update_event_table(t);
 //                update_event_table(t);
-                type::_tn = _event_table.get_current_time();
+    type::_tn = _event_table.get_current_time();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::Y_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
-                        << " ; " << _event_table.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::Y_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
+            << " ; " << _event_table.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
-
-            common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const
-            {
-                assert(false);
-                return common::Value();
-            }
-
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _graph_manager.lookahead(t); }
-
-            common::Models<Time> get_receivers() const
-            {
-                common::Models<Time> receivers;
-
-                for (auto& model : _graph_manager.children()) {
-                    if (model->event_number() > 0) {
-                        receivers.push_back(model);
-                    }
-                }
-                return receivers;
-            }
-
-            void update_event_table(typename Time::type t)
-            {
-                for (auto& model : _graph_manager.children()) {
-                    if (model->event_number() > 0) {
-                        _event_table.put(t, model);
-                    }
-                }
-            }
-
-        protected:
-            GraphManager _graph_manager;
-            common::SchedulerType _event_table;
-        };
+    return type::_tn;
+  }
+
+  common::Value observe(const typename Time::type & /* t */,
+                        unsigned int /* index */) const {
+    assert(false);
+    return common::Value();
+  }
 
 
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _graph_manager.lookahead(t);
+  }
+
+  common::Models<Time> get_receivers() const {
+    common::Models<Time> receivers;
+
+    for (auto &model : _graph_manager.children()) {
+      if (model->event_number() > 0) {
+        receivers.push_back(model);
+      }
+    }
+    return receivers;
+  }
+
+  void update_event_table(typename Time::type t) {
+    for (auto &model : _graph_manager.children()) {
+      if (model->event_number() > 0) {
+        _event_table.put(t, model);
+      }
     }
     }
+  }
+
+protected:
+  GraphManager _graph_manager;
+  common::SchedulerType _event_table;
+};
+
+}
 } // namespace artis pdevs
 } // namespace artis pdevs
 
 
 #endif
 #endif

+ 79 - 89
src/artis-star/kernel/pdevs/Dynamics.hpp

@@ -37,121 +37,111 @@
 #include <vector>
 #include <vector>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
+namespace pdevs {
 
 
-        template<class Time, class Dyn, class Parameters = common::NoParameters>
-        class Dynamics : public common::States<Time, Dyn> {
-            typedef pdevs::Simulator<Time, Dyn, Parameters> Simulator;
+template<class Time, class Dyn, class Parameters = common::NoParameters>
+class Dynamics : public common::States<Time, Dyn> {
+  typedef pdevs::Simulator<Time, Dyn, Parameters> Simulator;
 
 
-        public:
-            struct Observable {
-                unsigned int index;
-                std::string name;
-            };
-
-            typedef std::map<unsigned int, std::string> Observables;
+public:
+  struct Observable {
+    unsigned int index;
+    std::string name;
+  };
 
 
-            Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
-                    :
-                    _name(name), _simulator(context.simulator()) { }
+  typedef std::map<unsigned int, std::string> Observables;
 
 
-            virtual ~Dynamics() { }
+  Dynamics(const std::string &name, const Context<Time, Dyn, Parameters> &context)
+      :
+      _name(name), _simulator(context.simulator()) {}
 
 
-            virtual void
-            dconf(const typename Time::type& /* t */, const typename Time::type& /* e */,
-                    const common::Bag<Time>& /* bag */) { }
+  virtual ~Dynamics() {}
 
 
-            virtual void dint(const typename Time::type& /* t */) { }
+  virtual void
+  dconf(const typename Time::type & /* t */, const typename Time::type & /* e */,
+        const common::Bag<Time> & /* bag */) {}
 
 
-            virtual void
-            dext(const typename Time::type& /* t */, const typename Time::type& /* e */,
-                    const common::Bag<Time>& /* bag */) { }
+  virtual void dint(const typename Time::type & /* t */) {}
 
 
-            virtual void start(const typename Time::type& /* time */) { }
+  virtual void
+  dext(const typename Time::type & /* t */, const typename Time::type & /* e */,
+       const common::Bag<Time> & /* bag */) {}
 
 
-            virtual typename Time::type
-            ta(const typename Time::type& /* time */) const { return Time::infinity; }
+  virtual void start(const typename Time::type & /* time */) {}
 
 
-            virtual common::Bag<Time>
-            lambda(const typename Time::type& /* time */) const { return common::Bag<Time>(); }
+  virtual typename Time::type
+  ta(const typename Time::type & /* time */) const { return Time::infinity; }
 
 
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const { return common::Value(); }
+  virtual common::Bag<Time>
+  lambda(const typename Time::type & /* time */) const { return common::Bag<Time>(); }
 
 
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const { return common::Value(); }
 
 
-            const std::string& get_name() const { return _name; }
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
 
 
-            void input_port(common::Port p)
-            {
-                _simulator->add_in_port(p);
-            }
+  const std::string &get_name() const { return _name; }
 
 
-            size_t input_port_number() const { return _simulator->get_in_port_number(); }
+  void input_port(common::Port p) {
+    _simulator->add_in_port(p);
+  }
 
 
-            void input_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    _simulator->add_in_port(*it);
-                }
-            }
+  size_t input_port_number() const { return _simulator->get_in_port_number(); }
 
 
-            void observable(Observable observable)
-            {
-                _observables[observable.index] = observable.name;
-            }
+  void input_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      _simulator->add_in_port(*it);
+    }
+  }
+
+  void observable(Observable observable) {
+    _observables[observable.index] = observable.name;
+  }
+
+  void observables(std::initializer_list<Observable> list) {
+    for (typename std::initializer_list<Observable>::iterator it = list.begin();
+         it != list.end();
+         ++it) {
+      _observables[it->index] = it->name;
+    }
+  }
 
 
-            void observables(std::initializer_list<Observable> list)
-            {
-                for (typename std::initializer_list<Observable>::iterator it = list.begin();
-                     it != list.end();
-                     ++it) {
-                    _observables[it->index] = it->name;
-                }
-            }
+  virtual std::string observable_name(unsigned int observable_index) const {
+    assert(_observables.find(observable_index) != _observables.end());
 
 
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                assert(_observables.find(observable_index) != _observables.end());
+    return _observables.find(observable_index)->second;
+  }
 
 
-                return _observables.find(observable_index)->second;
-            }
+  void output_port(common::Port p) {
+    _simulator->add_out_port(p);
+  }
 
 
-            void output_port(common::Port p)
-            {
-                _simulator->add_out_port(p);
-            }
+  size_t output_port_number() const { return _simulator->get_out_port_number(); }
 
 
-            size_t output_port_number() const { return _simulator->get_out_port_number(); }
+  void output_ports(std::initializer_list<common::Port> list) {
+    for (typename std::initializer_list<common::Port>::iterator it =
+        list.begin(); it != list.end(); ++it) {
+      _simulator->add_out_port(*it);
+    }
+  }
 
 
-            void output_ports(std::initializer_list<common::Port> list)
-            {
-                for (typename std::initializer_list<common::Port>::iterator it =
-                        list.begin(); it != list.end(); ++it) {
-                    _simulator->add_out_port(*it);
-                }
-            }
+  void restore(const common::context::State<Time> &state) {
+    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+  }
 
 
-            void restore(const common::context::State<Time>& state)
-            {
-                common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
-            }
-
-            void save(common::context::State<Time>& state) const
-            {
-                common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
-            }
+  void save(common::context::State<Time> &state) const {
+    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+  }
 
 
-        private:
-            std::string _name;
-            Simulator* _simulator;
-            Observables _observables;
-        };
+private:
+  std::string _name;
+  Simulator *_simulator;
+  Observables _observables;
+};
 
 
-    }
+}
 } // namespace artis pdevs
 } // namespace artis pdevs
 
 
 #endif
 #endif

+ 139 - 150
src/artis-star/kernel/pdevs/GraphManager.hpp

@@ -37,158 +37,147 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-
-        template<class Time,
-                class Parameters = common::NoParameters,
-                class GraphParameters = common::NoParameters>
-        class GraphManager : public common::GraphManager<Time> {
-        public:
-            typedef GraphManager<Time, Parameters, GraphParameters> type;
-
-            struct ModelPort {
-                common::Model<Time>* model;
-                unsigned int port_index;
-                type* graph_manager;
-
-                ModelPort(common::Model<Time>* model, unsigned int port_index)
-                        :model(model),
-                         port_index(port_index),
-                         graph_manager(nullptr) { }
-
-                void operator>>(const ModelPort& dst)
-                {
-                    graph_manager->add_link(model, port_index, dst.model, dst.port_index);
-                }
-            };
-
-            GraphManager(common::Coordinator<Time>* coordinator,
-                    const Parameters& /* parameters */,
-                    const GraphParameters& /* graph_parameters */)
-                    :
-                    common::GraphManager<Time>(coordinator) { }
-
-            ~GraphManager() override = default;
-
-            ModelPort in(ModelPort p)
-            {
-                p.graph_manager = this;
-                return p;
-            }
-
-            ModelPort out(ModelPort p)
-            {
-                p.graph_manager = this;
-                return p;
-            }
-
-            void dispatch_events(common::Bag<Time> bag, typename Time::type t)
-            {
-                for (auto& ymsg : bag) {
-                    typename common::Links<Time>::Result result_model = _link_list.find(
-                            ymsg.get_model(),
-                            ymsg.port_index());
-
-                    for (typename common::Links<Time>::const_iterator it = result_model.first;
-                         it != result_model.second; ++it) {
-                        // event on output port of coupled Model
-                        if (it->second.get_model() == common::GraphManager<Time>::_coordinator) {
-                            dispatch_events_to_parent(it->second, ymsg.data(), t);
-                        } else { // event on input port of internal model
-                            it->second.get_model()->post_event(t,
-                                    common::ExternalEvent<Time>(it->second, ymsg.data()));
-                        }
-                    }
-                }
-            }
-
-            virtual void
-            dispatch_events_to_parent(common::Node<Time> node, const common::Value& content,
-                    typename Time::type t)
-            {
-                common::Bag<Time> ymessages;
-
-                ymessages.push_back(common::ExternalEvent<Time>(node, content));
-
-                if (common::GraphManager<Time>::_coordinator->get_parent()) {
-                    dynamic_cast < common::Coordinator<Time>* >(common::GraphManager<Time>::_coordinator->get_parent())
-                            ->dispatch_events(ymessages, t);
-                }
-            }
-
-            bool exist_link(common::Model<Time>* src_model, unsigned int src_port_index,
-                    common::Model<Time>* dst_model, unsigned int dst_port_index) const
-            {
-                return _link_list.exist(src_model, src_port_index, dst_model, dst_port_index);
-            }
-
-            virtual typename Time::type lookahead(const typename Time::type& t) const
-            { return t; }
-
-            void post_event(typename Time::type t, const common::ExternalEvent<Time>& event)
-            {
-                typename common::Links<Time>::Result result =
-                        _link_list.find(common::GraphManager<Time>::_coordinator,
-                                event.port_index());
-
-                for (typename common::Links<Time>::const_iterator it_r = result.first;
-                     it_r != result.second;
-                     ++it_r) {
-                    it_r->second.get_model()->post_event(t,
-                            common::ExternalEvent<Time>(it_r->second, event.data()));
-                }
-            }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
-                for (auto& child : common::GraphManager<Time>::_children) {
-                    ss << child->to_string(level + 1);
-                }
-                ss << _link_list.to_string(level);
-                return ss.str();
-            }
-
-        protected:
-            void remove_link(common::Model<Time>* src_model, unsigned int src_port_index,
-                    common::Model<Time>* dst_model, unsigned int dst_port_index)
-            {
-                assert(exist_link(src_model, src_port_index, dst_model, dst_port_index));
-
-                _link_list.remove(src_model, src_port_index, dst_model, dst_port_index);
-            }
-
-            void remove_links(common::Model<Time>* model)
-            {
-                _link_list.remove_links(model);
-            }
-
-        private:
-            void add_link(common::Model<Time>* src_model, unsigned int src_port_index,
-                    common::Model<Time>* dst_model, unsigned int dst_port_index)
-            {
-                assert((src_model != common::GraphManager<Time>::_coordinator and
-                        dst_model != common::GraphManager<Time>::_coordinator and
-                        src_model->exist_out_port(src_port_index) and
-                        dst_model->exist_in_port(dst_port_index)) or
-                        (src_model == common::GraphManager<Time>::_coordinator and
-                                dst_model != common::GraphManager<Time>::_coordinator and
-                                src_model->exist_in_port(src_port_index) and
-                                dst_model->exist_in_port(dst_port_index)) or
-                        (src_model != common::GraphManager<Time>::_coordinator and
-                                dst_model == common::GraphManager<Time>::_coordinator and
-                                src_model->exist_out_port(src_port_index) and
-                                dst_model->exist_out_port(dst_port_index)));
-
-                _link_list.add(src_model, src_port_index, dst_model, dst_port_index);
-            }
-
-            common::Links<Time> _link_list;
-        };
+namespace pdevs {
+
+template<class Time,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
+public:
+  typedef GraphManager<Time, Parameters, GraphParameters> type;
+
+  struct ModelPort {
+    common::Model<Time> *model;
+    unsigned int port_index;
+    type *graph_manager;
+
+    ModelPort(common::Model<Time> *model, unsigned int port_index)
+        : model(model),
+          port_index(port_index),
+          graph_manager(nullptr) {}
+
+    void operator>>(const ModelPort &dst) {
+      graph_manager->add_link(model, port_index, dst.model, dst.port_index);
+    }
+  };
+
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const Parameters & /* parameters */,
+               const GraphParameters & /* graph_parameters */)
+      :
+      common::GraphManager<Time>(coordinator) {}
+
+  ~GraphManager() override = default;
+
+  ModelPort in(ModelPort p) {
+    p.graph_manager = this;
+    return p;
+  }
+
+  ModelPort out(ModelPort p) {
+    p.graph_manager = this;
+    return p;
+  }
+
+  void dispatch_events(common::Bag<Time> bag, typename Time::type t) {
+    for (auto &ymsg : bag) {
+      typename common::Links<Time>::Result result_model = _link_list.find(
+          ymsg.get_model(),
+          ymsg.port_index());
+
+      for (typename common::Links<Time>::const_iterator it = result_model.first;
+           it != result_model.second; ++it) {
+        // event on output port of coupled Model
+        if (it->second.get_model() == common::GraphManager<Time>::_coordinator) {
+          dispatch_events_to_parent(it->second, ymsg.data(), t);
+        } else { // event on input port of internal model
+          it->second.get_model()->post_event(t,
+                                             common::ExternalEvent<Time>(it->second, ymsg.data()));
+        }
+      }
+    }
+  }
+
+  virtual void
+  dispatch_events_to_parent(common::Node<Time> node, const common::Value &content,
+                            typename Time::type t) {
+    common::Bag<Time> ymessages;
+
+    ymessages.push_back(common::ExternalEvent<Time>(node, content));
+
+    if (common::GraphManager<Time>::_coordinator->get_parent()) {
+      dynamic_cast < common::Coordinator<Time> * >(common::GraphManager<Time>::_coordinator
+          ->get_parent())
+          ->dispatch_events(ymessages, t);
+    }
+  }
+
+  bool exist_link(common::Model<Time> *src_model, unsigned int src_port_index,
+                  common::Model<Time> *dst_model, unsigned int dst_port_index) const {
+    return _link_list.exist(src_model, src_port_index, dst_model, dst_port_index);
+  }
+
+  virtual typename Time::type lookahead(const typename Time::type &t) const { return t; }
+
+  void post_event(typename Time::type t, const common::ExternalEvent<Time> &event) {
+    typename common::Links<Time>::Result result =
+        _link_list.find(common::GraphManager<Time>::_coordinator,
+                        event.port_index());
+
+    for (typename common::Links<Time>::const_iterator it_r = result.first;
+         it_r != result.second;
+         ++it_r) {
+      it_r->second.get_model()->post_event(t,
+                                           common::ExternalEvent<Time>(it_r->second, event.data()));
+    }
+  }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
 
 
+    ss << common::String::make_spaces(level * 2) << "Children :" << std::endl;
+    for (auto &child : common::GraphManager<Time>::_children) {
+      ss << child->to_string(level + 1);
     }
     }
+    ss << _link_list.to_string(level);
+    return ss.str();
+  }
+
+protected:
+  void remove_link(common::Model<Time> *src_model, unsigned int src_port_index,
+                   common::Model<Time> *dst_model, unsigned int dst_port_index) {
+    assert(exist_link(src_model, src_port_index, dst_model, dst_port_index));
+
+    _link_list.remove(src_model, src_port_index, dst_model, dst_port_index);
+  }
+
+  void remove_links(common::Model<Time> *model) {
+    _link_list.remove_links(model);
+  }
+
+private:
+  void add_link(common::Model<Time> *src_model, unsigned int src_port_index,
+                common::Model<Time> *dst_model, unsigned int dst_port_index) {
+    assert((src_model != common::GraphManager<Time>::_coordinator and
+        dst_model != common::GraphManager<Time>::_coordinator and
+        src_model->exist_out_port(src_port_index) and
+        dst_model->exist_in_port(dst_port_index)) or
+        (src_model == common::GraphManager<Time>::_coordinator and
+            dst_model != common::GraphManager<Time>::_coordinator and
+            src_model->exist_in_port(src_port_index) and
+            dst_model->exist_in_port(dst_port_index)) or
+        (src_model != common::GraphManager<Time>::_coordinator and
+            dst_model == common::GraphManager<Time>::_coordinator and
+            src_model->exist_out_port(src_port_index) and
+            dst_model->exist_out_port(dst_port_index)));
+
+    _link_list.add(src_model, src_port_index, dst_model, dst_port_index);
+  }
+
+  common::Links<Time> _link_list;
+};
+
+}
 } // namespace artis pdevs
 } // namespace artis pdevs
 
 
 #endif
 #endif

+ 159 - 168
src/artis-star/kernel/pdevs/Simulator.hpp

@@ -35,112 +35,104 @@
 #include <artis-star/kernel/pdevs/Context.hpp>
 #include <artis-star/kernel/pdevs/Context.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Simulator : public common::Simulator<Time> {
-            typedef Simulator<Time, Dynamics, Parameters> type;
-
-        public :
-            Simulator(const std::string& name, const Parameters& parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Simulator<Time>(name),
-                    _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) { }
-
-            ~Simulator() { }
-
-            const Dynamics& dynamics() const { return _dynamics; }
-
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                common::Simulator<Time>::restore(state);
-                _dynamics.restore(state);
-            }
-
-            virtual void save(common::context::State<Time>& state) const
-            {
-                common::Simulator<Time>::save(state);
-                _dynamics.save(state);
-            }
-
-            virtual std::string to_string(int level) const
-            {
-                std::ostringstream ss;
-
-                ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
-                   << type::get_name() << "\"" << std::endl;
-                return ss.str();
-            }
-
-            virtual void finish(const typename Time::type& t)
-            {
+namespace pdevs {
+
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time> {
+  typedef Simulator<Time, Dynamics, Parameters> type;
+
+public :
+  Simulator(const std::string &name, const Parameters &parameters)
+      :
+      common::Model<Time>(name),
+      common::Simulator<Time>(name),
+      _dynamics(name, Context<Time, Dynamics, Parameters>(parameters, this)) {}
+
+  ~Simulator() {}
+
+  const Dynamics &dynamics() const { return _dynamics; }
+
+  virtual void restore(const common::context::State<Time> &state) {
+    common::Simulator<Time>::restore(state);
+    _dynamics.restore(state);
+  }
+
+  virtual void save(common::context::State<Time> &state) const {
+    common::Simulator<Time>::save(state);
+    _dynamics.save(state);
+  }
+
+  virtual std::string to_string(int level) const {
+    std::ostringstream ss;
+
+    ss << common::String::make_spaces(level * 2) << "p-devs simulator \""
+       << type::get_name() << "\"" << std::endl;
+    return ss.str();
+  }
+
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #else
 #else
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 //                When i-message(t)
 //                When i-message(t)
 //                  tl = t - e
 //                  tl = t - e
 //                  tn = tl + ta(s)
 //                  tn = tl + ta(s)
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _dynamics.start(t);
-                type::_tl = t;
+    _dynamics.start(t);
+    type::_tl = t;
 
 
-                typename Time::type duration = _dynamics.ta(t);
+    typename Time::type duration = _dynamics.ta(t);
 
 
-                assert(duration >= 0);
+    assert(duration >= 0);
 
 
-                type::_tn = type::_tl + duration;
+    type::_tn = type::_tl + duration;
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::I_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::I_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            common::Value observe(const typename Time::type& t, unsigned int index) const
-            {
-                return _dynamics.observe(t, index);
-            }
+  common::Value observe(const typename Time::type &t, unsigned int index) const {
+    return _dynamics.observe(t, index);
+  }
 
 
-            virtual std::string observable_name(unsigned int observable_index) const
-            {
-                return _dynamics.observable_name(observable_index);
-            }
+  virtual std::string observable_name(unsigned int observable_index) const {
+    return _dynamics.observable_name(observable_index);
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 //                When *-message(t)
 //                When *-message(t)
 //                  if (t = tn) then
 //                  if (t = tn) then
 //                    y = lambda(s)
 //                    y = lambda(s)
@@ -148,70 +140,68 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": BEFORE";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": BEFORE";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    common::Bag<Time> bag = _dynamics.lambda(t);
+    if (t == type::_tn) {
+      common::Bag<Time> bag = _dynamics.lambda(t);
 
 
-                    if (not bag.empty()) {
-                        for (auto& event : bag) {
-                            event.set_model(this);
-                        }
-                        dynamic_cast < common::Coordinator<Time>* >(
-                                type::get_parent())->dispatch_events(bag, t);
-                    }
-                }
+      if (not bag.empty()) {
+        for (auto &event : bag) {
+          event.set_model(this);
+        }
+        dynamic_cast < common::Coordinator<Time> * >(
+            type::get_parent())->dispatch_events(bag, t);
+      }
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::OUTPUT,
-                                common::LevelType::FORMALISM)
-                                << ": AFTER";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::OUTPUT,
+                    common::LevelType::FORMALISM)
+                    << ": AFTER";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            void post_event(const typename Time::type& t, const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t, const common::ExternalEvent<Time> &event) {
 
 
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #else
 #else
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
+    type::add_event(event);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::POST_EVENT,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::POST_EVENT,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 //                When x-message(t)
 //                When x-message(t)
 //                  if (x is empty and t = tn) then
 //                  if (x is empty and t = tn) then
 //                    s = delta_int(s)
 //                    s = delta_int(s)
@@ -225,57 +215,58 @@ namespace artis {
 //                End
 //                End
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(type::_tl <= t and t <= type::_tn);
+    assert(type::_tl <= t and t <= type::_tn);
 
 
-                if (t == type::_tn) {
-                    if (type::event_number() == 0) {
-                        _dynamics.dint(t);
-                    } else {
-                        _dynamics.dconf(t, t - type::_tl, type::get_bag());
-                    }
-                } else {
-                    _dynamics.dext(t, t - type::_tl, type::get_bag());
-                }
-                type::_tl = t;
+    if (t == type::_tn) {
+      if (type::event_number() == 0) {
+        _dynamics.dint(t);
+      } else {
+        _dynamics.dconf(t, t - type::_tl, type::get_bag());
+      }
+    } else {
+      _dynamics.dext(t, t - type::_tl, type::get_bag());
+    }
+    type::_tl = t;
 
 
-                typename Time::type duration = _dynamics.ta(t);
+    typename Time::type duration = _dynamics.ta(t);
 
 
-                assert(duration >= 0);
+    assert(duration >= 0);
 
 
-                type::_tn = type::_tl + duration;
-                type::clear_bag();
+    type::_tn = type::_tl + duration;
+    type::clear_bag();
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::PDEVS,
-                                common::FunctionType::S_MESSAGE,
-                                common::LevelType::FORMALISM)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::PDEVS,
+                    common::FunctionType::S_MESSAGE,
+                    common::LevelType::FORMALISM)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            typename Time::type lookahead(const typename Time::type& t) const
-            { return _dynamics.lookahead(t); }
+  typename Time::type lookahead(const typename Time::type &t) const {
+    return _dynamics.lookahead(t);
+  }
 
 
-        private :
-            Dynamics _dynamics;
-        };
+private :
+  Dynamics _dynamics;
+};
 
 
-    }
+}
 } // namespace artis pdevs
 } // namespace artis pdevs
 
 
 #endif
 #endif

+ 30 - 31
src/artis-star/kernel/pdevs/mpi/Coordinator.hpp

@@ -25,48 +25,47 @@
  */
  */
 
 
 #ifndef PDEVS_MPI_COORDINATOR
 #ifndef PDEVS_MPI_COORDINATOR
-#define PDEVS_MPI_COORDINATOR 1
+#define PDEVS_MPI_COORDINATOR
 
 
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp>
 #include <artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-        namespace mpi {
+namespace pdevs {
+namespace mpi {
 
 
-            template<class Time,
-                    class GraphManager,
-                    class Parameters = common::NoParameters,
-                    class GraphParameters = common::NoParameters>
-            class Coordinator : public pdevs::Coordinator<Time, GraphManager,
-                    Parameters, GraphParameters> {
-                typedef pdevs::Coordinator<Time, GraphManager,
-                        Parameters, GraphParameters> parent_type;
-                typedef Coordinator<Time, GraphManager,
-                        Parameters, GraphParameters> type;
+template<class Time,
+    class GraphManager,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class Coordinator : public pdevs::Coordinator<Time, GraphManager,
+                                              Parameters, GraphParameters> {
+  typedef pdevs::Coordinator<Time, GraphManager,
+                             Parameters, GraphParameters> parent_type;
+  typedef Coordinator<Time, GraphManager,
+                      Parameters, GraphParameters> type;
 
 
-            public:
-                Coordinator(const std::string& name,
-                        const Parameters& parameters,
-                        const GraphParameters& graph_parameters)
-                        :
-                        common::Model<Time>(name),
-                        pdevs::Coordinator<Time, GraphManager,
-                                Parameters, GraphParameters>(name, parameters,
-                                graph_parameters) { }
+public:
+  Coordinator(const std::string &name,
+              const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      pdevs::Coordinator<Time, GraphManager,
+                         Parameters, GraphParameters>(name, parameters,
+                                                      graph_parameters) {}
 
 
-                virtual ~Coordinator() { }
+  virtual ~Coordinator() {}
 
 
-                virtual bool is_remote() const { return true; }
+  virtual bool is_remote() const { return true; }
 
 
-                void set_logical_processor(LogicalProcessor<Time>* logical_processor)
-                {
-                    parent_type::_graph_manager.set_logical_processor(logical_processor);
-                }
-            };
+  void set_logical_processor(LogicalProcessor<Time> *logical_processor) {
+    parent_type::_graph_manager.set_logical_processor(logical_processor);
+  }
+};
 
 
-        }
-    }
+}
+}
 } // namespace artis pdevs mpi
 } // namespace artis pdevs mpi
 
 
 #endif
 #endif

+ 26 - 24
src/artis-star/kernel/pdevs/mpi/GraphManager.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef PDEVS_MPI_GRAPH_MANAGER
 #ifndef PDEVS_MPI_GRAPH_MANAGER
-#define PDEVS_MPI_GRAPH_MANAGER 1
+#define PDEVS_MPI_GRAPH_MANAGER
 
 
 #include <artis-star/kernel/pdevs/mpi/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/mpi/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp>
 #include <artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp>
@@ -33,35 +33,37 @@
 #include <sstream>
 #include <sstream>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-        namespace mpi {
+namespace pdevs {
+namespace mpi {
 
 
-            template<class Time,
-                    class Parameters = common::NoParameters,
-                    class GraphParameters = common::NoParameters>
-            class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
-            public:
-                GraphManager(common::Coordinator<Time>* coordinator,
-                        const Parameters& parameters,
-                        const GraphParameters& graph_parameters)
-                        :
-                        pdevs::GraphManager<Time, GraphParameters>(coordinator, parameters, graph_parameters) { }
+template<class Time,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public pdevs::GraphManager<Time, Parameters, GraphParameters> {
+public:
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const Parameters &parameters,
+               const GraphParameters &graph_parameters)
+      :
+      pdevs::GraphManager<Time, GraphParameters>(coordinator, parameters, graph_parameters) {}
 
 
-                virtual ~GraphManager() { }
+  virtual ~GraphManager() {}
 
 
-                virtual void dispatch_events_to_parent(common::Node<Time> node,
-                        const common::Value& content,
-                        typename Time::type t) { _logical_processor->dispatch_events_to_parent(node, content, t); }
+  virtual void dispatch_events_to_parent(common::Node<Time> node,
+                                         const common::Value &content,
+                                         typename Time::type t) {
+    _logical_processor->dispatch_events_to_parent(node, content, t);
+  }
 
 
-                void set_logical_processor(
-                        LogicalProcessor<Time>* logical_processor) { _logical_processor = logical_processor; }
+  void set_logical_processor(
+      LogicalProcessor<Time> *logical_processor) { _logical_processor = logical_processor; }
 
 
-            private:
-                LogicalProcessor<Time>* _logical_processor;
-            };
+private:
+  LogicalProcessor<Time> *_logical_processor;
+};
 
 
-        }
-    }
+}
+}
 } // namespace artis pdevs mpi
 } // namespace artis pdevs mpi
 
 
 #endif
 #endif

+ 72 - 78
src/artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp

@@ -25,91 +25,85 @@
  */
  */
 
 
 #ifndef PDEVS_MPI_LOGICAL_PROCESSOR
 #ifndef PDEVS_MPI_LOGICAL_PROCESSOR
-#define PDEVS_MPI_LOGICAL_PROCESSOR 1
+#define PDEVS_MPI_LOGICAL_PROCESSOR
 
 
 #include <artis-star/kernel/pdevs/mpi/ModelProxy.hpp>
 #include <artis-star/kernel/pdevs/mpi/ModelProxy.hpp>
 
 
 #include <boost/mpi/communicator.hpp>
 #include <boost/mpi/communicator.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-        namespace mpi {
-
-            template<class Time>
-            class LogicalProcessor {
-                typedef LogicalProcessor<Time> type;
-
-            public:
-                LogicalProcessor(common::Model<Time>* model, int rank, int parent)
-                        :
-                        _rank(rank),
-                        _parent(parent),
-                        _model(model) { }
-
-                virtual ~LogicalProcessor() { }
-
-                void dispatch_events_to_parent(common::Node<Time> node,
-                        const common::Value& content,
-                        typename Time::type t)
-                {
-                    (void) t;
-
-                    _output_bag.push_back(
-                            common::ExternalEvent<Time>(node, content));
-                }
-
-                void loop()
-                {
-                    typename Time::type t;
-
-                    for (;;) {
-                        boost::mpi::status msg = _communicator.probe();
-
-                        switch (msg.tag()) {
-                        case finish_send_tag:
-                            return;
-                        case output_send_tag: {
-                            _communicator.recv(_parent, output_send_tag, t);
-                            _model->output(t);
-                            _communicator.send(_parent, output_receive_tag,
-                                    _output_bag);
-                            _output_bag.clear();
-                            break;
-                        }
-                        case post_event_send_tag: {
-                            common::ExternalEvent<Time> event;
-
-                            _communicator.recv(_parent, post_event_send_tag, t);
-                            _communicator.recv(_parent, post_event_send_tag, event);
-                            _model->post_event(t, event);
-                            break;
-                        }
-                        case start_send_tag:
-                            _communicator.recv(_parent, start_send_tag, t);
-                            _communicator.send(_parent, tn_receive_tag,
-                                    _model->start(t));
-                            break;
-                        case transition_send_tag:
-                            _communicator.recv(_parent, transition_send_tag, t);
-                            _communicator.send(_parent, tn_receive_tag,
-                                    _model->transition(t));
-                            break;
-                        default:
-                            throw std::runtime_error("Invalid tag");
-                        }
-                    }
-                };
-
-            private:
-                int _rank;
-                int _parent;
-                boost::mpi::communicator _communicator;
-                common::Model<Time>* _model;
-                common::Bag<Time> _output_bag;
-            };
-
-        }
+namespace pdevs {
+namespace mpi {
+
+template<class Time>
+class LogicalProcessor {
+  typedef LogicalProcessor<Time> type;
+
+public:
+  LogicalProcessor(common::Model<Time> *model, int rank, int parent)
+      :
+      _rank(rank),
+      _parent(parent),
+      _model(model) {}
+
+  virtual ~LogicalProcessor() {}
+
+  void dispatch_events_to_parent(common::Node<Time> node,
+                                 const common::Value &content,
+                                 typename Time::type t) {
+    (void) t;
+
+    _output_bag.push_back(
+        common::ExternalEvent<Time>(node, content));
+  }
+
+  void loop() {
+    typename Time::type t;
+
+    for (;;) {
+      boost::mpi::status msg = _communicator.probe();
+
+      switch (msg.tag()) {
+      case finish_send_tag:return;
+      case output_send_tag: {
+        _communicator.recv(_parent, output_send_tag, t);
+        _model->output(t);
+        _communicator.send(_parent, output_receive_tag,
+                           _output_bag);
+        _output_bag.clear();
+        break;
+      }
+      case post_event_send_tag: {
+        common::ExternalEvent<Time> event;
+
+        _communicator.recv(_parent, post_event_send_tag, t);
+        _communicator.recv(_parent, post_event_send_tag, event);
+        _model->post_event(t, event);
+        break;
+      }
+      case start_send_tag:_communicator.recv(_parent, start_send_tag, t);
+        _communicator.send(_parent, tn_receive_tag,
+                           _model->start(t));
+        break;
+      case transition_send_tag:_communicator.recv(_parent, transition_send_tag, t);
+        _communicator.send(_parent, tn_receive_tag,
+                           _model->transition(t));
+        break;
+      default:throw std::runtime_error("Invalid tag");
+      }
     }
     }
+  };
+
+private:
+  int _rank;
+  int _parent;
+  boost::mpi::communicator _communicator;
+  common::Model<Time> *_model;
+  common::Bag<Time> _output_bag;
+};
+
+}
+}
 } // namespace artis pdevs mpi
 } // namespace artis pdevs mpi
 
 
 #endif
 #endif

+ 123 - 133
src/artis-star/kernel/pdevs/mpi/ModelProxy.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef PDEVS_MPI_MODEL_PROXY
 #ifndef PDEVS_MPI_MODEL_PROXY
-#define PDEVS_MPI_MODEL_PROXY 1
+#define PDEVS_MPI_MODEL_PROXY
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Model.hpp>
@@ -33,142 +33,132 @@
 #include <boost/mpi/communicator.hpp>
 #include <boost/mpi/communicator.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-        namespace mpi {
-
-            enum Tags {
-                finish_send_tag,
-                output_send_tag,
-                post_event_send_tag,
-                start_send_tag,
-                transition_send_tag,
-                output_receive_tag,
-                tn_receive_tag
-            };
-
-            template<class Time>
-            class ModelProxy : public common::Model<Time> {
-                typedef common::Model<Time> parent_type;
-                typedef ModelProxy<Time> type;
-
-            public:
-                ModelProxy(const std::string& name, int rank, bool atomic)
-                        :
-                        common::Model<Time>(name), _atomic(atomic), _rank(rank) { }
-
-                virtual ~ModelProxy() { _communicator.send(_rank, finish_send_tag); }
-
-                virtual bool is_atomic() const { return _atomic; }
-
-                virtual void restore(const common::context::State<Time>& state)
-                {
+namespace pdevs {
+namespace mpi {
+
+enum Tags {
+  finish_send_tag,
+  output_send_tag,
+  post_event_send_tag,
+  start_send_tag,
+  transition_send_tag,
+  output_receive_tag,
+  tn_receive_tag
+};
+
+template<class Time>
+class ModelProxy : public common::Model<Time> {
+  typedef common::Model<Time> parent_type;
+  typedef ModelProxy<Time> type;
+
+public:
+  ModelProxy(const std::string &name, int rank, bool atomic)
+      :
+      common::Model<Time>(name), _atomic(atomic), _rank(rank) {}
+
+  virtual ~ModelProxy() { _communicator.send(_rank, finish_send_tag); }
+
+  virtual bool is_atomic() const { return _atomic; }
+
+  virtual void restore(const common::context::State<Time> &state) {
 // TODO
 // TODO
-                }
+  }
 
 
-                virtual void save(common::context::State<Time>& state) const
-                {
+  virtual void save(common::context::State<Time> &state) const {
 // TODO
 // TODO
-                }
-
-                virtual std::string to_string(int level) const
-                {
-                    (void) level;
-
-                    return std::string();
-                }
-
-                virtual void finish(const typename Time::type& /* t */)
-                { }
-
-                virtual common::Value observe(const typename Time::type& t,
-                        unsigned int index) const
-                {
-                    (void) t;
-                    (void) index;
-
-                    assert(false);
-
-                    return common::Value();
-                }
-
-                virtual void output(const typename Time::type& t)
-                {
-                    try {
-                        typename common::Bag<Time> bag;
-
-                        _communicator.send(_rank, output_send_tag, t);
-                        _communicator.recv(_rank, output_receive_tag, bag);
-                        dispatch_events(bag, t);
-                    }
-                    catch (const boost::mpi::exception& e) {
-                        std::cout << e.what() << std::endl;
-                    }
-                }
-
-                virtual void post_event(const typename Time::type& t,
-                        const common::ExternalEvent<Time>& event)
-                {
-                    try {
-                        _communicator.send(_rank, post_event_send_tag, t);
-                        _communicator.send(_rank, post_event_send_tag, event);
-                    }
-                    catch (const boost::mpi::exception& e) {
-                        std::cout << e.what() << std::endl;
-                    }
-                }
-
-                virtual typename Time::type dispatch_events(common::Bag<Time>& bag,
-                        const typename Time::type& t)
-                {
-                    for (auto& event : bag) {
-                        event.set_model(this);
-                    }
-                    return dynamic_cast < common::Coordinator<Time>* >(
-                            parent_type::get_parent())->dispatch_events(bag, t);
-                }
-
-                virtual typename Time::type start(const typename Time::type& t)
-                {
-                    try {
-                        _communicator.send(_rank, start_send_tag, t);
-
-                        typename Time::type tn;
-
-                        _communicator.recv(_rank, tn_receive_tag, tn);
-                        type::_tl = t;
-                        type::_tn = tn;
-                    }
-                    catch (const boost::mpi::exception& e) {
-                        std::cout << e.what() << std::endl;
-                    }
-                    return type::_tn;
-                }
-
-                virtual typename Time::type transition(const typename Time::type& t)
-                {
-                    try {
-                        _communicator.send(_rank, transition_send_tag, t);
-
-                        typename Time::type tn;
-
-                        _communicator.recv(_rank, tn_receive_tag, tn);
-                        type::_tl = t;
-                        type::_tn = tn;
-                    }
-                    catch (const boost::mpi::exception& e) {
-                        std::cout << e.what() << std::endl;
-                    }
-                    return type::_tn;
-                }
-
-            private:
-                bool _atomic;
-                boost::mpi::communicator _communicator;
-                int _rank;
-            };
-
-        }
+  }
+
+  virtual std::string to_string(int level) const {
+    (void) level;
+
+    return std::string();
+  }
+
+  virtual void finish(const typename Time::type & /* t */) {}
+
+  virtual common::Value observe(const typename Time::type &t,
+                                unsigned int index) const {
+    (void) t;
+    (void) index;
+
+    assert(false);
+
+    return common::Value();
+  }
+
+  virtual void output(const typename Time::type &t) {
+    try {
+      typename common::Bag<Time> bag;
+
+      _communicator.send(_rank, output_send_tag, t);
+      _communicator.recv(_rank, output_receive_tag, bag);
+      dispatch_events(bag, t);
+    }
+    catch (const boost::mpi::exception &e) {
+      std::cout << e.what() << std::endl;
+    }
+  }
+
+  virtual void post_event(const typename Time::type &t,
+                          const common::ExternalEvent<Time> &event) {
+    try {
+      _communicator.send(_rank, post_event_send_tag, t);
+      _communicator.send(_rank, post_event_send_tag, event);
+    }
+    catch (const boost::mpi::exception &e) {
+      std::cout << e.what() << std::endl;
+    }
+  }
+
+  virtual typename Time::type dispatch_events(common::Bag<Time> &bag,
+                                              const typename Time::type &t) {
+    for (auto &event : bag) {
+      event.set_model(this);
     }
     }
+    return dynamic_cast < common::Coordinator<Time> * >(
+        parent_type::get_parent())->dispatch_events(bag, t);
+  }
+
+  virtual typename Time::type start(const typename Time::type &t) {
+    try {
+      _communicator.send(_rank, start_send_tag, t);
+
+      typename Time::type tn;
+
+      _communicator.recv(_rank, tn_receive_tag, tn);
+      type::_tl = t;
+      type::_tn = tn;
+    }
+    catch (const boost::mpi::exception &e) {
+      std::cout << e.what() << std::endl;
+    }
+    return type::_tn;
+  }
+
+  virtual typename Time::type transition(const typename Time::type &t) {
+    try {
+      _communicator.send(_rank, transition_send_tag, t);
+
+      typename Time::type tn;
+
+      _communicator.recv(_rank, tn_receive_tag, tn);
+      type::_tl = t;
+      type::_tn = tn;
+    }
+    catch (const boost::mpi::exception &e) {
+      std::cout << e.what() << std::endl;
+    }
+    return type::_tn;
+  }
+
+private:
+  bool _atomic;
+  boost::mpi::communicator _communicator;
+  int _rank;
+};
+
+}
+}
 } // namespace artis pdevs mpi
 } // namespace artis pdevs mpi
 
 
 #endif
 #endif

+ 198 - 202
src/artis-star/kernel/pdevs/multithreading/Coordinator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef PDEVS_MULTITHREADING_COORDINATOR
 #ifndef PDEVS_MULTITHREADING_COORDINATOR
-#define PDEVS_MULTITHREADING_COORDINATOR 1
+#define PDEVS_MULTITHREADING_COORDINATOR
 
 
 #include <artis-star/common/utils/Multithreading.hpp>
 #include <artis-star/common/utils/Multithreading.hpp>
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
@@ -33,210 +33,206 @@
 #include <thread>
 #include <thread>
 
 
 namespace artis {
 namespace artis {
-    namespace pdevs {
-        namespace multithreading {
-
-            template<class Time>
-            struct start_message {
-                explicit start_message(typename Time::type t)
-                        :_t(t) { }
-
-                typename Time::type _t;
-            };
-
-            template<class Time>
-            struct transition_message {
-                explicit transition_message(typename Time::type t)
-                        :_t(t) { }
-
-                typename Time::type _t;
-            };
-
-            template<class Time>
-            struct done_start_message {
-                explicit done_start_message(typename Time::type tn,
-                        common::Model<Time>* child)
-                        :
-                        _tn(tn), _child(child) { }
-
-                typename Time::type _tn;
-                common::Model<Time>* _child;
-            };
-
-            template<class Time>
-            struct done_transition_message {
-                explicit done_transition_message(typename Time::type tn,
-                        common::Model<Time>* child)
-                        :
-                        _tn(tn), _child(child) { }
-
-                typename Time::type _tn;
-                common::Model<Time>* _child;
-            };
-
-            template<class Time,
-                    class GraphManager,
-                    class Parameters = common::NoParameters,
-                    class GraphParameters = common::NoParameters>
-            class Coordinator
-                    : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters> {
-                typedef pdevs::Coordinator<Time, GraphManager,
-                        Parameters, GraphParameters> parent_type;
-                typedef Coordinator<Time, GraphManager,
-                        Parameters, GraphParameters> type;
-                typedef done_start_message<Time> done_start_message_type;
-                typedef start_message<Time> start_message_type;
-                typedef done_transition_message<Time> done_transition_message_type;
-                typedef transition_message<Time> transition_message_type;
-
-            public:
-                Coordinator(const std::string& name, const Parameters& parameters,
-                        const GraphParameters& graph_parameters)
-                        :
-                        common::Model<Time>(name),
-                        pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(
-                                name, parameters, graph_parameters)
-                {
-                    type::_graph_manager.init();
-                    _thread = new std::thread([&] { loop(); });
-                }
-
-                virtual ~Coordinator()
-                {
-                    done();
-                    _thread->join();
-                    delete _thread;
-                }
-
-                void done() { get_sender().send(artis::common::Close()); }
-
-                artis::common::Sender get_sender() { return _incoming.get_sender(); }
-
-                void set_sender(common::Sender sender) { _sender = sender; }
-
-                void loop()
-                {
-                    try {
-                        for (;;) {
-                            _incoming.wait()
-                                    .template handle<start_message_type>(
-                                             [&](start_message_type const& msg) {
-                                                typename Time::type tn = start(msg._t);
-                                                _sender.send(done_start_message_type(tn, this));
-                                            })
-                                    .
-                                            template handle<done_start_message_type>(
-                                            [&](done_start_message_type const& msg) {
-                                                type::_event_table.init(msg._tn, msg._child);
-                                                --_received;
-                                                if (_received == 0) {
-                                                    _received_mutex.unlock();
-                                                }
-                                            })
-                                    .
-                                            template handle<transition_message_type>(
-                                            [&](transition_message_type const& msg) {
-                                                typename Time::type tn = transition(msg._t);
-                                                _sender.send(done_transition_message_type(tn,
-                                                        this));
-                                            })
-                                    .
-                                            template handle<done_transition_message_type>(
-                                            [&](done_transition_message_type const& msg) {
-                                                type::_event_table.put(msg._tn, msg._child);
-                                                --_received;
-                                                if (_received == 0) {
-                                                    _received_mutex.unlock();
-                                                }
-                                            });
-                        }
-                    }
-                    catch (artis::common::Close const&) { }
-                }
-
-                typename Time::type start(const typename Time::type& t)
-                {
-                    _received = 0;
-                    for (auto& child : parent_type::_graph_manager.children()) {
-                        if (child->is_atomic()) {
-                            type::_event_table.init(child->start(type::_tn), child);
-                        } else {
-                            ++_received;
-                        }
-                    }
-
-                    if (_received > 0) {
-                        _received_mutex.lock();
-                        type::_graph_manager.start(t);
-
-                        std::lock_guard<std::mutex> lock(_received_mutex);
-                    }
-
-                    type::_tl = t;
-                    type::_tn = type::_event_table.get_current_time();
-                    return type::_tn;
-                }
-
-                // TODO: to remove
-                virtual int get_receiver_number(typename Time::type t)
-                {
-                    return type::_event_table.get_current_models(t).size();
-                }
-
-                typename Time::type transition(const typename Time::type& t)
-                {
-                    assert(t >= type::_tl and t <= type::_tn);
-
-                    common::Models<Time> receivers = type::get_receivers();
-//                    common::Models<Time> IMM = type::_event_table.get_current_models(t);
-                    common::Models<Time> IMM = type::_event_table.get_current_models(t,
-                            type::_graph_manager.lookahead(t));
-
-                    _received = 0;
-                    for (auto& model : receivers) {
-                        if (model->is_atomic()) {
-                            type::_event_table.put(model->transition(t), model);
-                        } else {
-                            ++_received;
-                        }
-                    }
-                    for (auto& model : IMM) {
-                        if (std::find(receivers.begin(), receivers.end(),
-                                model) == receivers.end()) {
-                            if (model->is_atomic()) {
-                                type::_event_table.put(model->transition(t), model);
-                            } else {
-                                ++_received;
-                            }
-                        }
-                    }
-
-                    if (_received > 0) {
-                        _received_mutex.lock();
-                        type::_graph_manager.transition(receivers, t);
-                        type::_graph_manager.transition(IMM, t);
-
-                        std::lock_guard<std::mutex> lock(_received_mutex);
-                    }
-
-                    parent_type::update_event_table(t);
-                    type::_tl = t;
-                    type::_tn = type::_event_table.get_current_time();
-                    type::clear_bag();
-
-                    return type::_tn;
-                }
-
-            private:
-                std::thread* _thread;
-                artis::common::Receiver _incoming;
-                artis::common::Sender _sender;
-                unsigned int _received;
-                std::mutex _received_mutex;
-            };
+namespace pdevs {
+namespace multithreading {
+
+template<class Time>
+struct start_message {
+  explicit start_message(typename Time::type t)
+      : _t(t) {}
+
+  typename Time::type _t;
+};
+
+template<class Time>
+struct transition_message {
+  explicit transition_message(typename Time::type t)
+      : _t(t) {}
+
+  typename Time::type _t;
+};
+
+template<class Time>
+struct done_start_message {
+  explicit done_start_message(typename Time::type tn,
+                              common::Model<Time> *child)
+      :
+      _tn(tn), _child(child) {}
+
+  typename Time::type _tn;
+  common::Model<Time> *_child;
+};
+
+template<class Time>
+struct done_transition_message {
+  explicit done_transition_message(typename Time::type tn,
+                                   common::Model<Time> *child)
+      :
+      _tn(tn), _child(child) {}
+
+  typename Time::type _tn;
+  common::Model<Time> *_child;
+};
+
+template<class Time,
+    class GraphManager,
+    class Parameters = common::NoParameters,
+    class GraphParameters = common::NoParameters>
+class Coordinator
+    : public pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters> {
+  typedef pdevs::Coordinator<Time, GraphManager,
+                             Parameters, GraphParameters> parent_type;
+  typedef Coordinator<Time, GraphManager,
+                      Parameters, GraphParameters> type;
+  typedef done_start_message<Time> done_start_message_type;
+  typedef start_message<Time> start_message_type;
+  typedef done_transition_message<Time> done_transition_message_type;
+  typedef transition_message<Time> transition_message_type;
+
+public:
+  Coordinator(const std::string &name, const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      pdevs::Coordinator<Time, GraphManager, Parameters, GraphParameters>(
+          name, parameters, graph_parameters) {
+    type::_graph_manager.init();
+    _thread = new std::thread([&] { loop(); });
+  }
+
+  virtual ~Coordinator() {
+    done();
+    _thread->join();
+    delete _thread;
+  }
+
+  void done() { get_sender().send(artis::common::Close()); }
+
+  artis::common::Sender get_sender() { return _incoming.get_sender(); }
+
+  void set_sender(common::Sender sender) { _sender = sender; }
+
+  void loop() {
+    try {
+      for (;;) {
+        _incoming.wait()
+            .template handle<start_message_type>(
+                [&](start_message_type const &msg) {
+                  typename Time::type tn = start(msg._t);
+                  _sender.send(done_start_message_type(tn, this));
+                })
+            .
+                template handle<done_start_message_type>(
+                [&](done_start_message_type const &msg) {
+                  type::_event_table.init(msg._tn, msg._child);
+                  --_received;
+                  if (_received == 0) {
+                    _received_mutex.unlock();
+                  }
+                })
+            .
+                template handle<transition_message_type>(
+                [&](transition_message_type const &msg) {
+                  typename Time::type tn = transition(msg._t);
+                  _sender.send(done_transition_message_type(tn,
+                                                            this));
+                })
+            .
+                template handle<done_transition_message_type>(
+                [&](done_transition_message_type const &msg) {
+                  type::_event_table.put(msg._tn, msg._child);
+                  --_received;
+                  if (_received == 0) {
+                    _received_mutex.unlock();
+                  }
+                });
+      }
+    }
+    catch (artis::common::Close const &) {
+    }
+  }
+
+  typename Time::type start(const typename Time::type &t) {
+    _received = 0;
+    for (auto &child : parent_type::_graph_manager.children()) {
+      if (child->is_atomic()) {
+        type::_event_table.init(child->start(type::_tn), child);
+      } else {
+        ++_received;
+      }
+    }
+
+    if (_received > 0) {
+      _received_mutex.lock();
+      type::_graph_manager.start(t);
+
+      std::lock_guard<std::mutex> lock(_received_mutex);
+    }
+
+    type::_tl = t;
+    type::_tn = type::_event_table.get_current_time();
+    return type::_tn;
+  }
+
+  // TODO: to remove
+  virtual int get_receiver_number(typename Time::type t) {
+    return type::_event_table.get_current_models(t).size();
+  }
+
+  typename Time::type transition(const typename Time::type &t) {
+    assert(t >= type::_tl and t <= type::_tn);
 
 
+    common::Models<Time> receivers = type::get_receivers();
+//                    common::Models<Time> IMM = type::_event_table.get_current_models(t);
+    common::Models<Time> IMM = type::_event_table.get_current_models(t,
+                                                                     type::_graph_manager
+                                                                         .lookahead(t));
+
+    _received = 0;
+    for (auto &model : receivers) {
+      if (model->is_atomic()) {
+        type::_event_table.put(model->transition(t), model);
+      } else {
+        ++_received;
+      }
+    }
+    for (auto &model : IMM) {
+      if (std::find(receivers.begin(), receivers.end(),
+                    model) == receivers.end()) {
+        if (model->is_atomic()) {
+          type::_event_table.put(model->transition(t), model);
+        } else {
+          ++_received;
         }
         }
+      }
+    }
+
+    if (_received > 0) {
+      _received_mutex.lock();
+      type::_graph_manager.transition(receivers, t);
+      type::_graph_manager.transition(IMM, t);
+
+      std::lock_guard<std::mutex> lock(_received_mutex);
     }
     }
+
+    parent_type::update_event_table(t);
+    type::_tl = t;
+    type::_tn = type::_event_table.get_current_time();
+    type::clear_bag();
+
+    return type::_tn;
+  }
+
+private:
+  std::thread *_thread;
+  artis::common::Receiver _incoming;
+  artis::common::Sender _sender;
+  unsigned int _received;
+  std::mutex _received_mutex;
+};
+
+}
+}
 } // namespace artis pdevs multithreading
 } // namespace artis pdevs multithreading
 
 
 #endif
 #endif

+ 12 - 12
src/artis-star/kernel/qss/Data.hpp

@@ -28,22 +28,22 @@
 #define QSS_DATA
 #define QSS_DATA
 
 
 namespace artis {
 namespace artis {
-    namespace qss {
+namespace qss {
 
 
-        struct IntegratorData {
-            double value;
-        };
+struct IntegratorData {
+  double value;
+};
 
 
-        struct DerivativeData {
-            double x_dot;
-        };
+struct DerivativeData {
+  double x_dot;
+};
 
 
-        struct QuantifierData {
-            double up;
-            double down;
-        };
+struct QuantifierData {
+  double up;
+  double down;
+};
 
 
-    }
+}
 }
 }
 
 
 #endif
 #endif

+ 158 - 175
src/artis-star/kernel/qss/Derivative.hpp

@@ -31,183 +31,166 @@
 #include <artis-star/kernel/qss/Data.hpp>
 #include <artis-star/kernel/qss/Data.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace qss {
-
-        template<class Time, class Dyn, class Parameters = common::NoParameters>
-        class Derivative : public artis::pdevs::Dynamics<Time, Dyn, Parameters> {
-            typedef enum {
-                INIT = 0, WAIT, RESPONSE
-            } State;
-
-        public:
-            enum inputs {
-                RESET = 0, IN
-            };
-
-            enum outputs {
-                OUT = 0
-            };
-
-            enum states {
-                STATE = 0, INPUT_NUMBER, OUTPUT_VALUE, LAST_OUTPUT
-            };
-
-            typedef Derivative<Time, Dyn, Parameters> type;
-
-            Derivative(const std::string& name, const artis::pdevs::Context<Time, Dyn, Parameters>& context)
-                    :
-                    artis::pdevs::Dynamics<Time, Dyn, Parameters>(name, context),
-                    _external_number(0), _internal_number(0)
-            {
-                DECLARE_STATES(int,
-                        ((STATE, &type::_state)));
-                DECLARE_STATES(unsigned int,
-                        ((INPUT_NUMBER, &type::_input_number)));
-                DECLARE_STATES(double,
-                        ((OUTPUT_VALUE, &type::_output_value),
-                                (LAST_OUTPUT, &type::_output_value)));
-
-                this->input_ports({{RESET, "reset"},
-                                   {IN,    "in"}});
-                this->output_port({OUT, "out"});
-            }
-
-            virtual ~Derivative() { }
-
-            int external(const std::string& name, double Dyn::* var)
-            {
-                ++_external_number;
-                this->state_(LAST_OUTPUT + _external_number + 1, name, var);
-                this->input_port({IN + _external_number, name});
-                return IN + _external_number;
-            }
-
-            void internal(const std::string& name, double Dyn::* var)
-            {
-                assert(_internal_number == 0);
-
-                ++_internal_number;
-                this->state_(LAST_OUTPUT + 1, name, var);
-            }
-
-            virtual double compute() const = 0;
-
-            virtual void dconf(const typename Time::type& t, typename Time::type e,
-                    const common::Bag<Time>& bag)
-            {
-                dint(t);
-                dext(t, e, bag);
-            }
-
-            virtual void dint(const typename Time::type& /* time */)
-            {
-                if (_state == RESPONSE) {
-                    _last_output = _output_value;
-                }
-                _state = WAIT;
-            }
-
-            virtual void dext(const typename Time::type& t, typename Time::type e,
-                    const common::Bag<Time>& bag)
-            {
-                std::for_each(bag.begin(), bag.end(),
-                        [this, t, e](const common::ExternalEvent<Time>& event) {
-                            if (event.on_port(RESET)) {
-                                if (_input_number == 0) {
-                                    _output_value = compute();
-                                    _state = RESPONSE;
-                                } else {
-                                    _state = INIT;
-                                }
-                            } else {
-                                IntegratorData data;
-
-                                event.data()(data);
-                                this->get((event.port_index() - 1) + LAST_OUTPUT + 1).put(
-                                        dynamic_cast<Dyn*>(this),
-                                        data.value);
-                                switch (_state) {
-                                case INIT:
-                                    if (_input_number
-                                            == this->state_number() - (LAST_OUTPUT + 1)) {
-                                        _output_value = compute();
-                                        _state = RESPONSE;
-                                    }
-                                    break;
-                                case WAIT:
-                                case RESPONSE:
-                                    double value = compute();
-
-                                    if (value != _last_output) {
-                                        _output_value = value;
-                                        _state = RESPONSE;
-                                    } else {
-                                        _state = WAIT;
-                                    }
-                                }
-                            }
-                        });
-            }
-
-            virtual void start(const typename Time::type& /* time */)
-            {
-                _input_number = this->input_port_number() - 1;
-                if (_input_number == 0) {
-                    _output_value = compute();
-                    _state = RESPONSE;
-                } else {
-                    _state = INIT;
-                }
-            }
-
-            virtual typename Time::type ta(const typename Time::type& /* time */)
-            {
-                switch (_state) {
-                case INIT:
-                    return Time::infinity;
-                case WAIT:
-                    return Time::infinity;
-                case RESPONSE:
-                    return 0;
-                }
-                return Time::infinity;
-            }
-
-            virtual common::Bag<Time> lambda(const typename Time::type& /* time */) const
-            {
-                common::Bag<Time> msgs;
-
-                switch (_state) {
-                case INIT:
-                    break;
-                case WAIT:
-                    break;
-                case RESPONSE:
-                    const DerivativeData data = {_output_value};
-
-                    msgs.push_back(common::ExternalEvent<Time>(OUT, data));
-                }
-                return msgs;
-            }
-
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int /* index */) const
-            {
-                return common::Value();
-            }
-
-        private:
-            unsigned int _external_number;
-            unsigned int _internal_number;
-
-            // state
-            int _state;
-            unsigned int _input_number;
-            double _output_value;
-            double _last_output;
-        };
+namespace qss {
+
+template<class Time, class Dyn, class Parameters = common::NoParameters>
+class Derivative : public artis::pdevs::Dynamics<Time, Dyn, Parameters> {
+  typedef enum {
+    INIT = 0, WAIT, RESPONSE
+  } State;
+
+public:
+  enum inputs {
+    RESET = 0, IN
+  };
+
+  enum outputs {
+    OUT = 0
+  };
+
+  enum states {
+    STATE = 0, INPUT_NUMBER, OUTPUT_VALUE, LAST_OUTPUT
+  };
+
+  typedef Derivative<Time, Dyn, Parameters> type;
+
+  Derivative(const std::string &name, const artis::pdevs::Context<Time, Dyn, Parameters> &context)
+      :
+      artis::pdevs::Dynamics<Time, Dyn, Parameters>(name, context),
+      _external_number(0), _internal_number(0) {
+    DECLARE_STATES(int,
+                   ((STATE, &type::_state)));
+    DECLARE_STATES(unsigned int,
+                   ((INPUT_NUMBER, &type::_input_number)));
+    DECLARE_STATES(double,
+                   ((OUTPUT_VALUE, &type::_output_value),
+                       (LAST_OUTPUT, &type::_output_value)));
+
+    this->input_ports({{RESET, "reset"},
+                       {IN, "in"}});
+    this->output_port({OUT, "out"});
+  }
+
+  virtual ~Derivative() {}
+
+  int external(const std::string &name, double Dyn::* var) {
+    ++_external_number;
+    this->state_(LAST_OUTPUT + _external_number + 1, name, var);
+    this->input_port({IN + _external_number, name});
+    return IN + _external_number;
+  }
+
+  void internal(const std::string &name, double Dyn::* var) {
+    assert(_internal_number == 0);
+
+    ++_internal_number;
+    this->state_(LAST_OUTPUT + 1, name, var);
+  }
+
+  virtual double compute() const = 0;
+
+  virtual void dconf(const typename Time::type &t, typename Time::type e,
+                     const common::Bag<Time> &bag) {
+    dint(t);
+    dext(t, e, bag);
+  }
+
+  virtual void dint(const typename Time::type & /* time */) {
+    if (_state == RESPONSE) {
+      _last_output = _output_value;
+    }
+    _state = WAIT;
+  }
+
+  virtual void dext(const typename Time::type &t, typename Time::type e,
+                    const common::Bag<Time> &bag) {
+    std::for_each(bag.begin(), bag.end(),
+                  [this, t, e](const common::ExternalEvent<Time> &event) {
+                    if (event.on_port(RESET)) {
+                      if (_input_number == 0) {
+                        _output_value = compute();
+                        _state = RESPONSE;
+                      } else {
+                        _state = INIT;
+                      }
+                    } else {
+                      IntegratorData data;
+
+                      event.data()(data);
+                      this->get((event.port_index() - 1) + LAST_OUTPUT + 1).put(
+                          dynamic_cast<Dyn *>(this),
+                          data.value);
+                      switch (_state) {
+                      case INIT:
+                        if (_input_number
+                            == this->state_number() - (LAST_OUTPUT + 1)) {
+                          _output_value = compute();
+                          _state = RESPONSE;
+                        }
+                        break;
+                      case WAIT:
+                      case RESPONSE:double value = compute();
+
+                        if (value != _last_output) {
+                          _output_value = value;
+                          _state = RESPONSE;
+                        } else {
+                          _state = WAIT;
+                        }
+                      }
+                    }
+                  });
+  }
+
+  virtual void start(const typename Time::type & /* time */) {
+    _input_number = this->input_port_number() - 1;
+    if (_input_number == 0) {
+      _output_value = compute();
+      _state = RESPONSE;
+    } else {
+      _state = INIT;
+    }
+  }
+
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
+    switch (_state) {
+    case INIT:return Time::infinity;
+    case WAIT:return Time::infinity;
+    case RESPONSE:return 0;
+    }
+    return Time::infinity;
+  }
+
+  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const {
+    common::Bag<Time> msgs;
+
+    switch (_state) {
+    case INIT:break;
+    case WAIT:break;
+    case RESPONSE:const DerivativeData data = {_output_value};
 
 
+      msgs.push_back(common::ExternalEvent<Time>(OUT, data));
     }
     }
+    return msgs;
+  }
+
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int /* index */) const {
+    return common::Value();
+  }
+
+private:
+  unsigned int _external_number;
+  unsigned int _internal_number;
+
+  // state
+  int _state;
+  unsigned int _input_number;
+  double _output_value;
+  double _last_output;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 242 - 258
src/artis-star/kernel/qss/Integrator.hpp

@@ -31,282 +31,266 @@
 #include <artis-star/kernel/qss/Data.hpp>
 #include <artis-star/kernel/qss/Data.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace qss {
-
-        struct IntegratorParameters {
-            double x_0;
-        };
-
-        template<class Time>
-        class Integrator
-                : public artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters> {
-
-            typedef enum {
-                INIT,
-                WAIT_FOR_QUANTA,
-                WAIT_FOR_X_DOT,
-                WAIT_FOR_BOTH,
-                RUNNING
-            } State;
-
-        public:
-            enum inputs {
-                QUANTA, X_DOT, RESET
-            };
-
-            enum outputs {
-                OUT
-            };
-
-            typedef enum vars {
-                VALUE
-            } Observable;
-
-            enum states {
-                STATE,
-                LAST_OUT_DATE,
-                UP_THRESHOLD,
-                DOWN_THRESHOLD,
-                LAST_OUT_VALUE,
-                INIT_VALUE,
-                CURRENT_VALUE,
-                EXPECTED_VALUE,
-                ARCHIVE_X_DOT,
-                ARCHIVE_DATE
-            };
-
-            Integrator(const std::string& name,
-                    const artis::pdevs::Context<Time, Integrator<Time>, IntegratorParameters>& context)
-                    :
-                    artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters>(name,
-                            context)
-            {
-                DECLARE_STATES(int, ((STATE, &Integrator<Time>::_state)));
-                DECLARE_STATES(typename Time::type,
-                        ((LAST_OUT_DATE, &Integrator<Time>::_last_output_date)));
-                DECLARE_STATES(double, ((UP_THRESHOLD, &Integrator<Time>::_up_threshold),
-                        (DOWN_THRESHOLD, &Integrator<Time>::_down_threshold),
-                        (LAST_OUT_VALUE, &Integrator<Time>::_last_output_value),
-                        (INIT_VALUE, &Integrator<Time>::_init_value),
-                        (CURRENT_VALUE, &Integrator<Time>::_current_value),
-                        (EXPECTED_VALUE, &Integrator<Time>::_expected_value)));
-                DECLARE_STATES(std::vector<double>,
-                        ((ARCHIVE_X_DOT, &Integrator<Time>::_archive_x_dot)));
-                DECLARE_STATES(std::vector<typename Time::type>,
-                        ((ARCHIVE_DATE, &Integrator<Time>::_archive_date)));
-
-                this->input_ports({
-                        {QUANTA, "quanta"},
-                        {X_DOT,  "x_dot"},
-                        {RESET,  "reset"}});
-                this->output_port({OUT, "out"});
-                this->observable({VALUE, "value"});
-
-                _init_value = context.parameters().x_0;
-            }
-
-            virtual ~Integrator() { }
-
-            virtual void dconf(typename Time::type t, typename Time::type e,
-                    const common::Bag<Time>& bag)
-            {
-                dint(t);
-                dext(t, e, bag);
-            }
-
-            virtual void dint(const typename Time::type& time)
-            {
-                switch (_state) {
-                case RUNNING: {
-                    double last_derivative_value = _archive_x_dot.back();
-
-                    _last_output_value = _expected_value;
-                    _last_output_date = time;
-                    _archive_x_dot.clear();
-                    _archive_date.clear();
-                    _archive_x_dot.push_back(last_derivative_value);
-                    _archive_date.push_back(time);
-                    _current_value = _expected_value;
-                    _state = WAIT_FOR_QUANTA;
-                    break;
-                }
-                case INIT: {
-                    _state = WAIT_FOR_BOTH;
-                    _last_output_value = _current_value;
-                    _last_output_date = time;
-                    break;
-                }
-                default:
-                    assert(false);
-                }
-            }
-
-            virtual void dext(const typename Time::type& t, const typename Time::type& e,
-                    const common::Bag<Time>& bag)
-            {
-                bool reset = false;
-
-                std::for_each(bag.begin(), bag.end(),
-                        [this, t, e, &reset](const common::ExternalEvent<Time>& event) {
-                            if (event.on_port(QUANTA)) {
-                                QuantifierData data;
-
-                                event.data()(data);
-                                _up_threshold = data.up;
-                                _down_threshold = data.down;
-                                if (_state == WAIT_FOR_QUANTA) {
-                                    _state = RUNNING;
-                                }
-                                if (_state == WAIT_FOR_BOTH) {
-                                    _state = WAIT_FOR_X_DOT;
-                                }
-                            } else if (event.on_port(X_DOT)) {
-                                DerivativeData data;
-
-                                event.data()(data);
-                                _archive_x_dot.push_back(data.x_dot);
-                                _archive_date.push_back(t);
-                                if (_state == WAIT_FOR_X_DOT) {
-                                    _state = RUNNING;
-                                }
-                                if (_state == WAIT_FOR_BOTH) {
-                                    _state = WAIT_FOR_QUANTA;
-                                }
-                            } else if (event.on_port(RESET)) {
-                                IntegratorData data;
-
-                                event.data()(data);
-                                _current_value = data.value;
-                                reset = true;
-                                _archive_x_dot.clear();
-                                _archive_date.clear();
-                            }
-                        });
-                if (reset) {
-                    _state = INIT;
-                } else {
-                    if (_state == RUNNING) {
-                        _current_value = current_value(t);
-                        _expected_value = expected_value(t);
+namespace qss {
+
+struct IntegratorParameters {
+  double x_0;
+};
+
+template<class Time>
+class Integrator
+    : public artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters> {
+
+  typedef enum {
+    INIT,
+    WAIT_FOR_QUANTA,
+    WAIT_FOR_X_DOT,
+    WAIT_FOR_BOTH,
+    RUNNING
+  } State;
+
+public:
+  enum inputs {
+    QUANTA, X_DOT, RESET
+  };
+
+  enum outputs {
+    OUT
+  };
+
+  typedef enum vars {
+    VALUE
+  } Observable;
+
+  enum states {
+    STATE,
+    LAST_OUT_DATE,
+    UP_THRESHOLD,
+    DOWN_THRESHOLD,
+    LAST_OUT_VALUE,
+    INIT_VALUE,
+    CURRENT_VALUE,
+    EXPECTED_VALUE,
+    ARCHIVE_X_DOT,
+    ARCHIVE_DATE
+  };
+
+  Integrator(const std::string &name,
+             const artis::pdevs::Context<Time, Integrator<Time>, IntegratorParameters> &context)
+      :
+      artis::pdevs::Dynamics<Time, Integrator<Time>, IntegratorParameters>(name,
+                                                                           context) {
+    DECLARE_STATES(int, ((STATE, &Integrator<Time>::_state)));
+    DECLARE_STATES(typename Time::type,
+                   ((LAST_OUT_DATE, &Integrator<Time>::_last_output_date)));
+    DECLARE_STATES(double, ((UP_THRESHOLD, &Integrator<Time>::_up_threshold),
+        (DOWN_THRESHOLD, &Integrator<Time>::_down_threshold),
+        (LAST_OUT_VALUE, &Integrator<Time>::_last_output_value),
+        (INIT_VALUE, &Integrator<Time>::_init_value),
+        (CURRENT_VALUE, &Integrator<Time>::_current_value),
+        (EXPECTED_VALUE, &Integrator<Time>::_expected_value)));
+    DECLARE_STATES(std::vector<double>,
+                   ((ARCHIVE_X_DOT, &Integrator<Time>::_archive_x_dot)));
+    DECLARE_STATES(std::vector<typename Time::type>,
+                   ((ARCHIVE_DATE, &Integrator<Time>::_archive_date)));
+
+    this->input_ports({
+                          {QUANTA, "quanta"},
+                          {X_DOT, "x_dot"},
+                          {RESET, "reset"}});
+    this->output_port({OUT, "out"});
+    this->observable({VALUE, "value"});
+
+    _init_value = context.parameters().x_0;
+  }
+
+  virtual ~Integrator() {}
+
+  virtual void dconf(typename Time::type t, typename Time::type e,
+                     const common::Bag<Time> &bag) {
+    dint(t);
+    dext(t, e, bag);
+  }
+
+  virtual void dint(const typename Time::type &time) {
+    switch (_state) {
+    case RUNNING: {
+      double last_derivative_value = _archive_x_dot.back();
+
+      _last_output_value = _expected_value;
+      _last_output_date = time;
+      _archive_x_dot.clear();
+      _archive_date.clear();
+      _archive_x_dot.push_back(last_derivative_value);
+      _archive_date.push_back(time);
+      _current_value = _expected_value;
+      _state = WAIT_FOR_QUANTA;
+      break;
+    }
+    case INIT: {
+      _state = WAIT_FOR_BOTH;
+      _last_output_value = _current_value;
+      _last_output_date = time;
+      break;
+    }
+    default:assert(false);
+    }
+  }
+
+  virtual void dext(const typename Time::type &t, const typename Time::type &e,
+                    const common::Bag<Time> &bag) {
+    bool reset = false;
+
+    std::for_each(bag.begin(), bag.end(),
+                  [this, t, e, &reset](const common::ExternalEvent<Time> &event) {
+                    if (event.on_port(QUANTA)) {
+                      QuantifierData data;
+
+                      event.data()(data);
+                      _up_threshold = data.up;
+                      _down_threshold = data.down;
+                      if (_state == WAIT_FOR_QUANTA) {
+                        _state = RUNNING;
+                      }
+                      if (_state == WAIT_FOR_BOTH) {
+                        _state = WAIT_FOR_X_DOT;
+                      }
+                    } else if (event.on_port(X_DOT)) {
+                      DerivativeData data;
+
+                      event.data()(data);
+                      _archive_x_dot.push_back(data.x_dot);
+                      _archive_date.push_back(t);
+                      if (_state == WAIT_FOR_X_DOT) {
+                        _state = RUNNING;
+                      }
+                      if (_state == WAIT_FOR_BOTH) {
+                        _state = WAIT_FOR_QUANTA;
+                      }
+                    } else if (event.on_port(RESET)) {
+                      IntegratorData data;
+
+                      event.data()(data);
+                      _current_value = data.value;
+                      reset = true;
+                      _archive_x_dot.clear();
+                      _archive_date.clear();
                     }
                     }
-                }
-            }
+                  });
+    if (reset) {
+      _state = INIT;
+    } else {
+      if (_state == RUNNING) {
+        _current_value = current_value(t);
+        _expected_value = expected_value(t);
+      }
+    }
+  }
 
 
-            virtual void start(const typename Time::type& /* time */)
-            {
-                _current_value = _init_value;
-                _state = INIT;
-            }
+  virtual void start(const typename Time::type & /* time */) {
+    _current_value = _init_value;
+    _state = INIT;
+  }
 
 
-            virtual typename Time::type ta(const typename Time::type& /* time */)
-            {
-                double current_derivative;
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
+    double current_derivative;
 
 
-                switch (_state) {
-                case INIT:
-                    return 0;
-                case RUNNING:
+    switch (_state) {
+    case INIT:return 0;
+    case RUNNING:
 
 
-                    assert(_archive_date.size() > 0);
+      assert(_archive_date.size() > 0);
 
 
-                    current_derivative = _archive_x_dot.back();
-                    if (current_derivative == 0) {
-                        return Time::infinity;
-                    }
-                    if (current_derivative > 0) {
+      current_derivative = _archive_x_dot.back();
+      if (current_derivative == 0) {
+        return Time::infinity;
+      }
+      if (current_derivative > 0) {
 
 
-                        assert(_up_threshold - _current_value >= 0);
+        assert(_up_threshold - _current_value >= 0);
 
 
-                        return (_up_threshold - _current_value) / current_derivative;
-                    } else {
+        return (_up_threshold - _current_value) / current_derivative;
+      } else {
 
 
-                        assert(_down_threshold - _current_value <= 0);
+        assert(_down_threshold - _current_value <= 0);
 
 
-                        return (_down_threshold - _current_value) / current_derivative;
-                    }
-                default:
-                    return Time::infinity;
-                }
-            }
-
-            virtual common::Bag<Time> lambda(const typename Time::type& /* time */) const
-            {
-                common::Bag<Time> msgs;
-
-                switch (_state) {
-                case RUNNING: {
-                    const IntegratorData data = {_expected_value};
-
-                    msgs.push_back(common::ExternalEvent<Time>(OUT, data));
-                    break;
-                }
-                case INIT: {
-                    const IntegratorData data = {_current_value};
-
-                    msgs.push_back(common::ExternalEvent<Time>(OUT, data));
-                    break;
-                }
-                default:
-                    break;
-                }
-                return msgs;
-            }
-
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int index) const
-            {
-                switch (index) {
-                case VALUE:
-                    return (double) (_current_value);
-                default:
-                    return common::Value();
-                }
-            }
-
-        private:
-            double current_value(const typename Time::type& time) const
-            {
-                double val = _last_output_value;
-
-                if (_archive_date.size() > 0) {
-                    for (size_t i = 0; i < _archive_date.size() - 1; i++) {
-                        val +=
-                                (_archive_date[i + 1] - _archive_date[i]) * _archive_x_dot[i];
-                    }
-                    val += (time - _archive_date.back()) * _archive_x_dot.back();
-                }
-                return val;
-            }
+        return (_down_threshold - _current_value) / current_derivative;
+      }
+    default:return Time::infinity;
+    }
+  }
+
+  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const {
+    common::Bag<Time> msgs;
+
+    switch (_state) {
+    case RUNNING: {
+      const IntegratorData data = {_expected_value};
 
 
-            double expected_value(const typename Time::type& /* time */) const
-            {
-                double current_derivative = _archive_x_dot.back();
+      msgs.push_back(common::ExternalEvent<Time>(OUT, data));
+      break;
+    }
+    case INIT: {
+      const IntegratorData data = {_current_value};
+
+      msgs.push_back(common::ExternalEvent<Time>(OUT, data));
+      break;
+    }
+    default:break;
+    }
+    return msgs;
+  }
+
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int index) const {
+    switch (index) {
+    case VALUE:return (double) (_current_value);
+    default:return common::Value();
+    }
+  }
+
+private:
+  double current_value(const typename Time::type &time) const {
+    double val = _last_output_value;
+
+    if (_archive_date.size() > 0) {
+      for (size_t i = 0; i < _archive_date.size() - 1; i++) {
+        val +=
+            (_archive_date[i + 1] - _archive_date[i]) * _archive_x_dot[i];
+      }
+      val += (time - _archive_date.back()) * _archive_x_dot.back();
+    }
+    return val;
+  }
 
 
-                if (current_derivative == 0) {
-                    return _current_value;
-                } else if (current_derivative > 0) {
-                    return _up_threshold;
-                }
-                return _down_threshold;
-            }
+  double expected_value(const typename Time::type & /* time */) const {
+    double current_derivative = _archive_x_dot.back();
 
 
-            int _state;
+    if (current_derivative == 0) {
+      return _current_value;
+    } else if (current_derivative > 0) {
+      return _up_threshold;
+    }
+    return _down_threshold;
+  }
 
 
-            typename Time::type _last_output_date;
+  int _state;
 
 
-            double _up_threshold;
-            double _down_threshold;
+  typename Time::type _last_output_date;
 
 
-            double _last_output_value;
-            double _init_value;
-            double _current_value;
-            double _expected_value;
+  double _up_threshold;
+  double _down_threshold;
 
 
-            std::vector<double> _archive_x_dot;
-            std::vector<typename Time::type> _archive_date;
-        };
+  double _last_output_value;
+  double _init_value;
+  double _current_value;
+  double _expected_value;
 
 
-    }
+  std::vector<double> _archive_x_dot;
+  std::vector<typename Time::type> _archive_date;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 317 - 343
src/artis-star/kernel/qss/Quantifier.hpp

@@ -33,356 +33,330 @@
 #include <cmath>
 #include <cmath>
 
 
 namespace artis {
 namespace artis {
-    namespace qss {
-
-        struct QuantifierParameters {
-            bool allow_offsets;
-            bool zero_init_offset;
-            double quantum;
-            unsigned int archive_length;
-        };
-
-        template<class Time>
-        class Quantifier
-                : public artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters> {
-        public:
-            enum inputs {
-                IN, RESET
-            };
-
-            enum outputs {
-                OUT
-            };
-
-            enum states {
-                STATE, ADAPTIVE_STATE, STEP_NUMBER, OFFSET, UP_THRESHOLD, DOWN_THRESHOLD
-            };
-
-            Quantifier(const std::string& name,
-                    const artis::pdevs::Context<Time, Quantifier<Time>, QuantifierParameters>& context)
-                    :
-                    artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters>(name,
-                            context)
-            {
-                DECLARE_STATES(int,
-                        ((STATE, &Quantifier<Time>::_state), (ADAPTIVE_STATE, &Quantifier<Time>::_adaptive_state)));
-                DECLARE_STATES(unsigned int,
-                        ((STEP_NUMBER, &Quantifier<Time>::_step_number)));
-                DECLARE_STATES(double,
-                        ((OFFSET, &Quantifier<Time>::_offset), (UP_THRESHOLD, &Quantifier<Time>::_up_threshold), (DOWN_THRESHOLD, &Quantifier<Time>::_down_threshold)));
-
-                this->input_ports({{IN,    "in"},
-                                   {RESET, "reset"}});
-                this->output_port({OUT, "out"});
-                this->observables({{UP,    "up"},
-                                   {DOWN,  "down"},
-                                   {VALUE, "value"}});
-
-                _adaptive = context.parameters().allow_offsets;
-                _adaptive_state = _adaptive ? POSSIBLE : IMPOSSIBLE;
-                _zero_init_offset = context.parameters().zero_init_offset;
-                _step_size = context.parameters().quantum;
-
-                assert(_step_size > 0);
-
-                _past_length = context.parameters().archive_length;
-
-                assert(_past_length > 2);
-            }
-
-            virtual ~Quantifier() { }
-
-            virtual void dconf(const typename Time::type& t, const typename Time::type& e,
-                    const common::Bag<Time>& bag)
-            {
-                dint(t);
-                dext(t, e, bag);
-            }
-
-            virtual void dint(const typename Time::type& /* t */)
-            {
-                switch (_state) {
-                case INIT:
-                    break;
-                case IDLE:
-                    break;
-                case RESPONSE:
-                    _state = IDLE;
-                    break;
-                }
-            }
-
-            virtual void dext(const typename Time::type& t, const typename Time::type& e,
-                    const common::Bag<Time>& bag)
-            {
-                bool reset = false;
-
-                std::for_each(bag.begin(), bag.end(),
-                        [this, t, e, &reset](const common::ExternalEvent<Time>& event) {
-                            if (event.on_port(IN)) {
-                                IntegratorData data;
-                                double shifting_factor;
-                                double value;
-                                int cnt;
-
-                                event.data()(data);
-                                value = data.value;
-                                if (_state == INIT) {
-                                    init_step_number_and_offset(value);
-                                    update_thresholds();
-                                    _state = RESPONSE;
-                                } else {
-                                    cnt = 0;
-                                    while (value >= _up_threshold or value <= _down_threshold) {
-                                        cnt++;
-                                        if (value >= _up_threshold) {
-                                            _step_number++;
-                                        } else {
-                                            _step_number--;
-                                        }
-                                        switch (_adaptive_state) {
-                                        case IMPOSSIBLE:
-                                            update_thresholds();
-                                            break;
-                                        case POSSIBLE:
-                                            if (value >= _up_threshold) {
-                                                store_change(_step_size, t);
-                                            } else {
-                                                store_change(-_step_size, t);
-                                            }
-                                            shifting_factor = shift_quanta();
-
-                                            assert(shifting_factor >= 0
-                                                    and shifting_factor <= 1);
-
-                                            if (shifting_factor != 0 and shifting_factor != 1) {
-                                                if (value >= _up_threshold) {
-                                                    update_thresholds(shifting_factor,
-                                                            DIRECTION_DOWN);
-                                                } else {
-                                                    update_thresholds(shifting_factor,
-                                                            DIRECTION_UP);
-                                                }
-                                                _adaptive_state = DONE;
-                                            } else {
-                                                update_thresholds();
-                                            }
-                                            break;
-                                        case DONE:
-                                            init_step_number_and_offset(value);
-                                            _adaptive_state = POSSIBLE;
-                                            update_thresholds();
-                                            break;
-                                        }
-                                    }
-                                }
-                            } else if (event.on_port(RESET)) {
-                                _offset = 0;
-                                reset = true;
-                                _archive.clear();
+namespace qss {
+
+struct QuantifierParameters {
+  bool allow_offsets;
+  bool zero_init_offset;
+  double quantum;
+  unsigned int archive_length;
+};
+
+template<class Time>
+class Quantifier
+    : public artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters> {
+public:
+  enum inputs {
+    IN, RESET
+  };
+
+  enum outputs {
+    OUT
+  };
+
+  enum states {
+    STATE, ADAPTIVE_STATE, STEP_NUMBER, OFFSET, UP_THRESHOLD, DOWN_THRESHOLD
+  };
+
+  Quantifier(const std::string &name,
+             const artis::pdevs::Context<Time, Quantifier<Time>, QuantifierParameters> &context)
+      :
+      artis::pdevs::Dynamics<Time, Quantifier<Time>, QuantifierParameters>(name,
+                                                                           context) {
+    DECLARE_STATES(int,
+                   ((STATE, &Quantifier<Time>::_state), (ADAPTIVE_STATE, &Quantifier<Time>::_adaptive_state)));
+    DECLARE_STATES(unsigned int,
+                   ((STEP_NUMBER, &Quantifier<Time>::_step_number)));
+    DECLARE_STATES(double,
+                   ((OFFSET, &Quantifier<Time>::_offset), (UP_THRESHOLD, &Quantifier<Time>::_up_threshold), (DOWN_THRESHOLD, &Quantifier<
+                       Time>::_down_threshold)));
+
+    this->input_ports({{IN, "in"},
+                       {RESET, "reset"}});
+    this->output_port({OUT, "out"});
+    this->observables({{UP, "up"},
+                       {DOWN, "down"},
+                       {VALUE, "value"}});
+
+    _adaptive = context.parameters().allow_offsets;
+    _adaptive_state = _adaptive ? POSSIBLE : IMPOSSIBLE;
+    _zero_init_offset = context.parameters().zero_init_offset;
+    _step_size = context.parameters().quantum;
+
+    assert(_step_size > 0);
+
+    _past_length = context.parameters().archive_length;
+
+    assert(_past_length > 2);
+  }
+
+  virtual ~Quantifier() {}
+
+  virtual void dconf(const typename Time::type &t, const typename Time::type &e,
+                     const common::Bag<Time> &bag) {
+    dint(t);
+    dext(t, e, bag);
+  }
+
+  virtual void dint(const typename Time::type & /* t */) {
+    switch (_state) {
+    case INIT:break;
+    case IDLE:break;
+    case RESPONSE:_state = IDLE;
+      break;
+    }
+  }
+
+  virtual void dext(const typename Time::type &t, const typename Time::type &e,
+                    const common::Bag<Time> &bag) {
+    bool reset = false;
+
+    std::for_each(bag.begin(), bag.end(),
+                  [this, t, e, &reset](const common::ExternalEvent<Time> &event) {
+                    if (event.on_port(IN)) {
+                      IntegratorData data;
+                      double shifting_factor;
+                      double value;
+                      int cnt;
+
+                      event.data()(data);
+                      value = data.value;
+                      if (_state == INIT) {
+                        init_step_number_and_offset(value);
+                        update_thresholds();
+                        _state = RESPONSE;
+                      } else {
+                        cnt = 0;
+                        while (value >= _up_threshold or value <= _down_threshold) {
+                          cnt++;
+                          if (value >= _up_threshold) {
+                            _step_number++;
+                          } else {
+                            _step_number--;
+                          }
+                          switch (_adaptive_state) {
+                          case IMPOSSIBLE:update_thresholds();
+                            break;
+                          case POSSIBLE:
+                            if (value >= _up_threshold) {
+                              store_change(_step_size, t);
+                            } else {
+                              store_change(-_step_size, t);
                             }
                             }
-                        });
-                if (reset) {
-                    _state = INIT;
-                } else {
-                    _state = RESPONSE;
-                }
-            }
-
-            virtual void start(const typename Time::type& /* time */)
-            {
-                _offset = 0;
-                _state = INIT;
-            }
-
-            virtual typename Time::type ta(const typename Time::type& /* time */)
-            {
-                switch (_state) {
-                case INIT:
-                case IDLE:
-                    return Time::infinity;
-                case RESPONSE:
-                    return 0.0;
-                }
-                return Time::infinity;
-            }
-
-            virtual common::Bag<Time> lambda(const typename Time::type& /* time */) const
-            {
-                common::Bag<Time> msgs;
-                const QuantifierData data = {_up_threshold, _down_threshold};
-
-                msgs.push_back(common::ExternalEvent<Time>(OUT, data));
-                return msgs;
-            }
-
-            virtual common::Value observe(const typename Time::type& /* t */,
-                    unsigned int index) const
-            {
-                switch (index) {
-                case UP:
-                    return (double) _up_threshold;
-                case DOWN:
-                    return (double) _down_threshold;
-                case VALUE:
-                    return (double) (_up_threshold - _down_threshold);
-                default:
-                    return common::Value();
-                }
-            }
-
-        private:
-            typedef enum {
-                DIRECTION_UP, DIRECTION_DOWN
-            } Direction;
-
-            void init_step_number_and_offset(double value)
-            {
-                _step_number = static_cast<long int>(std::floor(value / _step_size));
-                if (_zero_init_offset) {
-                    _offset = 0;
-                } else {
-                    _offset = value - static_cast<double>(_step_number) * _step_size;
-                }
-            }
-
-            bool monotonous(unsigned int range)
-            {
-                if ((range + 1) > _archive.size()) {
-                    return false;
-                }
-                for (size_t i = 0; i < range; i++) {
-                    if (_archive[i].value * _archive[i + 1].value < 0) {
-                        return false;
-                    }
-                }
-                return true;
-            }
-
-            bool oscillating(unsigned int range)
-            {
-                if ((range + 1) > _archive.size()) {
-                    return false;
-                }
-                for (size_t i = _archive.size() - range; i < _archive.size() - 1; i++) {
-                    if (_archive[i].value * _archive[i + 1].value > 0) {
-                        return false;
-                    }
-                }
-                return true;
-            }
-
-            double shift_quanta()
-            {
-                double factor = 0;
-
-                if (oscillating(_past_length - 1) and
-                        _archive.back().date - _archive.front().date != 0) {
-                    double acc;
-                    double local_estim;
-                    int cnt;
-
-                    acc = 0;
-                    cnt = 0;
-                    for (size_t i = 0; i < _archive.size() - 2; ++i) {
-                        if (0 != (_archive[i + 2].date - _archive[i].date)) {
-                            if ((_archive.back().value * _archive[i + 1].value) > 0) {
-                                local_estim =
-                                        1 - (_archive[i + 1].date - _archive[i].date) /
-                                                (_archive[i + 2].date - _archive[i].date);
+                            shifting_factor = shift_quanta();
+
+                            assert(shifting_factor >= 0
+                                       and shifting_factor <= 1);
+
+                            if (shifting_factor != 0 and shifting_factor != 1) {
+                              if (value >= _up_threshold) {
+                                update_thresholds(shifting_factor,
+                                                  DIRECTION_DOWN);
+                              } else {
+                                update_thresholds(shifting_factor,
+                                                  DIRECTION_UP);
+                              }
+                              _adaptive_state = DONE;
                             } else {
                             } else {
-                                local_estim = (_archive[i + 1].date - _archive[i].date) /
-                                        (_archive[i + 2].date - _archive[i].date);
+                              update_thresholds();
                             }
                             }
-                            acc += local_estim;
-                            cnt++;
+                            break;
+                          case DONE:init_step_number_and_offset(value);
+                            _adaptive_state = POSSIBLE;
+                            update_thresholds();
+                            break;
+                          }
                         }
                         }
+                      }
+                    } else if (event.on_port(RESET)) {
+                      _offset = 0;
+                      reset = true;
+                      _archive.clear();
                     }
                     }
-                    acc = acc / cnt;
-                    factor = acc;
-                    _archive.resize(0);
-                }
-                return factor;
-            }
-
-            void store_change(double val, const typename Time::type& time)
-            {
-                record_t record;
-
-                record.date = time;
-                record.value = val;
-                _archive.push_back(record);
-                while (_archive.size() > _past_length) {
-                    _archive.pop_front();
-                }
-            }
-
-            void update_thresholds()
-            {
-                auto step_number = static_cast<double>(_step_number);
-
-                _up_threshold = _offset + _step_size * (step_number + 1);
-                _down_threshold = _offset + _step_size * (step_number - 1);
-            }
-
-            void update_thresholds(double factor)
-            {
-                auto step_number = static_cast<double>(_step_number);
-
-                _up_threshold = _offset + _step_size * (step_number + (1 - factor));
-                _down_threshold = _offset + _step_size * (step_number - (1 - factor));
-            }
-
-            void update_thresholds(double factor, Direction d)
-            {
-                auto step_number = static_cast<double>(_step_number);
-
-                if (d == DIRECTION_UP) {
-                    _up_threshold = _offset + _step_size * (step_number + (1 - factor));
-                    _down_threshold = _offset + _step_size * (step_number - 1);
-                } else {
-                    _up_threshold = _offset + _step_size * (step_number + 1);
-                    _down_threshold = _offset + _step_size * (step_number - (1 - factor));
-                }
-            }
-
-            typedef enum vars {
-                UP, DOWN, VALUE
-            } Observable;
-
-            typedef enum {
-                INIT, IDLE, RESPONSE
-            } State;
-
-            typedef enum {
-                IMPOSSIBLE, POSSIBLE, DONE
-            } AdaptiveState;
-
-            struct record_t {
-                double value;
-                typename Time::type date;
-            };
-
-            // parameters
-            bool _adaptive;
-            bool _zero_init_offset;
-            unsigned int _past_length;
-            double _step_size;
-
-            // state
-            int _state;
-            int _adaptive_state;
-
-            unsigned int _step_number; // long int
-
-            double _offset;
-            double _up_threshold;
-            double _down_threshold;
-
-            std::deque<record_t> _archive;
-        };
+                  });
+    if (reset) {
+      _state = INIT;
+    } else {
+      _state = RESPONSE;
+    }
+  }
+
+  virtual void start(const typename Time::type & /* time */) {
+    _offset = 0;
+    _state = INIT;
+  }
+
+  virtual typename Time::type ta(const typename Time::type & /* time */) {
+    switch (_state) {
+    case INIT:
+    case IDLE:return Time::infinity;
+    case RESPONSE:return 0.0;
+    }
+    return Time::infinity;
+  }
+
+  virtual common::Bag<Time> lambda(const typename Time::type & /* time */) const {
+    common::Bag<Time> msgs;
+    const QuantifierData data = {_up_threshold, _down_threshold};
+
+    msgs.push_back(common::ExternalEvent<Time>(OUT, data));
+    return msgs;
+  }
+
+  virtual common::Value observe(const typename Time::type & /* t */,
+                                unsigned int index) const {
+    switch (index) {
+    case UP:return (double) _up_threshold;
+    case DOWN:return (double) _down_threshold;
+    case VALUE:return (double) (_up_threshold - _down_threshold);
+    default:return common::Value();
+    }
+  }
+
+private:
+  typedef enum {
+    DIRECTION_UP, DIRECTION_DOWN
+  } Direction;
+
+  void init_step_number_and_offset(double value) {
+    _step_number = static_cast<long int>(std::floor(value / _step_size));
+    if (_zero_init_offset) {
+      _offset = 0;
+    } else {
+      _offset = value - static_cast<double>(_step_number) * _step_size;
+    }
+  }
+
+  bool monotonous(unsigned int range) {
+    if ((range + 1) > _archive.size()) {
+      return false;
+    }
+    for (size_t i = 0; i < range; i++) {
+      if (_archive[i].value * _archive[i + 1].value < 0) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  bool oscillating(unsigned int range) {
+    if ((range + 1) > _archive.size()) {
+      return false;
+    }
+    for (size_t i = _archive.size() - range; i < _archive.size() - 1; i++) {
+      if (_archive[i].value * _archive[i + 1].value > 0) {
+        return false;
+      }
+    }
+    return true;
+  }
+
+  double shift_quanta() {
+    double factor = 0;
+
+    if (oscillating(_past_length - 1) and
+        _archive.back().date - _archive.front().date != 0) {
+      double acc;
+      double local_estim;
+      int cnt;
+
+      acc = 0;
+      cnt = 0;
+      for (size_t i = 0; i < _archive.size() - 2; ++i) {
+        if (0 != (_archive[i + 2].date - _archive[i].date)) {
+          if ((_archive.back().value * _archive[i + 1].value) > 0) {
+            local_estim =
+                1 - (_archive[i + 1].date - _archive[i].date) /
+                    (_archive[i + 2].date - _archive[i].date);
+          } else {
+            local_estim = (_archive[i + 1].date - _archive[i].date) /
+                (_archive[i + 2].date - _archive[i].date);
+          }
+          acc += local_estim;
+          cnt++;
+        }
+      }
+      acc = acc / cnt;
+      factor = acc;
+      _archive.resize(0);
+    }
+    return factor;
+  }
+
+  void store_change(double val, const typename Time::type &time) {
+    record_t record;
+
+    record.date = time;
+    record.value = val;
+    _archive.push_back(record);
+    while (_archive.size() > _past_length) {
+      _archive.pop_front();
+    }
+  }
+
+  void update_thresholds() {
+    auto step_number = static_cast<double>(_step_number);
+
+    _up_threshold = _offset + _step_size * (step_number + 1);
+    _down_threshold = _offset + _step_size * (step_number - 1);
+  }
+
+  void update_thresholds(double factor) {
+    auto step_number = static_cast<double>(_step_number);
+
+    _up_threshold = _offset + _step_size * (step_number + (1 - factor));
+    _down_threshold = _offset + _step_size * (step_number - (1 - factor));
+  }
 
 
+  void update_thresholds(double factor, Direction d) {
+    auto step_number = static_cast<double>(_step_number);
+
+    if (d == DIRECTION_UP) {
+      _up_threshold = _offset + _step_size * (step_number + (1 - factor));
+      _down_threshold = _offset + _step_size * (step_number - 1);
+    } else {
+      _up_threshold = _offset + _step_size * (step_number + 1);
+      _down_threshold = _offset + _step_size * (step_number - (1 - factor));
     }
     }
+  }
+
+  typedef enum vars {
+    UP, DOWN, VALUE
+  } Observable;
+
+  typedef enum {
+    INIT, IDLE, RESPONSE
+  } State;
+
+  typedef enum {
+    IMPOSSIBLE, POSSIBLE, DONE
+  } AdaptiveState;
+
+  struct record_t {
+    double value;
+    typename Time::type date;
+  };
+
+  // parameters
+  bool _adaptive;
+  bool _zero_init_offset;
+  unsigned int _past_length;
+  double _step_size;
+
+  // state
+  int _state;
+  int _adaptive_state;
+
+  unsigned int _step_number; // long int
+
+  double _offset;
+  double _up_threshold;
+  double _down_threshold;
+
+  std::deque<record_t> _archive;
+};
+
+}
 }
 }
 
 
 #endif
 #endif

+ 130 - 136
src/artis-star/kernel/sss/Coordinator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef SSS_COORDINATOR
 #ifndef SSS_COORDINATOR
-#define SSS_COORDINATOR 1
+#define SSS_COORDINATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -36,150 +36,144 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace sss {
-
-        template<class Time>
-        class Parameters {
-        public:
-            Parameters(typename Time::type time_step)
-                    :_time_step(time_step) { }
-
-            typename Time::type _time_step;
-        };
-
-        template<class Time, class Policy, class GraphManager,
-                class Parameters = Parameters<Time>,
-                class GraphParameters = common::NoParameters>
-        class Coordinator : public common::Coordinator<Time>,
-                            public sss::Model<Time> {
-            typedef Coordinator<Time, Policy, GraphManager,
-                    Parameters, GraphParameters> type;
-
-        public:
-            typedef Parameters parameters_type;
-            typedef GraphParameters graph_parameters_type;
-
-            Coordinator(const std::string& name,
-                    const Parameters& parameters,
-                    const GraphParameters& graph_parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Coordinator<Time>(name),
-                    sss::Model<Time>(name),
-                    _graph_manager(this, graph_parameters),
-                    _time_step(parameters._time_step) { }
-
-            virtual ~Coordinator() { }
-
-            GraphManager& get_graph_manager() { return _graph_manager; }
-
-            const GraphManager& get_graph_manager() const { return _graph_manager; }
-
-            virtual bool is_atomic() const { return common::Coordinator<Time>::is_atomic(); }
-
-            virtual std::string to_string(int level) const { return common::Coordinator<Time>::to_string(level); }
-
-            typename Time::type start(const typename Time::type& t)
-            {
-                assert(_graph_manager.children().size() > 0);
-
-                type::_tl = t;
-                type::_tn = t;
-                for (auto& child : _graph_manager.children()) {
-                    child->start(t);
-                }
-                return type::_tn;
-            }
+namespace sss {
 
 
-            typename Time::type dispatch_events(const common::Bag<Time>& bag,
-                    const typename Time::type& t)
-            {
-                _graph_manager.dispatch_events(bag, t);
-                return type::_tn;
-            }
+template<class Time>
+class Parameters {
+public:
+  Parameters(typename Time::type time_step)
+      : _time_step(time_step) {}
 
 
-            void observation(std::ostream& file) const
-            {
-                for (auto& child : _graph_manager.children()) {
-                    child->observation(file);
-                }
-            }
+  typename Time::type _time_step;
+};
 
 
-            void output(const typename Time::type& t)
-            {
-                if (t == type::_tn) {
-                    for (auto& model : _graph_manager.children()) {
-                        model->update_buffer(t);
-                    }
-                    for (auto& model : _graph_manager.children()) {
-                        if (not model->is_send() && model->is_marked()) {
-                            model->output(t);
-                            model->send();
-                        }
-                    }
-                }
-            }
+template<class Time, class Policy, class GraphManager,
+    class Parameters = Parameters<Time>,
+    class GraphParameters = common::NoParameters>
+class Coordinator : public common::Coordinator<Time>,
+                    public sss::Model<Time> {
+  typedef Coordinator<Time, Policy, GraphManager,
+                      Parameters, GraphParameters> type;
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
-                if (t == type::_tn) {
-                    _graph_manager.post_event(t, event);
-                } else {
-                    _policy(t, event, type::_tl, type::_tn);
-                }
-            }
+public:
+  typedef Parameters parameters_type;
+  typedef GraphParameters graph_parameters_type;
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
-                if (t == type::_tn) {
-                    bool end = true;
-
-                    for (auto& event : _policy.bag()) {
-                        post_event(t, event);
-                    }
-                    for (auto& model : _graph_manager.children()) {
-                        if (not model->is_marked()) {
-                            if (model->all_ports_are_assigned()) {
-                                model->transition(t);
-                                model->mark();
-                                end = false;
-                            } else {
-                                end = false;
-                            }
-                        } else {
-                            if (not model->is_send()) {
-                                end = false;
-                            } else {
-                                if (t == model->get_tn()) {
-                                    model->transition(t);
-                                }
-                            }
-                        }
-                    }
-
-                    if (end) {
-                        for (auto& model : _graph_manager.children()) {
-                            model->unmark();
-                            model->unsend();
-                        }
-                        type::_tl = t;
-                        type::_tn = t + _time_step;
-                    }
-                }
-                type::clear_bag();
-                return type::_tn;
-            }
+  Coordinator(const std::string &name,
+              const Parameters &parameters,
+              const GraphParameters &graph_parameters)
+      :
+      common::Model<Time>(name),
+      common::Coordinator<Time>(name),
+      sss::Model<Time>(name),
+      _graph_manager(this, graph_parameters),
+      _time_step(parameters._time_step) {}
+
+  virtual ~Coordinator() {}
+
+  GraphManager &get_graph_manager() { return _graph_manager; }
+
+  const GraphManager &get_graph_manager() const { return _graph_manager; }
 
 
-            virtual void update_buffer(typename Time::type /* time */) { }
+  virtual bool is_atomic() const { return common::Coordinator<Time>::is_atomic(); }
 
 
-        private:
-            GraphManager _graph_manager;
-            typename Time::type _time_step;
-            Policy _policy;
-        };
+  virtual std::string to_string(int level) const { return common::Coordinator<Time>::to_string(level); }
 
 
+  typename Time::type start(const typename Time::type &t) {
+    assert(_graph_manager.children().size() > 0);
+
+    type::_tl = t;
+    type::_tn = t;
+    for (auto &child : _graph_manager.children()) {
+      child->start(t);
+    }
+    return type::_tn;
+  }
+
+  typename Time::type dispatch_events(const common::Bag<Time> &bag,
+                                      const typename Time::type &t) {
+    _graph_manager.dispatch_events(bag, t);
+    return type::_tn;
+  }
+
+  void observation(std::ostream &file) const {
+    for (auto &child : _graph_manager.children()) {
+      child->observation(file);
+    }
+  }
+
+  void output(const typename Time::type &t) {
+    if (t == type::_tn) {
+      for (auto &model : _graph_manager.children()) {
+        model->update_buffer(t);
+      }
+      for (auto &model : _graph_manager.children()) {
+        if (not model->is_send() && model->is_marked()) {
+          model->output(t);
+          model->send();
+        }
+      }
     }
     }
+  }
+
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
+    if (t == type::_tn) {
+      _graph_manager.post_event(t, event);
+    } else {
+      _policy(t, event, type::_tl, type::_tn);
+    }
+  }
+
+  typename Time::type transition(const typename Time::type &t) {
+    if (t == type::_tn) {
+      bool end = true;
+
+      for (auto &event : _policy.bag()) {
+        post_event(t, event);
+      }
+      for (auto &model : _graph_manager.children()) {
+        if (not model->is_marked()) {
+          if (model->all_ports_are_assigned()) {
+            model->transition(t);
+            model->mark();
+            end = false;
+          } else {
+            end = false;
+          }
+        } else {
+          if (not model->is_send()) {
+            end = false;
+          } else {
+            if (t == model->get_tn()) {
+              model->transition(t);
+            }
+          }
+        }
+      }
+
+      if (end) {
+        for (auto &model : _graph_manager.children()) {
+          model->unmark();
+          model->unsend();
+        }
+        type::_tl = t;
+        type::_tn = t + _time_step;
+      }
+    }
+    type::clear_bag();
+    return type::_tn;
+  }
+
+  virtual void update_buffer(typename Time::type /* time */) {}
+
+private:
+  GraphManager _graph_manager;
+  typename Time::type _time_step;
+  Policy _policy;
+};
+
+}
 } // namespace artis sss
 } // namespace artis sss
 
 
 #endif
 #endif

+ 33 - 35
src/artis-star/kernel/sss/Dynamics.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef SSS_DYNAMICS
 #ifndef SSS_DYNAMICS
-#define SSS_DYNAMICS 1
+#define SSS_DYNAMICS
 
 
 #include <artis-star/common/Bag.hpp>
 #include <artis-star/common/Bag.hpp>
 #include <artis-star/common/ExternalEvent.hpp>
 #include <artis-star/common/ExternalEvent.hpp>
@@ -33,52 +33,50 @@
 #include <artis-star/common/States.hpp>
 #include <artis-star/common/States.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace sss {
+namespace sss {
 
 
-        template<class Time,
-                class Parameters = common::NoParameters>
-        class Dynamics : public common::States<Time, Dyn> {
-        public:
-            Dynamics(const std::string& name, const Parameters& /* parameters */)
-                    :
-                    _name(name) { }
+template<class Time,
+    class Parameters = common::NoParameters>
+class Dynamics : public common::States<Time, Dyn> {
+public:
+  Dynamics(const std::string &name, const Parameters & /* parameters */)
+      :
+      _name(name) {}
 
 
-            virtual ~Dynamics() { }
+  virtual ~Dynamics() {}
 
 
-            virtual void transition(const common::Bag<Time>& /* x */,
-                    typename Time::type /* t */) { }
+  virtual void transition(const common::Bag<Time> & /* x */,
+                          typename Time::type /* t */) {}
 
 
-            virtual typename Time::type
-            start(typename Time::type/* time */) { return Time::infinity; }
+  virtual typename Time::type
+  start(typename Time::type/* time */) { return Time::infinity; }
 
 
-            common::Bag<Time> lambda(
-                    typename Time::type /* time */) const { return common::Bag<Time>(); }
+  common::Bag<Time> lambda(
+      typename Time::type /* time */) const { return common::Bag<Time>(); }
 
 
-            virtual void observation(std::ostream& /* file */) const { }
+  virtual void observation(std::ostream & /* file */) const {}
 
 
-            const std::string& get_name() const { return _name; }
+  const std::string &get_name() const { return _name; }
 
 
-            void restore(const common::context::State<Time>& state)
-            {
-                common::States<Time, Dyn>::restore(static_cast<Dyn*>(this), state);
-                _simulator->set_tn(state.last_time());
-                _simulator->set_tl(state.next_time());
-            }
+  void restore(const common::context::State<Time> &state) {
+    common::States<Time, Dyn>::restore(static_cast<Dyn *>(this), state);
+    _simulator->set_tn(state.last_time());
+    _simulator->set_tl(state.next_time());
+  }
 
 
-            void save(common::context::State<Time>& state) const
-            {
-                common::States<Time, Dyn>::save(static_cast<const Dyn*>(this), state);
-                state.last_time(_simulator->get_tn());
-                state.next_time(_simulator->get_tl());
-            }
+  void save(common::context::State<Time> &state) const {
+    common::States<Time, Dyn>::save(static_cast<const Dyn *>(this), state);
+    state.last_time(_simulator->get_tn());
+    state.next_time(_simulator->get_tl());
+  }
 
 
-            virtual void update_buffer(typename Time::type /* time */) { }
+  virtual void update_buffer(typename Time::type /* time */) {}
 
 
-        private:
-            std::string _name;
-        };
+private:
+  std::string _name;
+};
 
 
-    }
+}
 } // namespace artis sss
 } // namespace artis sss
 
 
 #endif
 #endif

+ 82 - 85
src/artis-star/kernel/sss/GraphManager.hpp

@@ -35,92 +35,89 @@
 #include <artis-star/kernel/sss/Model.hpp>
 #include <artis-star/kernel/sss/Model.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace sss {
-
-        template<class Time,
-                class GraphParameters = common::NoParameters>
-        class GraphManager : public common::GraphManager<Time> {
-        public:
-            GraphManager(common::Coordinator<Time>* coordinator,
-                    const GraphParameters& /* parameters */)
-                    :
-                    common::GraphManager<Time>(coordinator) { }
-
-            virtual ~GraphManager() { }
-
-            void add_link(common::Model<Time>* src_model,
-                    const std::string& src_port_name,
-                    common::Model<Time>* dst_model,
-                    const std::string& dst_port_name)
-            {
-                assert((src_model != _coordinator and
-                        dst_model != _coordinator and
-                        src_model->exist_out_port(src_port_name) and
-                        dst_model->exist_in_port(dst_port_name)) or
-                        (src_model == _coordinator and
-                                dst_model != _coordinator and
-                                src_model->exist_in_port(src_port_name) and
-                                dst_model->exist_in_port(dst_port_name)) or
-                        (src_model != _coordinator and
-                                dst_model == _coordinator and
-                                src_model->exist_out_port(src_port_name) and
-                                dst_model->exist_out_port(dst_port_name)));
-
-                _link_list.add(src_model, src_port_name, dst_model, dst_port_name);
-            }
-
-            void dispatch_events(common::Bag<Time> bag,
-                    typename Time::type t)
-            {
-                for (auto& ymsg : bag) {
-                    typename common::Links<Time>::Result result_model =
-                            _link_list.find(ymsg.get_model(),
-                                    ymsg.get_port_name());
-
-                    for (typename common::Links<Time>::const_iterator it =
-                            result_model.first; it != result_model.second; ++it) {
-                        // event on output port of coupled model
-                        if (it->second.get_model() == _coordinator) {
-                            common::Bag<Time> ymessages;
-
-                            ymessages.push_back(
-                                    common::ExternalEvent<Time>(
-                                            it->second,
-                                            ymsg.data()));
-                            if (_coordinator->get_parent()) {
-                                dynamic_cast < common::Coordinator<
-                                        Time>* >(_coordinator->get_parent())
-                                        ->dispatch_events(ymessages, t);
-                            }
-                        } else { // event on input port of internal model
-                            it->second.get_model()->post_event(
-                                    t, common::ExternalEvent<Time>(
-                                            it->second,
-                                            ymsg.data()));
-                        }
-                    }
-                }
-            }
-
-            void post_event(typename Time::type t,
-                    const common::ExternalEvent<Time>& event)
-            {
-                typename common::Links<Time>::Result result =
-                        _link_list.find(_coordinator, event.get_port_name());
-
-                for (typename common::Links<Time>::const_iterator it_r =
-                        result.first; it_r != result.second; ++it_r) {
-                    it_r->second.get_model()->post_event(
-                            t, common::ExternalEvent<Time>(it_r->second,
-                                    event.data()));
-                }
-            }
-
-        private:
-            common::Links<Time> _link_list;
-        };
-
+namespace sss {
+
+template<class Time,
+    class GraphParameters = common::NoParameters>
+class GraphManager : public common::GraphManager<Time> {
+public:
+  GraphManager(common::Coordinator<Time> *coordinator,
+               const GraphParameters & /* parameters */)
+      :
+      common::GraphManager<Time>(coordinator) {}
+
+  virtual ~GraphManager() {}
+
+  void add_link(common::Model<Time> *src_model,
+                const std::string &src_port_name,
+                common::Model<Time> *dst_model,
+                const std::string &dst_port_name) {
+    assert((src_model != _coordinator and
+        dst_model != _coordinator and
+        src_model->exist_out_port(src_port_name) and
+        dst_model->exist_in_port(dst_port_name)) or
+        (src_model == _coordinator and
+            dst_model != _coordinator and
+            src_model->exist_in_port(src_port_name) and
+            dst_model->exist_in_port(dst_port_name)) or
+        (src_model != _coordinator and
+            dst_model == _coordinator and
+            src_model->exist_out_port(src_port_name) and
+            dst_model->exist_out_port(dst_port_name)));
+
+    _link_list.add(src_model, src_port_name, dst_model, dst_port_name);
+  }
+
+  void dispatch_events(common::Bag<Time> bag,
+                       typename Time::type t) {
+    for (auto &ymsg : bag) {
+      typename common::Links<Time>::Result result_model =
+          _link_list.find(ymsg.get_model(),
+                          ymsg.get_port_name());
+
+      for (typename common::Links<Time>::const_iterator it =
+          result_model.first; it != result_model.second; ++it) {
+        // event on output port of coupled model
+        if (it->second.get_model() == _coordinator) {
+          common::Bag<Time> ymessages;
+
+          ymessages.push_back(
+              common::ExternalEvent<Time>(
+                  it->second,
+                  ymsg.data()));
+          if (_coordinator->get_parent()) {
+            dynamic_cast < common::Coordinator<
+                Time> * >(_coordinator->get_parent())
+                ->dispatch_events(ymessages, t);
+          }
+        } else { // event on input port of internal model
+          it->second.get_model()->post_event(
+              t, common::ExternalEvent<Time>(
+                  it->second,
+                  ymsg.data()));
+        }
+      }
+    }
+  }
+
+  void post_event(typename Time::type t,
+                  const common::ExternalEvent<Time> &event) {
+    typename common::Links<Time>::Result result =
+        _link_list.find(_coordinator, event.get_port_name());
+
+    for (typename common::Links<Time>::const_iterator it_r =
+        result.first; it_r != result.second; ++it_r) {
+      it_r->second.get_model()->post_event(
+          t, common::ExternalEvent<Time>(it_r->second,
+                                         event.data()));
     }
     }
+  }
+
+private:
+  common::Links<Time> _link_list;
+};
+
+}
 } // namespace artis sss
 } // namespace artis sss
 
 
 #endif
 #endif

+ 86 - 91
src/artis-star/kernel/sss/Model.hpp

@@ -25,103 +25,98 @@
  */
  */
 
 
 #ifndef SSS_MODEL
 #ifndef SSS_MODEL
-#define SSS_MODEL 1
+#define SSS_MODEL
 
 
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Model.hpp>
 
 
 namespace artis {
 namespace artis {
-    namespace sss {
-
-        template<class Time>
-        class Model : public virtual common::Model<Time> {
-        public:
-            Model(const std::string& name)
-                    :
-                    common::Model<Time>(name)
-            {
-                assigned = 0;
-                _mark = false;
-                _send = false;
-            }
-
-            virtual ~Model() { }
-
-            virtual void update_buffer(typename Time::type /* time */) = 0;
-
-            void add_event(const common::ExternalEvent<Time>& message)
-            {
-                common::Model<Time>::add_event(message);
-                std::map<std::string, bool>::iterator it =
-                        port_assigned.find(message.get_port_name());
-
-                if (it != port_assigned.end() and not it->second) {
-                    port_assigned[message.get_port_name()] = true;
-                    ++assigned;
-                }
-            }
-
-            void add_in_port(const std::string& port_name, bool sync)
-            {
-                common::Model<Time>::add_in_port(port_name);
-                if (sync) {
-                    port_assigned[port_name] = false;
-                }
-            }
-
-            bool all_ports_are_assigned() const { return assigned == port_assigned.size(); }
-
-            void clear_bag()
-            {
-                common::Model<Time>::clear_bag();
-
-                for (auto& p: port_assigned) {
-                    p.second = false;
-                }
-                assigned = 0;
-            }
-
-            bool is_marked() const { return _mark; }
-
-            bool is_send() const { return _send; }
-
-            void mark() { _mark = true; }
-
-            void send() { _send = true; }
-
-            void unmark() { _mark = false; }
-
-            void unsend() { _send = false; }
-
-        private:
-            std::map<std::string, bool> port_assigned;
-            unsigned int assigned;
-            bool _mark;
-            bool _send;
-        };
-
-        template<class Time>
-        class Models : public std::vector<sss::Model<Time>*> {
-        public:
-            Models() { }
-
-            virtual ~Models() { }
-
-            std::string to_string() const
-            {
-                std::ostringstream ss;
-
-                ss << "{ ";
-                for (typename Models<Time>::const_iterator it =
-                        Models<Time>::begin();
-                     it != Models<Time>::end(); ++it) {
-                    ss << (*it)->get_name() << " ";
-                }
-                ss << "}";
-                return ss.str();
-            }
-        };
+namespace sss {
+
+template<class Time>
+class Model : public virtual common::Model<Time> {
+public:
+  Model(const std::string &name)
+      :
+      common::Model<Time>(name) {
+    assigned = 0;
+    _mark = false;
+    _send = false;
+  }
+
+  virtual ~Model() {}
+
+  virtual void update_buffer(typename Time::type /* time */) = 0;
+
+  void add_event(const common::ExternalEvent<Time> &message) {
+    common::Model<Time>::add_event(message);
+    std::map<std::string, bool>::iterator it =
+        port_assigned.find(message.get_port_name());
+
+    if (it != port_assigned.end() and not it->second) {
+      port_assigned[message.get_port_name()] = true;
+      ++assigned;
+    }
+  }
+
+  void add_in_port(const std::string &port_name, bool sync) {
+    common::Model<Time>::add_in_port(port_name);
+    if (sync) {
+      port_assigned[port_name] = false;
+    }
+  }
+
+  bool all_ports_are_assigned() const { return assigned == port_assigned.size(); }
+
+  void clear_bag() {
+    common::Model<Time>::clear_bag();
+
+    for (auto &p: port_assigned) {
+      p.second = false;
+    }
+    assigned = 0;
+  }
+
+  bool is_marked() const { return _mark; }
+
+  bool is_send() const { return _send; }
 
 
+  void mark() { _mark = true; }
+
+  void send() { _send = true; }
+
+  void unmark() { _mark = false; }
+
+  void unsend() { _send = false; }
+
+private:
+  std::map<std::string, bool> port_assigned;
+  unsigned int assigned;
+  bool _mark;
+  bool _send;
+};
+
+template<class Time>
+class Models : public std::vector<sss::Model<Time> *> {
+public:
+  Models() {}
+
+  virtual ~Models() {}
+
+  std::string to_string() const {
+    std::ostringstream ss;
+
+    ss << "{ ";
+    for (typename Models<Time>::const_iterator it =
+        Models<Time>::begin();
+         it != Models<Time>::end(); ++it) {
+      ss << (*it)->get_name() << " ";
     }
     }
+    ss << "}";
+    return ss.str();
+  }
+};
+
+}
 } // namespace artis sss
 } // namespace artis sss
 
 
 #endif
 #endif

+ 131 - 139
src/artis-star/kernel/sss/Simulator.hpp

@@ -25,7 +25,7 @@
  */
  */
 
 
 #ifndef SSS_SIMULATOR
 #ifndef SSS_SIMULATOR
-#define SSS_SIMULATOR 1
+#define SSS_SIMULATOR
 
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Parameters.hpp>
 #include <artis-star/common/Parameters.hpp>
@@ -37,194 +37,186 @@
 #include <cassert>
 #include <cassert>
 
 
 namespace artis {
 namespace artis {
-    namespace sss {
-
-        template<class Time, class Dynamics,
-                class Parameters = common::NoParameters>
-        class Simulator : public common::Simulator<Time>,
-                          public sss::Model<Time> {
-            typedef Simulator<Time, Dynamics, Parameters> type;
-
-        public:
-            Simulator(const std::string& name, const typename Time::type& time_step,
-                    const Parameters& parameters)
-                    :
-                    common::Model<Time>(name),
-                    common::Simulator<Time>(name),
-                    sss::Model<Time>(name),
-                    _dynamics(name, parameters),
-                    _time_step(time_step) { }
-
-            ~Simulator() { }
-
-            virtual bool is_atomic() const { return common::Simulator<Time>::is_atomic(); }
-
-            virtual void restore(const common::context::State<Time>& state)
-            {
-                common::Simulator<Time>::restore(state);
-                _dynamics.restore(state);
-            }
-
-            virtual void save(context::State<Time>& state) const
-            {
-                common::Simulator<Time>::save(state);
-                _dynamics.save(state);
-            }
-
-            virtual std::string to_string(int level) const { return common::Simulator<Time>::to_string(level); }
-
-            virtual void finish(const typename Time::type& t)
-            {
+namespace sss {
+
+template<class Time, class Dynamics,
+    class Parameters = common::NoParameters>
+class Simulator : public common::Simulator<Time>,
+                  public sss::Model<Time> {
+  typedef Simulator<Time, Dynamics, Parameters> type;
+
+public:
+  Simulator(const std::string &name, const typename Time::type &time_step,
+            const Parameters &parameters)
+      :
+      common::Model<Time>(name),
+      common::Simulator<Time>(name),
+      sss::Model<Time>(name),
+      _dynamics(name, parameters),
+      _time_step(time_step) {}
+
+  ~Simulator() {}
+
+  virtual bool is_atomic() const { return common::Simulator<Time>::is_atomic(); }
+
+  virtual void restore(const common::context::State<Time> &state) {
+    common::Simulator<Time>::restore(state);
+    _dynamics.restore(state);
+  }
+
+  virtual void save(context::State <Time> &state) const {
+    common::Simulator<Time>::save(state);
+    _dynamics.save(state);
+  }
+
+  virtual std::string to_string(int level) const { return common::Simulator<Time>::to_string(level); }
+
+  virtual void finish(const typename Time::type &t) {
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void) t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FormalismType::SSS,
-                                common::FunctionType::FINISH,
-                                common::LevelType::FORMALISM);
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FormalismType::SSS,
+                    common::FunctionType::FINISH,
+                    common::LevelType::FORMALISM);
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
-            }
+  }
 
 
-            typename Time::type start(const typename Time::type& t)
-            {
+  typename Time::type start(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::I_MESSAGE)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::I_MESSAGE)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                _dynamics.start(t);
-                type::_tl = t;
-                type::_tn = t;
+    _dynamics.start(t);
+    type::_tl = t;
+    type::_tn = t;
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::I_MESSAGE)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::I_MESSAGE)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            void observation(std::ostream& file) const
-            {
-                _dynamics.observation(file);
-            }
+  void observation(std::ostream &file) const {
+    _dynamics.observation(file);
+  }
 
 
-            void output(const typename Time::type& t)
-            {
+  void output(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::OUTPUT) << ": BEFORE";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::OUTPUT) << ": BEFORE";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                if (t == type::_tn) {
-                    common::Bag<Time> bag = _dynamics.lambda(t);
+    if (t == type::_tn) {
+      common::Bag<Time> bag = _dynamics.lambda(t);
 
 
-                    if (not bag.empty()) {
-                        for (auto& event : bag) {
-                            event.set_model(this);
-                        }
-                        dynamic_cast < common::Coordinator<Time>* >(
-                                type::get_parent())->dispatch_events(bag, t);
-                    }
-                }
+      if (not bag.empty()) {
+        for (auto &event : bag) {
+          event.set_model(this);
+        }
+        dynamic_cast < common::Coordinator<Time> * >(
+            type::get_parent())->dispatch_events(bag, t);
+      }
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::OUTPUT) << ": AFTER";
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::OUTPUT) << ": AFTER";
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            void post_event(const typename Time::type& t,
-                    const common::ExternalEvent<Time>& event)
-            {
+  void post_event(const typename Time::type &t,
+                  const common::ExternalEvent<Time> &event) {
 
 
 #ifndef WITH_TRACE
 #ifndef WITH_TRACE
-                (void)t;
+    (void) t;
 #endif
 #endif
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::POST_EVENT)
-                        << ": BEFORE => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::POST_EVENT)
+            << ": BEFORE => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                type::add_event(event);
+    type::add_event(event);
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::POST_EVENT)
-                        << ": AFTER => " << event.to_string();
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::POST_EVENT)
+            << ": AFTER => " << event.to_string();
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-            }
+  }
 
 
-            typename Time::type transition(const typename Time::type& t)
-            {
+  typename Time::type transition(const typename Time::type &t) {
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::S_MESSAGE)
-                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::S_MESSAGE)
+            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                assert(t == type::_tn);
+    assert(t == type::_tn);
 
 
-                if (type::is_marked()) {
-                    if (type::is_send()) {
-                        type::_tl = t;
-                        type::_tn = t + _time_step;
-                    }
-                } else {
-                    _dynamics.transition(type::get_bag(), t);
-                    type::clear_bag();
-                }
+    if (type::is_marked()) {
+      if (type::is_send()) {
+        type::_tl = t;
+        type::_tn = t + _time_step;
+      }
+    } else {
+      _dynamics.transition(type::get_bag(), t);
+      type::clear_bag();
+    }
 
 
 #ifdef WITH_TRACE
 #ifdef WITH_TRACE
-                common::Trace<Time>::trace()
-                        << common::TraceElement<Time>(type::get_name(), t,
-                                common::FunctionType::S_MESSAGE)
-                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
-                        << type::_tn;
-                common::Trace<Time>::trace().flush();
+    common::Trace<Time>::trace()
+            << common::TraceElement<Time>(type::get_name(), t,
+                    common::FunctionType::S_MESSAGE)
+            << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+            << type::_tn;
+    common::Trace<Time>::trace().flush();
 #endif
 #endif
 
 
-                return type::_tn;
-            }
+    return type::_tn;
+  }
 
 
-            virtual void update_buffer(typename Time::type time) { _dynamics.update_buffer(time); }
+  virtual void update_buffer(typename Time::type time) { _dynamics.update_buffer(time); }
 
 
-        private :
-            Dynamics _dynamics;
-            typename Time::type _time_step;
-        };
+private :
+  Dynamics _dynamics;
+  typename Time::type _time_step;
+};
 
 
-    }
+}
 } // namespace artis sss
 } // namespace artis sss
 
 
 #endif
 #endif