Sfoglia il codice sorgente

Fix: update scheduler when message

Eric Ramat 11 anni fa
parent
commit
730f37c92e

+ 3 - 1
src/common/EventTable.cpp

@@ -32,7 +32,9 @@
 namespace paradevs { namespace common {
 
 Model* EventTable::get_current_model()
-{ return back().get_model(); }
+{
+    return back().get_model();
+}
 
 void EventTable::init(common::Time time, Model* model)
 {

+ 3 - 0
src/common/Trace.hpp

@@ -120,6 +120,9 @@ class Trace
 public:
     static Trace& trace();
 
+    void clear()
+    { _trace.clear(); }
+
     const TraceElements& elements() const
     { return _trace; }
 

+ 19 - 12
src/pdevs/Coordinator.cpp

@@ -114,27 +114,23 @@ common::Time Coordinator::s_message(common::Time t)
     common::Trace::trace().flush();
 
     for (Models::const_iterator it = IMM.begin(); it != IMM.end(); ++it) {
-        common::Time tn = (*it)->s_message(_tn);
+        common::Time tn = (*it)->s_message(t);
 
         _event_table.put(tn, *it);
     }
 
-    _tl = t;
-
-    bool found = false;
-
     for (Models::const_iterator it = _child_list.begin();
-         not found and it != _child_list.end(); ++it) {
+         it != _child_list.end(); ++it) {
         Model* model = dynamic_cast < Model* >(*it);
 
-        if (model->is_atomic() and
-            dynamic_cast < Simulator* >(model)->message_number() > 0) {
-            found = true;
+        if (model->message_number() > 0) {
+            _event_table.put(t, model);
         }
     }
-    if (not found) {
-        _tn = _event_table.get_current_time();
-    }
+
+    _tl = t;
+    _tn = _event_table.get_current_time();
+    clear_messages();
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::S_MESSAGE)
@@ -154,6 +150,8 @@ void Coordinator::post_message(common::Time t, const common::Message& message)
                            << ": BEFORE => " << message.to_string();
     common::Trace::trace().flush();
 
+    _x_messages.push_back(message);
+
     std::pair < common::Links::iterator, common::Links::iterator > result =
         _link_list.equal_range(common::Node(message.get_port_name(), this));
 
@@ -164,6 +162,15 @@ void Coordinator::post_message(common::Time t, const common::Message& message)
         model->post_message(t, common::Message(it_r->second.get_port_name(),
                                                model, message.get_content()));
     }
+    for (Models::const_iterator it = _child_list.begin();
+         it != _child_list.end(); ++it) {
+        Model* model = dynamic_cast < Model* >(*it);
+
+        if (model->message_number() > 0) {
+            _event_table.put(t, model);
+        }
+    }
+    _tn = _event_table.get_current_time();
 
     common::Trace::trace() << common::TraceElement(get_name(), t,
                                                    common::POST_MESSAGE)

+ 9 - 0
src/pdevs/Model.hpp

@@ -47,8 +47,17 @@ public:
 
     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* >

+ 0 - 5
src/pdevs/Simulator.cpp

@@ -123,11 +123,6 @@ void Simulator::observation(std::ostream &file) const
     _dynamics->observation(file);
 }
 
-void Simulator::clear_messages()
-{
-    _x_messages.clear();
-}
-
 void Simulator::post_message(common::Time t, const common::Message& message)
 {
 

+ 0 - 4
src/pdevs/Simulator.hpp

@@ -51,15 +51,11 @@ public :
     virtual bool is_atomic() const
     { return true;}
 
-    virtual void clear_messages();
     virtual void post_message(common::Time /* t */,
                               const common::Message& /* message */);
-    virtual bool message_number() const
-    { return _x_messages.size(); }
 
 private :
     Dynamics* _dynamics;
-    common::Messages _x_messages;
 };
 
 } } // namespace paradevs pdevs

+ 9 - 11
src/tests/pdevs_tests.cpp

@@ -250,6 +250,7 @@ TEST_CASE("pdevs/only_one", "run")
     paradevs::pdevs::OnlyOneBuilder builder;
     paradevs::pdevs::RootCoordinator rc(0, 10, builder);
 
+    paradevs::common::Trace::trace().clear();
     rc.run();
 
     REQUIRE(paradevs::common::Trace::trace().elements().
@@ -279,6 +280,7 @@ TEST_CASE("pdevs/flat", "run")
     paradevs::pdevs::FlatBuilder builder;
     paradevs::pdevs::RootCoordinator rc(0, 10, builder);
 
+    paradevs::common::Trace::trace().clear();
     rc.run();
 
     REQUIRE(paradevs::common::Trace::trace().elements().
@@ -294,9 +296,6 @@ TEST_CASE("pdevs/flat", "run")
             filter_model_name("b2").
             filter_type(paradevs::common::START).size() == 1);
 
-    REQUIRE(paradevs::common::Trace::trace().elements().
-            filter_type(paradevs::common::DELTA_CONF).size() == 0);
-
     REQUIRE(paradevs::common::Trace::trace().elements().
             filter_model_name("a1").
             filter_type(paradevs::common::DELTA_EXT).size() == 0);
@@ -340,6 +339,9 @@ TEST_CASE("pdevs/flat", "run")
         REQUIRE(paradevs::common::Trace::trace().elements().
                 filter_model_name("a2").filter_time(t).
                 filter_type(paradevs::common::DELTA_EXT).size() == 1);
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("a2").filter_time(t).
+                filter_type(paradevs::common::DELTA_CONF).size() == 0);
     }
 
     for (unsigned int t = 0; t <= 10; ++t) {
@@ -363,13 +365,9 @@ TEST_CASE("pdevs/hierachical", "run")
     paradevs::pdevs::HierachicalBuilder builder;
     paradevs::pdevs::RootCoordinator rc(0, 10, builder);
 
+    paradevs::common::Trace::trace().clear();
     rc.run();
 
-    std::cout << paradevs::common::Trace::trace().elements().
-        filter_model_name("b1").
-        filter_type(paradevs::common::I_MESSAGE).to_string()
-              << std::endl;
-
     REQUIRE(paradevs::common::Trace::trace().elements().
             filter_model_name("a1").
             filter_type(paradevs::common::START).size() == 1);
@@ -383,9 +381,6 @@ TEST_CASE("pdevs/hierachical", "run")
             filter_model_name("b2").
             filter_type(paradevs::common::START).size() == 1);
 
-    REQUIRE(paradevs::common::Trace::trace().elements().
-            filter_type(paradevs::common::DELTA_CONF).size() == 0);
-
     REQUIRE(paradevs::common::Trace::trace().elements().
             filter_model_name("a1").
             filter_type(paradevs::common::DELTA_EXT).size() == 0);
@@ -429,6 +424,9 @@ TEST_CASE("pdevs/hierachical", "run")
         REQUIRE(paradevs::common::Trace::trace().elements().
                 filter_model_name("a2").filter_time(t).
                 filter_type(paradevs::common::DELTA_EXT).size() == 1);
+        REQUIRE(paradevs::common::Trace::trace().elements().
+                filter_model_name("a2").filter_time(t).
+                filter_type(paradevs::common::DELTA_CONF).size() == 0);
     }
 
     for (unsigned int t = 0; t <= 10; ++t) {