瀏覽代碼

Added Seeder to aDEVS

Roman Cardenas 5 年之前
父節點
當前提交
82e80fa352

+ 2 - 0
.gitignore

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

+ 9 - 1
devstone/adevs/CMakeLists.txt

@@ -7,6 +7,14 @@ add_compile_options(-g)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../simulators/adevs/include)
 include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 
+find_package(Boost COMPONENTS program_options thread unit_test_framework REQUIRED)
+
+include_directories(${Boost_INCLUDE_DIRS})
+
+
 set(CMAKE_CXX_STANDARD 17)
 
-add_executable(DEVStone src/DEVStone.cpp src/DummyAtomic.cpp src/DEVSWrapper.cpp src/li.cpp src/hoMod.cpp src/hi.cpp src/hi.hpp src/ho.cpp src/ho.hpp)
+add_executable(DEVStone src/DEVStone.cpp src/DummyAtomic.cpp src/DEVSWrapper.cpp
+        src/li.cpp src/hoMod.cpp src/hi.cpp src/hi.hpp src/ho.cpp src/seeder.cpp)
+
+target_link_libraries(DEVStone ${Boost_PROGRAM_OPTIONS_LIBRARY})

+ 1 - 2
devstone/adevs/src/DEVSWrapper.hpp

@@ -5,8 +5,7 @@
 #ifndef DEVSTONE_ADEVS_DEVSWRAPPER_HPP
 #define DEVSTONE_ADEVS_DEVSWRAPPER_HPP
 
-#include <adevs.h>
-#include "DEVStone.hpp"
+#include "utils.hpp"
 #include "DummyAtomic.hpp"
 #include <vector>
 

+ 46 - 3
devstone/adevs/src/DEVStone.cpp

@@ -2,11 +2,54 @@
 // Created by rcardenas on 3/9/20.
 //
 
-
 #include "DEVStone.hpp"
-#include "li.hpp"
 
