Parcourir la source

Add dtss simulator and coordinator

Eric Ramat il y a 11 ans
Parent
commit
f18eda916f
48 fichiers modifiés avec 1144 ajouts et 977 suppressions
  1. 1 1
      src/CMakeLists.txt
  2. 1 1
      src/apps/CMakeLists.txt
  3. 10 10
      src/apps/main.cpp
  4. 6 12
      src/pdevs/Model.cpp
  5. 23 8
      src/devs/Model.cpp
  6. 4 4
      src/common/CMakeLists.txt
  7. 61 0
      src/common/Coordinator.hpp
  8. 15 0
      src/common/EventTable.cpp
  9. 5 3
      src/common/EventTable.hpp
  10. 13 24
      src/common/Message.cpp
  11. 8 19
      src/common/Message.hpp
  12. 84 0
      src/common/Model.cpp
  13. 29 7
      src/common/Model.hpp
  14. 20 21
      src/devs/Model.hpp
  15. 1 0
      src/common/Trace.cpp
  16. 1 1
      src/common/Trace.hpp
  17. 0 32
      src/devs/CMakeLists.txt
  18. 0 208
      src/devs/Coordinator.cpp
  19. 0 99
      src/devs/Simulator.cpp
  20. 32 0
      src/dtss/CMakeLists.txt
  21. 146 0
      src/dtss/Coordinator.cpp
  22. 23 21
      src/devs/Coordinator.hpp
  23. 5 6
      src/devs/Dynamics.cpp
  24. 9 15
      src/devs/Dynamics.hpp
  25. 49 0
      src/dtss/EventTable.cpp
  26. 48 0
      src/dtss/EventTable.hpp
  27. 6 5
      src/devs/RootCoordinator.cpp
  28. 5 5
      src/devs/RootCoordinator.hpp
  29. 85 0
      src/dtss/Simulator.cpp
  30. 16 13
      src/devs/Simulator.hpp
  31. 4 4
      src/pdevs/CMakeLists.txt
  32. 94 61
      src/pdevs/Coordinator.cpp
  33. 16 17
      src/pdevs/Coordinator.hpp
  34. 2 2
      src/pdevs/Dynamics.cpp
  35. 5 4
      src/pdevs/Dynamics.hpp
  36. 3 3
      src/pdevs/EventTable.cpp
  37. 2 2
      src/pdevs/EventTable.hpp
  38. 0 76
      src/pdevs/Model.hpp
  39. 4 3
      src/pdevs/RootCoordinator.cpp
  40. 3 3
      src/pdevs/RootCoordinator.hpp
  41. 71 42
      src/pdevs/Simulator.cpp
  42. 7 10
      src/pdevs/Simulator.hpp
  43. 12 23
      src/tests/CMakeLists.txt
  44. 0 168
      src/tests/devs_examples.cpp
  45. 176 0
      src/tests/dtss_tests.cpp
  46. 23 28
      src/tests/devs_examples.hpp
  47. 10 10
      src/tests/pdevs_tests.cpp
  48. 6 6
      src/tests/pdevs_tests.hpp

+ 1 - 1
src/CMakeLists.txt

@@ -1,5 +1,5 @@
 ADD_SUBDIRECTORY(apps)
 ADD_SUBDIRECTORY(common)
-ADD_SUBDIRECTORY(devs)
+ADD_SUBDIRECTORY(dtss)
 ADD_SUBDIRECTORY(pdevs)
 ADD_SUBDIRECTORY(tests)

+ 1 - 1
src/apps/CMakeLists.txt

