Parcourir la source

Modify examples

Eric Ramat il y a 11 ans
Parent
commit
89e92b8c8c
2 fichiers modifiés avec 124 ajouts et 22 suppressions
  1. 23 14
      src/apps/main.cpp
  2. 101 8
      src/tests/mixed_tests.hpp

+ 23 - 14
src/apps/main.cpp

@@ -32,30 +32,44 @@
 
 #include <tests/mixed_tests.hpp>
 
+template < int size >
 void run_flat_with_heap()
 {
+    boost::timer t;
+
+    std::cout << "run_flat_with_heap [" << size << "] ..." << std::endl;
+
     paradevs::common::RootCoordinator <
         paradevs::MyTime, paradevs::pdevs::Coordinator <
             paradevs::MyTime,
             paradevs::common::scheduler::HeapScheduler < paradevs::MyTime >,
-            paradevs::LinearGraphManager >
-        > rc(0, 500, "root", paradevs::pdevs::Parameters());
+            paradevs::LinearGraphManager < size > >
+        > rc(0, 100, "root", paradevs::pdevs::Parameters());
 
     paradevs::common::Trace < paradevs::MyTime >::trace().clear();
     rc.run();
+
+    std::cout << "... OK -> " << t.elapsed() << std::endl;
 }
 
+template < int size >
 void run_flat_with_vector()
 {
+    boost::timer t;
+
+    std::cout << "run_flat_with_vector [" << size << "] ..." << std::endl;
+
     paradevs::common::RootCoordinator <
         paradevs::MyTime, paradevs::pdevs::Coordinator <
             paradevs::MyTime,
             paradevs::common::scheduler::VectorScheduler < paradevs::MyTime >,
-            paradevs::LinearGraphManager >
-        > rc(0, 500, "root", paradevs::pdevs::Parameters());
+            paradevs::LinearGraphManager < size > >
+        > rc(0, 100, "root", paradevs::pdevs::Parameters());
 
     paradevs::common::Trace < paradevs::MyTime >::trace().clear();
     rc.run();
+
+    std::cout << "... OK -> " << t.elapsed() << std::endl;
 }
 
 void run_hierarchic_with_heap()
@@ -65,7 +79,7 @@ void run_hierarchic_with_heap()
             paradevs::MyTime,
             paradevs::common::scheduler::VectorScheduler < paradevs::MyTime >,
             paradevs::Root2GraphManager >
-        > rc(0, 500, "root", paradevs::pdevs::Parameters());
+        > rc(0, 100, "root", paradevs::pdevs::Parameters());
 
     paradevs::common::Trace < paradevs::MyTime >::trace().clear();
     rc.run();
@@ -78,7 +92,7 @@ void run_hierarchic_with_vector()
             paradevs::MyTime,
             paradevs::common::scheduler::VectorScheduler < paradevs::MyTime >,
             paradevs::Root3GraphManager >
-        > rc(0, 500, "root", paradevs::pdevs::Parameters());
+        > rc(0, 100, "root", paradevs::pdevs::Parameters());
 
     paradevs::common::Trace < paradevs::MyTime >::trace().clear();
     rc.run();
@@ -88,18 +102,13 @@ int main()
 {
     boost::timer t;
 
-    std::cout << "run_flat_with_heap ..." << std::endl;
-    run_flat_with_heap();
-
-    double t1 = t.elapsed();
+    srand(108364);
 
-    std::cout << "... OK -> " << t1 << std::endl;
-    std::cout << "run_flat_with_vector ..." << std::endl;
-    run_flat_with_vector();
+    run_flat_with_heap < 200 >();
+    run_flat_with_vector < 200 >();
 
     double t2 = t.elapsed();
 
-    std::cout << "... OK -> "  << (t2 - t1) << std::endl;
     std::cout << "run_hierarchic_with_heap ..." << std::endl;
     run_hierarchic_with_heap();
 

+ 101 - 8
src/tests/mixed_tests.hpp

@@ -326,6 +326,98 @@ public:
     }
 };
 
