Browse Source

Working on aDEVS yet

Román Cárdenas 6 years ago
parent
commit
e472036aa9

+ 2 - 0
.gitignore

@@ -2,3 +2,5 @@
 .log
 
 cmake-build-debug/
+
+.DS_Store

+ 1 - 1
devstone/adevs/CMakeLists.txt

@@ -9,4 +9,4 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
 set(CMAKE_CXX_STANDARD 17)
 
-add_executable(DEVStone src/DEVStone.cpp)
+add_executable(DEVStone src/DEVStone.cpp src/DummyAtomic.cpp src/DEVSWrapper.cpp)

+ 37 - 0
devstone/adevs/src/DEVSWrapper.cpp

@@ -0,0 +1,37 @@
+//
+// Created by Román Cárdenas Rodríguez on 09/03/2020.
+//
+
+#include "DEVSWrapper.hpp"
+
+const int DEVSWrapper::in = 0;
+const int DEVSWrapper::out = 1;
+
+DEVSWrapper::DEVSWrapper(int depthIn, int widthIn, int intDelayIn, int extDelayIn, double procTimeIn):
+        adevs::Digraph<IO_Type>()
+{
+    depth = depthIn;
+    width = widthIn;
+    intDelay = intDelayIn;
+    extDelay = extDelayIn;
+    procTime = procTimeIn;
+
+    if (depth == 1) {
+        DummyAtomic *a = new DummyAtomic(intDelay, extDelay, procTime);
+        add(a);
+        couple(this, this->in, a, a->in);
+        couple(a, a->out, this, this->out);
+    } else {
+        DEVSWrapper c = generateCoupled();
+        add(c);
+        couple(this, this->in, c, c->in);
+        couple(c, c->out, this, this->out);
+    }
+    for (int i = 0; i < width - 1; ++i) {
+        DummyAtomic a = DummyAtomic(intDelay, extDelay, procTime);
+        add(a);
+    }
+}
+
+
+

+ 16 - 38
devstone/adevs/src/DEVSWrapper.hpp

@@ -5,47 +5,25 @@
 #ifndef DEVSTONE_ADEVS_DEVSWRAPPER_HPP
 #define DEVSTONE_ADEVS_DEVSWRAPPER_HPP
 
+#include <adevs.h>
+#include "DEVStone.hpp"
 #include "DummyAtomic.hpp"
 
