Просмотр исходного кода

Added all submodules. Working with aDEVS

Roman Cardenas 6 лет назад
Родитель
Сommit
9edc500fd3

+ 2 - 0
.gitignore

@@ -1,2 +1,4 @@
 .idea/
 .log
+
+cmake-build-debug/

+ 12 - 0
devstone/adevs/CMakeLists.txt

@@ -0,0 +1,12 @@
+cmake_minimum_required(VERSION 3.15)
+set (CMAKE_CXX_STANDARD 17)
+set (CMAKE_CXX_COMPILER "g++")
+project(devstone-adevs)
+add_compile_options(-g)
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../simulators/adevs/include)
+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+set(CMAKE_CXX_STANDARD 17)
+
+add_executable(DEVStone src/DEVStone.cpp)

+ 6 - 0
devstone/adevs/main.cpp

@@ -0,0 +1,6 @@
+#include <iostream>
+
+int main() {
+    std::cout << "Hello, World!" << std::endl;
+    return 0;
+}

+ 51 - 0
devstone/adevs/src/DEVSWrapper.hpp

@@ -0,0 +1,51 @@
+//
+// Created by rcardenas on 3/9/20.
+//
+
+#ifndef DEVSTONE_ADEVS_DEVSWRAPPER_HPP
+#define DEVSTONE_ADEVS_DEVSWRAPPER_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();
+};
+
+#endif //DEVSTONE_ADEVS_DEVSWRAPPER_HPP

+ 5 - 0
devstone/adevs/src/DEVStone.cpp

@@ -0,0 +1,5 @@
+//
+// Created by rcardenas on 3/9/20.
+//
+
+#include "DEVSWrapper.hpp"

+ 81 - 0
devstone/adevs/src/DummyAtomic.hpp

@@ -0,0 +1,81 @@
+//
+// Created by rcardenas on 3/9/20.
+//
+
+#ifndef DEVSTONE_ADEVS_DUMMYATOMIC_HPP
+#define DEVSTONE_ADEVS_DUMMYATOMIC_HPP
+
+#include <cstdlib>
+#include <adevs.h>
+
+typedef adevs::PortValue<int> Integer;
+
+
+class DummyAtomic: public adevs::Atomic<Integer> {
+    private:
+        /// Model state variables
+        int intDelay, extDelay, sigma;  // TODO include Dhrystone stuff
+        double procTime;
+        Integer *val;
+        double t;
+    public:
+        /// Model input port
+        static const int in;
+        /// Model output port
+        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;
+        }
+        /// 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;
+            }
+        }
+        /// 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);
+        }
+        /// Output function.
+        void output_func(adevs::Bag<Integer>& y) override {
+            y.insert(val);
+        }
+        /// 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 {}
+        /// Destructor
+        ~DummyAtomic() override = default;
+};
+
+
+#endif //DEVSTONE_ADEVS_DUMMYATOMIC_HPP