@@ -14,7 +14,7 @@ ADD_EXECUTABLE(paradevs main.cpp)
 SET_TARGET_PROPERTIES(paradevs PROPERTIES ${PARADEVS_APP_PROPERTIES})
 
 TARGET_LINK_LIBRARIES(paradevs
-  common devs examples pdevs
+  common pdevs
   ${GLIBMM_LIBRARIES}
   ${LIBXML_LIBRARIES}
   ${GTHREAD_LIBRARIES}

+ 10 - 10
src/apps/main.cpp

@@ -24,21 +24,21 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <devs/RootCoordinator.hpp>
-#include <tests/devs_examples.hpp>
+// #include <devs/RootCoordinator.hpp>
+// #include <tests/devs_examples.hpp>
 
-using namespace paradevs;
+// using namespace paradevs;
 
-void devs_examples()
-{
-    devs::MyBuilder builder;
-    devs::RootCoordinator rc(0, 10, builder);
+// void devs_examples()
+// {
+//     devs::MyBuilder builder;
+//     devs::RootCoordinator rc(0, 10, builder);
 
-    rc.run();
-}
+//     rc.run();
+// }
 
 int main()
 {
-    devs_examples();
+    // devs_examples();
     return 0;
 }

+ 6 - 12
src/pdevs/Model.cpp

@@ -1,5 +1,5 @@
 /**
- * @file Model.cpp
+ * @file Bag.cpp
  * @author The PARADEVS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -24,28 +24,22 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <pdevs/Model.hpp>
+#include <common/Bag.hpp>
 
 #include <sstream>
 
-namespace paradevs { namespace pdevs {
+namespace paradevs { namespace common {
 
-Model::Model(const std::string& name) : common::Model(name)
-{ }
-
-Model::~Model()
-{ }
-
-std::string Models::to_string() const
+std::string Bag::to_string() const
 {
     std::ostringstream ss;
 
     ss << "{ ";
     for (const_iterator it = begin(); it != end(); ++it) {
-        ss << (*it)->get_name() << " ";
+        ss << it->to_string() << " ";
     }
     ss << "}";
     return ss.str();
 }
 
-} } // namespace paradevs pdevs
+} } // namespace paradevs common

+ 23 - 8
src/devs/Model.cpp

@@ -1,5 +1,5 @@
 /**
- * @file Model.cpp
+ * @file Bag.hpp
  * @author The PARADEVS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -24,14 +24,29 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <devs/Model.hpp>
+#ifndef COMMON_BAG
+#define COMMON_BAG 1
 
-namespace paradevs { namespace devs {
+#include <common/ExternalEvent.hpp>
 
-Model::Model(const std::string& name) : common::Model(name)
-{ }
+#include <string>
+#include <vector>
 
-Model::~Model()
-{ }
+namespace paradevs { namespace common {
 
-} } // namespace paradevs devs
+class ExternalEvent;
+
+class Bag : public std::vector < ExternalEvent >
+{
+public:
+    Bag()
+    { }
+    virtual ~Bag()
+    { }
+
+    std::string to_string() const;
+};
+
+} } // namespace paradevs common
+
+#endif

+ 4 - 4
src/common/CMakeLists.txt

@@ -9,11 +9,11 @@ LINK_DIRECTORIES(
   ${GLIBMM_LIBRARY_DIRS}
   ${LIBXML_LIBRARY_DIR})
 
-SET(COMMON_CPP Builder.cpp EventTable.cpp InternalEvent.cpp Links.cpp
-  Message.cpp Node.cpp Trace.cpp)
+SET(COMMON_CPP Bag.cpp Builder.cpp EventTable.cpp ExternalEvent.cpp
+  InternalEvent.cpp Links.cpp Model.cpp Node.cpp Trace.cpp)
 
-SET(COMMON_HPP Builder.hpp EventTable.hpp InternalEvent.hpp Links.hpp
-  Message.hpp Node.hpp Time.hpp Trace.cpp)
+SET(COMMON_HPP Bag.hpp Builder.hpp EventTable.hpp ExternalEvent.hpp
+  InternalEvent.hpp Links.hpp Node.hpp Time.hpp Trace.cpp)
 
 ADD_LIBRARY(common SHARED ${COMMON_CPP};${COMMON_HPP})
 

+ 61 - 0
src/common/Coordinator.hpp

@@ -0,0 +1,61 @@
+/**
+ * @file Coordinator.hpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COMMON_COORDINATOR
+#define COMMON_COORDINATOR 1
+
+#include <common/Bag.hpp>
+#include <common/ExternalEvent.hpp>
+#include <common/Links.hpp>
+#include <common/Model.hpp>
+#include <common/Node.hpp>
+
+#include <iostream>
+
+namespace paradevs { namespace common {
+
+class Coordinator : public Model
+{
+public :
+    Coordinator(const std::string& name) : Model(name)
+    { }
+
+    virtual ~Coordinator()
+    { }
+
+// DEVS methods
+    virtual void output(common::Time t) =0;
+    virtual void post_message(common::Time t,
+                              const common::ExternalEvent& event) =0;
+    virtual common::Time dispatch_events(common::Bag bag,
+                                         common::Time t) =0;
+    virtual common::Time start(common::Time t) =0;
+    virtual common::Time transition(common::Time t) =0;
+};
+
+} } // namespace paradevs common
+
+#endif

+ 15 - 0
src/common/EventTable.cpp

@@ -36,6 +36,21 @@ Model* EventTable::get_current_model()
     return back().get_model();
 }
 
+Models EventTable::get_current_models(Time time) const
+{
+    common::Models models;
+    bool found = true;
+
+    for (const_reverse_iterator it = rbegin(); found and it != rend(); ++it) {
+        if (it->get_time() == time) {
+            models.push_back(it->get_model());
+        } else {
+            found = false;
+        }
+    }
+    return models;
+}
+
 void EventTable::init(common::Time time, Model* model)
 {
     push_back(InternalEvent(time, model));

+ 5 - 3
src/common/EventTable.hpp

@@ -41,11 +41,13 @@ public:
 
     Model* get_current_model();
 
-    common::Time get_current_time() const
+    Models get_current_models(Time time) const;
+
+    Time get_current_time() const
     { return back().get_time(); }
 
-    void init(common::Time time, Model* model);
-    void put(common::Time time, Model* model);
+    void init(Time time, Model* model);
+    void put(Time time, Model* model);
 
     std::string to_string() const;
 

+ 13 - 24
src/common/Message.cpp

@@ -1,5 +1,5 @@
 /**
- * @file Message.cpp
+ * @file ExternalEvent.cpp
  * @author The PARADEVS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -24,43 +24,44 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <common/Message.hpp>
+#include <common/ExternalEvent.hpp>
 #include <common/Node.hpp>
 
 #include <sstream>
 
 namespace paradevs { namespace common {
 
-Message::Message(const std::string& port_name, double content) :
+ExternalEvent::ExternalEvent(const std::string& port_name, double content) :
     _port_name(port_name), _model(0), _content(content)
 { }
 
-Message::Message(const std::string& port_name, Model* model, double content) :
+ExternalEvent::ExternalEvent(const std::string& port_name, Model* model,
+                             double content) :
     _port_name(port_name), _model(model), _content(content)
 { }
 
-Message::Message()
+ExternalEvent::ExternalEvent()
 { }
 
-Message::~Message()
+ExternalEvent::~ExternalEvent()
 { }
 
-const std::string& Message::get_port_name() const
+const std::string& ExternalEvent::get_port_name() const
 { return _port_name; }
 
-double Message::get_content() const
+double ExternalEvent::get_content() const
 { return _content; }
 
-void Message::set_content(double content)
+void ExternalEvent::set_content(double content)
 { _content = content; }
 
-Model* Message::get_model() const
+Model* ExternalEvent::get_model() const
 { return _model; }
 
-void Message::set_model(Model* model)
+void ExternalEvent::set_model(Model* model)
 { _model = model; }
 
-std::string Message::to_string() const
+std::string ExternalEvent::to_string() const
 {
     std::ostringstream ss;
 
@@ -69,16 +70,4 @@ std::string Message::to_string() const
     return ss.str();
 }
 
-std::string Messages::to_string() const
-{
-    std::ostringstream ss;
-
-    ss << "{ ";
-    for (const_iterator it = begin(); it != end(); ++it) {
-        ss << it->to_string() << " ";
-    }
-    ss << "}";
-    return ss.str();
-}
-
 } } // namespace paradevs common

+ 8 - 19
src/common/Message.hpp

@@ -1,5 +1,5 @@
 /**
- * @file Message.hpp
+ * @file ExternalEvent.hpp
  * @author The PARADEVS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -24,8 +24,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef COMMON_MESSAGE
-#define COMMON_MESSAGE 1
+#ifndef COMMON_EXTERNAL_EVENT
+#define COMMON_EXTERNAL_EVENT 1
 
 #include <common/Model.hpp>
 
@@ -36,13 +36,13 @@ namespace paradevs { namespace common {
 
 class Model;
 
-class Message
+class ExternalEvent
 {
 public:
-    Message(const std::string& port_name, double content);
-    Message(const std::string& port_name, Model* model, double content);
-    Message();
-    virtual ~Message();
+    ExternalEvent(const std::string& port_name, double content);
+    ExternalEvent(const std::string& port_name, Model* model, double content);
+    ExternalEvent();
+    virtual ~ExternalEvent();
 
     double get_content() const;
     Model* get_model() const;
@@ -59,17 +59,6 @@ private :
     double      _content;
 };
 
-class Messages : public std::vector < Message >
-{
-public:
-    Messages()
-    { }
-    virtual ~Messages()
-    { }
-
-    std::string to_string() const;
-};
-
 } } // namespace paradevs common
 
 #endif

+ 84 - 0
src/common/Model.cpp

@@ -0,0 +1,84 @@
+/**
+ * @file Model.cpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common/Model.hpp>
+
+#include <sstream>
+
+namespace paradevs { namespace common {
+
+Model::Model(const std::string& name) :
+    _tl(0), _tn(0), _parent(0), _name(name), _inputs(0)
+{ }
+
+Model::~Model()
+{
+    if (_inputs) {
+        delete _inputs;
+    }
+}
+
+void Model::add_event(const common::ExternalEvent& message)
+{
+    if (_inputs == 0) {
+        _inputs = new Bag;
+    }
+    _inputs->push_back(message);
+}
+
+const common::Bag& Model::get_bag() const
+{ return *_inputs; }
+
+void Model::clear_bag()
+{
+    if (_inputs) {
+        delete _inputs;
+        _inputs = 0;
+    }
+}
+
+unsigned int Model::event_number() const
+{
+    if (_inputs) {
+        return _inputs->size();
+    } else {
+        return 0;
+    }
+}
+
+std::string Models::to_string() const
+{
+    std::ostringstream ss;
+
+    ss << "{ ";
+    for (const_iterator it = begin(); it != end(); ++it) {
+        ss << (*it)->get_name() << " ";
+    }
+    ss << "}";
+    return ss.str();
+}
+
+} } // namespace paradevs common

+ 29 - 7
src/common/Model.hpp

@@ -27,6 +27,8 @@
 #ifndef COMMON_MODEL
 #define COMMON_MODEL 1
 
+#include <common/Bag.hpp>
+#include <common/ExternalEvent.hpp>
 #include <common/Time.hpp>
 
 #include <iostream>
@@ -34,14 +36,21 @@
 
 namespace paradevs { namespace common {
 
+class Bag;
+class ExternalEvent;
+
 class Model
 {
 public:
-    Model(const std::string& name) : _tl(0), _tn(0), _parent(0), _name(name)
-    { }
+    Model(const std::string& name);
+    virtual ~Model();
 
-    virtual ~Model()
-    { }
+    virtual void observation(std::ostream& file) const =0;
+    virtual void output(common::Time t) =0;
+    virtual void post_message(common::Time t,
+                              const common::ExternalEvent& event) = 0;
+    virtual common::Time start(common::Time t) =0;
+    virtual common::Time transition(common::Time t) =0;
 
     virtual const std::string& get_name() const
     { return _name; }
@@ -49,11 +58,14 @@ public:
     Model* get_parent() const
     { return _parent; }
 
-    virtual void observation(std::ostream& file) const = 0;
-
     void set_parent(Model* parent)
     { _parent = parent; }
 
+    void add_event(const common::ExternalEvent& event);
+    void clear_bag();
+    const common::Bag& get_bag() const;
+    unsigned int event_number() const;
+
 protected:
     Time        _tl;
     Time        _tn;
@@ -61,9 +73,19 @@ protected:
 private :
     Model*      _parent;
     std::string _name;
+    Bag*        _inputs;
 };
 
-typedef std::vector < Model* > Models;
+class Models : public std::vector < Model* >
+{
+public:
+    Models()
+    { }
+    virtual ~Models()
+    { }
+
+    std::string to_string() const;
+};
 
 } } // namespace paradevs common
 

+ 20 - 21
src/devs/Model.hpp

@@ -1,5 +1,5 @@
 /**
- * @file Model.hpp
+ * @file Simulator.hpp
  * @author The PARADEVS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -24,31 +24,30 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef DEVS_MODEL
-#define DEVS_MODEL 1
+#ifndef COMMON_SIMULATOR
+#define COMMON_SIMULATOR 1
 
-#include <common/Message.hpp>
-#include <common/Model.hpp>
-#include <common/Time.hpp>
+#include <common/Links.hpp>
+#include <common/Node.hpp>
 
-#include <vector>
+namespace paradevs { namespace common {
 
-namespace paradevs { namespace devs {
-
-class Model : public common::Model
+class Simulator : public Model
 {
-public:
-    Model(const std::string& name);
-    virtual ~Model();
-
-    virtual common::Time i_message(common::Time /* t */) =0;
-    virtual common::Time s_message(common::Time /* t */) =0;
-    virtual common::Time x_message(const common::Message& /* message */,
-                                   common::Time /* t */) =0;
+public :
+    Simulator(const std::string& name) : Model(name)
+    { }
+    virtual ~Simulator()
+    { }
+
+    virtual void observation(std::ostream& file) const =0;
+    virtual void output(common::Time t) =0;
+    virtual void post_message(common::Time t,
+                              const common::ExternalEvent& event) = 0;
+    virtual common::Time start(common::Time t) =0;
+    virtual common::Time transition(common::Time t) =0;
 };
 
-typedef std::vector < Model* > Models;
-
-} } // namespace paradevs devs
+} } // namespace paradevs common
 
 #endif

+ 1 - 0
src/common/Trace.cpp