-int main() {
+
+int main(int argc, char* argv[]) {
+    auto start = hclock::now();
+
+    // Declare the supported options.
+    po::options_description desc("Allowed options");
+    desc.add_options()
+            ("help", "produce help message")
+            ("kind", po::value<string>()->required(), "set kind of devstone: LI, HI or HO")
+            ("width", po::value<int>()->required(), "set width of the DEVStone: integer value")
+            ("depth", po::value<int>()->required(), "set depth of the DEVStone: integer value")
+            ("int-cycles", po::value<int>()->required(), "set the Dhrystone cycles to expend in internal transtions: integer value")
+            ("ext-cycles", po::value<int>()->required(), "set the Dhrystone cycles to expend in external transtions: integer value")
+            ("time-advance", po::value<int>()->default_value(1), "set the time expend in external transtions by the Dhrystone in miliseconds: integer value")
+            ;
+
+    po::variables_map vm;
+    try {
+        po::store(po::parse_command_line(argc, argv, desc), vm);
+        po::notify(vm);
+    } catch ( boost::program_options::required_option be ){
+        if (vm.count("help")) {
+            cout << desc << "\n";
+            return 0;
+        } else {
+            cout << be.what() << endl;
+            cout << endl;
+            cout << "for mode information run: " << argv[0] << " --help" << endl;
+            return 1;
+        }
+    }
+    string kind = vm["kind"].as<string>();
+    if (kind != "LI"  && kind != "HI" && kind != "HO") {
+        cout << "The kind needs to be LI, HI or HO and received value was: " << kind;
+        cout << endl;
+        cout << "for mode information run: " << argv[0] << " --help" << endl;
+        return 1;
+    }
+
+    int width = vm["width"].as<int>();
+    int depth = vm["depth"].as<int>();
+    int int_cycles = vm["int-cycles"].as<int>();
+    int ext_cycles = vm["ext-cycles"].as<int>();
+    int time_advance = vm["time-advance"].as<int>();
+
+
     LI c = LI(2, 1, 0, 0, 0.0);
  return 0;
 }

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

@@ -5,8 +5,18 @@
 #ifndef DEVSTONE_ADEVS_DEVSTONE_HPP
 #define DEVSTONE_ADEVS_DEVSTONE_HPP
 
-#include <adevs.h>
+#include <boost/program_options.hpp>
+#include <iostream>
+#include <chrono>
 
-typedef adevs::PortValue<int*> IO_Type;  // Define the type of the messages to be sent
+#include "utils.hpp"
+#include "li.hpp"
+#include "hi.hpp"
+#include "ho.hpp"
+#include "hoMod.hpp"
+
+using namespace std;
+namespace po=boost::program_options;
+using hclock=chrono::high_resolution_clock;
 
 #endif //DEVSTONE_ADEVS_DEVSTONE_HPP

+ 1 - 1
devstone/adevs/src/DummyAtomic.hpp

@@ -7,7 +7,7 @@
 
 #include <adevs.h>
 #include <list>
-#include "DEVStone.hpp"
+#include "utils.hpp"
 
 
 class DummyAtomic: public adevs::Atomic<IO_Type> {

+ 2 - 4
devstone/adevs/src/hi.hpp

@@ -5,12 +5,10 @@
 #ifndef DEVSTONE_ADEVS_HI_HPP
 #define DEVSTONE_ADEVS_HI_HPP
 
-#include <adevs.h>
-#include "DEVStone.hpp"
+#include "utils.hpp"
 #include "DEVSWrapper.hpp"
 
-class HI: public DEVSWrapper
-{
+class HI: public DEVSWrapper {
 public:
     HI(int depthIn, int widthIn, int intDelayIn, int extDelayIn, double procTimeIn);
 };

+ 1 - 2
devstone/adevs/src/hoMod.hpp

@@ -5,8 +5,7 @@
 #ifndef DEVSTONE_ADEVS_HOMOD_HPP
 #define DEVSTONE_ADEVS_HOMOD_HPP
 
-#include <adevs.h>
-#include "DEVStone.hpp"
+#include "utils.hpp"
 #include "DummyAtomic.hpp"
 
 

+ 2 - 4
devstone/adevs/src/li.hpp

@@ -5,12 +5,10 @@
 #ifndef DEVSTONE_ADEVS_LI_HPP
 #define DEVSTONE_ADEVS_LI_HPP
 
-#include <adevs.h>
-#include "DEVStone.hpp"
+#include "utils.hpp"
 #include "DEVSWrapper.hpp"
 
-class LI: public DEVSWrapper
-{
+class LI: public DEVSWrapper {
 public:
     LI(int depthIn, int widthIn, int intDelayIn, int extDelayIn, double procTimeIn);
 };

+ 49 - 0
devstone/adevs/src/seeder.cpp

@@ -0,0 +1,49 @@
+//
+// Created by rcardenas on 3/13/20.
+//
+
+#include "seeder.hpp"
+
+const int Seeder::out = 0;
+
+Seeder::Seeder(int nMessagesIn): adevs::Atomic<IO_Type>() {
+    nMessages = nMessagesIn;
+    sigma = DBL_MAX;
+    t = 0.0;
+}
+
+/// External transition function
+void Seeder::delta_ext(double e, const adevs::Bag<IO_Type>& x) { }
+
+/// Internal transition function
+void Seeder::delta_int() {
+    t += sigma;
+    sigma = DBL_MAX;
+}
+
+/// Confluent transition function.
+void Seeder::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 Seeder::output_func(adevs::Bag<IO_Type >& y) {
+    // Get the departing customer
+    for (int i = 0; i < nMessages; i++) {
+        y.insert(IO_Type(out, 0));
+    }
+}
+
+/// Time advance function.
+double Seeder::ta() {
+    return sigma;
+}
+
+/// Garbage collection. No heap allocation in output_func, so do nothing.
+void Seeder::gc_output(adevs::Bag<IO_Type>&) {}
+
+/// Destructor
+Seeder::~Seeder() = default;

+ 41 - 0
devstone/adevs/src/seeder.hpp

@@ -0,0 +1,41 @@
+//
+// Created by rcardenas on 3/13/20.
+//
+
+#ifndef DEVSTONE_ADEVS_SEEDER_HPP
+#define DEVSTONE_ADEVS_SEEDER_HPP
+
+#include <adevs.h>
+#include <list>
+#include "utils.hpp"
+
+
+class Seeder: public adevs::Atomic<IO_Type> {
+private:
+    /// Model state variables
+    double sigma;
+    int nMessages;
+    double t;
+public:
+    /// Model output port
+    static const int out;
+
+    /// Constructor.  The processing time is provided as an argument.
+    Seeder(int nMessagesIn);
+    /// External transition function
+    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<IO_Type>& x);
+    /// Output function.
+    void output_func(adevs::Bag<IO_Type>& y);
+    /// Time advance function.
+    double ta();
+    /// Garbage collection.
+    void gc_output(adevs::Bag<IO_Type>&);
+    /// Destructor
+    ~Seeder();
+};
+
+#endif //DEVSTONE_ADEVS_SEEDER_HPP

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

@@ -0,0 +1,12 @@
+//
+// Created by rcardenas on 3/13/20.
+//
+
+#ifndef DEVSTONE_ADEVS_UTILS_HPP
+#define DEVSTONE_ADEVS_UTILS_HPP
+
+#include <adevs.h>
+
+typedef adevs::PortValue<int*> IO_Type;  // Define the type of the messages to be sent
+
+#endif //DEVSTONE_ADEVS_UTILS_HPP

+ 1 - 1
devstone/cadmium/src/cadmium-dynamic-devstone.cpp

@@ -118,7 +118,7 @@ int main(int argc, char* argv[]){
 
     auto runner_init = hclock::now();
 
-    std::cout << "Runner setup time: " << std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>(runner_init - model_init).count() << " seconds" << std::endl;
+    std::cout << "Engine setup time: " << std::chrono::duration_cast<std::chrono::duration<double, std::ratio<1>>>(runner_init - model_init).count() << " seconds" << std::endl;
 
     r.run_until(1000000);
 

+ 2 - 2
devstone_comparative.py

@@ -20,8 +20,8 @@ XDEVS_JAVA_PARALLEL_CMD = "java -classpath simulators/xdevs-java/out/ xdevs.core
 XDEVS_JAVA_PARALLEL_CHAINED_CMD = "java -classpath simulators/xdevs-java/out/ xdevs.core.devstone.DEVStone {model_type} {depth} {width} {int_cycles} {ext_cycles} chainedparallel false"
 PYPDEVS_CMD = "python3 devstone/pythonpdevs/main.py -m {model_type} -d {depth} -w {width} -i {int_cycles} -e {ext_cycles}"
 PYPDEVS_MIN_CMD = ""
-CADMIUM_CMD = "devstone/cadmium/build/cadmium-dynamic-devstone --kind={model_type} --depth={depth} --width={width} --int-cycles={int_cycles} --ext-cycles={ext_cycles} --event-list=events_devstone.txt"
-CADMIUM_CONC_CMD = "devstone/cadmium/build/cadmium-dynamic-conc-devstone --kind={model_type} --depth={depth} --width={width} --int-cycles={int_cycles} --ext-cycles={ext_cycles} --event-list=events_devstone.txt --threads=" + str(threads)
+CADMIUM_CMD = "devstone/cadmium/build/cadmium-dynamic-devstone --kind={model_type} --depth={depth} --width={width} --int-cycles={int_cycles} --ext-cycles={ext_cycles}"
+CADMIUM_CONC_CMD = "devstone/cadmium/build/cadmium-dynamic-conc-devstone --kind={model_type} --depth={depth} --width={width} --int-cycles={int_cycles} --ext-cycles={ext_cycles} --threads=" + str(threads)
 CDBOOST_CMD = "devstone/cdboost/build/cdboost-devstone --kind={model_type} --depth={depth} --width={width} --int-cycles={int_cycles} --ext-cycles={ext_cycles} --event-list=events_devstone.txt"
 ADEVS_CMD = "devstone/adevs/build/DEVStone"  # TODO