Parcourir la source

Add DTSS policies

Eric Ramat il y a 4 ans
Parent
commit
8a58bb498e

+ 1 - 1
src/artis-star/kernel/dtss/CMakeLists.txt

@@ -6,6 +6,6 @@ INCLUDE_DIRECTORIES(
 LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
-SET(DTSS_HPP Coordinator.hpp Dynamics.hpp GraphManager.hpp Simulator.hpp)
+SET(DTSS_HPP Coordinator.hpp Dynamics.hpp GraphManager.hpp Policy.hpp Simulator.hpp)
 
 INSTALL(FILES ${DTSS_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/kernel/dtss)

+ 1 - 0
src/artis-star/kernel/dtss/Coordinator.hpp

@@ -206,6 +206,7 @@ namespace artis {
                     for (auto& event : _policy.bag()) {
                         post_event(t, event);
                     }
+                    _policy.clear();
                     for (auto& model : _graph_manager.children()) {
                         model->transition(t);
                     }

+ 101 - 0
src/artis-star/kernel/dtss/Policy.hpp

@@ -0,0 +1,101 @@
+/**
+ * @file kernel/dtss/Coordinator.hpp
+ * @author The ARTIS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * ARTIS - the multimodeling and simulation environment
+ * This file is a part of the ARTIS environment
+ *
+ * Copyright (C) 2013-2019 ULCO http://www.univ-littoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef DTSS_POLICY
+#define DTSS_POLICY 1
+
+#include <artis-star/common/Bag.hpp>
+
+#include <cassert>
+
+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 */) { }
+        };
+
+    }
+}
+
+#endif