@@ -50,6 +50,7 @@ std::string TraceElements::to_string() const
         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()) {

+ 1 - 1
src/common/Trace.hpp

@@ -38,7 +38,7 @@
 namespace paradevs { namespace common {
 
 enum TraceType { NONE = 0, I_MESSAGE, POST_MESSAGE, S_MESSAGE, Y_MESSAGE,
-                 DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START };
+                 DELTA_INT, DELTA_EXT, DELTA_CONF, TA, LAMBDA, START, OUTPUT };
 
 class TraceElement
 {

+ 0 - 32
src/devs/CMakeLists.txt

@@ -1,32 +0,0 @@
-INCLUDE_DIRECTORIES(
-  ${PARADEVS_BINARY_DIR}/src
-  ${PARADEVS_SOURCE_DIR}/src
-  ${Boost_INCLUDE_DIRS}
-  ${GLIBMM_INCLUDE_DIRS}
-  ${LIBXML_INCLUDE_DIRS})
-
-LINK_DIRECTORIES(
-  ${GLIBMM_LIBRARY_DIRS}
-  ${LIBXML_LIBRARY_DIR})
-
-SET(DEVS_CPP Coordinator.cpp Dynamics.cpp Model.cpp RootCoordinator.cpp Simulator.cpp)
-
-SET(DEVS_HPP Coordinator.hpp Dynamics.hpp Model.hpp RootCoordinator.hpp Simulator.hpp)
-
-ADD_LIBRARY(devs SHARED ${DEVS_CPP};${DEVS_HPP})
-
-SET_TARGET_PROPERTIES(devs PROPERTIES ${PARADEVS_LIBRARY_PROPERTIES})
-SET_TARGET_PROPERTIES(devs PROPERTIES OUTPUT_NAME
-  "paradevs-devs-${PARADEVS_VERSION_SHORT}")
-
-TARGET_LINK_LIBRARIES(devs
-  ${GLIBMM_LIBRARIES}
-  ${LIBXML_LIBRARIES}
-  ${GTHREAD_LIBRARIES})
-
-INSTALL(TARGETS devs
-  RUNTIME DESTINATION bin
-  LIBRARY DESTINATION lib
-  ARCHIVE DESTINATION lib)
-
-INSTALL(FILES ${DEVS_HPP} DESTINATION ${PARADEVS_INCLUDE_DIRS}/devs)

+ 0 - 208
src/devs/Coordinator.cpp

@@ -1,208 +0,0 @@
-/**
- * @file Coordinator.cpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
-
-/*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <devs/Coordinator.hpp>
-#include <devs/Simulator.hpp>
-
-#include <cassert>
-
-namespace paradevs { namespace devs {
-
-Coordinator::Coordinator(const std::string& name) : Model(name)
-{ }
-
-Coordinator::~Coordinator()
-{
-    for (unsigned int i = 0; i < _child_list.size(); i++)
-    { delete _child_list[i]; }
-}
-
-common::Time Coordinator::i_message(common::Time t)
-{
-
-    std::cout << "[" << get_name() << "] at " << t << ": BEFORE - i_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    assert(_child_list.size() > 0);
-
-    for (unsigned int i = 0; i < _child_list.size(); i++) {
-        Model* model = _child_list[i];
-
-        _event_table.init(model->i_message(_tn), model);
-    }
-    _tl = t;
-    _tn = _event_table.get_current_time();
-
-    std::cout << "[" << get_name() << "] at " << t << ": AFTER - i_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    return _tn;
-}
-
-common::Time Coordinator::s_message(common::Time t)
-{
-
-    std::cout << "[" << get_name() << "] at " << t << ": BEFORE - s_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-    std::cout << "[" << get_name() << "]: " << _event_table.to_string()
-              << std::endl;
-
-    assert(t == _tn);
-
-    Model* current = dynamic_cast < devs::Model* >(
-        _event_table.get_current_model());
-    common::Time tn = current->s_message(_tn);
-
-    _event_table.put(tn, current);
-
-    _tl = t;
-    _tn = _event_table.get_current_time();
-
-    std::cout << "[" << get_name() << "] at " << t << ": AFTER - s_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-    std::cout << "[" << get_name() << "]: " << _event_table.to_string()
-              << std::endl;
-    std::cout << "**************" << std::endl;
-
-    return _tn;
-}
-
-common::Time Coordinator::x_message(const common::Message& xmsg, common::Time t)
-{
-
-    std::cout << "[" << get_name() << "] at " << t << ": BEFORE - x_message on "
-              << xmsg.get_port_name() << " => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-    std::cout << "[" << get_name() << "] " << _link_list.to_string()
-              << std::endl;
-
-    assert(_tl <= t and t <= _tn);
-
-    std::pair < common::Links::iterator, common::Links::iterator > result =
-        _link_list.equal_range(common::Node(xmsg.get_port_name(), this));
-
-    for (common::Links::iterator it_r = result.first; it_r != result.second;
-         ++it_r) {
-        _tn = dynamic_cast < devs::Simulator* >(
-            (*it_r).second.get_model())->x_message(
-                common::Message(it_r->second.get_port_name(),
-                                it_r->second.get_model(),
-                                xmsg.get_content()), t);
-        _event_table.put(
-            _tn,
-            dynamic_cast < devs::Simulator* >(it_r->second.get_model()));
-    }
-
-    _tl = t;
-    _tn = _event_table.get_current_time();
-
-    std::cout << "[" << get_name() << "] at " << t << ": AFTER - x_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    return _tn;
-}
-
-common::Time Coordinator::y_message(common::Messages messages, common::Time t)
-{
-
-    std::cout << "[" << get_name() << "] at " << t << ": BEFORE - y_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-    std::cout << "[" << get_name() << "] at " << t << ": "
-              << messages.to_string() << std::endl;
-
-    if (not messages.empty()) {
-        bool internal = false;
-
-        while (not messages.empty()) {
-            common::Message ymsg = messages.back();
-
-            messages.pop_back();
-
-            std::pair < common::Links::iterator ,
-                        common::Links::iterator > result_model =
-                _link_list.equal_range(common::Node(ymsg.get_port_name(),
-                                                    ymsg.get_model()));
-
-            for (common::Links::iterator it = result_model.first;
-                 it != result_model.second; ++it) {
-                // event on output port of coupled model
-                if (it->second.get_model() == this) {
-                    common::Messages ymessages;
-
-                    ymessages.push_back(
-                        common::Message(it->second.get_port_name(),
-                                        it->second.get_model(),
-                                        ymsg.get_content()));
-                    dynamic_cast < devs::Coordinator* >(
-                        get_parent())->y_message(ymessages, t);
-                } else { // event on input port of internal model
-                    common::Message message(
-                        it->second.get_port_name(),
-                        it->second.get_model(),
-                        ymsg.get_content());
-                    common::Time tn = dynamic_cast < devs::Model* >(
-                        it->second.get_model())->x_message(message, t);
-
-                    _event_table.put(
-                        tn,
-                        dynamic_cast < devs::Model* >(it->second.get_model()));
-                    internal = true;
-                }
-            }
-        }
-        if (internal) {
-            _tl = t;
-            _tn = _event_table.get_current_time();
-        }
-    }
-
-    std::cout << "[" << get_name() << "] at " << t << ": AFTER - y_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    return _tn;
-}
-
-void Coordinator::observation(std::ostream& file) const
-{
-    for (unsigned i = 0; i < _child_list.size(); i++) {
-        _child_list[i]->observation(file);
-    }
-}
-
-void Coordinator::add_child(Model* child)
-{
-    _child_list.push_back(child);
-    child->set_parent(this);
-}
-
-void Coordinator::add_link(const common::Node& source,
-                           const common::Node& destination)
-{
-    _link_list.insert(std::pair < common::Node, common::Node >(source,
-                                                               destination));
-}
-
-} } // namespace paradevs devs

+ 0 - 99
src/devs/Simulator.cpp

@@ -1,99 +0,0 @@
-/**
- * @file Simulator.cpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
-
-/*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <devs/Coordinator.hpp>
-#include <devs/Simulator.hpp>
-
-#include <cassert>
-#include <stdexcept>
-
-namespace paradevs { namespace devs {
-
-Simulator::Simulator(Dynamics* dynamics) :
-    Model(dynamics->get_name()), _dynamics(dynamics)
-{ }
-
-Simulator::~Simulator()
-{ delete _dynamics; }
-
-common::Time Simulator::i_message(common::Time t)
-{
-    _tl = t;
-    _tn = _tl + _dynamics->start();
-    return _tn;
-}
-
-common::Time Simulator::s_message(common::Time t)
-{
-
-    std::cout << "[" << get_name() << "] at " << t << ": BEFORE - s_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    assert(t == _tn);
-
-    common::Messages msgs = _dynamics->lambda();
-
-    if (not msgs.empty()) {
-        for (common::Messages::iterator it = msgs.begin(); it != msgs.end(); ++it) {
-            it->set_model(this);
-        }
-        dynamic_cast < Coordinator* >(get_parent())->y_message(msgs, t);
-    }
-
-    _dynamics->dint(t);
-    _tl = t;
-    _tn = t + _dynamics->ta();
-
-    std::cout << "[" << get_name() << "] at " << t << ": AFTER - s_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    return _tn;
-}
-
-common::Time Simulator::x_message(const common::Message& msg, common::Time t)
-{
-
-    std::cout << "[" << get_name() << "] at " << t << ": BEFORE - x_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    assert(_tl <= t and t <= _tn);
-
-    common::Time e = t - _tl;
-
-    _dynamics->dext(e, msg);
-    _tl = t;
-    _tn = _tl + _dynamics->ta();
-
-    std::cout << "[" << get_name() << "] at " << t << ": AFTER - x_message => "
-              << "tl = " << _tl << " ; tn = " << _tn << std::endl;
-
-    return _tn;
-}
-
-void Simulator::observation(std::ostream &file) const
-{ _dynamics->observation(file); }
-
-} } // namespace paradevs devs

+ 32 - 0
src/dtss/CMakeLists.txt

@@ -0,0 +1,32 @@
+INCLUDE_DIRECTORIES(
+  ${PARADEVS_BINARY_DIR}/src
+  ${PARADEVS_SOURCE_DIR}/src
+  ${Boost_INCLUDE_DIRS}
+  ${GLIBMM_INCLUDE_DIRS}
+  ${LIBXML_INCLUDE_DIRS})
+
+LINK_DIRECTORIES(
+  ${GLIBMM_LIBRARY_DIRS}
+  ${LIBXML_LIBRARY_DIR})
+
+SET(DTSS_CPP Coordinator.cpp Dynamics.cpp Simulator.cpp)
+
+SET(DTSS_HPP Coordinator.hpp Dynamics.hpp Simulator.hpp)
+
+ADD_LIBRARY(dtss SHARED ${DTSS_CPP};${DTSS_HPP})
+
+SET_TARGET_PROPERTIES(dtss PROPERTIES ${PARADEVS_LIBRARY_PROPERTIES})
+SET_TARGET_PROPERTIES(dtss PROPERTIES OUTPUT_NAME
+  "paradevs-dtss-${PARADEVS_VERSION_SHORT}")
+
+TARGET_LINK_LIBRARIES(dtss
+  ${GLIBMM_LIBRARIES}
+  ${LIBXML_LIBRARIES}
+  ${GTHREAD_LIBRARIES})
+
+INSTALL(TARGETS dtss
+  RUNTIME DESTINATION bin
+  LIBRARY DESTINATION lib
+  ARCHIVE DESTINATION lib)
+
+INSTALL(FILES ${DTSS_HPP} DESTINATION ${PARADEVS_INCLUDE_DIRS}/dtss)

+ 146 - 0
src/dtss/Coordinator.cpp

@@ -0,0 +1,146 @@
+/**
+ * @file Coordinator.cpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common/Trace.hpp>
+
+#include <dtss/Coordinator.hpp>
+#include <dtss/Simulator.hpp>
+
+#include <algorithm>
+#include <cassert>
+
+namespace paradevs { namespace dtss {
+
+Coordinator::Coordinator(const std::string& name, common::Time time_step) :
+    common::Coordinator(name), _time_step(time_step)
+{ }
+
+Coordinator::~Coordinator()
+{
+    for (unsigned int i = 0; i < _child_list.size(); i++)
+    { delete _child_list[i]; }
+}
+
+common::Time Coordinator::start(common::Time t)
+{
+    assert(_child_list.size() > 0);
+
+    for (auto & child : _child_list) {
+        child->start(_tn);
+    }
+    _tn = t;
+    return _tn;
+}
+
+common::Time Coordinator::dispatch_events(common::Bag bag, common::Time t)
+{
+    for (auto & ymsg : bag) {
+        std::pair < common::Links::iterator ,
+                    common::Links::iterator > result_model =
+            _link_list.equal_range(common::Node(ymsg.get_port_name(),
+                                                ymsg.get_model()));
+
+        for (common::Links::iterator it = result_model.first;
+             it != result_model.second; ++it) {
+            // event on output port of coupled model
+            if (it->second.get_model() == this) {
+                common::Bag ymessages;
+
+                ymessages.push_back(
+                    common::ExternalEvent(it->second.get_port_name(),
+                                          it->second.get_model(),
+                                          ymsg.get_content()));
+                dynamic_cast < Coordinator* >(get_parent())->dispatch_events(
+                    ymessages, t);
+            } else { // event on input port of internal model
+                Model* model = dynamic_cast < Model* >(
+                    it->second.get_model());
+                common::ExternalEvent message(it->second.get_port_name(),
+                                              model, ymsg.get_content());
+
+                model->post_message(t, message);
+            }
+        }
+    }
+    return _tn;
+}
+
+void Coordinator::observation(std::ostream& file) const
+{
+    for (unsigned i = 0; i < _child_list.size(); i++) {
+        _child_list[i]->observation(file);
+    }
+}
+
+void Coordinator::output(common::Time t)
+{
+    assert(t == _tn);
+
+    for (auto & model : _child_list) {
+        model->output(t);
+    }
+}
+
+void Coordinator::post_message(common::Time t,
+                               const common::ExternalEvent& message)
+{
+    std::pair < common::Links::iterator, common::Links::iterator > result =
+        _link_list.equal_range(common::Node(message.get_port_name(), this));
+
+    for (common::Links::iterator it_r = result.first;
+         it_r != result.second; ++it_r) {
+        Model* model = dynamic_cast < Model* >((*it_r).second.get_model());
+
+        model->post_message(t,
+                            common::ExternalEvent(it_r->second.get_port_name(),
+                                                  model,
+                                                  message.get_content()));
+    }
+}
+
+common::Time Coordinator::transition(common::Time t)
+{
+    assert(t >= _tl and t <= _tn);
+
+    for (auto & model : _child_list) {
+        model->transition(t);
+    }
+    _tn = t + _time_step;
+    return _tn;
+}
+
+void Coordinator::add_child(Model* child)
+{
+    _child_list.push_back(child);
+    child->set_parent(this);
+}
+
+void Coordinator::add_link(const common::Node& source,
+                           const common::Node& destination)
+{ _link_list.insert(std::pair < common::Node, common::Node >(source,
+                                                             destination)); }
+
+} } // namespace paradevs dtss

+ 23 - 21
src/devs/Coordinator.hpp

@@ -24,45 +24,47 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef DEVS_COORDINATOR
-#define DEVS_COORDINATOR 1
-
-#include <devs/Model.hpp>
+#ifndef DTSS_COORDINATOR
+#define DTSS_COORDINATOR 1
 
+#include <common/Bag.hpp>
+#include <common/Coordinator.hpp>
 #include <common/EventTable.hpp>
 #include <common/Links.hpp>
-#include <common/Message.hpp>
+#include <common/ExternalEvent.hpp>
 #include <common/Node.hpp>
-#include <common/Time.hpp>
 
 #include <iostream>
 
-namespace paradevs { namespace devs {
+namespace paradevs { namespace dtss {
 
-class Coordinator : public Model
+class Coordinator : public common::Coordinator
 {
-public :
-    Coordinator(const std::string& name);
+public:
+    Coordinator(const std::string& name, common::Time time_step);
     virtual ~Coordinator();
 
 // DEVS methods
-    virtual common::Time i_message(common::Time /* t */);
-    virtual common::Time s_message(common::Time /* t */);
-    virtual common::Time x_message(const common::Message& /* message */,
-                                   common::Time /* t */);
-    virtual common::Time y_message(common::Messages /* messages */, common::Time /* t */);
+    virtual void output(common::Time /* t */);
+    virtual void post_message(common::Time /* t */,
+                              const common::ExternalEvent& /* message */);
+    virtual common::Time dispatch_events(common::Bag /* bag */,
+                                         common::Time /* t */);
+    virtual common::Time start(common::Time /* t */);
+    virtual common::Time transition(common::Time /* t */);
     virtual void observation(std::ostream& file) const;
 
 // graph methods
     virtual void add_child(Model* child);
-    virtual void add_link(const common::Node& source, const common::Node& destination);
+    virtual void add_link(const common::Node& source,
+                          const common::Node& destination);
 
-private :
-    common::Links      _link_list;
-    Models             _child_list;
-    common::EventTable _event_table;
+private:
+    common::Links  _link_list;
+    common::Models _child_list;
+    common::Time   _time_step;
 };
 
-} } // namespace paradevs devs
+} } // namespace paradevs dtss
 
 #endif

