Parcourir la source

Add new graph manager for multiQSS

Eric Ramat il y a 4 ans
Parent
commit
5a8af48d66
4 fichiers modifiés avec 194 ajouts et 38 suppressions
  1. 1 3
      AUTHORS
  2. 1 1
      src/qss/CMakeLists.txt
  3. 50 34
      src/qss/GraphManager.hpp
  4. 142 0
      src/qss/MultiGraphManager.hpp

+ 1 - 3
AUTHORS

@@ -26,6 +26,4 @@ Main programmer and founder
 
 
 Contributors
-------------
-
-- Christopher Herbez <christopher.herbez@gmail.com>
+------------

+ 1 - 1
src/qss/CMakeLists.txt

@@ -5,6 +5,6 @@ INCLUDE_DIRECTORIES(
 LINK_DIRECTORIES(
         ${Boost_LIBRARY_DIRS})
 
-SET(QSS_HPP GraphManager.hpp)
+SET(QSS_HPP GraphManager.hpp MultiGraphManager.hpp)
 
 INSTALL(FILES ${QSS_HPP} DESTINATION ${ARTIS_ADDONS_INCLUDE_DIRS}/qss)

+ 50 - 34
src/qss/GraphManager.hpp

@@ -36,7 +36,8 @@ namespace artis {
 namespace qss {
 
 template<class DerivativeParameters>
-struct QSSParameters {
+struct QSSParameters
+{
   artis::qss::IntegratorParameters integrator;
   artis::qss::QuantifierParameters quantifier;
   DerivativeParameters derivative;
@@ -48,18 +49,31 @@ template<class Time,
 class GraphManager :
     public artis::pdevs::GraphManager<Time,
                                       QSSParameters<DerivativeParameters>,
-                                      artis::common::NoParameters> {
+                                      artis::common::NoParameters>
+{
 public:
-  enum submodels {
-    S_Derivative, S_Integrator, S_Quantifier
+  struct submodel
+  {
+    enum values
+    {
+      S_Derivative, S_Integrator, S_Quantifier
+    };
   };
 
-  enum inputs {
-    RESET
+  struct input
+  {
+    enum values
+    {
+      RESET
+    };
   };
 
-  enum outputs {
-    OUT
+  struct output
+  {
+    enum values
+    {
+      OUT
+    };
   };
 
   GraphManager(common::Coordinator <Time> *coordinator,
@@ -75,37 +89,39 @@ public:
       ),
       _derivative("d", parameters.derivative),
       _integrator("i", parameters.integrator),
-      _quantifier("q", parameters.quantifier) {
-    this->add_child(S_Derivative, &_derivative);
-    this->add_child(S_Integrator, &_integrator);
-    this->add_child(S_Quantifier, &_quantifier);
-
-    coordinator->input_port({RESET, "reset"});
-    coordinator->output_port({OUT, "out"});
-
-    this->in({coordinator, RESET})
-        >> this->in({&_derivative, Derivative::RESET});
-    this->in({coordinator, RESET})
-        >> this->in({&_integrator, Integrator<Time>::RESET});
-    this->in({coordinator, RESET})
-        >> this->in({&_quantifier, Quantifier<Time>::RESET});
-
-    this->out({&_derivative, Derivative::OUT})
-        >> this->in({&_integrator, Integrator<Time>::X_DOT});
-    this->out({&_integrator, Integrator<Time>::OUT})
-        >> this->in({&_quantifier, Quantifier<Time>::IN});
-    this->out({&_quantifier, Quantifier<Time>::OUT})
-        >> this->in({&_integrator, Integrator<Time>::QUANTA});
-    this->out({&_integrator, Integrator<Time>::OUT})
-        >> this->out({coordinator, OUT});
-    this->out({&_integrator, Integrator<Time>::OUT})
-        >> this->in({&_derivative, Derivative::IN});
+      _quantifier("q", parameters.quantifier)
+  {
+    this->add_child(submodel::S_Derivative, &_derivative);
+    this->add_child(submodel::S_Integrator, &_integrator);
+    this->add_child(submodel::S_Quantifier, &_quantifier);
+
+    coordinator->input_port({input::RESET, "reset"});
+    coordinator->output_port({output::OUT, "out"});
+
+    this->in({coordinator, input::RESET})
+        >> this->in({&_derivative, Derivative::input::RESET});
+    this->in({coordinator, input::RESET})
+        >> this->in({&_integrator, Integrator<Time>::input::RESET});
+    this->in({coordinator, input::RESET})
+        >> this->in({&_quantifier, Quantifier<Time>::input::RESET});
+
+    this->out({&_derivative, Derivative::output::OUT})
+        >> this->in({&_integrator, Integrator<Time>::input::X_DOT});
+    this->out({&_integrator, Integrator<Time>::output::OUT})
+        >> this->in({&_quantifier, Quantifier<Time>::input::IN});
+    this->out({&_quantifier, Quantifier<Time>::output::OUT})
+        >> this->in({&_integrator, Integrator<Time>::input::QUANTA});
+    this->out({&_integrator, Integrator<Time>::output::OUT})
+        >> this->out({coordinator, output::OUT});
+    this->out({&_integrator, Integrator<Time>::output::OUT})
+        >> this->in({&_derivative, Derivative::input::IN});
   }
 
   ~GraphManager() override = default;
 
   artis::pdevs::Simulator<Time, Derivative, DerivativeParameters> *
-  derivative() { return &_derivative; }
+  derivative()
+  { return &_derivative; }
 
 private:
   artis::pdevs::Simulator<Time, Derivative, DerivativeParameters> _derivative;

+ 142 - 0
src/qss/MultiGraphManager.hpp

@@ -0,0 +1,142 @@
+/**
+ * @file kernel/qss/MultiGraphManager.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 QSS_MULTI_GRAPH_MANAGER
+#define QSS_MULTI_GRAPH_MANAGER
+
+#include <artis-star/kernel/pdevs/GraphManager.hpp>
+#include <artis-star/kernel/qss/MultiDerivative.hpp>
+#include <artis-star/kernel/qss/Integrator.hpp>
+#include <artis-star/kernel/qss/Quantifier.hpp>
+
+namespace artis {
+namespace qss {
+
+template<class DerivativeParameters>
+struct MultiQSSParameters
+{
+  std::vector <artis::qss::IntegratorParameters> integrators;
+  std::vector <artis::qss::QuantifierParameters> quantifiers;
+  DerivativeParameters derivative;
+};
+
+template<class Time,
+    class Derivative,
+    class DerivativeParameters = artis::common::NoParameters>
+class MultiGraphManager :
+    public artis::pdevs::GraphManager<Time,
+                                      MultiQSSParameters<DerivativeParameters>,
+                                      artis::common::NoParameters>
+{
+public:
+  struct submodel
+  {
+    enum values
+    {
+      S_Derivative = 0, S_Integrator = 1, S_Quantifier = 1000
+    };
+  };
+
+  struct input
+  {
+    enum values
+    {
+      RESET
+    };
+  };
+
+  MultiGraphManager(common::Coordinator <Time> *coordinator,
+                    const MultiQSSParameters<DerivativeParameters> &parameters,
+                    const artis::common::NoParameters &graph_parameters)
+      :
+      artis::pdevs::GraphManager<Time,
+                                 MultiQSSParameters<DerivativeParameters>,
+                                 artis::common::NoParameters>(
+          coordinator, parameters, graph_parameters),
+      _derivative("d", parameters.derivative)
+  {
+    this->add_child(submodel::S_Derivative, &_derivative);
+    coordinator->input_port({input::RESET, "reset"});
+    this->in({coordinator, input::RESET})
+        >> this->in({&_derivative, Derivative::input::RESET});
+    for (unsigned int index = 0; index < _derivative.dynamics().variable_number(); ++index) {
+      _integrators.push_back(new IntegratorSimulator("i_" + std::to_string(index),
+                                                     parameters.integrators[index]));
+      _quantifiers.push_back(new QuantifierSimulator("q_" + std::to_string(index),
+                                                     parameters.quantifiers[index]));
+      this->add_child(submodel::S_Integrator + index, _integrators.back());
+      this->add_child(submodel::S_Quantifier + index, _quantifiers.back());
+      coordinator->output_port({index, "out_" + std::to_string(index)});
+      this->in({coordinator, input::RESET})
+          >> this->in({_integrators.back(), Integrator<Time>::input::RESET});
+      this->in({coordinator, input::RESET})
+          >> this->in({_quantifiers.back(), Quantifier<Time>::input::RESET});
+
+      this->out({&_derivative, index})
+          >> this->in({_integrators.back(), Integrator<Time>::input::X_DOT});
+      this->out({_integrators.back(), Integrator<Time>::output::OUT})
+          >> this->in({_quantifiers.back(), Quantifier<Time>::input::IN});
+      this->out({_quantifiers.back(), Quantifier<Time>::output::OUT})
+          >> this->in({_integrators.back(), Integrator<Time>::input::QUANTA});
+      this->out({_integrators.back(), Integrator<Time>::output::OUT})
+          >> this->out({coordinator, index});
+      this->out({_integrators.back(), Integrator<Time>::output::OUT})
+          >> this->in({&_derivative, Derivative::input::INTERNAL + index});
+    }
+  }
+
+  ~MultiGraphManager() override
+  {
+    std::for_each(_integrators.begin(),
+                  _integrators.end(),
+                  std::default_delete<IntegratorSimulator>());
+    std::for_each(_quantifiers.begin(),
+                  _quantifiers.end(),
+                  std::default_delete<QuantifierSimulator>());
+  }
+
+  artis::pdevs::Simulator<Time, Derivative, DerivativeParameters> *derivative()
+  { return &_derivative; }
+
+private:
+  typedef artis::pdevs::Simulator<Time,
+                                  artis::qss::Integrator<Time>,
+                                  artis::qss::IntegratorParameters> IntegratorSimulator;
+  typedef std::vector<IntegratorSimulator *> IntegratorSimulators;
+  typedef artis::pdevs::Simulator<Time,
+                                  artis::qss::Quantifier<Time>,
+                                  artis::qss::QuantifierParameters> QuantifierSimulator;
+  typedef std::vector<QuantifierSimulator *> QuantifierSimulators;
+
+  artis::pdevs::Simulator<Time, Derivative, DerivativeParameters> _derivative;
+  IntegratorSimulators _integrators;
+  QuantifierSimulators _quantifiers;
+};
+
+}
+}
+
+#endif