浏览代码

Simplify QSS

Eric Ramat 5 年之前
父节点
当前提交
76de9a3c4b
共有 2 个文件被更改,包括 17 次插入31 次删除
  1. 10 6
      src/tests/qss/graph_manager.hpp
  2. 7 25
      src/tests/qss/models.hpp

+ 10 - 6
src/tests/qss/graph_manager.hpp

@@ -122,9 +122,10 @@ namespace artis {
                         const artis::common::NoParameters& graph_parameters)
                         :
                         artis::pdevs::qss::GraphManager<common::DoubleTime, Predator, PreyPredatorParameters>(
-                                coordinator, parameters, graph_parameters) {
+                                coordinator, parameters, graph_parameters)
+                {
                     coordinator->input_port({IN_X, "in_x"});
-                    in({coordinator, IN_X}) >> in({derivative(), Predator::IN_X});
+                    in({coordinator, IN_X}) >> in({derivative(), derivative()->dynamics().IN_X});
                 }
 
                 ~PredatorGraphManager() override = default;
@@ -142,9 +143,10 @@ namespace artis {
                         const artis::common::NoParameters& graph_parameters)
                         :
                         artis::pdevs::qss::GraphManager<common::DoubleTime, Prey, PreyPredatorParameters>(
-                                coordinator, parameters, graph_parameters) {
+                                coordinator, parameters, graph_parameters)
+                {
                     coordinator->input_port({IN_Y, "in_y"});
-                    in({coordinator, IN_Y}) >> in({derivative(), Prey::IN_Y});
+                    in({coordinator, IN_Y}) >> in({derivative(), derivative()->dynamics().IN_Y});
                 }
 
                 ~PreyGraphManager() override = default;
@@ -173,8 +175,10 @@ namespace artis {
                 {
                     add_child(PREDATOR, &_predator);
                     add_child(PREY, &_prey);
-                    out({&_predator, PredatorGraphManager::OUT}) >> in({&_prey, PreyGraphManager::IN_Y});
-                    out({&_prey, PreyGraphManager::OUT}) >> in({&_predator, PredatorGraphManager::IN_X});
+                    out({&_predator, PredatorGraphManager::OUT})
+                            >> in({&_prey, PreyGraphManager::IN_Y});
+                    out({&_prey, PreyGraphManager::OUT})
+                            >> in({&_predator, PredatorGraphManager::IN_X});
                 }
 
                 ~PreyPredatorGraphManager() override = default;

+ 7 - 25
src/tests/qss/models.hpp

@@ -56,10 +56,6 @@ namespace artis {
             class Parabola
                     : public artis::pdevs::qss::Derivative<common::DoubleTime, Parabola, ParabolaParameters> {
             public:
-                enum states {
-                    X = LAST_OUTPUT + 1
-                };
-
                 Parabola(const std::string& name,
                         const artis::pdevs::Context<common::DoubleTime, Parabola, ParabolaParameters>& context)
                         :
@@ -67,7 +63,7 @@ namespace artis {
                                 name,
                                 context), _alpha(context.parameters().alpha)
                 {
-                    DECLARE_STATES(double, ((X, &Parabola::_x)));
+                    internal("X", &Parabola::_x);
                 }
 
                 ~Parabola() override = default;
@@ -90,13 +86,7 @@ namespace artis {
             class Predator
                     : public artis::pdevs::qss::Derivative<common::DoubleTime, Predator, PreyPredatorParameters> {
             public:
-                enum inputs {
-                    IN_X = IN + 1
-                };
-
-                enum states {
-                    Y = LAST_OUTPUT + 1, X
-                };
+                unsigned int IN_X;
 
                 Predator(const std::string& name,
                         const artis::pdevs::Context<common::DoubleTime, Predator, PreyPredatorParameters>& context)
@@ -106,9 +96,8 @@ namespace artis {
                                 context), _b(context.parameters().b), _d(context.parameters().d),
                         _e(context.parameters().e)
                 {
-                    DECLARE_STATES(double, ((X, &Predator::_x), (Y, &Predator::_y)));
-
-                    input_port({IN_X, "in_x"});
+                    internal("Y", &Predator::_y);
+                    IN_X = external("X", &Predator::_x);
                 }
 
                 ~Predator() override = default;
@@ -129,13 +118,7 @@ namespace artis {
             class Prey
                     : public artis::pdevs::qss::Derivative<common::DoubleTime, Prey, PreyPredatorParameters> {
             public:
-                enum inputs {
-                    IN_Y = IN + 1
-                };
-
-                enum states {
-                    X = LAST_OUTPUT + 1, Y
-                };
+                unsigned int IN_Y;
 
                 Prey(const std::string& name,
                         const artis::pdevs::Context<common::DoubleTime, Prey, PreyPredatorParameters>& context)
@@ -144,9 +127,8 @@ namespace artis {
                                 name,
                                 context), _a(context.parameters().a), _b(context.parameters().b)
                 {
-                    DECLARE_STATES(double, ((X, &Prey::_x), (Y, &Prey::_y)));
-
-                    input_port({IN_Y, "in_y"});
+                    internal("X", &Prey::_x);
+                    IN_Y = external("Y", &Prey::_y);
                 }
 
                 ~Prey() override = default;