+ 5 - 6
src/devs/Dynamics.cpp

@@ -24,9 +24,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <devs/Dynamics.hpp>
+#include <dtss/Dynamics.hpp>
 
-namespace paradevs { namespace devs {
+namespace paradevs { namespace dtss {
 
 Dynamics::Dynamics(const std::string& name) : _name(name)
 { }
@@ -34,8 +34,7 @@ Dynamics::Dynamics(const std::string& name) : _name(name)
 Dynamics::~Dynamics()
 { }
 
-common::Messages Dynamics::lambda() const
-{ return common::Messages(); }
-
-} } // namespace paradevs devs
+common::Bag Dynamics::lambda(common::Time /* time */) const
+{ return common::Bag(); }
 
+} } // namespace paradevs dtss

+ 9 - 15
src/devs/Dynamics.hpp

@@ -24,20 +24,18 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef DEVS_DYNAMICS
-#define DEVS_DYNAMICS 1
+#ifndef DTSS_DYNAMICS
+#define DTSS_DYNAMICS 1
 
-#include <common/Message.hpp>
+#include <common/Bag.hpp>
+#include <common/ExternalEvent.hpp>
 #include <common/Time.hpp>
 
 #include <limits>
 #include <string>
 #include <vector>
 
-namespace paradevs { namespace devs {
-
-class Message;
-class Messages;
+namespace paradevs { namespace dtss {
 
 class Dynamics
 {
@@ -45,15 +43,11 @@ public:
     Dynamics(const std::string& name);
     virtual ~Dynamics();
 
-    virtual void dint(const common::Time& /* t */)
-    { }
-    virtual void dext(const common::Time& /* e */, const common::Message& /* msg */)
+    virtual void transition(const common::Bag& /* x */, common::Time /* t */)
     { }
-    virtual common::Time start()
-    { return std::numeric_limits < double >::max(); }
-    virtual common::Time ta() const
+    virtual common::Time start(common::Time /* time */)
     { return std::numeric_limits < double >::max(); }
-    virtual common::Messages lambda() const;
+    virtual common::Bag lambda(common::Time /* time */) const;
     virtual void observation(std::ostream& /* file */) const
     { }
 
@@ -64,6 +58,6 @@ private:
     std::string _name;
 };
 
-} } // namespace paradevs devs
+} } // namespace paradevs dtss
 
 #endif

+ 49 - 0
src/dtss/EventTable.cpp

@@ -0,0 +1,49 @@
+/**
+ * @file EventTable.cpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <pdevs/EventTable.hpp>
+
+#include <algorithm>
+#include <sstream>
+
+namespace paradevs { namespace pdevs {
+
+common::Models EventTable::get_current_models(common::Time time) const
+{
+    common::Models models;
+    bool found = true;
+
+    for (const_reverse_iterator it = rbegin(); found and it != rend(); ++it) {
+        if (it->get_time() == time) {
+            models.push_back(it->get_model());
+        } else {
+            found = false;
+        }
+    }
+    return models;
+}
+
+} } // namespace paradevs pdevs

+ 48 - 0
src/dtss/EventTable.hpp

@@ -0,0 +1,48 @@
+/**
+ * @file EventTable.hpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PDEVS_EVENT_TABLE
+#define PDEVS_EVENT_TABLE 1
+
+#include <common/EventTable.hpp>
+#include <common/Model.hpp>
+
+namespace paradevs { namespace pdevs {
+
+class EventTable : public common::EventTable
+{
+public:
+    EventTable()
+    { }
+    virtual ~EventTable()
+    { }
+
+    common::Models get_current_models(common::Time time) const;
+};
+
+} } // namespace paradevs pdevs
+
+#endif

+ 6 - 5
src/devs/RootCoordinator.cpp

@@ -24,9 +24,9 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <devs/RootCoordinator.hpp>
+#include <pdevs/RootCoordinator.hpp>
 
-namespace paradevs { namespace devs {
+namespace paradevs { namespace pdevs {
 
 RootCoordinator::RootCoordinator(const common::Time& t_start,
                                  const common::Time& t_max,
@@ -40,10 +40,11 @@ RootCoordinator::~RootCoordinator()
 
 void RootCoordinator::run()
 {
-    _tn = _root->i_message(_tn);
+    _tn = _root->start(_tn);
     while (_tn <= _t_max) {
-        _tn = _root->s_message(_tn);
+        _root->output(_tn);
+        _tn = _root->transition(_tn);
     }
 }
 
-} } // namespace paradevs devs
+} } // namespace paradevs pdevs

+ 5 - 5
src/devs/RootCoordinator.hpp

@@ -24,13 +24,13 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef DEVS_ROOT_COORDINATOR
-#define DEVS_ROOT_COORDINATOR 1
+#ifndef PDEVS_ROOT_COORDINATOR
+#define PDEVS_ROOT_COORDINATOR 1
 
 #include <common/Builder.hpp>
-#include <devs/Coordinator.hpp>
+#include <pdevs/Coordinator.hpp>
 
-namespace paradevs { namespace devs {
+namespace paradevs { namespace pdevs {
 
 class RootCoordinator
 {
@@ -48,6 +48,6 @@ private :
     common::Time _tn;
 };
 
-} } // namespace paradevs devs
+} } // namespace paradevs pdevs
 
 #endif

+ 85 - 0
src/dtss/Simulator.cpp

@@ -0,0 +1,85 @@
+/**
+ * @file Simulator.cpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <common/Trace.hpp>
+
+#include <dtss/Coordinator.hpp>
+#include <dtss/Simulator.hpp>
+
+#include <cassert>
+#include <stdexcept>
+
+namespace paradevs { namespace dtss {
+
+Simulator::Simulator(Dynamics* dynamics, common::Time time_step) :
+    common::Simulator(dynamics->get_name()), _dynamics(dynamics),
+    _time_step(time_step)
+{ }
+
+Simulator::~Simulator()
+{ delete _dynamics; }
+
+common::Time Simulator::start(common::Time t)
+{
+    _dynamics->start(t);
+    _tn = t;
+    return _tn;
+}
+
+void Simulator::observation(std::ostream &file) const
+{ _dynamics->observation(file); }
+
+void Simulator::output(common::Time t)
+{
+    if(t == _tn) {
+        common::Bag bag = _dynamics->lambda(t);
+
+        if (not bag.empty()) {
+            for (common::Bag::iterator it = bag.begin(); it != bag.end();
+                 ++it) {
+                it->set_model(this);
+            }
+            dynamic_cast < Coordinator* >(get_parent())->dispatch_events(bag,
+                                                                         t);
+        }
+    }
+}
+
+void Simulator::post_message(common::Time /* t */,
+                             const common::ExternalEvent& event)
+{ add_event(event); }
+
+common::Time Simulator::transition(common::Time t)
+{
+    assert(t == _tn);
+
+    _dynamics->transition(get_bag(), t);
+    _tn = t + _time_step;
+    clear_bag();
+    return _tn;
+}
+
+} } // namespace paradevs dtss