+class Beep : public paradevs::pdevs::Dynamics < MyTime >
+{
+public:
+    Beep(const std::string& name) : paradevs::pdevs::Dynamics < MyTime >(name)
+    { }
+    virtual ~Beep()
+    { }
+
+    void dint(typename MyTime::type t)
+    {
+
+        common::Trace < MyTime >::trace() <<
+            common::TraceElement < MyTime >(get_name(), t,
+                                            common::DELTA_INT);
+        common::Trace < MyTime >::trace().flush();
+
+        if (_phase == SEND) {
+            _phase = WAIT;
+        }
+    }
+
+    void dext(typename MyTime::type t, typename MyTime::type /* e */,
+              const common::Bag < MyTime >& msgs)
+    {
+
+        common::Trace < MyTime >::trace()
+            << common::TraceElement < MyTime >(get_name(), t,
+                                               common::DELTA_EXT)
+            << "messages = " << msgs.to_string();
+        common::Trace < MyTime >::trace().flush();
+
+        _phase = SEND;
+    }
+
+    void dconf(typename MyTime::type t, typename MyTime::type /* e */,
+               const common::Bag < MyTime >& msgs)
+    {
+
+        common::Trace < MyTime >::trace()
+            << common::TraceElement < MyTime >(get_name(), t,
+                                               common::DELTA_CONF)
+            << "messages = " << msgs.to_string();
+        common::Trace < MyTime >::trace().flush();
+
+    }
+
+    typename MyTime::type start(typename MyTime::type t)
+    {
+        common::Trace < MyTime >::trace()
+            << common::TraceElement < MyTime >(get_name(), t,
+                                               common::START);
+        common::Trace < MyTime >::trace().flush();
+
+        _phase = WAIT;
+        return 0;
+    }
+
+    typename MyTime::type ta(typename MyTime::type t) const
+    {
+        common::Trace < MyTime >::trace()
+            << common::TraceElement < MyTime >(get_name(), t,
+                                               common::TA);
+        common::Trace < MyTime >::trace().flush();
+
+        if (_phase == WAIT) {
+            return (rand() % 100) / 10.;
+        } else {
+            return 0;
+        }
+    }
+
+    common::Bag < MyTime > lambda(typename MyTime::type t) const
+    {
+        common::Bag < MyTime > msgs;
+
+        msgs.push_back(common::ExternalEvent < MyTime >("out", 0.));
+
+        common::Trace < MyTime >::trace()
+            << common::TraceElement < MyTime >(get_name(), t,
+                                               common::LAMBDA)
+            << "messages = " << msgs.to_string();
+        common::Trace < MyTime >::trace().flush();
+
+        return msgs;
+    }
+
+private:
+    enum Phase { WAIT, SEND };
+
+    Phase _phase;
+};
+
 struct LastBagPolicy
 {
     const common::Bag < MyTime >& bag() const
@@ -423,35 +515,36 @@ private:
     dtss::Coordinator < MyTime, LastBagPolicy, S2GraphManager > S2;
 };
 
+template < int size >
 class LinearGraphManager : public pdevs::GraphManager < MyTime >
 {
 public:
     LinearGraphManager(common::Coordinator < MyTime >* coordinator) :
         pdevs::GraphManager < MyTime >(coordinator)
     {
-        for (unsigned int i = 1; i <= 200; ++i) {
+        for (unsigned int i = 1; i <= size; ++i) {
             std::ostringstream ss;
 
             ss << "a" << i;
-            _models.push_back(new pdevs::Simulator < MyTime, A1 >(ss.str()));
+            _models.push_back(new pdevs::Simulator < MyTime, Beep >(ss.str()));
         }
-        for (unsigned int i = 0; i < 200; ++i) {
+        for (unsigned int i = 0; i < size; ++i) {
             add_child(_models[i]);
         }
-        for (unsigned int i = 0; i < 199; ++i) {
+        for (unsigned int i = 0; i < size - 1; ++i) {
             add_link(_models[i], "out", _models[i + 1], "in");
         }
     }
 
     virtual ~LinearGraphManager()
     {
-        for (unsigned int i = 0; i < 200; ++i) {
+        for (unsigned int i = 0; i < size; ++i) {
             delete _models[i];
         }
     }
 
 private:
-    std::vector < pdevs::Simulator < MyTime, A1 >* > _models;
+    std::vector < pdevs::Simulator < MyTime, Beep >* > _models;
 };
 
 class Linear2GraphManager : public pdevs::GraphManager < MyTime >
@@ -464,7 +557,7 @@ public:
             std::ostringstream ss;
 
             ss << "a" << i;
-            _models.push_back(new pdevs::Simulator < MyTime, A1 >(ss.str()));
+            _models.push_back(new pdevs::Simulator < MyTime, Beep >(ss.str()));
         }
         for (unsigned int i = 0; i < 100; ++i) {
             add_child(_models[i]);
@@ -484,7 +577,7 @@ public:
     }
 
 private:
-    std::vector < pdevs::Simulator < MyTime, A1 >* > _models;
+    std::vector < pdevs::Simulator < MyTime, Beep >* > _models;
 };
 
 class Root2GraphManager : public pdevs::GraphManager < MyTime >