-class DEVSWrapper: public adevs::Digraph<int> {
-    private:
-        int depth;
-        int width;
-        int intDelay, extDelay;  // TODO include Dhrystone stuff
-        double procTime;
 
-    
-    public:
-        /// Model input port
-        static const int in;
-        /// Model output port
-        static const int out;
-
-        DEVSWrapper(int depthIn, int widthIn, int intDelayIn, int extDelayIn, double procTimeIn): adevs::Digraph<int>() {
-            depth = depthIn;
-            width = widthIn;
-            intDelay = intDelayIn;
-            extDelay = extDelayIn;
-            procTime = procTimeIn;
-
-            if (depth == 1) {
-                DummyAtomic *a = new DummyAtomic(intDelay, extDelay, procTime);
-                add(a);
-                couple(this, this->in, a, a->in);
-                couple(a, a->out, this, this->out);
-            } else {
-                DEVSWrapper c = generateCoupled();
-                add(c);
-                couple(this, this->in, c, c->in);
-                couple(c, c->out, this, this->out);
-            }
-            for (int i = 0; i < width - 1; ++i) {
-                DummyAtomic a = DummyAtomic(intDelay, extDelay, procTime);
-                add(a);
-            }
-        }
-
-        virtual DEVSWrapper generateCoupled();
+class DEVSWrapper: public adevs::Digraph<IO_Type> {
+private:
+    int depth;
+    int width;
+    int intDelay, extDelay;
+    double procTime;
+public:
+    /// Model input port
+    static const int in;
+    /// Model output port
+    static const int out;
+    /// Constructor
+    DEVSWrapper(int depthIn, int widthIn, int intDelayIn, int extDelayIn, double procTimeIn);
+    virtual DEVSWrapper generateCoupled();
 };
 
 #endif //DEVSTONE_ADEVS_DEVSWRAPPER_HPP

+ 9 - 1
devstone/adevs/src/DEVStone.cpp

@@ -2,4 +2,12 @@
 // Created by rcardenas on 3/9/20.
 //
 
-#include "DEVSWrapper.hpp"
+
+#include "DEVStone.hpp"
+//#include "DEVSWrapper.hpp"
+#include "DummyAtomic.hpp"
+
+int main() {
+ DummyAtomic a = DummyAtomic(0, 0, 0.0);
+ return 0;
+}

+ 12 - 0
devstone/adevs/src/DEVStone.hpp

@@ -0,0 +1,12 @@
+//
+// Created by Román Cárdenas Rodríguez on 09/03/2020.
+//
+
+#ifndef DEVSTONE_ADEVS_DEVSTONE_HPP
+#define DEVSTONE_ADEVS_DEVSTONE_HPP
+
+#include <adevs.h>
+
+typedef adevs::PortValue<int*> IO_Type;  // Define the type of the messages to be sent
+
+#endif //DEVSTONE_ADEVS_DEVSTONE_HPP

+ 64 - 0
devstone/adevs/src/DummyAtomic.cpp

@@ -0,0 +1,64 @@
+//
+// Created by Román Cárdenas Rodríguez on 09/03/2020.
+//
+
+#include "DummyAtomic.hpp"
+
+const int DummyAtomic::in = 0;
+const int DummyAtomic::out = 1;
+
+DummyAtomic::DummyAtomic(int intDelayIn, int extDelayIn, double procTimeIn): adevs::Atomic<IO_Type>() {
+    intDelay = intDelayIn;
+    extDelay = extDelayIn;
+    procTime = procTimeIn;
+    sigma = DBL_MAX;
+    t = 0.0;
+}
+
+/// External transition function
+void DummyAtomic::delta_ext(double e, const adevs::Bag<IO_Type>& x) {
+    t += e;
+    if (sigma != DBL_MAX) {
+        sigma -= e;
+    }
+    // Add the new values to the back of the list.
+    adevs::Bag<IO_Type>::const_iterator i = x.begin();
+    values.push_back(new int(*((*i).value)));
+    sigma = procTime;
+}
+
+/// Internal transition function
+void DummyAtomic::delta_int() {
+    t += sigma;
+    // Done with the job, so set time of next event to infinity
+    sigma = DBL_MAX;
+    values.clear();
+}
+
+/// Confluent transition function.
+void DummyAtomic::delta_conf(const adevs::Bag<IO_Type>& x) {
+    // Discard the old job
+    delta_int();
+    // Process the incoming job
+    delta_ext(0.0, x);
+}
+
+/// Output function.
+void DummyAtomic::output_func(adevs::Bag<IO_Type >& y) {
+    // Get the departing customer
+    std::list<int*>::iterator i;
+    for (i = values.begin(); i != values.end(); i++) {
+        y.insert(IO_Type(out, *i));
+    }
+}
+
+/// Time advance function.
+double DummyAtomic::ta() {
+    return sigma;
+}
+
+/// Garbage collection. No heap allocation in output_func, so do nothing.
+void DummyAtomic::gc_output(adevs::Bag<IO_Type>&) {}
+
+/// Destructor
+DummyAtomic::~DummyAtomic() = default;

+ 17 - 52
devstone/adevs/src/DummyAtomic.hpp

@@ -5,18 +5,19 @@
 #ifndef DEVSTONE_ADEVS_DUMMYATOMIC_HPP
 #define DEVSTONE_ADEVS_DUMMYATOMIC_HPP
 
-#include <cstdlib>
 #include <adevs.h>
+#include <list>
+#include "DEVStone.hpp"
 
-typedef adevs::PortValue<int> Integer;
 
-
-class DummyAtomic: public adevs::Atomic<Integer> {
+class DummyAtomic: public adevs::Atomic<IO_Type> {
     private:
         /// Model state variables
-        int intDelay, extDelay, sigma;  // TODO include Dhrystone stuff
+        int intDelay;  // TODO include Dhrystone stuff
+        int extDelay;
+        double sigma;
         double procTime;
-        Integer *val;
+        std::list<int*> values;
         double t;
     public:
         /// Model input port
@@ -25,57 +26,21 @@ class DummyAtomic: public adevs::Atomic<Integer> {
         static const int out;
 
         /// Constructor.  The processing time is provided as an argument.
-        DummyAtomic(int intDelayIn, int extDelayIn, double procTimeIn): adevs::Atomic<Integer>() {
-            intDelay = intDelayIn;
-            extDelay = extDelayIn;
-            procTime = procTimeIn;
-            sigma = DBL_MAX;
-            val = nullptr;
-            t = 0.0;
-        }
-        /// Internal transition function
-        void delta_int() override {
-            t += sigma;
-            // Done with the job, so set time of next event to infinity
-            sigma = DBL_MAX;
-            val = nullptr;
-        }
+        DummyAtomic(int intDelayIn, int extDelayIn, double procTimeIn);
         /// External transition function
-        void delta_ext(double e, const adevs::Bag<Integer>& x) override {
-            t += e;
-            // If we are waiting for a job
-            if (sigma == DBL_MAX)
-            {
-                val = new Integer((*(x.begin())).value);
-                sigma = procTime;
-            }
-            // Otherwise, model just continues with time of next event unchanged
-            else
-            {
-                sigma -= e;
-            }
-        }
+        void delta_ext(double e, const adevs::Bag<IO_Type>& x);
+        /// Internal transition function
+        void delta_int();
         /// Confluent transition function.
-        void delta_conf(const adevs::Bag<Integer>& x) override {
-            // Discard the old job
-            delta_int();
-            // Process the incoming job
-            delta_ext(0.0,x);
-        }
+        void delta_conf(const adevs::Bag<IO_Type>& x);
         /// Output function.
-        void output_func(adevs::Bag<Integer>& y) override {
-            y.insert(val);
-        }
+        void output_func(adevs::Bag<IO_Type>& y);
         /// Time advance function.
-        double ta() override { return sigma; }
-        /**
-        Garbage collection. No heap allocation in output_func, so
-        do nothing.
-        */
-        void gc_output(adevs::Bag<Integer>&) override {}
+        double ta();
+        /// Garbage collection.
+        void gc_output(adevs::Bag<IO_Type>&);
         /// Destructor
-        ~DummyAtomic() override = default;
+        ~DummyAtomic();
 };
 
-
 #endif //DEVSTONE_ADEVS_DUMMYATOMIC_HPP