+ 16 - 13
src/devs/Simulator.hpp

@@ -24,35 +24,38 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef DEVS_SIMULATOR
-#define DEVS_SIMULATOR 1
+#ifndef DTSS_SIMULATOR
+#define DTSS_SIMULATOR 1
 
-#include <devs/Model.hpp>
-#include <devs/Dynamics.hpp>
 #include <common/Links.hpp>
 #include <common/Node.hpp>
+#include <common/Simulator.hpp>
 
-namespace paradevs { namespace devs {
+#include <dtss/Dynamics.hpp>
 
-class Simulator : public Model
+namespace paradevs { namespace dtss {
+
+class Simulator : public common::Simulator
 {
 public :
-    Simulator(Dynamics* dynamics);
+    Simulator(Dynamics* dynamics, common::Time time_step);
     virtual ~Simulator();
 
-    virtual common::Time i_message(common::Time /* t */);
-    virtual common::Time s_message(common::Time /* t */);
-    virtual common::Time x_message(const common::Message& /* message */,
-                                   common::Time /* t */);
     virtual void observation(std::ostream& file) const;
+    virtual void output(common::Time /* t */);
+    virtual void post_message(common::Time /* t */,
+                              const common::ExternalEvent& /* message */);
+    virtual common::Time start(common::Time /* t */);
+    virtual common::Time transition(common::Time /* t */);
 
     virtual Dynamics* get_dynamics() const
     { return _dynamics; }
 
 private :
-    Dynamics* _dynamics;
+    Dynamics*    _dynamics;
+    common::Time _time_step;
 };
 
-} } // namespace paradevs devs
+} } // namespace paradevs dtss
 
 #endif

+ 4 - 4
src/pdevs/CMakeLists.txt

@@ -9,11 +9,11 @@ LINK_DIRECTORIES(
   ${GLIBMM_LIBRARY_DIRS}
   ${LIBXML_LIBRARY_DIR})
 
-SET(PDEVS_CPP Coordinator.cpp Dynamics.cpp EventTable.cpp Model.cpp
-  RootCoordinator.cpp Simulator.cpp)
+SET(PDEVS_CPP Coordinator.cpp Dynamics.cpp EventTable.cpp RootCoordinator.cpp
+  Simulator.cpp)
 
-SET(PDEVS_HPP Coordinator.hpp Dynamics.hpp EventTable.hpp
-  Model.hpp RootCoordinator.hpp Simulator.hpp)
+SET(PDEVS_HPP Coordinator.hpp Dynamics.hpp EventTable.hpp RootCoordinator.hpp
+  Simulator.hpp)
 
 ADD_LIBRARY(pdevs SHARED ${PDEVS_CPP};${PDEVS_HPP})
 

+ 94 - 61
src/pdevs/Coordinator.cpp

@@ -34,7 +34,7 @@
 
 namespace paradevs { namespace pdevs {
 
-Coordinator::Coordinator(const std::string& name) : Model(name)
+Coordinator::Coordinator(const std::string& name) : common::Coordinator(name)
 { }
 
 Coordinator::~Coordinator()
@@ -43,7 +43,7 @@ Coordinator::~Coordinator()
     { delete _child_list[i]; }
 }
 
-common::Time Coordinator::i_message(common::Time t)
+common::Time Coordinator::start(common::Time t)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -54,10 +54,8 @@ common::Time Coordinator::i_message(common::Time t)
 
     assert(_child_list.size() > 0);
 
-    for (unsigned int i = 0; i < _child_list.size(); i++) {
-        Model* model = _child_list[i];
-
-        _event_table.init(model->i_message(_tn), model);
+    for (auto & child : _child_list) {
+        _event_table.init(child->start(_tn), child);
     }
     _tl = t;
     _tn = _event_table.get_current_time();
@@ -80,7 +78,41 @@ common::Time Coordinator::i_message(common::Time t)
  *   ...
  *  send done to parent
  **************************************************/
-common::Time Coordinator::s_message(common::Time t)
+void Coordinator::output(common::Time t)
+{
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::OUTPUT)
+                           << ": BEFORE";
+    common::Trace::trace().flush();
+
+    assert(t == _tn);
+
+    common::Models IMM = _event_table.get_current_models(t);
+
+    for (auto & model : IMM) {
+        model->output(t);
+    }
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::OUTPUT)
+                           << ": AFTER";
+    common::Trace::trace().flush();
+
+}
+
+/*******************************************************************
+ * when x-message(t)
+ *   receivers = { r | r in children, N in Ir, Z(N,r)(x) isn't empty
+ *   for each r in receivers
+ *     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
+ *   tl = t
+ *   tn = min(tn_d | d in D)
+ *******************************************************************/
+common::Time Coordinator::transition(common::Time t)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -90,47 +122,48 @@ common::Time Coordinator::s_message(common::Time t)
                            << " ; scheduler = " << _event_table.to_string();
     common::Trace::trace().flush();
 
-    assert(t == _tn);
+    assert(t >= _tl and t <= _tn);
 
-    Models IMM = _event_table.get_current_models(t);
+    common::Models receivers = _event_table.get_current_models(t);
 
