Parcourir la source

Clean and optimize code

Eric Ramat il y a 4 ans
Parent
commit
76caeac1d1
67 fichiers modifiés avec 3708 ajouts et 3680 suppressions
  1. 1 3
      .gitignore
  2. 2 0
      .idea/.gitignore
  3. 1 0
      .idea/.name
  4. 2 0
      .idea/artis-star.iml
  5. 24 0
      .idea/inspectionProfiles/Project_Default.xml
  6. 4 0
      .idea/misc.xml
  7. 8 0
      .idea/modules.xml
  8. 6 0
      .idea/vcs.xml
  9. 1 1
      AUTHORS
  10. 1 1
      CMakeLists.txt
  11. 1 3
      README
  12. 3 3
      src/CMakeLists.txt
  13. 6 10
      src/apps/CMakeLists.txt
  14. 1 9
      src/apps/main.cpp
  15. 2 2
      src/artis-star.pc.in
  16. 46 46
      src/artis-star/common/Bag.hpp
  17. 6 9
      src/artis-star/common/CMakeLists.txt
  18. 99 83
      src/artis-star/common/Coordinator.hpp
  19. 78 83
      src/artis-star/common/ExternalEvent.hpp
  20. 39 43
      src/artis-star/common/GraphManager.hpp
  21. 41 47
      src/artis-star/common/InternalEvent.hpp
  22. 87 87
      src/artis-star/common/Links.hpp
  23. 252 238
      src/artis-star/common/Model.hpp
  24. 34 37
      src/artis-star/common/Node.hpp
  25. 9 9
      src/artis-star/common/Parameters.hpp
  26. 59 61
      src/artis-star/common/RootCoordinator.hpp
  27. 17 19
      src/artis-star/common/Scheduler.hpp
  28. 32 28
      src/artis-star/common/Simulator.hpp
  29. 129 129
      src/artis-star/common/Value.hpp
  30. 2 2
      src/artis-star/common/observer/CMakeLists.txt
  31. 57 59
      src/artis-star/common/observer/Observer.hpp
  32. 50 50
      src/artis-star/common/observer/Output.hpp
  33. 170 167
      src/artis-star/common/observer/View.hpp
  34. 6 10
      src/artis-star/common/scheduler/CMakeLists.txt
  35. 93 92
      src/artis-star/common/scheduler/HeapScheduler.hpp
  36. 12 12
      src/artis-star/common/scheduler/SchedulerHandle.hpp
  37. 83 82
      src/artis-star/common/scheduler/VectorScheduler.hpp
  38. 5 5
      src/artis-star/common/time/CMakeLists.txt
  39. 14 13
      src/artis-star/common/time/DoubleTime.hpp
  40. 12 11
      src/artis-star/common/time/Time.hpp
  41. 5 9
      src/artis-star/common/utils/CMakeLists.txt
  42. 179 186
      src/artis-star/common/utils/Multithreading.hpp
  43. 16 15
      src/artis-star/common/utils/String.hpp
  44. 164 170
      src/artis-star/common/utils/Trace.hpp
  45. 4 7
      src/artis-star/kernel/dtss/CMakeLists.txt
  46. 151 153
      src/artis-star/kernel/dtss/Coordinator.hpp
  47. 54 28
      src/artis-star/kernel/dtss/Dynamics.hpp
  48. 104 79
      src/artis-star/kernel/dtss/GraphManager.hpp
  49. 124 103
      src/artis-star/kernel/dtss/Simulator.hpp
  50. 5 8
      src/artis-star/kernel/pdevs/CMakeLists.txt
  51. 184 188
      src/artis-star/kernel/pdevs/Coordinator.hpp
  52. 70 85
      src/artis-star/kernel/pdevs/Dynamics.hpp
  53. 120 136
      src/artis-star/kernel/pdevs/GraphManager.hpp
  54. 132 136
      src/artis-star/kernel/pdevs/Simulator.hpp
  55. 6 9
      src/artis-star/kernel/pdevs/mpi/CMakeLists.txt
  56. 33 30
      src/artis-star/kernel/pdevs/mpi/Coordinator.hpp
  57. 28 25
      src/artis-star/kernel/pdevs/mpi/GraphManager.hpp
  58. 72 72
      src/artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp
  59. 123 113
      src/artis-star/kernel/pdevs/mpi/ModelProxy.hpp
  60. 5 8
      src/artis-star/kernel/pdevs/multithreading/CMakeLists.txt
  61. 191 199
      src/artis-star/kernel/pdevs/multithreading/Coordinator.hpp
  62. 5 8
      src/artis-star/kernel/sss/CMakeLists.txt
  63. 124 128
      src/artis-star/kernel/sss/Coordinator.hpp
  64. 24 30
      src/artis-star/kernel/sss/Dynamics.hpp
  65. 83 83
      src/artis-star/kernel/sss/GraphManager.hpp
  66. 94 102
      src/artis-star/kernel/sss/Model.hpp
  67. 113 116
      src/artis-star/kernel/sss/Simulator.hpp

+ 1 - 3
.gitignore

@@ -1,4 +1,2 @@
 *~
-build/
-.idea
-.DS_Store
+build/

+ 2 - 0
.idea/.gitignore

@@ -0,0 +1,2 @@
+# Default ignored files
+/workspace.xml

+ 1 - 0
.idea/.name

@@ -0,0 +1 @@
+ARTIS_STAR

+ 2 - 0
.idea/artis-star.iml

@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module classpath="CMake" type="CPP_MODULE" version="4" />

+ 24 - 0
.idea/inspectionProfiles/Project_Default.xml

@@ -0,0 +1,24 @@
+<component name="InspectionProjectProfileManager">
+  <profile version="1.0">
+    <option name="myName" value="Project Default" />
+    <inspection_tool class="ClangTidy" enabled="true" level="WARNING" enabled_by_default="true">
+      <option name="clangTidyCheckOptions">
+        <list>
+          <ClangTidyCheckOption>
+            <option name="optionName" value="readability-function-size.LineThreshold" />
+            <option name="optionValue" value="10" />
+          </ClangTidyCheckOption>
+          <ClangTidyCheckOption>
+            <option name="optionName" value="&#9;readability-function-size.BranchThreshold" />
+            <option name="optionValue" value="3" />
+          </ClangTidyCheckOption>
+          <ClangTidyCheckOption>
+            <option name="optionName" value="readability-function-size.ParameterThreshold" />
+            <option name="optionValue" value="4" />
+          </ClangTidyCheckOption>
+        </list>
+      </option>
+      <option name="clangTidyChecks" value="clang-analyzer-*,cppcoreguidelines-*,readability-*" />
+    </inspection_tool>
+  </profile>
+</component>

+ 4 - 0
.idea/misc.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/artis-star.iml" filepath="$PROJECT_DIR$/.idea/artis-star.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

+ 1 - 1
AUTHORS

@@ -6,7 +6,7 @@ Copyright
 =========
 
 - ULCO
-  - Copyright © 2013-2018
+  - Copyright © 2013-2019
   - Université du Littoral Côte d'Opale
   - http://www.univ-littoral.fr
 

+ 1 - 1
CMakeLists.txt

@@ -1,5 +1,5 @@
 CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(ARTIS CXX C)
+PROJECT(ARTIS_STAR CXX C)
 ENABLE_TESTING()
 
 SET(ARTIS_MAJOR 1)

+ 1 - 3
README

@@ -8,7 +8,6 @@ systems. It addresses the reliability issue by using recent
 developments in the theory of modeling and simulation proposed by B. Zeigler
 with the Discrete Event System Specification formalism (DEVS).
 
-
 Requirements
 ------------
 
@@ -24,8 +23,7 @@ To build VLE you need:
 Getting the code
 ----------------
 
-The source tree is currently hosted on GitHub. To view the repository
-online :
+The source tree is currently hosted on GitHub. To view the repository online:
     https://gogs.univ-littoral.fr/devs-lab/artis-star
 
 The URL to clone it:

+ 3 - 3
src/CMakeLists.txt

@@ -1,8 +1,8 @@
 IF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-  message("TRACE on")
-  add_definitions(-DWITH_TRACE)
+    message("TRACE on")
+    add_definitions(-DWITH_TRACE)
 ELSE ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
-  message("TRACE off")
+    message("TRACE off")
 ENDIF ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
 
 ADD_SUBDIRECTORY(apps)

+ 6 - 10
src/apps/CMakeLists.txt

@@ -1,20 +1,16 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIRS}
-  ${Boost_LIBRARY_DIRS})
+        ${Boost_LIBRARY_DIRS})
 
 ADD_EXECUTABLE(artis-star main.cpp ${MIXED_TESTS_HPP})
 SET_TARGET_PROPERTIES(artis-star PROPERTIES ${ARTIS_APP_PROPERTIES})
 
 TARGET_LINK_LIBRARIES(artis-star
-  ${Boost_SYSTEM_LIBRARY}
-  ${Boost_TIMER_LIBRARY})
+        ${Boost_SYSTEM_LIBRARY}
+        ${Boost_TIMER_LIBRARY})
 
 INSTALL(TARGETS artis-star DESTINATION bin)

+ 1 - 9
src/apps/main.cpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -24,15 +24,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <artis-star/common/Value.hpp>
-
 int main()
 {
-    artis::common::Value v1;
-    artis::common::Value v2(10);
-    artis::common::Value v3(v2);
-    artis::common::Value v4(v1);
-
-    v1 = v2;
     return 0;
 }

+ 2 - 2
src/artis-star.pc.in

@@ -3,8 +3,8 @@ exec_prefix=${prefix}
 libdir=${exec_prefix}/@ARTIS_PKGCONFIG_LIBDIR@
 includedir=${prefix}/include
 
-Name: vle
-Description: ARTIS multimodelling and Simulation tools
+Name: artis-star
+Description: ARTIS multimodeling and Simulation tools
 Requires:
 Version: @ARTIS_VERSION@
 Libs:	-L${libdir} \

+ 46 - 46
src/artis-star/common/Bag.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -35,57 +35,57 @@
 #include <string>
 #include <vector>
 
-namespace artis { namespace common {
-
-template < class Time >
-class ExternalEvent;
-
-template < class Time >
-class Bag : public std::vector < ExternalEvent < Time > >
-{
-public:
-    Bag()
-    { }
-    virtual ~Bag()
-    { }
-
-    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();
-    }
+namespace artis {
+    namespace common {
 
-private:
-    friend class boost::serialization::access;
+        template<class Time>
+        class ExternalEvent;
 
-    template<class Archive>
-    void save(Archive & ar, const unsigned int version) const
-    {
-        (void) version;
+        template<class Time>
+        class Bag : public std::vector<ExternalEvent<Time> > {
+        public:
+            Bag() { }
 
-        ar & *dynamic_cast < const std::vector < ExternalEvent < Time > >* >(
-            this);
-    }
+            virtual ~Bag() { }
 
-    template<class Archive>
-    void load(Archive & ar, const unsigned int version)
-    {
-        (void) version;
+            std::string to_string() const
+            {
+                std::ostringstream ss;
 
-        ar & *dynamic_cast < std::vector < ExternalEvent < Time > >* >(this);
-    }
+                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;
+
+            template<class Archive>
+            void save(Archive& ar, const unsigned int version) const
+            {
+                (void) version;
 
-    BOOST_SERIALIZATION_SPLIT_MEMBER()
-};
+                ar & *dynamic_cast < const std::vector<ExternalEvent<Time> >* >(
+                        this);
+            }
 
-} } // namespace artis common
+            template<class Archive>
+            void load(Archive& ar, const unsigned int version)
+            {
+                (void) version;
+
+                ar & *dynamic_cast < std::vector<ExternalEvent<Time> >* >(this);
+            }
+
+            BOOST_SERIALIZATION_SPLIT_MEMBER()
+        };
+
+    }
+} // namespace artis common
 
 #endif