-    for (Models::const_iterator it = _child_list.begin();
+    for (common::Models::const_iterator it = _child_list.begin();
          it != _child_list.end(); ++it) {
         Model* model = dynamic_cast < Model* >(*it);
 
-        if (model->is_atomic() and
-            dynamic_cast < Simulator* >(model)->message_number() > 0) {
-            Models::const_iterator itm = std::find(IMM.begin(), IMM.end(),
-                                                   model);
-            if (itm == IMM.end()) {
-                IMM.push_back(model);
+        if (model->event_number() > 0) {
+            common::Models::const_iterator itm = std::find(receivers.begin(),
+                                                           receivers.end(),
+                                                           model);
+            if (itm == receivers.end()) {
+                receivers.push_back(model);
             }
         }
     }
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::S_MESSAGE)
-                           << ": IMM = " << IMM.to_string();
+                           << ": receivers = " << receivers.to_string();
     common::Trace::trace().flush();
 
-    for (Models::const_iterator it = IMM.begin(); it != IMM.end(); ++it) {
-        common::Time tn = (*it)->s_message(t);
+    for (common::Models::const_iterator it = receivers.begin();
+         it != receivers.end(); ++it) {
+        common::Time tn = (*it)->transition(t);
 
         _event_table.put(tn, *it);
     }
 
-    for (Models::const_iterator it = _child_list.begin();
+    for (common::Models::const_iterator it = _child_list.begin();
          it != _child_list.end(); ++it) {
         Model* model = dynamic_cast < Model* >(*it);
 
-        if (model->message_number() > 0) {
+        if (model->event_number() > 0) {
             _event_table.put(t, model);
         }
     }
 
     _tl = t;
     _tn = _event_table.get_current_time();
-    clear_messages();
+    clear_bag();
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::S_MESSAGE)
@@ -142,7 +175,8 @@ common::Time Coordinator::s_message(common::Time t)
     return _tn;
 }
 
-void Coordinator::post_message(common::Time t, const common::Message& message)
+void Coordinator::post_message(common::Time t,
+                               const common::ExternalEvent& message)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -150,7 +184,7 @@ void Coordinator::post_message(common::Time t, const common::Message& message)
                            << ": BEFORE => " << message.to_string();
     common::Trace::trace().flush();
 
-    _x_messages.push_back(message);
+    add_event(message);
 
     std::pair < common::Links::iterator, common::Links::iterator > result =
         _link_list.equal_range(common::Node(message.get_port_name(), this));
@@ -159,14 +193,16 @@ void Coordinator::post_message(common::Time t, const common::Message& message)
          it_r != result.second; ++it_r) {
         Model* model = dynamic_cast < Model* >((*it_r).second.get_model());
 
-        model->post_message(t, common::Message(it_r->second.get_port_name(),
-                                               model, message.get_content()));
+        model->post_message(t,
+                            common::ExternalEvent(it_r->second.get_port_name(),
+                                                  model,
+                                                  message.get_content()));
     }
-    for (Models::const_iterator it = _child_list.begin();
+    for (common::Models::const_iterator it = _child_list.begin();
          it != _child_list.end(); ++it) {
         Model* model = dynamic_cast < Model* >(*it);
 
-        if (model->message_number() > 0) {
+        if (model->event_number() > 0) {
             _event_table.put(t, model);
         }
     }
@@ -179,47 +215,44 @@ void Coordinator::post_message(common::Time t, const common::Message& message)
 
 }
 
-common::Time Coordinator::y_message(common::Messages messages, common::Time t)
+/*******************************************************************
+ * when y-message(y_d, t) with output y_d from d
+ *******************************************************************/
+common::Time Coordinator::dispatch_events(common::Bag bag, common::Time t)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::Y_MESSAGE)
                            << ": BEFORE => "
                            << "tl = " << _tl << " ; tn = " << _tn
-                           << " ; messages = " << messages.to_string();
+                           << " ; bag = " << bag.to_string();
     common::Trace::trace().flush();
 
-    if (not messages.empty()) {
-        while (not messages.empty()) {
-            common::Message ymsg = messages.back();
-
-            messages.pop_back();
-
-            std::pair < common::Links::iterator ,
-                        common::Links::iterator > result_model =
-                _link_list.equal_range(common::Node(ymsg.get_port_name(),
-                                                    ymsg.get_model()));
-
-            for (common::Links::iterator it = result_model.first;
-                 it != result_model.second; ++it) {
-                // event on output port of coupled model
-                if (it->second.get_model() == this) {
-                    common::Messages ymessages;
-
-                    ymessages.push_back(
-                        common::Message(it->second.get_port_name(),
-                                        it->second.get_model(),
-                                        ymsg.get_content()));
-                    dynamic_cast < Coordinator* >(get_parent())->y_message(
-                        ymessages, t);
-                } else { // event on input port of internal model
-                    Model* model = dynamic_cast < Model* >(
-                        it->second.get_model());
-                    common::Message message(it->second.get_port_name(),
-                                            model, ymsg.get_content());
-
-                    model->post_message(t, message);
-                }
+    for (auto & ymsg : bag) {
+        std::pair < common::Links::iterator ,
+                    common::Links::iterator > result_model =
+            _link_list.equal_range(common::Node(ymsg.get_port_name(),
+                                                ymsg.get_model()));
+
+        for (common::Links::iterator it = result_model.first;
+             it != result_model.second; ++it) {
+            // event on output port of coupled model
+            if (it->second.get_model() == this) {
+                common::Bag ymessages;
+
+                ymessages.push_back(
+                    common::ExternalEvent(it->second.get_port_name(),
+                                          it->second.get_model(),
+                                          ymsg.get_content()));
+                dynamic_cast < Coordinator* >(get_parent())->dispatch_events(
+                    ymessages, t);
+            } else { // event on input port of internal model
+                Model* model = dynamic_cast < Model* >(
+                    it->second.get_model());
+                common::ExternalEvent message(it->second.get_port_name(),
+                                              model, ymsg.get_content());
+
+                model->post_message(t, message);
             }
         }
     }

+ 16 - 17
src/pdevs/Coordinator.hpp

@@ -27,43 +27,42 @@
 #ifndef PDEVS_COORDINATOR
 #define PDEVS_COORDINATOR 1
 
-#include <pdevs/Model.hpp>
 #include <pdevs/EventTable.hpp>
 
+#include <common/Bag.hpp>
+#include <common/Coordinator.hpp>
 #include <common/Links.hpp>
-#include <common/Message.hpp>
+#include <common/ExternalEvent.hpp>
 #include <common/Node.hpp>
 
 #include <iostream>
 
 namespace paradevs { namespace pdevs {
 
-class Coordinator : public Model
+class Coordinator : public common::Coordinator
 {
-public :
+public:
     Coordinator(const std::string& name);
     virtual ~Coordinator();
 
 // DEVS methods
-    virtual common::Time i_message(common::Time /* t */);
-    virtual common::Time s_message(common::Time /* t */);
-    virtual common::Time y_message(common::Messages /* messages */,
-                                   common::Time /* t */);
-    virtual void observation(std::ostream& file) const;
-
-    virtual bool is_atomic() const
-    { return false;}
-
+    virtual void output(common::Time /* t */);
     virtual void post_message(common::Time /* t */,
-                              const common::Message& /* message */);
+                              const common::ExternalEvent& /* message */);
+    virtual common::Time dispatch_events(common::Bag /* bag */,
+                                         common::Time /* t */);
+    virtual common::Time start(common::Time /* t */);
+    virtual common::Time transition(common::Time /* t */);
+    virtual void observation(std::ostream& file) const;
 
 // graph methods
     virtual void add_child(Model* child);
-    virtual void add_link(const common::Node& source, const common::Node& destination);
+    virtual void add_link(const common::Node& source,
+                          const common::Node& destination);
 
-private :
+private:
     common::Links      _link_list;
-    Models             _child_list;
+    common::Models     _child_list;
     pdevs::EventTable  _event_table;
 };
 

+ 2 - 2
src/pdevs/Dynamics.cpp

@@ -34,8 +34,8 @@ Dynamics::Dynamics(const std::string& name) : _name(name)
 Dynamics::~Dynamics()
 { }
 
-common::Messages Dynamics::lambda(common::Time /* time */) const
-{ return common::Messages(); }
+common::Bag Dynamics::lambda(common::Time /* time */) const
+{ return common::Bag(); }
 
 } } // namespace paradevs pdevs
 

+ 5 - 4
src/pdevs/Dynamics.hpp

@@ -27,7 +27,8 @@
 #ifndef PDEVS_DYNAMICS
 #define PDEVS_DYNAMICS 1
 
-#include <common/Message.hpp>
+#include <common/Bag.hpp>
+#include <common/ExternalEvent.hpp>
 #include <common/Time.hpp>
 
 #include <limits>
@@ -43,18 +44,18 @@ public:
     virtual ~Dynamics();
 
     virtual void dconf(common::Time /* t */, common::Time /* e */,
-                       const common::Messages& /* msgs */)
+                       const common::Bag& /* bag */)
     { }
     virtual void dint(common::Time /* t */)
     { }
     virtual void dext(common::Time /* t */, common::Time /* e */,
-                      const common::Messages& /* msgs */)
+                      const common::Bag& /* bag */)
     { }
     virtual common::Time start(common::Time /* time */)
     { return std::numeric_limits < double >::max(); }
     virtual common::Time ta(common::Time /* time */) const
     { return std::numeric_limits < double >::max(); }
-    virtual common::Messages lambda(common::Time /* time */) const;
+    virtual common::Bag lambda(common::Time /* time */) const;
     virtual void observation(std::ostream& /* file */) const
     { }
 

+ 3 - 3
src/pdevs/EventTable.cpp

@@ -31,14 +31,14 @@
 
 namespace paradevs { namespace pdevs {
 
-Models EventTable::get_current_models(common::Time time) const
+common::Models EventTable::get_current_models(common::Time time) const
 {
-    Models models;
+    common::Models models;
     bool found = true;
 
     for (const_reverse_iterator it = rbegin(); found and it != rend(); ++it) {
         if (it->get_time() == time) {
-            models.push_back(dynamic_cast < Model* >(it->get_model()));
+            models.push_back(it->get_model());
         } else {
             found = false;
         }

+ 2 - 2
src/pdevs/EventTable.hpp

@@ -28,7 +28,7 @@
 #define PDEVS_EVENT_TABLE 1
 
 #include <common/EventTable.hpp>
-#include <pdevs/Model.hpp>
+#include <common/Model.hpp>
 
 namespace paradevs { namespace pdevs {
 
@@ -40,7 +40,7 @@ public:
     virtual ~EventTable()
     { }
 
-    Models get_current_models(common::Time time) const;
+    common::Models get_current_models(common::Time time) const;
 };
 
 } } // namespace paradevs pdevs

+ 0 - 76
src/pdevs/Model.hpp

@@ -1,76 +0,0 @@
-/**
- * @file Model.hpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
-
-/*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef PDEVS_MODEL
-#define PDEVS_MODEL 1
-
-#include <pdevs/Dynamics.hpp>
-#include <common/Message.hpp>
-#include <common/Time.hpp>
-
-#include <iostream>
-#include <vector>
-
-namespace paradevs { namespace pdevs {
-
-class Model : public common::Model
-{
-public:
-    Model(const std::string& name);
-    virtual ~Model();
-
-    virtual common::Time i_message(common::Time /* t */) = 0;
-    virtual common::Time s_message(common::Time /* t */) =0;
-
-    virtual bool is_atomic() const = 0;
-
-    virtual void clear_messages()
-    { _x_messages.clear(); }
-
-    virtual void post_message(common::Time /* t */,
-                              const common::Message& /* message */) = 0;
-
-    virtual bool message_number() const
-    { return _x_messages.size(); }
-
-protected:
-    common::Messages _x_messages;
-};
-
-class Models : public std::vector < Model* >
-{
-public:
-    Models()
-    { }
-    virtual ~Models()
-    { }
-
-    std::string to_string() const;
-};
-
-} } // namespace paradevs pdevs
-
-#endif

+ 4 - 3
src/pdevs/RootCoordinator.cpp

@@ -31,7 +31,7 @@ namespace paradevs { namespace pdevs {
 RootCoordinator::RootCoordinator(const common::Time& t_start,
                                  const common::Time& t_max,
                                  const common::Builder& builder) :
-    _root(dynamic_cast < Coordinator* >(builder.build())),
+    _root(dynamic_cast < common::Coordinator* >(builder.build())),
     _t_max(t_max), _tn(t_start)
 { }
 
@@ -40,9 +40,10 @@ RootCoordinator::~RootCoordinator()
 
 void RootCoordinator::run()
 {
-    _tn = _root->i_message(_tn);
+    _tn = _root->start(_tn);
     while (_tn <= _t_max) {
-        _tn = _root->s_message(_tn);
+        _root->output(_tn);
+        _tn = _root->transition(_tn);
     }
 }
 

+ 3 - 3
src/pdevs/RootCoordinator.hpp

@@ -42,10 +42,10 @@ public :
     void run();
 
 private :
-    Coordinator* _root;
-    common::Time _t_max;
+    common::Coordinator* _root;
+    common::Time         _t_max;
 
-    common::Time _tn;
+    common::Time         _tn;
 };
 
 } } // namespace paradevs pdevs

+ 71 - 42
src/pdevs/Simulator.cpp

@@ -35,13 +35,18 @@
 namespace paradevs { namespace pdevs {
 
 Simulator::Simulator(Dynamics* dynamics) :
-    Model(dynamics->get_name()), _dynamics(dynamics)
+    common::Simulator(dynamics->get_name()), _dynamics(dynamics)
 { }
 
 Simulator::~Simulator()
 { delete _dynamics; }
 
-common::Time Simulator::i_message(common::Time t)
+/*************************************************
+ * when i-message(t)
+ *   tl = t - e
+ *   tn = tl + ta(s)
+ *************************************************/
+common::Time Simulator::start(common::Time t)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -62,68 +67,47 @@ common::Time Simulator::i_message(common::Time t)
     return _tn;
 }
 
+void Simulator::observation(std::ostream &file) const
+{
+    _dynamics->observation(file);
+}
+
 /*************************************************
  * when *-message(t)
  *   if (t = tn) then
  *     y = lambda(s)
- *     send #-message(y,t) to parent
- *     if (???) then
- *       s = delta_int(s)
- *     else
- *       s = delta_conf(s,x)
- *  else
- *    s = delta_ext(s,t-tl,x)
- *  tn = t + ta(s)
- *  tl = t
- *  empty x
- *  send done to parent
+ *     send y-message(y,t) to parent
  *************************************************/
-common::Time Simulator::s_message(common::Time t)
+void Simulator::output(common::Time t)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
-                                                   common::S_MESSAGE)
-                           << ": BEFORE => "
-                           << "tl = " << _tl << " ; tn = " << _tn;
+                                                   common::OUTPUT)
+                           << ": BEFORE";
     common::Trace::trace().flush();
 
     if(t == _tn) {
-        common::Messages msgs = _dynamics->lambda(t);
+        common::Bag bag = _dynamics->lambda(t);
 
-        if (not msgs.empty()) {
-            for (common::Messages::iterator it = msgs.begin(); it != msgs.end();
+        if (not bag.empty()) {
+            for (common::Bag::iterator it = bag.begin(); it != bag.end();
                  ++it) {
                 it->set_model(this);
             }
-            dynamic_cast < Coordinator* >(get_parent())->y_message(msgs, t);
+            dynamic_cast < Coordinator* >(get_parent())->dispatch_events(bag,
+                                                                         t);
         }
-        if (message_number() == 0) {
-            _dynamics->dint(t);
-        } else {
-            _dynamics->dconf(t, t - _tl, _x_messages);
-        }
-    } else {
-        _dynamics->dext(t, t - _tl, _x_messages);
     }
-    _tn = t + _dynamics->ta(t);
-    _tl = t;
-    clear_messages();
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
-                                                   common::S_MESSAGE)
-                           << ": AFTER => "
-                           << "tl = " << _tl << " ; tn = " << _tn;
+                                                   common::OUTPUT)
+                           << ": AFTER";
     common::Trace::trace().flush();
 
-    return _tn;
 }
 
-void Simulator::observation(std::ostream &file) const
-{
-    _dynamics->observation(file);
-}
-
-void Simulator::post_message(common::Time t, const common::Message& message)
+void Simulator::post_message(common::Time t,
+                             const common::ExternalEvent& message)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -131,7 +115,7 @@ void Simulator::post_message(common::Time t, const common::Message& message)
                            << ": BEFORE => " << message.to_string();
     common::Trace::trace().flush();
 
-    _x_messages.push_back(message);
+    add_event(message);
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::POST_MESSAGE)
@@ -140,4 +124,49 @@ void Simulator::post_message(common::Time t, const common::Message& message)
 
 }
 
+/*************************************************
+ * when x-message(t)
+ *   if (x is empty and t = tn) then
+ *       s = delta_int(s)
+ *  else if (x isn't empty and t = tn)
+ *       s = delta_conf(s,x)
+ *  else if (x isn't empty and t < tn)
+ *    e = t - tl
+ *    s = delta_ext(s,e,x)
+ *  tn = t + ta(s)
+ *  tl = t
+ *************************************************/
+common::Time Simulator::transition(common::Time t)
+{
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::S_MESSAGE)
+                           << ": BEFORE => "
+                           << "tl = " << _tl << " ; tn = " << _tn;
+    common::Trace::trace().flush();
+
+    assert(_tl <= t and t <= _tn);
+
+    if(t == _tn) {
+        if (event_number() == 0) {
+            _dynamics->dint(t);
+        } else {
+            _dynamics->dconf(t, t - _tl, get_bag());
+        }
+    } else {
+        _dynamics->dext(t, t - _tl, get_bag());
+    }
+    _tn = t + _dynamics->ta(t);
+    _tl = t;
+    clear_bag();
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::S_MESSAGE)
+                           << ": AFTER => "
+                           << "tl = " << _tl << " ; tn = " << _tn;
+    common::Trace::trace().flush();
+
+    return _tn;
+}
+
 } } // namespace paradevs pdevs

+ 7 - 10
src/pdevs/Simulator.hpp

@@ -29,31 +29,28 @@
 
 #include <common/Links.hpp>
 #include <common/Node.hpp>
+#include <common/Simulator.hpp>
 
-#include <pdevs/Model.hpp>
 #include <pdevs/Dynamics.hpp>
 
 namespace paradevs { namespace pdevs {
 
-class Simulator : public Model
+class Simulator : public common::Simulator
 {
 public :
     Simulator(Dynamics* dynamics);
     virtual ~Simulator();
 
-    virtual common::Time i_message(common::Time /* t */);
-    virtual common::Time s_message(common::Time /* t */);
     virtual void observation(std::ostream& file) const;
+    virtual void output(common::Time /* t */);
+    virtual void post_message(common::Time /* t */,
+                              const common::ExternalEvent& /* message */);
+    virtual common::Time start(common::Time /* t */);
+    virtual common::Time transition(common::Time /* t */);
 
     virtual Dynamics* get_dynamics() const
     { return _dynamics; }
 
-    virtual bool is_atomic() const
-    { return true;}
-
-    virtual void post_message(common::Time /* t */,
-                              const common::Message& /* message */);
-
 private :
     Dynamics* _dynamics;
 };

+ 12 - 23
src/tests/CMakeLists.txt

@@ -9,29 +9,7 @@ LINK_DIRECTORIES(
   ${GLIBMM_LIBRARY_DIRS}
   ${LIBXML_LIBRARY_DIR})
 
-SET(EXAMPLES_CPP devs_examples.cpp)
-
-SET(EXAMPLES_HPP devs_examples.hpp)
-
-ADD_LIBRARY(examples SHARED ${EXAMPLES_CPP};${EXAMPLES_HPP})
-
-SET_TARGET_PROPERTIES(examples PROPERTIES ${PARADEVS_LIBRARY_PROPERTIES})
-SET_TARGET_PROPERTIES(examples PROPERTIES OUTPUT_NAME
-  "paradevs-examples${PARADEVS_VERSION_SHORT}")
-
-TARGET_LINK_LIBRARIES(examples
-  ${GLIBMM_LIBRARIES}
-  ${LIBXML_LIBRARIES}
-  ${GTHREAD_LIBRARIES})
-
-INSTALL(TARGETS examples
-  RUNTIME DESTINATION bin
-  LIBRARY DESTINATION lib
-  ARCHIVE DESTINATION lib)
-
-INSTALL(FILES ${EXAMPLES_HPP} DESTINATION ${PARADEVS_INCLUDE_DIRS}/examples)
-
-# tests
+# pdevs tests
 ADD_EXECUTABLE(pdevs-tests pdevs_tests.hpp pdevs_tests.cpp)
 SET_TARGET_PROPERTIES(pdevs-tests PROPERTIES ${PARADEVS_APP_PROPERTIES})
 
@@ -41,3 +19,14 @@ TARGET_LINK_LIBRARIES(pdevs-tests
   ${LIBXML_LIBRARIES}
   ${GTHREAD_LIBRARIES}
   ${Boost_FILESYSTEM_LIBRARY})
+
+# dtss tests
+ADD_EXECUTABLE(dtss-tests dtss_tests.hpp dtss_tests.cpp)
+SET_TARGET_PROPERTIES(dtss-tests PROPERTIES ${PARADEVS_APP_PROPERTIES})
+
+TARGET_LINK_LIBRARIES(dtss-tests
+  common dtss pdevs
+  ${GLIBMM_LIBRARIES}
+  ${LIBXML_LIBRARIES}
+  ${GTHREAD_LIBRARIES}
+  ${Boost_FILESYSTEM_LIBRARY})

+ 0 - 168
src/tests/devs_examples.cpp

@@ -1,168 +0,0 @@
-/**
- * @file devs_examples.cpp
- * @author The PARADEVS Development Team
- * See the AUTHORS or Authors.txt file
- */
-
-/*
- * PARADEVS - the multimodeling and simulation environment
- * This file is a part of the PARADEVS environment
- *
- * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <tests/devs_examples.hpp>
-#include <devs/Coordinator.hpp>
-
-namespace paradevs { namespace devs {
-
-void A::dint(const common::Time& t)
-{
-
-    std::cout << "[ model " << get_name() << " ] dint at " << t << std::endl;
-
-    if (_phase == SEND) {
-        _phase = WAIT;
-    }
-}
-
-void A::dext(const common::Time& /* e */, const common::Message& msg)
-{
-
-    std::cout << "[ model " << get_name() << " ] dext: "
-              << msg.get_content()
-              << " on " << msg.get_port_name() << std::endl;
-
-    _phase = SEND;
-}
-
-common::Time A::start()
-{
-
-    std::cout << "[ model " << get_name() << " ] start" << std::endl;
-
-    _phase = WAIT;
-    return 0;
-}
-
-common::Time A::ta() const
-{
-    if (_phase == WAIT) {
-        return 1;
-    } else {
-        return 0;
-    }
-}
-
-common::Messages A::lambda() const
-{
-
-    std::cout << "[ model " << get_name() << " ] lambda" << std::endl;
-
-    common::Messages msgs;
-
-    msgs.push_back(common::Message("out", 0, true));
-    return msgs;
-}
-
-void A::observation(std::ostream& /* file */) const
-{ }
-
-void B::dint(const common::Time& t)
-{
-
-    std::cout << "[ model " << get_name() << " ] dint at " << t
-              << std::endl;
-
-    if (_phase == SEND) {
-        _phase = WAIT;
-    }
-}
-
-void B::dext(const common::Time& /* e */, const common::Message& msg)
-{
-
-    std::cout << "[ model " << get_name() << " ] dext: "
-              << msg.get_content()
-              << " on " << msg.get_port_name() << std::endl;
-
-    _phase = SEND;
-}
-
-common::Time B::start()
-{
-
-    std::cout << "[ model " << get_name() << " ] start" << std::endl;
-
-    _phase = WAIT;
-    return 0;
-}
-
-common::Time B::ta() const
-{
-    if (_phase == WAIT) {
-        return std::numeric_limits < double >::max();
-    } else {
-        return 0;
-    }
-}
-
-common::Messages B::lambda() const
-{
-
-    std::cout << "[ model " << get_name() << " ] lambda" << std::endl;
-
-    common::Messages msgs;
-
-    msgs.push_back(common::Message("out", 0, true));
-    return msgs;
-}
-
-void B::observation(std::ostream& /* file */) const
-{ }
-
-common::Model* MyBuilder::build() const
-{
-    devs::Coordinator* root = new devs::Coordinator("root");
-
-    devs::Coordinator* S1 = new devs::Coordinator("S1");
-    {
-        devs::Simulator* a = new devs::Simulator(new A("a1"));
-        devs::Simulator* b = new devs::Simulator(new B("b1"));
-
-        S1->add_child(a);
-        S1->add_child(b);
-        S1->add_link(common::Node("out", a), common::Node("in", b));
-        S1->add_link(common::Node("out", b), common::Node("out", S1));
-    }
-
-    devs::Coordinator* S2 = new devs::Coordinator("S2");
-    {
-        devs::Simulator* a = new devs::Simulator(new A("a2"));
-        devs::Simulator* b = new devs::Simulator(new B("b2"));
-
-        S2->add_child(a);
-        S2->add_child(b);
-        S2->add_link(common::Node("out", a), common::Node("in", b));
-        S2->add_link(common::Node("in", S2), common::Node("in", a));
-    }
-    root->add_child(S1);
-    root->add_child(S2);
-    root->add_link(common::Node("out", S1), common::Node("in", S2));
-    return root;
-}
-
-} } // namespace paradevs devs

+ 176 - 0
src/tests/dtss_tests.cpp