+ 6 - 9
src/artis-star/common/CMakeLists.txt

@@ -1,17 +1,14 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
+        ${Boost_LIBRARY_DIRS})
 
 SET(COMMON_HPP Bag.hpp Coordinator.hpp ExternalEvent.hpp
-  GraphManager.hpp InternalEvent.hpp Links.hpp Model.hpp Node.hpp Parameters.hpp
-  RootCoordinator.hpp Scheduler.hpp Simulator.hpp Value.hpp)
+        GraphManager.hpp InternalEvent.hpp Links.hpp Model.hpp Node.hpp Parameters.hpp
+        RootCoordinator.hpp Scheduler.hpp Simulator.hpp Value.hpp)
 
 INSTALL(FILES ${COMMON_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/common)
 

+ 99 - 83
src/artis-star/common/Coordinator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -35,95 +35,111 @@
 
 #include <sstream>
 
-namespace artis { namespace common {
+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 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 std::string to_string(int /* level */) const
+            {
+                std::ostringstream ss;
+
+                ss << "Coordinator " << Coordinator<Time>::get_name();
+                return ss.str();
+            }
 
-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)
-    { }
+// DEVS methods
+            virtual common::Value observe(const typename Time::type& t, unsigned int index) const = 0;
 
-    virtual ~Coordinator()
-    { }
+            virtual void output(const typename Time::type& t) = 0;
 
-    virtual const GraphManager < Time >& get_graph_manager() const = 0;
+            virtual void post_event(const typename Time::type& t, const common::ExternalEvent<Time>& event) = 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 typename Time::type dispatch_events(const common::Bag<Time>& bag,
+                    const typename Time::type& t) = 0;
 
-        if (it != graph_manager.child_map().end()) {
-            return it->second;
-        } else {
-            return nullptr;
-        }
-    }
+            virtual typename Time::type start(const typename Time::type& t) = 0;
 
-    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 typename Time::type transition(const typename Time::type& t) = 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);
-
-        if (it != graph_manager.children_map().end()) {
-            return it->second.size();
-        } else {
-            return 0;
-        }
     }
-
-    virtual bool is_atomic() const
-    { return false; }
-
-    virtual std::string to_string(int /* level */) const
-    {
-        std::ostringstream ss;
-
-        ss << "Coordinator "
-           << Coordinator < Time >::get_name();
-        return ss.str();
-    }
-
-// DEVS methods
-    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

+ 78 - 83
src/artis-star/common/ExternalEvent.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -38,92 +38,87 @@
 #include <string>
 #include <vector>
 
-namespace artis { namespace common {
-
-template < class Time >
-class Node;
-template < class Time >
-class Model;
-
-template < class Time >
-class ExternalEvent
-{
-public:
-    ExternalEvent(unsigned 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 ExternalEvent& event) :
-        _port_index(event._port_index), _model(event._model),
-        _data(event._data)
-    { }
-
-    ExternalEvent() : _model(nullptr)
-    { }
-
-    virtual ~ExternalEvent()
-    { }
-
-    const Value& data() const
-    { return _data; }
-
-    unsigned int get_port_index() const
-    { return _port_index; }
-
-    void data(const Value& data)
-    { _data = data; }
-
-    Model < Time >* get_model() const
-    { return _model; }
-
-    bool on_port(unsigned int port_index) const
-    { return _port_index == port_index; }
-
-    void set_model(Model < Time >* model)
-    { _model = model; }
-
-    std::string to_string() const
-    {
-        std::ostringstream ss;
-
-        ss << "( " << _port_index << " , "
-           << (_model ? _model->get_name() : "<>")
-           << " , ";
-        if (not _data.empty()) {
-            ss << _data.to_string();
-        } else {
-            ss << "null";
-        }
-        ss << ")";
-        return ss.str();
-    }
+namespace artis {
+    namespace common {
 
-private:
-    friend class boost::serialization::access;
+        template<class Time>
+        class Node;
 
-    template<class Archive>
-    void serialize(Archive & ar, const unsigned int version)
-    {
-        (void) version;
+        template<class Time>
+        class Model;
 
-        ar & _port_index;
-        _model = 0;
-        // ar & _model;
-        ar & _data;
-        // ar & _model->get_name();
-    }
+        template<class Time>
+        class ExternalEvent {
+        public:
+            ExternalEvent(unsigned 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 ExternalEvent& event)
+                    :
+                    _port_index(event._port_index), _model(event._model),
+                    _data(event._data) { }
+
+            ExternalEvent()
+                    :_model(nullptr) { }
+
+            virtual ~ExternalEvent() { }
+
+            const Value& data() const { return _data; }
+
+            unsigned int get_port_index() const { return _port_index; }
+
+            void data(const Value& data) { _data = data; }
 
-    unsigned int    _port_index;
-    Model < Time >* _model;
-    Value           _data;
-};
+            Model<Time>* get_model() const { return _model; }
 
-} } // namespace artis common
+            bool on_port(unsigned int port_index) const { return _port_index == port_index; }
+
+            void set_model(Model<Time>* model) { _model = model; }
+
+            std::string to_string() const
+            {
+                std::ostringstream ss;
+
+                ss << "( " << _port_index << " , "
+                   << (_model ? _model->get_name() : "<>")
+                   << " , ";
+                if (not _data.empty()) {
+                    ss << _data.to_string();
+                } else {
+                    ss << "null";
+                }
+                ss << ")";
+                return ss.str();
+            }
+
+        private:
+            friend class boost::serialization::access;
+
+            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();
+            }
+
+            unsigned int _port_index;
+            Model<Time>* _model;
+            Value _data;
+        };
+
+    }
+} // namespace artis common
 
 #endif

+ 39 - 43
src/artis-star/common/GraphManager.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -24,8 +24,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_GRAPH_MANANGER
-#define COMMON_GRAPH_MANANGER
+#ifndef COMMON_GRAPH_MANAGER
+#define COMMON_GRAPH_MANAGER
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/Links.hpp>
@@ -35,55 +35,51 @@
 
 #include <sstream>
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-template < class Time >
-class GraphManager
-{
-public:
-    GraphManager(common::Coordinator < Time >* coordinator) :
-        _coordinator(coordinator)
-    { }
+        template<class Time>
+        class GraphManager {
+        public:
+            GraphManager(common::Coordinator<Time>* coordinator)
+                    :
+                    _coordinator(coordinator) { }
 
-    virtual ~GraphManager()
-    { }
+            virtual ~GraphManager() { }
 
-    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_child(unsigned int index, common::Model<Time>* child)
+            {
+                _children.push_back(child);
+                _child_map[index] = child;
+                child->set_parent(_coordinator);
+            }
 
-    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);
-    }
+            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::Models<Time>& children() const { return _children; }
 
-    const common::ModelMap < Time >& child_map() const
-    { return _child_map; }
+            const common::ModelMap<Time>& child_map() const { return _child_map; }
 
-    const common::ModelsMap < Time >& children_map() const
-    { return _children_map; }
+            const common::ModelsMap<Time>& children_map() const { return _children_map; }
 
-    common::Coordinator < Time >* get_coordinator() const
-    { return _coordinator; }
+            common::Coordinator<Time>* get_coordinator() const { return _coordinator; }
 
-protected:
-    common::Models < Time >        _children;
-    common::ModelMap < Time >      _child_map;
-    common::ModelsMap < Time >     _children_map;
-    common::Coordinator < Time >*  _coordinator;
-};
+        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

+ 41 - 47
src/artis-star/common/InternalEvent.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,64 +31,58 @@
 
 #include <functional>
 
-namespace artis { namespace common {
+namespace artis {
+    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

+ 87 - 87
src/artis-star/common/Links.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -33,93 +33,93 @@
 #include <map>
 #include <sstream>
 
-namespace artis { namespace common {
-
-template < class Time >
-class Node;
-
-template < class Time >
-class Links : public std::multimap < Node < Time >,
-                                     Node < Time > >
-{
-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)
-    {
-        std::multimap < Node < Time >,
-                        Node < Time > >::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 =
-	std::multimap < Node < Time >,
-			Node < Time > >::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;
-    }
+namespace artis {
+    namespace common {
+
+        template<class Time>
+        class Node;
+
+        template<class Time>
+        class Links : public std::multimap<Node<Time>,
+                Node<Time> > {
+        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)
+            {
+                std::multimap<Node<Time>,
+                        Node<Time> >::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 =
+                        std::multimap<Node<Time>,
+                                Node<Time> >::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;
+            }
+
+            Links::Result find(Model<Time>* out_model,
+                    unsigned int out_port_index) const
+            {
+                return std::multimap<Node<Time>,
+                        Node<Time> >::equal_range(
+                        common::Node<Time>(
+                                out_model, out_port_index));
+            }
+
+            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();
+            }
+        };
 
-    Links::Result find(Model < Time >* out_model,
-                       unsigned int out_port_index) const
-    {
-        return std::multimap < Node < Time >,
-                               Node < Time > >::equal_range(
-                                   common::Node < Time >(
-                                       out_model, out_port_index));
     }
-
-    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

+ 252 - 238
src/artis-star/common/Model.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -39,281 +39,295 @@
 #include <iostream>
 #include <sstream>
 
-namespace artis { namespace common {
+namespace artis {
+    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));
+            // 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;
-    }
+                _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));
+            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;
-    }
+                _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));
+            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);
-    }
+                _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));
+            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);
-    }
+                _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_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();
-    }
+            bool exist_out_port(unsigned int port_index) const
+            {
+                return _out_port_map.find(port_index) != _out_port_map.end();
+            }
 
-    std::string get_in_port_name(unsigned int port_index) const
-    {
-        assert(exist_in_port(port_index));
+            std::string get_in_port_name(unsigned int port_index) const
+            {
+                assert(exist_in_port(port_index));
 
-        return _in_port_map.find(port_index)->second;
-    }
+                return _in_port_map.find(port_index)->second;
+            }
 
-    std::string get_out_port_name(unsigned int port_index) const
-    {
-        assert(exist_out_port(port_index));
+            std::string get_out_port_name(unsigned int port_index) const
+            {
+                assert(exist_out_port(port_index));
 
-        return _out_port_map.find(port_index)->second;
-    }
+                return _out_port_map.find(port_index)->second;
+            }
 
-    const std::string& get_name() const
-    { return _name; }
+            const std::string& get_name() const { return _name; }
 
-    Model < Time >* get_parent() const
-    { return _parent; }
+            Model<Time>* get_parent() const { return _parent; }
 
-    // TODO: to remove
-    virtual int get_receiver_number(typename Time::type t)
-    { (void)t; return 0; }
+            // TODO: to remove
+            virtual int get_receiver_number(typename Time::type t)
+            {
+                (void) t;
 
-    virtual const Model < Time >* get_submodel(unsigned int index) const
-    { (void)index; assert(false); }
+                return 0;
+            }
 
-    virtual const Model < Time >* get_submodel(unsigned int index,
-                                               unsigned int rank) const
-    { (void)index; (void)rank; assert(false); }
+            virtual const Model<Time>* get_submodel(unsigned int index) const
+            {
+                (void) index;
 
-    virtual unsigned int get_submodel_number(unsigned int index) const
-    { (void)index; assert(false); }
+                assert(false);
 
-    virtual bool is_atomic() const = 0;
+                return nullptr;
+            }
 
-    virtual bool is_remote() const
-    { return false; }
+            virtual const Model<Time>* get_submodel(unsigned int index,
+                    unsigned int rank) const
+            {
+                (void) index;
+                (void) rank;
 
-    virtual std::string observable_name(unsigned int observable_index) const
-    { (void)observable_index; assert(false); }
+                assert(false);
 
-    std::string path() const
-    { return (_parent != nullptr ? _parent->path() : "") + ":" + get_name(); }
+                return nullptr;
+            }
 
-    void set_parent(Model < Time >* parent)
-    { _parent = parent; }
+            virtual unsigned int get_submodel_number(unsigned int index) const
+            {
+                (void) index;
 
-    virtual std::string to_string(int /* level */) const =0;
+                assert(false);
 
-    // event
-    void add_event(const common::ExternalEvent < Time >& message)
-    {
-        if (_inputs == 0) {
-            _inputs = new Bag < Time >;
-        }
-        _inputs->push_back(message);
-    }
+                return 0;
+            }
 
-    void clear_bag()
-    {
-        if (_inputs) {
-            delete _inputs;
-            _inputs = 0;
-        }
-    }
+            virtual bool is_atomic() const = 0;
 
-    unsigned int event_number() const
-    {
-        if (_inputs) {
-            return _inputs->size();
-        } else {
-            return 0;
-        }
-    }
+            virtual bool is_remote() const { return false; }
 
-    const common::Bag < Time >& get_bag()
-    {
-        if (_inputs == 0) {
-            _inputs = new Bag < Time >;
-        }
-        return *_inputs;
-    }
+            virtual std::string observable_name(unsigned int observable_index) const
+            {
+                (void) observable_index;
 
-    // time
-    typename Time::type get_tl() const
-    { return _tl; }
-
-    typename Time::type get_tn() const
-    { return _tn; }
-
-    // devs methods
-    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;
-
-    // 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();
-    }
-};
+                assert(false);
+
+                return std::string();
+            }
+
+            std::string path() const { return (_parent != nullptr ? _parent->path() : "") + ":" + get_name(); }
+
+            void set_parent(Model<Time>* parent) { _parent = parent; }
 
-} } // namespace artis common
+            virtual std::string to_string(int /* level */) 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;
+            }
+
+            // time
+            typename Time::type get_tl() const { return _tl; }
+
+            typename Time::type get_tn() const { return _tn; }
+
+            // devs methods
+            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;
+
+            // 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();
+            }
+        };
+
+    }
+} // namespace artis common
 
 #endif

+ 34 - 37
src/artis-star/common/Node.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,51 +31,48 @@
 
 #include <string>
 
-namespace artis { namespace common {
+namespace artis {
+    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

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

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -27,15 +27,15 @@
 #ifndef COMMON_PARAMETERS
 #define COMMON_PARAMETERS 1
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-class NoParameters
-{
-public:
-    NoParameters()
-    { }
-};
+        class NoParameters {
+        public:
+            NoParameters() { }
+        };
 
-} } // namespace artis common
+    }
+} // namespace artis common
 
 #endif

+ 59 - 61
src/artis-star/common/RootCoordinator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -34,72 +34,70 @@
 #include <sstream>
 #include <string>
 
-namespace artis { namespace common {
-
-template < class Time, class Coordinator >
-class RootCoordinator
-{
-public :
-    RootCoordinator(
-        const typename Time::type& t_start,
-        const typename Time::type& t_max,
-        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(t_max), _tn(t_start)
-    { }
-
-    RootCoordinator(const typename Time::type& t_start,
+namespace artis {
+    namespace common {
+
+        template<class Time, class Coordinator>
+        class RootCoordinator {
+        public :
+            RootCoordinator(
+                    const typename Time::type& t_start,
                     const typename Time::type& t_max,
                     const std::string& root_name,
-                    const typename Coordinator::parameters_type& parameters) :
-        _root(root_name, parameters, NoParameters()), _observer(&_root),
-        _t_max(t_max), _tn(t_start)
-    { }
+                    const typename Coordinator::parameters_type& parameters,
+                    const typename Coordinator::graph_parameters_type& graph_parameters)
+                    :
+                    _root(root_name, parameters, graph_parameters), _observer(&_root),
+                    _t_max(t_max), _tn(t_start) { }
 
-    RootCoordinator(const typename Time::type& t_start,
+            RootCoordinator(const typename Time::type& t_start,
                     const typename Time::type& t_max,
-                    const std::string& root_name) :
-        _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
-        _t_max(t_max), _tn(t_start)
-    { }
-
-    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()
-    {
-        _observer.init();
-        _tn = _root.start(_tn);
-        while (_tn <= _t_max) {
-            _root.output(_tn);
-            _tn = _root.transition(_tn);
-            _observer.observe(_tn);
-        }
-    }
+                    const std::string& root_name,
+                    const typename Coordinator::parameters_type& parameters)
+                    :
+                    _root(root_name, parameters, NoParameters()), _observer(&_root),
+                    _t_max(t_max), _tn(t_start) { }
 
-    std::string to_string() const
-    {
-        std::ostringstream ss;
+            RootCoordinator(const typename Time::type& t_start,
+                    const typename Time::type& t_max,
+                    const std::string& root_name)
+                    :
+                    _root(root_name, NoParameters(), NoParameters()), _observer(&_root),
+                    _t_max(t_max), _tn(t_start) { }
+
+            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()
+            {
+                _observer.init();
+                _tn = _root.start(_tn);
+                while (_tn <= _t_max) {
+                    _root.output(_tn);
+                    _tn = _root.transition(_tn);
+                    _observer.observe(_tn);
+                }
+            }
+
+            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;
+        };
 
-        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

+ 17 - 19
src/artis-star/common/Scheduler.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -28,32 +28,30 @@
 #define COMMON_SCHEDULER 1
 
 #include <artis-star/common/scheduler/HeapScheduler.hpp>
+#include <artis-star/common/time/DoubleTime.hpp>
 
-namespace artis { namespace common {
+namespace artis {
+    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

+ 32 - 28
src/artis-star/common/Simulator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,38 +31,42 @@
 
 #include <sstream>
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-template < class Time >
-class Simulator : public virtual Model < Time >
-{
-public :
-    Simulator(const std::string& name) : Model < Time >(name)
-    { }
-    virtual ~Simulator()
-    { }
+        template<class Time>
+        class Simulator : public virtual Model<Time> {
+        public :
+            Simulator(const std::string& name)
+                    :Model<Time>(name) { }
 
-    virtual bool is_atomic() const
-    { return true; }
+            virtual ~Simulator() { }
 
-    virtual std::string to_string(int /* level */) const
-    {
-        std::ostringstream ss;
+            virtual bool is_atomic() const { return true; }
 
-        ss << "Simulator " << Simulator < Time >::get_name();
-        return ss.str();
-    }
+            virtual std::string to_string(int /* level */) const
+            {
+                std::ostringstream ss;
+
+                ss << "Simulator " << Simulator<Time>::get_name();
+                return ss.str();
+            }
 
 // DEVS methods
-    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;
-};
-
-} } // namespace artis common
+            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;
+        };
+
+    }
+} // namespace artis common
 
 #endif

+ 129 - 129
src/artis-star/common/Value.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -30,141 +30,141 @@
 #include <boost/serialization/serialization.hpp>
 #include <boost/serialization/array.hpp>
 
+#include <cassert>
 #include <cstring>
 #include <typeinfo>
 #include <vector>
 
 #include <iostream>
 
-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()); }
-
-    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 Z >
-    bool is_type() const
-    { return _type_id == typeid(Z).hash_code(); }
-
-    void operator=(const Value& value)
-    {
-        if (_content) {
-            delete _content;
-        }
-        if (value._content) {
-            assign(value._content, value._size, value._type_id);
-        } else {
-            _content = nullptr;
-            _size = 0;
-            _type_id = 0;
-        }
-    }
-
+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()); }
+
+            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 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 (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<bool>()) {
+                    bool v;
+
+                    operator()(v);
+                    return v ? "true" : "false";
+                }
+                if (is_type<std::vector<double> >()) {
+                    std::vector<double> v;
+
+                    operator()(v);
+                    return "";
+                } else if (is_type<std::vector<int> >()) {
+                    std::vector<int> v;
+
+                    operator()(v);
+                    return "";
+                } else if (is_type<std::vector<bool> >()) {
+                    std::vector<bool> v;
+
+                    operator()(v);
+                    return "";
+                } 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;
+        };
 
-    std::string to_string() const
-    {
-        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 < bool >()) {
-            bool v;
-
-            operator()(v);
-            return v ? "true" : "false";
-        } if (is_type < std::vector < double > >()) {
-            std::vector < double > v;
-
-            operator()(v);
-            return "";
-        } else if (is_type < std::vector < int > >()) {
-            std::vector < int > v;
-
-            operator()(v);
-            return "";
-        } else if (is_type < std::vector < bool > >()) {
-            std::vector < bool > v;
-
-            operator()(v);
-            return "";
-        } 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

+ 2 - 2
src/artis-star/common/observer/CMakeLists.txt

@@ -1,9 +1,9 @@
 INCLUDE_DIRECTORIES(
-  ${CMAKE_SOURCE_DIR}/src)
+        ${CMAKE_SOURCE_DIR}/src)
 
 LINK_DIRECTORIES()
 
 SET(COMMON_OBSERVER_HPP Observer.hpp Output.hpp View.hpp)
 
 INSTALL(FILES ${COMMON_OBSERVER_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/common/observer)
+        ${ARTIS_INCLUDE_DIRS}/common/observer)

+ 57 - 59
src/artis-star/common/observer/Observer.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -32,65 +32,63 @@
 
 #include <vector>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
+
+        template<typename Time>
+        class Observer {
+        public:
+            typedef std::map<std::string, View<Time>*> Views;
+
+            Observer(const common::Model<Time>* model)
+                    :
+                    _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)
+            {
+                for (typename Views::iterator it = _views.begin(); it != _views.end();
+                     ++it) {
+                    it->second->observe(t);
+                }
+            }
+
+        private:
+            const common::Model<Time>* _model;
+            Views _views;
+        };
 
-template < typename Time >
-class Observer
-{
-public:
-    typedef std::map < std::string, View < Time >* > Views;
-
-    Observer(const common::Model < Time >* model) :
-        _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)
-    {
-        for (typename Views::iterator it = _views.begin(); it != _views.end();
-             ++it) {
-            it->second->observe(t);
-        }
-    }
-
-private:
-    const common::Model < Time >* _model;
-    Views                         _views;
-};
-
-} }
+}
 
 #endif

+ 50 - 50
src/artis-star/common/observer/Output.hpp

@@ -4,7 +4,7 @@
  */
 
 /*
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -29,66 +29,66 @@
 
 #include <boost/format.hpp>
 
-namespace artis { namespace observer {
+namespace artis {
+    namespace observer {
 
-template < typename Time >
-class Output
-{
-public:
-    Output(const Observer < Time >& observer) : _observer(observer)
-    { }
+        template<typename Time>
+        class Output {
+        public:
+            Output(const Observer<Time>& observer)
+                    :_observer(observer) { }
 
-    virtual ~Output()
-    { }
+            virtual ~Output() { }
 
-    void operator()() const
-    {
-        const typename Observer < Time >::Views& views = _observer.views();
+            void operator()() 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());
-            typename View < Time >::Values values = it->second->values();
-            double begin = it->second->begin();
-            double end = it->second->end();
+                for (typename Observer<Time>::Views::const_iterator it =
+                        views.begin(); it != views.end(); ++it) {
+                    std::ofstream o((boost::format("%1%.csv") % it->first).str());
+                    typename View<Time>::Values values = it->second->values();
+                    double begin = it->second->begin();
+                    double end = it->second->end();
 
-            o.precision(10);
-            // write header
-            o << "time";
-            for (typename View < Time >::Values::const_iterator
-                     itv = values.begin(); itv != values.end(); ++itv) {
-                o << ";" << itv->first;
-            }
-            o << std::endl;
+                    o.precision(10);
+                    // write header
+                    o << "time";
+                    for (typename View<Time>::Values::const_iterator
+                                 itv = values.begin(); itv != values.end(); ++itv) {
+                        o << ";" << itv->first;
+                    }
+                    o << std::endl;
 
-            // write values
-            for (double t = begin; t <= end; ++t) {
-                o << utils::DateTime::toJulianDay(t);
-                // o << t;
-                for (typename View < Time >::Values::const_iterator itv =
-                         values.begin(); itv != values.end(); ++itv) {
-                    typename View < Time >::Value::const_iterator itp =
-                        itv->second.begin();
+                    // write values
+                    for (double t = begin; t <= end; ++t) {
+                        o << utils::DateTime::toJulianDay(t);
+                        // o << t;
+                        for (typename View<Time>::Values::const_iterator itv =
+                                values.begin(); itv != values.end(); ++itv) {
+                            typename View<Time>::Value::const_iterator itp =
+                                    itv->second.begin();
 
-                    while (itp != itv->second.end() and itp->first < t) {
-                        ++itp;
-                    }
-                    o << ";";
-                    if (itp != itv->second.end()) {
-                        o << itp->second;
-                    } else {
-                        o << "NA";
+                            while (itp != itv->second.end() and itp->first < t) {
+                                ++itp;
+                            }
+                            o << ";";
+                            if (itp != itv->second.end()) {
+                                o << itp->second;
+                            } else {
+                                o << "NA";
+                            }
+                        }
+                        o << std::endl;
                     }
                 }
-                o << std::endl;
             }
-        }
-    }
 
-private:
-    const Observer < Time >& _observer;
-};
+        private:
+            const Observer<Time>& _observer;
+        };
 
-} }
+    }
+}
 
 #endif

+ 170 - 167
src/artis-star/common/observer/View.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -34,208 +34,211 @@
 #include <boost/format.hpp>
 #include <boost/lexical_cast.hpp>
 
-namespace artis { namespace observer {
+namespace artis {
+    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; }
 
-    double begin() const
-    {
-        double t = common::DoubleTime::infinity;
+            double begin() const
+            {
+                double t = common::DoubleTime::infinity;
 
-        // for (SelectorValues::const_iterator it = _values.begin(); it!= _values.end();
-        //      ++it) {
-        //     if (t > it->second.begin()->first) {
-        //         t = it->second.begin()->first;
-        //     }
-        // }
-        return t;
-    }
-
-    View* clone() const
-    {
-        View* v = new View();
-
-        // 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();
+                // for (SelectorValues::const_iterator it = _values.begin(); it!= _values.end();
+                //      ++it) {
+                //     if (t > it->second.begin()->first) {
+                //         t = it->second.begin()->first;
+                //     }
+                // }
+                return t;
+            }
 
-        //     while (itp != it->second.end()) {
-        //         v->_values[it->first].push_back(*itp);
-        //         ++itp;
-        //     }
-        // }
-        // v->_model = 0;
-        return v;
-    }
+            View* clone() const
+            {
+                View* v = new View();
 
-    double end() const
-    {
-        double t = 0;
-
-        // for (SelectorValues::const_iterator it = _values.begin(); it!= _values.end();
-        //      ++it) {
-        //     if (t < it->second.back().first) {
-        //         t = it->second.back().first;
-        //     }
-        // }
-        return t;
-    }
+                // v->_selectors = _selectors;
+                // for (Values::const_iterator it = _values.begin(); it!= _values.end();
+                //      ++it) {
 
-    double get(double t, const std::string& selector_name,
-               const std::string& variable_name) const
-    {
-        SelectorValues::const_iterator it = _values.find(selector_name);
+                //     v->_values[it->first] = Value();
+                //     Value::const_iterator itp = it->second.begin();
 
-        if (it != _values.end()) {
-            VariableValues::const_iterator itp = it->second.find(variable_name);
+                //     while (itp != it->second.end()) {
+                //         v->_values[it->first].push_back(*itp);
+                //         ++itp;
+                //     }
+                // }
+                // v->_model = 0;
+                return v;
+            }
 
-            if (itp != it->second.end()) {
-                Values::const_iterator itv = itp->second.begin();
+            double end() const
+            {
+                double t = 0;
+
+                // for (SelectorValues::const_iterator it = _values.begin(); it!= _values.end();
+                //      ++it) {
+                //     if (t < it->second.back().first) {
+                //         t = it->second.back().first;
+                //     }
+                // }
+                return t;
+            }
 
-                while (itv != itp->second.end() and itv->first < t) {
-                    ++itv;
-                }
-                if (itv != itp->second.end()) {
-                    // TODO: to improve
-                    return boost::lexical_cast < double >(itv->second);
-                } else {
-                    return 0;
+            double get(double t, 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 itp = it->second.find(variable_name);
+
+                    if (itp != it->second.end()) {
+                        Values::const_iterator itv = itp->second.begin();
+
+                        while (itv != itp->second.end() and itv->first < t) {
+                            ++itv;
+                        }
+                        if (itv != itp->second.end()) {
+                            // TODO: to improve
+                            return boost::lexical_cast<double>(itv->second);
+                        } else {
+                            return 0;
+                        }
+                    } else {
+                        return 0;
+                    }
                 }
-            } else {
                 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);
+            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 (it != _values.end()) {
+                    VariableValues::const_iterator itv = it->second.find(variable_name);
 
-            if (itv != it->second.end()) {
-                return itv->second;
-            } else {
-                assert(false);
+                    if (itv != it->second.end()) {
+                        return itv->second;
+                    } else {
+                        assert(false);
+                    }
+                } else {
+                    assert(false);
+                }
             }
-        } else {
-            assert(false);
-        }
-    }
 
-    const Values& get(const std::string& selector_name) const
-    {
-        SelectorValues::const_iterator it = _values.find(selector_name);
+            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);
+                if (it != _values.end()) {
+                    assert(it->second.size() == 1);
 
-            return it->second.begin()->second;
-        } else {
-            assert(false);
-        }
-    }
+                    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(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];
 
-    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)
-    {
-        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) {
-            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);
+                if (values.find(path) == values.end()) {
+                    values[path] = Values();
+                }
+                values[path].push_back(
+                        std::make_pair(time, model->observe(time, 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;
+            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)
 
-            if (it->second.size() > 1) {
-                size_t i = 0;
+                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);
+                    }
+                }
+            }
 
-                observe(it->second, i, time, model, it->first,
-                        it->second.back());
-            } else {
-                if (model) {
-                    observe(time, model, it->first, it->second.back());
+            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;
-    }
+            void selector(const std::string& name, const Selector& chain)
+            {
+                _selectors[name] = chain;
+            }
 
-    const SelectorValues& values() const
-    { return _values;}
+            const SelectorValues& values() const { return _values; }
 
-private:
-    typedef std::map < std::string, Selector > Selectors;
+        private:
+            typedef std::map<std::string, Selector> Selectors;
 
-    Selectors                            _selectors;
-    SelectorValues                       _values;
-    const artis::common::Model < Time >* _model;
-};
+            Selectors _selectors;
+            SelectorValues _values;
+            const artis::common::Model<Time>* _model;
+        };
 
-} }
+    }
+}
 
 #endif

+ 6 - 10
src/artis-star/common/scheduler/CMakeLists.txt

@@ -1,17 +1,13 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR}
-  ${Boost_LIBRARY_DIRS})
+        ${Boost_LIBRARY_DIRS})
 
 SET(COMMON_SCHEDULER_HPP HeapScheduler.hpp SchedulerHandle.hpp
-  VectorScheduler.hpp)
+        VectorScheduler.hpp)
 
 INSTALL(FILES ${COMMON_SCHEDULER_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/common/scheduler)
+        ${ARTIS_INCLUDE_DIRS}/common/scheduler)

+ 93 - 92
src/artis-star/common/scheduler/HeapScheduler.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -33,99 +33,100 @@
 
 #include <sstream>
 
-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();
-    }
+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(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;
+                }
+
+                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);
+                        }
+                    }
+                }
+
+                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();
+                }
+            };
 
-    models_type get_current_models(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;
-    }
-
-    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);
-            }
-        }
-    }
-
-    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

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

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -27,20 +27,20 @@
 #ifndef COMMON_SCHEDULER_SCHEDULER_HANDLE_HPP
 #define COMMON_SCHEDULER_SCHEDULER_HANDLE_HPP 1
 
-namespace artis { namespace common { namespace scheduler {
+namespace artis {
+    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

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

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -33,89 +33,90 @@
 #include <algorithm>
 #include <sstream>
 
-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;
+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;
+                        }
+                    }
+                }
+            };
 
-        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

+ 5 - 5
src/artis-star/common/time/CMakeLists.txt

@@ -1,12 +1,12 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${Boost_LIBRARY_DIRS})
+        ${Boost_LIBRARY_DIRS})
 
 SET(COMMON_TIME_HPP DoubleTime.hpp Time.hpp)
 
 INSTALL(FILES ${COMMON_TIME_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/common/time)
+        ${ARTIS_INCLUDE_DIRS}/common/time)

+ 14 - 13
src/artis-star/common/time/DoubleTime.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,20 +31,21 @@
 
 #include <limits>
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-template < typename T >
-struct Limits
-{
-    static constexpr T negative_infinity =
-        -std::numeric_limits < T >::infinity();
-    static constexpr T positive_infinity =
-        std::numeric_limits < T >::infinity();
-    static constexpr T null = 0;
-};
+        template<typename T>
+        struct Limits {
+            static constexpr T negative_infinity =
+                    -std::numeric_limits<T>::infinity();
+            static constexpr T positive_infinity =
+                    std::numeric_limits<T>::infinity();
+            static constexpr T null = 0;
+        };
 
-typedef Time < double, Limits < double > > DoubleTime;
+        typedef Time<double, Limits<double> > DoubleTime;
 
-} } // namespace artis common
+    }
+} // namespace artis common
 
 #endif

+ 12 - 11
src/artis-star/common/time/Time.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -27,17 +27,18 @@
 #ifndef COMMON_TIME_TIME
 #define COMMON_TIME_TIME 1
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-template < typename Type, typename Limits >
-struct Time
-{
-    static constexpr Type negative_infinity = Limits::negative_infinity;
-    static constexpr Type infinity = Limits::positive_infinity;
-    static constexpr Type null = Limits::null;
-    typedef Type type;
-};
+        template<typename Type, typename Limits>
+        struct Time {
+            static constexpr Type negative_infinity = Limits::negative_infinity;
+            static constexpr Type infinity = Limits::positive_infinity;
+            static constexpr Type null = Limits::null;
+            typedef Type type;
+        };
 
-} } // namespace artis common
+    }
+} // namespace artis common
 
 #endif

+ 5 - 9
src/artis-star/common/utils/CMakeLists.txt

@@ -1,16 +1,12 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR}
-  ${Boost_LIBRARY_DIRS})
+        ${Boost_LIBRARY_DIRS})
 
 SET(COMMON_UTILS_HPP Multithreading.hpp String.hpp Trace.hpp)
 
 INSTALL(FILES ${COMMON_UTILS_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/common/utils)
+        ${ARTIS_INCLUDE_DIRS}/common/utils)

+ 179 - 186
src/artis-star/common/utils/Multithreading.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,220 +31,213 @@
 #include <queue>
 #include <mutex>
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-struct BaseMessage
-{
-    virtual ~BaseMessage()
-    { }
-};
+        struct BaseMessage {
+            virtual ~BaseMessage() { }
+        };
 
-template < typename Msg >
-struct Message : BaseMessage
-{
-    explicit Message(Msg const& content) : _content(content)
-    { }
+        template<typename Msg>
+        struct Message : BaseMessage {
+            explicit Message(Msg const& content)
+                    :_content(content) { }
 
-    Msg _content;
-};
+            Msg _content;
+        };
 
-class Close
-{ };
+        class Close {
+        };
 
-class MessageQueue
-{
-public:
-    template < typename T >
-    void push(T const& msg)
-    {
-        std::lock_guard < std::mutex > lock(_mutex);
+        class MessageQueue {
+        public:
+            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();
-    }
+                _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);
+            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;
-    }
+                _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:
+            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);
-        }
-    }
+        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));
-    }
+            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();
-        }
-    }
+            ~TemplateDispatcher() noexcept(false)
+            {
+                if (not _chained) {
+                    wait_and_dispatch();
+                }
+            }
 
-private:
-    TemplateDispatcher(TemplateDispatcher const&)=delete;
+        private:
+            TemplateDispatcher(TemplateDispatcher const&) = delete;
 
-    TemplateDispatcher& operator=(TemplateDispatcher const&)=delete;
+            TemplateDispatcher& operator=(TemplateDispatcher const&) = delete;
 
-    void wait_and_dispatch()
-    {
-        for(;;) {
-            auto msg = _queue->wait_and_pop();
+            void wait_and_dispatch()
+            {
+                for (;;) {
+                    auto msg = _queue->wait_and_pop();
 
-            if (dispatch(msg)) {
-                break;
+                    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));
-    }
+            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();
-        }
-    }
+            ~Dispatcher() noexcept(false)
+            {
+                if (not _chained) {
+                    wait_and_dispatch();
+                }
+            }
 
-private:
-    Dispatcher(Dispatcher const&)=delete;
+        private:
+            Dispatcher(Dispatcher const&) = delete;
 
-    Dispatcher& operator=(Dispatcher const&)=delete;
+            Dispatcher& operator=(Dispatcher const&) = delete;
 
-    void wait_and_dispatch()
-    {
-        for(;;) {
-            auto msg = _queue->wait_and_pop();
+            void wait_and_dispatch()
+            {
+                for (;;) {
+                    auto msg = _queue->wait_and_pop();
 
-            dispatch(msg);
-        }
-    }
+                    dispatch(msg);
+                }
+            }
 
-    bool dispatch(std::shared_ptr < BaseMessage > const& msg)
-    {
-        if (dynamic_cast < Message < Close >* >(msg.get())) {
-            throw Close();
-        }
-        return false;
-    }
+            bool dispatch(std::shared_ptr<BaseMessage> const& msg)
+            {
+                if (dynamic_cast < Message<Close>* >(msg.get())) {
+                    throw Close();
+                }
+                return false;
+            }
 
-    MessageQueue* _queue;
-    bool          _chained;
-};
+            MessageQueue* _queue;
+            bool _chained;
+        };
 
-class Receiver
-{
-public:
-    Receiver()
-    { }
+        class Receiver {
+        public:
+            Receiver() { }
 
-    operator Sender()
-    { return Sender(&_queue); }
+            operator Sender() { return Sender(&_queue); }
 
-    Dispatcher wait()
-    { return Dispatcher(&_queue); }
+            Dispatcher wait() { return Dispatcher(&_queue); }
 
-private:
-    MessageQueue _queue;
-};
+        private:
+            MessageQueue _queue;
+        };
 
-} }  // namespace artis common
+    }
+}  // namespace artis common
 
 #endif

+ 16 - 15
src/artis-star/common/utils/String.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -29,22 +29,23 @@
 
 #include <string>
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-class String
-{
-public:
-    static std::string make_spaces(unsigned int number)
-    {
-        std::string 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;
-    }
-};
+                for (unsigned int i = 0; i < number; ++i) {
+                    str += " ";
+                }
+                return str;
+            }
+        };
 
-} }  // namespace artis common
+    }
+}  // namespace artis common
 
 #endif

+ 164 - 170
src/artis-star/common/utils/Trace.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -35,225 +35,219 @@
 #include <string>
 #include <vector>
 
-namespace artis { namespace common {
+namespace artis {
+    namespace common {
 
-enum TraceType { NONE = 0, I_MESSAGE, POST_EVENT, S_MESSAGE, Y_MESSAGE,
-                 DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START, OUTPUT };
+        enum TraceType {
+            NONE = 0, I_MESSAGE, POST_EVENT, S_MESSAGE, Y_MESSAGE,
+            DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START, OUTPUT
+        };
 
-template < class Time >
-class TraceElement
-{
-public:
-    TraceElement() : _time(Time::null), _type(NONE)
-    { }
+        template<class Time>
+        class TraceElement {
+        public:
+            TraceElement()
+                    :_time(Time::null), _type(NONE) { }
 
-    TraceElement(const std::string& model_name, typename Time::type time,
-                 TraceType type) :
-        _model_name(model_name), _time(time), _type(type)
-    { }
+            TraceElement(const std::string& model_name, typename Time::type time, TraceType type)
+                    :_model_name(model_name), _time(time), _type(type) { }
 
-    virtual ~TraceElement()
-    { }
+            virtual ~TraceElement() { }
 
-    const std::string& get_comment() const
-    { return _comment; }
+            const std::string& get_comment() const { return _comment; }
 
-    const std::string& get_model_name() const
-    { return _model_name; }
+            const std::string& get_model_name() const { return _model_name; }
 
-    typename Time::type get_time() const
-    { return _time; }
+            typename Time::type get_time() const { return _time; }
 
-    TraceType get_type() const
-    { return _type; }
+            TraceType get_type() const { return _type; }
 
-    void set_comment(const std::string& comment)
-    { _comment = comment; }
+            void set_comment(const std::string& comment) { _comment = comment; }
 
-private:
-    std::string         _model_name;
-    typename Time::type _time;
-    TraceType           _type;
-    std::string         _comment;
-};
+        private:
+            std::string _model_name;
+            typename Time::type _time;
+            TraceType _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;
-    }
+        template<class Time>
+        class TraceElements : public std::vector<TraceElement<Time> > {
+        public:
+            TraceElements() { }
 
-    TraceElements filter_time(typename Time::type time) const
-    {
-        TraceElements result;
+            virtual ~TraceElements() { }
 
-        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_model_name(const std::string& model_name) const
+            {
+                TraceElements<Time> result;
 
-    TraceElements filter_type(TraceType type) const
-    {
-        TraceElements 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;
+            }
 
-        std::copy_if(TraceElements < Time >::begin(),
-                     TraceElements < Time >::end(), std::back_inserter(result),
-                     [type](TraceElement < Time > const & x)
-                     { return x.get_type() == type; });
-        return result;
-    }
+            TraceElements filter_time(typename Time::type time) const
+            {
+                TraceElements result;
 
-    std::string to_string() const
-    {
-        std::ostringstream ss;
+                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;
+            }
 
-        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() << " <";
-            switch (it->get_type())
+            TraceElements filter_type(TraceType type) const
             {
-            case NONE: ss << "none"; break;
-            case I_MESSAGE: ss << "i_message"; break;
-            case POST_EVENT:  ss << "post_event"; break;
-            case S_MESSAGE: ss << "s_message"; break;
-            case Y_MESSAGE: ss << "y_message"; break;
-            case DELTA_INT: ss << "delta_int"; break;
-            case DELTA_EXT: ss << "delta_ext"; break;
-            case DELTA_CONF:  ss << "delta_conf"; break;
-            case TA: ss << "ta"; break;
-            case LAMBDA: ss << "lambda"; break;
-            case START: ss << "start"; break;
-            case OUTPUT: ss << "output"; break;
-            };
-            ss << ">";
-            if (not it->get_comment().empty()) {
-                ss << " => " << it->get_comment();
+                TraceElements result;
+
+                std::copy_if(TraceElements<Time>::begin(),
+                        TraceElements<Time>::end(), std::back_inserter(result),
+                        [type](TraceElement<Time> const& x) { return x.get_type() == type; });
+                return result;
             }
-            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()); }
-            );
-        return *_instance;
-    }
+            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() << " <";
+                    switch (it->get_type()) {
+                    case NONE:
+                        ss << "none";
+                        break;
+                    case I_MESSAGE:
+                        ss << "i_message";
+                        break;
+                    case POST_EVENT:
+                        ss << "post_event";
+                        break;
+                    case S_MESSAGE:
+                        ss << "s_message";
+                        break;
+                    case Y_MESSAGE:
+                        ss << "y_message";
+                        break;
+                    case DELTA_INT:
+                        ss << "delta_int";
+                        break;
+                    case DELTA_EXT:
+                        ss << "delta_ext";
+                        break;
+                    case DELTA_CONF:
+                        ss << "delta_conf";
+                        break;
+                    case TA:
+                        ss << "ta";
+                        break;
+                    case LAMBDA:
+                        ss << "lambda";
+                        break;
+                    case START:
+                        ss << "start";
+                        break;
+                    case OUTPUT:
+                        ss << "output";
+                        break;
+                    };
+                    ss << ">";
+                    if (not it->get_comment().empty()) {
+                        ss << " => " << it->get_comment();
+                    }
+                    ss << std::endl;
+                }
+                return ss.str();
+            }
+        };
+
+        template<class Time>
+        class Trace {
+        public:
+            virtual ~Trace() { }
 
-    void clear()
-    { _trace.clear(); }
+            static Trace& trace()
+            {
+                std::call_once(_flag, []() { _instance.reset(new Trace()); });
+                return *_instance;
+            }
 
-    const TraceElements < Time >& elements() const
-    { return _trace; }
+            void clear() { _trace.clear(); }
 
-    void flush()
-    {
-        std::lock_guard < std::mutex > lock(_mutex);
+            const TraceElements<Time>& elements() const { return _trace; }
 
-        if (_sstream) {
-            _element.set_comment(_sstream->str());
-            delete _sstream;
-            _sstream = 0;
-        }
-        _trace.push_back(_element);
-    }
+            void flush()
+            {
+                std::lock_guard<std::mutex> lock(_mutex);
+
+                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::once_flag _flag;
+            static std::shared_ptr<Trace<Time> > _instance;
+            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 >
-artis::common::Trace < Time >& operator<<(
-    artis::common::Trace < Time >& trace,
-    const artis::common::TraceElement < Time >& e)
+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());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.set_element(e);
     return trace;
 }
 
-template < class Time >
-artis::common::Trace < Time >& operator<<(
-    artis::common::Trace < Time >& trace,
-    const std::string& str)
+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());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.sstream() << str;
     return trace;
 }
 
-template < class Time >
-artis::common::Trace < Time >& operator<<(
-    artis::common::Trace < Time >& trace,
-    typename Time::type t)
+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());
+    std::lock_guard<std::mutex> lock(trace.mutex());
 
     trace.sstream() << t;
     return trace;
 }
 
-template < class Time >
-std::shared_ptr < artis::common::Trace < Time > >
-artis::common::Trace < Time >::_instance = nullptr;
+template<class Time>
+std::shared_ptr<artis::common::Trace<Time> > artis::common::Trace<Time>::_instance = nullptr;
 
-template < class Time >
-std::once_flag artis::common::Trace < Time >::_flag;
+template<class Time>
+std::once_flag artis::common::Trace<Time>::_flag;
 
 #endif

+ 4 - 7
src/artis-star/kernel/dtss/CMakeLists.txt

@@ -1,13 +1,10 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
+        ${Boost_LIBRARY_DIRS})
 
 SET(DTSS_HPP Coordinator.hpp Dynamics.hpp GraphManager.hpp Simulator.hpp)
 

+ 151 - 153
src/artis-star/kernel/dtss/Coordinator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -34,205 +34,203 @@
 #include <cassert>
 #include <iostream>
 
-namespace artis { namespace dtss {
-
-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 >
-{
-    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_paramaters) :
-        common::Model < Time >(name),
-        common::Coordinator < Time >(name),
-        _graph_manager(this, graph_paramaters),
-        _time_step(parameters._time_step)
-    { }
-
-    virtual ~Coordinator()
-    { }
-
-    typename Time::type start(const typename Time::type& t)
-    {
+namespace artis {
+    namespace dtss {
+
+        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> {
+            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),
+                    _graph_manager(this, parameters, graph_parameters),
+                    _time_step(parameters._time_step) { }
+
+            virtual ~Coordinator() { }
+
+            const common::GraphManager<Time>& get_graph_manager() const { return _graph_manager; }
+
+            typename Time::type start(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::Y_MESSAGE)
-            << ": 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::Y_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn << " ; bag = " << bag.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-        _graph_manager.dispatch_events(bag, t);
+                _graph_manager.dispatch_events(bag, t);
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::Y_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::Y_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        return type::_tn;
-    }
+                return type::_tn;
+            }
 
-    void observation(std::ostream& file) const
-    {
-        for (auto & child : _graph_manager.children()) {
-            child->observation(file);
-        }
-    }
+            common::Value observe(const typename Time::type& /* t */,
+                    unsigned int /* index */) const
+            {
+                assert(false);
+                return common::Value();
+            }
 
-    void output(const typename Time::type& t)
-    {
+            void output(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT)
-            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-            << type::_tn;
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT)
-            << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": BEFORE => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": BEFORE => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": AFTER => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": AFTER => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-    }
+            }
 
-    typename Time::type transition(const typename Time::type& t)
-    {
+            typename Time::type transition(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::S_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        if (t == type::_tn) {
-            for (auto & event : _policy.bag()) {
-                post_event(t, event);
-            }
-            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);
+                    }
+                    for (auto& model : _graph_manager.children()) {
+                        model->transition(t);
+                    }
+                    type::_tl = t;
+                    type::_tn = t + _time_step;
+                }
+                type::clear_bag();
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::S_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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

+ 54 - 28
src/artis-star/kernel/dtss/Dynamics.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -30,42 +30,68 @@
 #include <artis-star/common/Bag.hpp>
 #include <artis-star/common/ExternalEvent.hpp>
 #include <artis-star/common/Parameters.hpp>
+#include <artis-star/kernel/dtss/Simulator.hpp>
 
-namespace artis { namespace dtss {
+namespace artis {
+    namespace dtss {
 
-template < class Time,
-           class Parameters = common::NoParameters >
-class Dynamics
-{
-public:
-    Dynamics(const std::string& name, const Parameters& /* parameters */) :
-        _name(name)
-    { }
+        template<class Time, class Dyn,
+                class Parameters = common::NoParameters>
+        class Dynamics {
+            typedef dtss::Simulator<Time, Dyn, Parameters> Simulator;
 
-    virtual ~Dynamics()
-    { }
+        public:
+            Dynamics(const std::string& name, const Context<Time, Dyn, Parameters>& context)
+                    :
+                    _name(name), _simulator(context.simulator()) { }
 
-    virtual void transition(const common::Bag < Time >& /* x */,
-                            typename Time::type /* t */)
-    { }
+            virtual ~Dynamics() { }
 
-    virtual typename Time::type start(typename Time::type/* time */)
-    { return Time::infinity; }
+            virtual void transition(const common::Bag<Time>& /* x */,
+                    typename Time::type /* t */) { }
 
-    common::Bag < Time > lambda(
-        typename Time::type /* time */) const
-    { return common::Bag < Time >(); }
+            virtual typename Time::type start(typename Time::type/* time */) { return Time::infinity; }
 
-    virtual void observation(std::ostream& /* file */) const
-    { }
+            virtual common::Bag<Time> lambda(
+                    typename Time::type /* time */) const { return common::Bag<Time>(); }
 
-    const std::string& get_name() const
-    { return _name; }
+            virtual common::Value observe(const typename Time::type& /* t */,
+                    unsigned int /* index */) const { return common::Value(); }
 
-private:
-    std::string _name;
-};
+            const std::string& get_name() const { return _name; }
 
-} } // namespace artis dtss
+            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 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);
+                }
+            }
+
+        private:
+            std::string _name;
+            Simulator* _simulator;
+        };
+
+    }
+} // namespace artis dtss
 
 #endif

+ 104 - 79
src/artis-star/kernel/dtss/GraphManager.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -33,89 +33,114 @@
 #include <artis-star/common/Model.hpp>
 #include <artis-star/common/Parameters.hpp>
 
-namespace artis { namespace dtss {
-
-template < class Time,
-           class GraphParameters = common::NoParameters >
-class GraphManager : public common::GraphManager < Time >
-{
-public:
-    GraphManager(common::Coordinator < Time >* coordinator,
-                 const GraphParameters& /* parameters */) :
-        common::GraphParameters < 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);
-    }
+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) { }
+
+            virtual ~GraphManager() { }
+
+            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.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()));
-                    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 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_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) {
+                            common::Bag<Time> ymessages;
+
+                            ymessages.push_back(
+                                    common::ExternalEvent<Time>(
+                                            it->second, ymsg.data()));
+                            dynamic_cast < common::Coordinator<Time>* >(
+                                    common::GraphManager<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()));
-        }
-    }
+            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.get_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()));
+                }
+            }
+
+        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);
+            }
 
-private:
-    common::Links < Time > _link_list;
-};
+            common::Links<Time> _link_list;
+        };
 
-} } // namespace artis dtss
+    }
+} // namespace artis dtss
 
 #endif

+ 124 - 103
src/artis-star/kernel/dtss/Simulator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -34,154 +34,175 @@
 
 #include <cassert>
 
-namespace artis { namespace dtss {
+namespace artis {
+    namespace dtss {
 
-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>
+        class Simulator;
 
-public:
-    Simulator(const std::string& name, const typename Time::type& time_step,
-        const Parameters& parameters) :
-        common::Model < Time >(name),
-        common::Simulator < Time >(name),
-        _dynamics(name, parameters),
-        _time_step(time_step)
-    { }
+        template<class Time, class Dynamics,
+                class Parameters = common::NoParameters>
+        class Context {
+            typedef dtss::Simulator<Time, Dynamics, Parameters> Simulator;
 
-    ~Simulator()
-    {  }
+        public:
+            Context(const Parameters& parameters, Simulator* simulator)
+                    :
+                    _parameters(parameters), _simulator(simulator) { }
 
-    typename Time::type start(const typename Time::type& t)
-    {
+            virtual ~Context() { }
+
+            const Parameters& parameters() const { return _parameters; }
+
+            Simulator* simulator() const { return _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;
+
+        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() { }
+
+            typename Time::type start(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        _dynamics.start(t);
-        type::_tl = t;
-        type::_tn = t;
+                _dynamics.start(t);
+                type::_tl = t;
+                type::_tn = t;
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        return type::_tn;
-    }
+                return type::_tn;
+            }
 
-    void observation(std::ostream &file) const
-    {
-        _dynamics.observation(file);
-    }
+            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)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT) << ": BEFORE";
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT) << ": BEFORE";
+                common::Trace<Time>::trace().flush();
 #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);
+                        }
+                        dynamic_cast < common::Coordinator<Time>* >(
+                                type::get_parent())->dispatch_events(bag, t);
+                    }
                 }
-                dynamic_cast < common::Coordinator < Time >* >(
-                    type::get_parent())->dispatch_events(bag, t);
-            }
-        }
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT) << ": AFTER";
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT) << ": AFTER";
+                common::Trace<Time>::trace().flush();
 #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
-        (void)t;
+                (void)t;
 #endif
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": BEFORE => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": BEFORE => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-        type::add_event(event);
+                type::add_event(event);
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": AFTER => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": AFTER => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-    }
+            }
 
-    typename Time::type transition(const typename Time::type& t)
-    {
+            typename Time::type transition(const typename Time::type& t)
+            {
 
- #ifdef WITH_TRACE
-       common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::S_MESSAGE)
-            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-            << type::_tn;
-        common::Trace < Time >::trace().flush();
+#ifdef WITH_TRACE
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::S_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::S_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        return type::_tn;
-    }
+                return type::_tn;
+            }
 
-private :
-    Dynamics            _dynamics;
-    typename Time::type _time_step;
-};
+        private :
+            Dynamics _dynamics;
+            typename Time::type _time_step;
+        };
 
-} } // namespace artis dtss
+    }
+} // namespace artis dtss
 
 #endif

+ 5 - 8
src/artis-star/kernel/pdevs/CMakeLists.txt

@@ -1,16 +1,13 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
+        ${Boost_LIBRARY_DIRS})
 
 SET(PDEVS_HPP Coordinator.hpp Dynamics.hpp GraphManager.hpp
-  Simulator.hpp)
+        Simulator.hpp)
 
 INSTALL(FILES ${PDEVS_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/kernel/pdevs)
 

+ 184 - 188
src/artis-star/kernel/pdevs/Coordinator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -36,76 +36,71 @@
 #include <cassert>
 #include <iostream>
 
-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()
-    { }
-
-    const common::GraphManager < Time >& 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();
-    }
+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() { }
+
+            const common::GraphManager<Time>& get_graph_manager() const { return _graph_manager; }
+
+            virtual std::string to_string(int level) const
+            {
+                std::ostringstream ss;
 
-    typename Time::type start(const typename Time::type& t)
-    {
+                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();
+            }
+
+            typename Time::type start(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl
+                        << " ; tn = " << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        return type::_tn;
-    }
+                return type::_tn;
+            }
 
 /**************************************************
  * when *-message(t)
@@ -116,45 +111,45 @@ public:
  *   ...
  *  send done to parent
  **************************************************/
-    void output(const typename Time::type& t)
-    {
+            void output(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT)
-            << ": 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::OUTPUT)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn << " ; scheduler = " << _event_table.to_string();
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT)
-            << ": IMM = " << IMM.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT)
+                        << ": IMM = " << IMM.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-        for (auto & model : IMM) {
-            model->output(t);
-        }
+                for (auto& model : IMM) {
+                    model->output(t);
+                }
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT)
-            << ": 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::OUTPUT)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn << " ; scheduler = " << _event_table.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-    }
+            }
 
 /*******************************************************************
  * when x-message(t)
@@ -163,153 +158,154 @@ public:
  *     send x-message(Z(N,r)(x), t) with input value Z(N,r)(x) to r
  *   for each r in IMM and not in receivers
  *     send x-message(empty, t) to r
- *   sort event list acocrding to tn
+ *   sort event list according to tn
  *   tl = t
  *   tn = min(tn_d | d in D)
  *******************************************************************/
-    typename Time::type transition(const typename Time::type& t)
-    {
+            typename Time::type transition(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::S_MESSAGE)
-            << ": 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::S_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn << " ; scheduler = " << _event_table.to_string();
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::S_MESSAGE)
-            << ": receivers = " << receivers.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::S_MESSAGE)
+                        << ": receivers = " << receivers.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-        for (auto & model : receivers) {
-            _event_table.put(model->transition(t), model);
-        }
+                for (auto& model : receivers) {
+                    _event_table.put(model->transition(t), model);
+                }
 
-        update_event_table(t);
-        type::_tl = t;
-        type::_tn = _event_table.get_current_time();
-        type::clear_bag();
+                update_event_table(t);
+                type::_tl = t;
+                type::_tn = _event_table.get_current_time();
+                type::clear_bag();
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::S_MESSAGE)
-            << ": 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::S_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn << " ; scheduler = " << _event_table.to_string();
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": BEFORE => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": BEFORE => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": AFTER => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": AFTER => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-    }
+            }
 
 /*******************************************************************
  * when y-message(y_d, t) with output y_d from d
  *******************************************************************/
-    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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >( type::get_name(), t,
-                                              common::Y_MESSAGE)
-            << ": 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::Y_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn << " ; bag = " << bag.to_string()
+                        << " ; " << _event_table.to_string();
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::Y_MESSAGE)
-            << ": 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::Y_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn
+                        << " ; " << _event_table.to_string();
+                common::Trace<Time>::trace().flush();
 #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();
+            }
 
-    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 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 update_event_table(typename Time::type t)
-    {
-        for (auto & model : _graph_manager.children()) {
-            if (model->event_number() > 0) {
-                _event_table.put(t, 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;
-    common::SchedulerType _event_table;
-};
+        protected:
+            GraphManager _graph_manager;
+            common::SchedulerType _event_table;
+        };
 
-} } // namespace artis pdevs
+    }
+} // namespace artis pdevs
 
 #endif

+ 70 - 85
src/artis-star/kernel/pdevs/Dynamics.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -35,112 +35,97 @@
 #include <string>
 #include <vector>
 
-namespace artis { namespace pdevs {
+namespace artis {
+    namespace pdevs {
 
-template < class Time, class Dyn, class Parameters = common::NoParameters >
-class Dynamics
-{
-    typedef pdevs::Simulator < Time, Dyn, Parameters > Simulator;
+        template<class Time, class Dyn, class Parameters = common::NoParameters>
+        class Dynamics {
+            typedef pdevs::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 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 input_port(common::Port p)
-    {
-        _simulator->add_in_port(p);
-    }
+            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 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 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);
+            }
 
-    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);
+                }
+            }
 
-private:
-    std::string _name;
-    Simulator*  _simulator;
-    Observables _observables;
-};
+        private:
+            std::string _name;
+            Simulator* _simulator;
+            Observables _observables;
+        };
 
-} } // namespace artis pdevs
+    }
+} // namespace artis pdevs
 
 #endif

+ 120 - 136
src/artis-star/kernel/pdevs/GraphManager.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -24,8 +24,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PDEVS_GRAPH_MANANGER
-#define PDEVS_GRAPH_MANANGER
+#ifndef PDEVS_GRAPH_MANAGER
+#define PDEVS_GRAPH_MANAGER
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/GraphManager.hpp>
@@ -36,150 +36,134 @@
 
 #include <sstream>
 
-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)
-    { }
-
-    virtual ~GraphManager()
-    { }
-
-    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.get_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()));
+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;
             }
-        }
-    }
 
-    virtual void dispatch_events_to_parent(common::Node < Time > node,
-                                           const common::Value& content,
-                                           typename Time::type t)
-    {
-        common::Bag < Time > ymessages;
+            ModelPort out(ModelPort p)
+            {
+                p.graph_manager = this;
+                return p;
+            }
 
-        ymessages.push_back(
-            common::ExternalEvent <Time >(node, content));
+            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_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()));
+                        }
+                    }
+                }
+            }
 
-        dynamic_cast < common::Coordinator < Time >* >(
-            common::GraphManager < Time >::_coordinator->get_parent())
-            ->dispatch_events(ymessages, t);
-    }
+            virtual void dispatch_events_to_parent(common::Node<Time> node, const common::Value& content,
+                    typename Time::type t)
+            {
+                common::Bag<Time> ymessages;
 
-    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);
-    }
+                ymessages.push_back(common::ExternalEvent<Time>(node, content));
 
-    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.get_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()));
-        }
-    }
+                dynamic_cast < common::Coordinator<Time>* >(common::GraphManager<Time>::_coordinator->get_parent())
+                        ->dispatch_events(ymessages, t);
+            }
 
-    virtual std::string to_string(int level) const
-    {
-    	std::ostringstream ss;
+            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);
+            }
 
-    	ss << common::String::make_spaces(level * 2) << "Childs :" << std::endl;
-        for (auto & child : common::GraphManager < Time >::_children) {
-            ss << child->to_string(level + 1);
-        }
-        ss << _link_list.to_string(level);
-        return ss.str();
-    }
+            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.get_port_index());
 
-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);
-    }
+                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()));
+                }
+            }
 
-    common::Links < Time > _link_list;
-};
+            virtual std::string to_string(int level) const
+            {
+                std::ostringstream ss;
 
-} } // namespace artis pdevs
+                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 pdevs
 
 #endif

+ 132 - 136
src/artis-star/kernel/pdevs/Simulator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -35,101 +35,96 @@
 
 #include <cassert>
 
-namespace artis { namespace pdevs {
+namespace artis {
+    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;
+        };
 
-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() { }
 
-    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();
+            }
 
 /*************************************************
  * when i-message(t)
  *   tl = t - e
  *   tn = tl + ta(s)
  *************************************************/
-    typename Time::type start(const typename Time::type& t)
-    {
+            typename Time::type start(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        type::_tl = t;
-        type::_tn =
-            type::_tl + _dynamics.start(t);
+                type::_tl = t;
+                type::_tn =
+                        type::_tl + _dynamics.start(t);
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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);
+            }
 
 /*************************************************
  * when *-message(t)
@@ -137,64 +132,64 @@ public :
  *     y = lambda(s)
  *     send y-message(y,t) to parent
  *************************************************/
-    void output(const typename Time::type& t)
-    {
+            void output(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT) << ": BEFORE";
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT) << ": BEFORE";
+                common::Trace<Time>::trace().flush();
 #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);
+                        }
+                        dynamic_cast < common::Coordinator<Time>* >(
+                                type::get_parent())->dispatch_events(bag, t);
+                    }
                 }
-                dynamic_cast < common::Coordinator < Time >* >(
-                    type::get_parent())->dispatch_events(bag, t);
-            }
-        }
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT) << ": AFTER";
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT) << ": AFTER";
+                common::Trace<Time>::trace().flush();
 #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
-        (void)t;
+                (void)t;
 #endif
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": BEFORE => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": BEFORE => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-        type::add_event(event);
+                type::add_event(event);
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": AFTER => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": AFTER => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-    }
+            }
 
 /*************************************************
  * when x-message(t)
@@ -208,48 +203,49 @@ public :
  *  tn = t + ta(s)
  *  tl = t
  *************************************************/
-    typename Time::type transition(const typename Time::type& t)
-    {
+            typename Time::type transition(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::S_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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::_tn = t + _dynamics.ta(t);
-        type::_tl = t;
-        type::clear_bag();
+                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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::S_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = " << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        return type::_tn;
-    }
+                return type::_tn;
+            }
 
-private :
-    Dynamics _dynamics;
-};
+        private :
+            Dynamics _dynamics;
+        };
 
-} } // namespace artis pdevs
+    }
+} // namespace artis pdevs
 
 #endif

+ 6 - 9
src/artis-star/kernel/pdevs/mpi/CMakeLists.txt

@@ -1,16 +1,13 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
+        ${Boost_LIBRARY_DIRS})
 
 SET(PDEVS_MPI_HPP Coordinator.hpp GraphManager.hpp LogicalProcessor.hpp
-  ModelProxy.hpp)
+        ModelProxy.hpp)
 
 INSTALL(FILES ${PDEVS_MPI_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/kernel/pdevs/mpi)
+        ${ARTIS_INCLUDE_DIRS}/kernel/pdevs/mpi)

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

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -30,40 +30,43 @@
 #include <artis-star/kernel/pdevs/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp>
 
-namespace artis { namespace pdevs { namespace mpi {
+namespace artis {
+    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

+ 28 - 25
src/artis-star/kernel/pdevs/mpi/GraphManager.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -24,41 +24,44 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef PDEVS_MPI_GRAPH_MANANGER
-#define PDEVS_MPI_GRAPH_MANANGER 1
+#ifndef PDEVS_MPI_GRAPH_MANAGER
+#define PDEVS_MPI_GRAPH_MANAGER 1
 
 #include <artis-star/kernel/pdevs/mpi/Coordinator.hpp>
 #include <artis-star/kernel/pdevs/mpi/LogicalProcessor.hpp>
 
 #include <sstream>
 
-namespace artis { namespace pdevs { namespace mpi {
+namespace artis {
+    namespace pdevs {
+        namespace mpi {
 
-template < class Time,
-           class GraphParameters = common::NoParameters >
-class GraphManager : public pdevs::GraphManager < Time, GraphParameters >
-{
-public:
-    GraphManager(common::Coordinator < Time >* coordinator,
-                 const GraphParameters& parameters) :
-        pdevs::GraphManager < Time, GraphParameters >(coordinator, 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

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

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,85 +31,85 @@
 
 #include <boost/mpi/communicator.hpp>
 
-namespace artis { namespace pdevs { namespace mpi {
+namespace artis {
+    namespace pdevs {
+        namespace mpi {
 
-template < class Time >
-class LogicalProcessor
-{
-    typedef LogicalProcessor < Time > type;
+            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)
-    { }
+            public:
+                LogicalProcessor(common::Model<Time>* model, int rank, int parent)
+                        :
+                        _rank(rank),
+                        _parent(parent),
+                        _model(model) { }
 
-    virtual ~LogicalProcessor()
-    { }
+                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:
+                void dispatch_events_to_parent(common::Node<Time> node,
+                        const common::Value& content,
+                        typename Time::type t)
                 {
-                    _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;
+                    (void) t;
 
-                    _communicator.recv(_parent, post_event_send_tag, t);
-                    _communicator.recv(_parent, post_event_send_tag, event);
-                    _model->post_event(t, event);
-                    break;
+                    _output_bag.push_back(
+                            common::ExternalEvent<Time>(node, content));
                 }
-            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;
-};
+                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

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

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -32,120 +32,130 @@
 
 #include <boost/mpi/communicator.hpp>
 
-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 std::string to_string(int level) const
-    {
-        (void) level;
-
-        return std::string();
-    }
-
-    virtual void observation(std::ostream& file) const
-    {
-        (void) file;
-    }
-
-    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);
+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 std::string to_string(int level) const
+                {
+                    (void) level;
+
+                    return std::string();
+                }
+
+                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;
+            };
 
-            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

+ 5 - 8
src/artis-star/kernel/pdevs/multithreading/CMakeLists.txt

@@ -1,15 +1,12 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
+        ${Boost_LIBRARY_DIRS})
 
 SET(PDEVS_MULTITHREADING_HPP Coordinator.hpp)
 
 INSTALL(FILES ${PDEVS_MULTITHREADING_HPP} DESTINATION
-  ${ARTIS_INCLUDE_DIRS}/kernel/pdevs/multithreading)
+        ${ARTIS_INCLUDE_DIRS}/kernel/pdevs/multithreading)

+ 191 - 199
src/artis-star/kernel/pdevs/multithreading/Coordinator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -32,206 +32,198 @@
 
 #include <thread>
 
-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; }
-
-    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::_event_table.get_current_models(t);
-
-        type::add_models_with_inputs(receivers);
-
-        _received = 0;
-        for (auto & model : receivers) {
-            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);
+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; }
+
+                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::_event_table.get_current_models(t);
+
+                    type::add_models_with_inputs(receivers);
+
+                    _received = 0;
+                    for (auto& model : receivers) {
+                        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);
+
+                        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;
+            };
 
-            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

+ 5 - 8
src/artis-star/kernel/sss/CMakeLists.txt

@@ -1,15 +1,12 @@
 INCLUDE_DIRECTORIES(
-  ${ARTIS_BINARY_DIR}/src
-  ${ARTIS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
+        ${ARTIS_BINARY_DIR}/src
+        ${ARTIS_SOURCE_DIR}/src
+        ${Boost_INCLUDE_DIRS})
 
 LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
+        ${Boost_LIBRARY_DIRS})
 
 SET(SSS_HPP Coordinator.hpp Dynamics.hpp GraphManager.hpp Model.hpp
-  Simulator.hpp)
+        Simulator.hpp)
 
 INSTALL(FILES ${SSS_HPP} DESTINATION ${ARTIS_INCLUDE_DIRS}/kernel/sss)

+ 124 - 128
src/artis-star/kernel/sss/Coordinator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -36,151 +36,147 @@
 #include <cassert>
 #include <iostream>
 
-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_paramaters) :
-        common::Model < Time >(name),
-        common::Coordinator < Time >(name),
-        sss::Model < Time >(name),
-        _graph_manager(this, graph_paramaters),
-        _time_step(parameters._time_step)
-    { }
-
-    virtual ~Coordinator()
-    { }
-
-    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 artis {
+    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;
+
+        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() { }
+
+            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;
             }
-        }
-    }
 
-    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;
+            typename Time::type dispatch_events(const common::Bag<Time>& bag,
+                    const typename Time::type& t)
+            {
+                _graph_manager.dispatch_events(bag, t);
+                return type::_tn;
+            }
 
-            for (auto & event : _policy.bag()) {
-                post_event(t, event);
+            void observation(std::ostream& file) const
+            {
+                for (auto& child : _graph_manager.children()) {
+                    child->observation(file);
+                }
             }
-            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;
+
+            void output(const typename Time::type& t)
+            {
+                if (t == type::_tn) {
+                    for (auto& model : _graph_manager.children()) {
+                        model->update_buffer(t);
                     }
-                } else {
-                    if (not model->is_send()) {
-                        end = false;
-                    } else {
-                        if (t == model->get_tn()) {
-                            model->transition(t);
+                    for (auto& model : _graph_manager.children()) {
+                        if (not model->is_send() && model->is_marked()) {
+                            model->output(t);
+                            model->send();
                         }
                     }
                 }
             }
 
-            if (end) {
-                for (auto & model : _graph_manager.children()) {
-                    model->unmark();
-                    model->unsend();
+            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);
                 }
-                type::_tl = t;
-                type::_tn = t + _time_step;
             }
-        }
-        type::clear_bag();
-        return type::_tn;
-    }
 
-    virtual void update_buffer(typename Time::type /* time */)
-    { }
+            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;
-};
+        private:
+            GraphManager _graph_manager;
+            typename Time::type _time_step;
+            Policy _policy;
+        };
 
-} } // namespace artis sss
+    }
+} // namespace artis sss
 
 #endif

+ 24 - 30
src/artis-star/kernel/sss/Dynamics.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -31,44 +31,38 @@
 #include <artis-star/common/ExternalEvent.hpp>
 #include <artis-star/common/Parameters.hpp>
 
-namespace artis { namespace sss {
+namespace artis {
+    namespace sss {
 
-template < class Time,
-           class Parameters = common::NoParameters >
-class Dynamics
-{
-public:
-    Dynamics(const std::string& name, const Parameters& /* parameters */) :
-        _name(name)
-    { }
+        template<class Time,
+                class Parameters = common::NoParameters>
+        class Dynamics {
+        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 { }
 
-    virtual void update_buffer(typename Time::type /* time */)
-    { }
+            virtual void update_buffer(typename Time::type /* time */) { }
 
-    const std::string& get_name() const
-    { return _name; }
+            const std::string& get_name() const { return _name; }
 
-private:
-    std::string _name;
-};
+        private:
+            std::string _name;
+        };
 
-} } // namespace artis sss
+    }
+} // namespace artis sss
 
 #endif

+ 83 - 83
src/artis-star/kernel/sss/GraphManager.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -24,8 +24,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef SSS_GRAPH_MANANGER
-#define SSS_GRAPH_MANANGER
+#ifndef SSS_GRAPH_MANAGER
+#define SSS_GRAPH_MANAGER
 
 #include <artis-star/common/Coordinator.hpp>
 #include <artis-star/common/GraphManager.hpp>
@@ -34,91 +34,91 @@
 
 #include <artis-star/kernel/sss/Model.hpp>
 
-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);
-    }
+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()));
-                    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 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()));
+                            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()));
-        }
-    }
+            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;
-};
+        private:
+            common::Links<Time> _link_list;
+        };
 
-} } // namespace artis sss
+    }
+} // namespace artis sss
 
 #endif

+ 94 - 102
src/artis-star/kernel/sss/Model.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -29,108 +29,100 @@
 
 #include <artis-star/common/Model.hpp>
 
-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());
+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();
+            }
+        };
 
-        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

+ 113 - 116
src/artis-star/kernel/sss/Simulator.hpp

@@ -8,7 +8,7 @@
  * ARTIS - the multimodeling and simulation environment
  * This file is a part of the ARTIS environment
  *
- * Copyright (C) 2013-2018 ULCO http://www.univ-littoral.fr
+ * 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
@@ -36,170 +36,167 @@
 
 #include <cassert>
 
-namespace artis { namespace sss {
+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;
+        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)
-    { }
+        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()
-    {  }
+            ~Simulator() { }
 
-    virtual bool is_atomic() const
-    { return common::Simulator < Time >::is_atomic(); }
+            virtual bool is_atomic() const { return common::Simulator<Time>::is_atomic(); }
 
-    virtual std::string to_string(int level) const
-    { return common::Simulator < Time >::to_string(level); }
+            virtual std::string to_string(int level) const { return common::Simulator<Time>::to_string(level); }
 
-    typename Time::type start(const typename Time::type& t)
-    {
+            typename Time::type start(const typename Time::type& t)
+            {
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #endif
 
-        _dynamics.start(t);
-        type::_tl = t;
-        type::_tn = t;
+                _dynamics.start(t);
+                type::_tl = t;
+                type::_tn = t;
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::I_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT) << ": BEFORE";
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT) << ": BEFORE";
+                common::Trace<Time>::trace().flush();
 #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);
+                        }
+                        dynamic_cast < common::Coordinator<Time>* >(
+                                type::get_parent())->dispatch_events(bag, t);
+                    }
                 }
-                dynamic_cast < common::Coordinator < Time >* >(
-                    type::get_parent())->dispatch_events(bag, t);
-            }
-        }
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::OUTPUT) << ": AFTER";
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::OUTPUT) << ": AFTER";
+                common::Trace<Time>::trace().flush();
 #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
-        (void)t;
+                (void)t;
 #endif
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": BEFORE => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": BEFORE => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-        type::add_event(event);
+                type::add_event(event);
 
 #ifdef WITH_TRACE
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::POST_EVENT)
-            << ": AFTER => " << event.to_string();
-        common::Trace < Time >::trace().flush();
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::POST_EVENT)
+                        << ": AFTER => " << event.to_string();
+                common::Trace<Time>::trace().flush();
 #endif
 
-    }
+            }
 
-    typename Time::type transition(const typename Time::type& t)
-    {
+            typename Time::type transition(const typename Time::type& t)
+            {
 
- #ifdef WITH_TRACE
-       common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::S_MESSAGE)
-            << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
-            << type::_tn;
-        common::Trace < Time >::trace().flush();
+#ifdef WITH_TRACE
+                common::Trace<Time>::trace()
+                        << common::TraceElement<Time>(type::get_name(), t,
+                                common::S_MESSAGE)
+                        << ": BEFORE => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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
-        common::Trace < Time >::trace()
-            << common::TraceElement < Time >(type::get_name(), t,
-                                             common::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::S_MESSAGE)
+                        << ": AFTER => " << "tl = " << type::_tl << " ; tn = "
+                        << type::_tn;
+                common::Trace<Time>::trace().flush();
 #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