@@ -0,0 +1,176 @@
+/**
+ * @file examples.cpp
+ * @author The PARADEVS Development Team
+ * See the AUTHORS or Authors.txt file
+ */
+
+/*
+ * PARADEVS - the multimodeling and simulation environment
+ * This file is a part of the PARADEVS environment
+ *
+ * Copyright (C) 2013 ULCO http://www.univ-litoral.fr
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <tests/dtss_tests.hpp>
+
+#include <common/Trace.hpp>
+
+#include <dtss/Coordinator.hpp>
+#include <pdevs/RootCoordinator.hpp>
+
+#define CATCH_CONFIG_MAIN
+#include "catch.hpp"
+
+namespace paradevs { namespace dtss {
+
+void A::transition(const common::Bag& /* x */, common::Time t)
+{
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::DELTA_INT);
+    common::Trace::trace().flush();
+}
+
+common::Time A::start(common::Time t)
+{
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::START);
+    common::Trace::trace().flush();
+
+    return 0;
+}
+
+common::Bag A::lambda(common::Time t) const
+{
+    common::Bag msgs;
+
+    msgs.push_back(common::ExternalEvent("out", 0, true));
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::LAMBDA)
+                           << "messages = " << msgs.to_string();
+    common::Trace::trace().flush();
+
+    return msgs;
+}
+
+void B::transition(const common::Bag& x, common::Time t)
+{
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::DELTA_INT)
+                           << "x = " << x.to_string();
+    common::Trace::trace().flush();
+}
+
+common::Time B::start(common::Time t)
+{
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::START);
+    common::Trace::trace().flush();
+
+    return 0;
+}
+
+common::Bag B::lambda(common::Time t) const
+{
+    common::Bag msgs;
+
+    msgs.push_back(common::ExternalEvent("out", 0, true));
+
+    common::Trace::trace() << common::TraceElement(get_name(), t,
+                                                   common::LAMBDA)
+                           << "messages = " << msgs.to_string();
+    common::Trace::trace().flush();
+
+    return msgs;
+}
+
+common::Model* OnlyOneBuilder::build() const
+{
+    dtss::Coordinator* root = new dtss::Coordinator("root", 1);
+    dtss::Simulator* a = new dtss::Simulator(new A("a"), 1);
+
+    root->add_child(a);
+    return root;
+}
+
+common::Model* TwoBuilder::build() const
+{
+    dtss::Coordinator* root = new dtss::Coordinator("root", 1);
+    dtss::Simulator* a = new dtss::Simulator(new A("a"), 1);
+    dtss::Simulator* b = new dtss::Simulator(new B("b"), 1);
+
+    root->add_child(a);
+    root->add_child(b);
+    root->add_link(common::Node("out", a), common::Node("in", b));
+    return root;
+}
+
+} } // namespace paradevs dtss
+
+TEST_CASE("dtss/only_one", "run")
+{
+    paradevs::dtss::OnlyOneBuilder builder;
+    paradevs::pdevs::RootCoordinator rc(0, 10, builder);
+
+    paradevs::common::Trace::trace().clear();
+    rc.run();
+
+    REQUIRE(paradevs::common::Trace::trace().elements().
+            filter_model_name("a").
+            filter_type(paradevs::common::START).size() == 1);
+    for (unsigned int t = 0; t <= 10; ++t) {
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("a").filter_time(t).
+                filter_type(paradevs::common::DELTA_INT).size() == 1);
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("a").filter_time(t).
+                filter_type(paradevs::common::LAMBDA).size() == 1);
+    }
+}
+
+TEST_CASE("dtss/two", "run")
+{
+    paradevs::dtss::TwoBuilder builder;
+    paradevs::pdevs::RootCoordinator rc(0, 10, builder);
+
+    paradevs::common::Trace::trace().clear();
+    rc.run();
+
+    REQUIRE(paradevs::common::Trace::trace().elements().
+            filter_model_name("a").
+            filter_type(paradevs::common::START).size() == 1);
+    for (unsigned int t = 0; t <= 10; ++t) {
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("a").filter_time(t).
+                filter_type(paradevs::common::DELTA_INT).size() == 1);
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("a").filter_time(t).
+                filter_type(paradevs::common::LAMBDA).size() == 1);
+    }
+
+    REQUIRE(paradevs::common::Trace::trace().elements().
+            filter_model_name("b").
+            filter_type(paradevs::common::START).size() == 1);
+    for (unsigned int t = 0; t <= 10; ++t) {
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("b").filter_time(t).
+                filter_type(paradevs::common::DELTA_INT).size() == 1);
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("b").filter_time(t).
+                filter_type(paradevs::common::LAMBDA).size() == 1);
+    }
+}

+ 23 - 28
src/tests/devs_examples.hpp

@@ -1,5 +1,5 @@
 /**
- * @file devs_examples.hpp
+ * @file pdevs_examples.hpp
  * @author The PARADEVS Development Team
  * See the AUTHORS or Authors.txt file
  */
@@ -25,10 +25,10 @@
  */
 
 #include <common/Builder.hpp>
-#include <devs/Dynamics.hpp>
-#include <devs/Simulator.hpp>
+#include <dtss/Dynamics.hpp>
+#include <dtss/Simulator.hpp>
 
-namespace paradevs { namespace devs {
+namespace paradevs { namespace dtss {
 
 class A : public Dynamics
 {
@@ -38,17 +38,9 @@ public:
     virtual ~A()
     { }
 
-    virtual void dint(const common::Time& t);
-    virtual void dext(const common::Time& /* e */, const common::Message& msg);
-    virtual common::Time start();
-    virtual common::Time ta() const;
-    virtual common::Messages lambda() const;
-    virtual void observation(std::ostream& /* file */) const;
-
-private:
-    enum Phase { WAIT, SEND };
-
-    Phase _phase;
+    virtual void transition(const common::Bag& /* x */, common::Time /* t */);
+    virtual common::Time start(common::Time /* t */);
+    virtual common::Bag lambda(common::Time /* t */) const;
 };
 
 class B : public Dynamics
@@ -59,28 +51,31 @@ public:
     virtual ~B()
     { }
 
-    virtual void dint(const common::Time& t);
-    virtual void dext(const common::Time& /* e */, const common::Message& msg);
-    virtual common::Time start();
-    virtual common::Time ta() const;
-    virtual common::Messages lambda() const;
-    virtual void observation(std::ostream& /* file */) const;
+    virtual void transition(const common::Bag& /* x */, common::Time /* t */);
+    virtual common::Time start(common::Time /* t */);
+    virtual common::Bag lambda(common::Time /* t */) const;
+};
 
-private:
-    enum Phase { WAIT, SEND };
+class OnlyOneBuilder : public common::Builder
+{
+public:
+    OnlyOneBuilder()
+    { }
+    virtual ~OnlyOneBuilder()
+    { }
 
-    Phase _phase;
+    virtual common::Model* build() const;
 };
 
-class MyBuilder : public common::Builder
+class TwoBuilder : public common::Builder
 {
 public:
-    MyBuilder()
+    TwoBuilder()
     { }
-    virtual ~MyBuilder()
+    virtual ~TwoBuilder()
     { }
 
     virtual common::Model* build() const;
 };
 
-} } // namespace paradevs devs
+} } // namespace paradevs dtss

+ 10 - 10
src/tests/pdevs_tests.cpp

@@ -48,7 +48,7 @@ void A::dint(common::Time t)
     }
 }
 
-void A::dext(common::Time t, common::Time /* e */, const common::Messages& msgs)
+void A::dext(common::Time t, common::Time /* e */, const common::Bag& msgs)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -60,7 +60,7 @@ void A::dext(common::Time t, common::Time /* e */, const common::Messages& msgs)
 }
 
 void A::dconf(common::Time t, common::Time /* e */,
-              const common::Messages& msgs)
+              const common::Bag& msgs)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -93,11 +93,11 @@ common::Time A::ta(common::Time t) const
     }
 }
 
-common::Messages A::lambda(common::Time t) const
+common::Bag A::lambda(common::Time t) const
 {
-    common::Messages msgs;
+    common::Bag msgs;
 
-    msgs.push_back(common::Message("out", 0, true));
+    msgs.push_back(common::ExternalEvent("out", 0, true));
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::LAMBDA)
@@ -122,7 +122,7 @@ void B::dint(common::Time t)
     }
 }
 
-void B::dext(common::Time t, common::Time /* e */, const common::Messages& msgs)
+void B::dext(common::Time t, common::Time /* e */, const common::Bag& msgs)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -134,7 +134,7 @@ void B::dext(common::Time t, common::Time /* e */, const common::Messages& msgs)
 }
 
 void B::dconf(common::Time t, common::Time /* e */,
-              const common::Messages& msgs)
+              const common::Bag& msgs)
 {
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
@@ -168,11 +168,11 @@ common::Time B::ta(common::Time t) const
     }
 }
 
-common::Messages B::lambda(common::Time t) const
+common::Bag B::lambda(common::Time t) const
 {
-    common::Messages msgs;
+    common::Bag msgs;
 
-    msgs.push_back(common::Message("out", 0, true));
+    msgs.push_back(common::ExternalEvent("out", 0, true));
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::LAMBDA)

+ 6 - 6
src/tests/pdevs_tests.hpp

@@ -40,12 +40,12 @@ public:
 
     virtual void dint(common::Time /* t */);
     virtual void dext(common::Time /* t */, common::Time /* e */,
-                      const common::Messages& /* msgs */);
+                      const common::Bag& /* msgs */);
     virtual void dconf(common::Time /* t */, common::Time /* e */,
-                       const common::Messages& /* msgs */);
+                       const common::Bag& /* msgs */);
     virtual common::Time start(common::Time /* t */);
     virtual common::Time ta(common::Time /* t */) const;
-    virtual common::Messages lambda(common::Time /* t */) const;
+    virtual common::Bag lambda(common::Time /* t */) const;
     virtual void observation(std::ostream& /* file */) const;
 
 private:
@@ -64,12 +64,12 @@ public:
 
     virtual void dint(common::Time /* t */);
     virtual void dext(common::Time /* t */, common::Time /* e */,
-                      const common::Messages& /* msgs */);
+                      const common::Bag& /* msgs */);
     virtual void dconf(common::Time /* t */, common::Time /* e */,
-                       const common::Messages& /* msgs */);
+                       const common::Bag& /* msgs */);
     virtual common::Time start(common::Time /* t */);
     virtual common::Time ta(common::Time /* t */) const;
-    virtual common::Messages lambda(common::Time /* t */) const;
+    virtual common::Bag lambda(common::Time /* t */) const;
     virtual void observation(std::ostream& /* file */) const;
 
 private: