|
@@ -33,6 +33,7 @@
|
|
|
#include <artis-star/kernel/pdevs/Dynamics.hpp>
|
|
|
|
|
|
#include <chrono>
|
|
|
+#include <iostream>
|
|
|
|
|
|
#define DELAY 100
|
|
|
|
|
@@ -80,7 +81,8 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::DELTA_INT);
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::DELTA_INT);
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
@@ -93,7 +95,8 @@ namespace artis {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void dext(typename common::DoubleTime::type t, typename common::DoubleTime::type /* e */,
|
|
|
+ void
|
|
|
+ dext(typename common::DoubleTime::type t, typename common::DoubleTime::type /* e */,
|
|
|
const common::Bag<common::DoubleTime>& msgs) override
|
|
|
{
|
|
|
|
|
@@ -104,7 +107,8 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::DELTA_EXT)
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::DELTA_EXT)
|
|
|
<< "messages = " << msgs.to_string();
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
@@ -112,7 +116,8 @@ namespace artis {
|
|
|
_phase = SEND;
|
|
|
}
|
|
|
|
|
|
- void dconf(typename common::DoubleTime::type t, typename common::DoubleTime::type /* e */,
|
|
|
+ void dconf(typename common::DoubleTime::type t,
|
|
|
+ typename common::DoubleTime::type /* e */,
|
|
|
const common::Bag<common::DoubleTime>& msgs) override
|
|
|
{
|
|
|
|
|
@@ -123,14 +128,16 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::DELTA_CONF)
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::DELTA_CONF)
|
|
|
<< "messages = " << msgs.to_string();
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
- typename common::DoubleTime::type start(typename common::DoubleTime::type t) override
|
|
|
+ typename common::DoubleTime::type
|
|
|
+ start(typename common::DoubleTime::type t) override
|
|
|
{
|
|
|
|
|
|
#ifndef WITH_TRACE
|
|
@@ -139,7 +146,8 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::START);
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::START);
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
@@ -147,7 +155,8 @@ namespace artis {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
- typename common::DoubleTime::type ta(typename common::DoubleTime::type t) const override
|
|
|
+ typename common::DoubleTime::type
|
|
|
+ ta(typename common::DoubleTime::type t) const override
|
|
|
{
|
|
|
|
|
|
#ifndef WITH_TRACE
|
|
@@ -167,7 +176,8 @@ namespace artis {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- common::Bag<common::DoubleTime> lambda(typename common::DoubleTime::type t) const override
|
|
|
+ common::Bag<common::DoubleTime>
|
|
|
+ lambda(typename common::DoubleTime::type t) const override
|
|
|
{
|
|
|
#ifndef WITH_TRACE
|
|
|
(void)t;
|
|
@@ -175,12 +185,14 @@ namespace artis {
|
|
|
common::Bag<common::DoubleTime> msgs;
|
|
|
|
|
|
if (_phase == SEND) {
|
|
|
- msgs.push_back(artis::common::ExternalEvent<common::DoubleTime>(OUT, _value));
|
|
|
+ msgs.push_back(
|
|
|
+ artis::common::ExternalEvent<common::DoubleTime>(OUT, _value));
|
|
|
}
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::LAMBDA)
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::LAMBDA)
|
|
|
<< "messages = " << msgs.to_string();
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
@@ -227,7 +239,8 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::DELTA_INT);
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::DELTA_INT);
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
@@ -236,7 +249,8 @@ namespace artis {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void dext(typename common::DoubleTime::type t, typename common::DoubleTime::type /* e */,
|
|
|
+ void
|
|
|
+ dext(typename common::DoubleTime::type t, typename common::DoubleTime::type /* e */,
|
|
|
const common::Bag<common::DoubleTime>& msgs) override
|
|
|
{
|
|
|
|
|
@@ -247,7 +261,8 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::DELTA_EXT)
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::DELTA_EXT)
|
|
|
<< "messages = " << msgs.to_string();
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
@@ -269,14 +284,16 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::DELTA_CONF)
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::DELTA_CONF)
|
|
|
<< "messages = " << msgs.to_string();
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
|
}
|
|
|
|
|
|
- typename common::DoubleTime::type start(typename common::DoubleTime::type t) override
|
|
|
+ typename common::DoubleTime::type
|
|
|
+ start(typename common::DoubleTime::type t) override
|
|
|
{
|
|
|
|
|
|
#ifndef WITH_TRACE
|
|
@@ -285,7 +302,8 @@ namespace artis {
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::START);
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::START);
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
|
|
|
@@ -323,12 +341,14 @@ namespace artis {
|
|
|
common::Bag<common::DoubleTime> msgs;
|
|
|
|
|
|
if (_phase == SEND) {
|
|
|
- msgs.push_back(artis::common::ExternalEvent<common::DoubleTime>(OUT, _value));
|
|
|
+ msgs.push_back(
|
|
|
+ artis::common::ExternalEvent<common::DoubleTime>(OUT, _value));
|
|
|
}
|
|
|
|
|
|
#ifdef WITH_TRACE
|
|
|
common::Trace<common::DoubleTime>::trace()
|
|
|
- << common::TraceElement<common::DoubleTime>(get_name(), t, common::LAMBDA)
|
|
|
+ << common::TraceElement<common::DoubleTime>(get_name(), t,
|
|
|
+ common::LAMBDA)
|
|
|
<< "messages = " << msgs.to_string();
|
|
|
common::Trace<common::DoubleTime>::trace().flush();
|
|
|
#endif
|
|
@@ -364,14 +384,16 @@ namespace artis {
|
|
|
_last_time = t;
|
|
|
}
|
|
|
|
|
|
- typename common::DoubleTime::type start(typename common::DoubleTime::type t) override
|
|
|
+ typename common::DoubleTime::type
|
|
|
+ start(typename common::DoubleTime::type t) override
|
|
|
{
|
|
|
_phase = S1;
|
|
|
_last_time = t;
|
|
|
return ta(t);
|
|
|
}
|
|
|
|
|
|
- typename common::DoubleTime::type ta(typename common::DoubleTime::type /* t */) const override
|
|
|
+ typename common::DoubleTime::type
|
|
|
+ ta(typename common::DoubleTime::type /* t */) const override
|
|
|
{
|
|
|
if (_phase == S1) {
|
|
|
return 5;
|
|
@@ -380,7 +402,8 @@ namespace artis {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- common::Bag<common::DoubleTime> lambda(typename common::DoubleTime::type t) const override
|
|
|
+ common::Bag<common::DoubleTime>
|
|
|
+ lambda(typename common::DoubleTime::type t) const override
|
|
|
{
|
|
|
|
|
|
std::cout << (t - _last_time) << std::endl;
|
|
@@ -397,17 +420,29 @@ namespace artis {
|
|
|
typename common::DoubleTime::type _last_time;
|
|
|
};
|
|
|
|
|
|
- class ThreeStateModel : public artis::pdevs::Dynamics<common::DoubleTime, ThreeStateModel> {
|
|
|
+ class ThreeStateModel
|
|
|
+ : public artis::pdevs::Dynamics<common::DoubleTime, ThreeStateModel> {
|
|
|
public:
|
|
|
enum outputs {
|
|
|
OUT
|
|
|
};
|
|
|
|
|
|
+ enum states {
|
|
|
+ HEIGHTS, SPEEDS, SCALES, N, INDEX, SIGMA, LAST_TIME
|
|
|
+ };
|
|
|
+
|
|
|
ThreeStateModel(const std::string& name,
|
|
|
const artis::pdevs::Context<common::DoubleTime, ThreeStateModel, artis::common::NoParameters>& context)
|
|
|
:
|
|
|
artis::pdevs::Dynamics<common::DoubleTime, ThreeStateModel>(name, context)
|
|
|
{
|
|
|
+ States(std::vector<double>,
|
|
|
+ ((HEIGHTS, &ThreeStateModel::heights), (SPEEDS, &ThreeStateModel::speeds), (SCALES, &ThreeStateModel::scales)));
|
|
|
+ States(unsigned int,
|
|
|
+ ((N, &ThreeStateModel::n), (INDEX, &ThreeStateModel::index)));
|
|
|
+ States(typename common::DoubleTime::type,
|
|
|
+ ((SIGMA, &ThreeStateModel::sigma), (LAST_TIME, &ThreeStateModel::_last_time)));
|
|
|
+
|
|
|
output_ports({{OUT, "out"}});
|
|
|
}
|
|
|
|
|
@@ -424,7 +459,9 @@ namespace artis {
|
|
|
typename common::DoubleTime::type /* e */,
|
|
|
const common::Bag<common::DoubleTime>& msgs) override
|
|
|
{
|
|
|
- for (common::Bag<common::DoubleTime>::const_iterator it = msgs.begin(); it != msgs.end(); ++it) {
|
|
|
+ for (common::Bag<common::DoubleTime>::const_iterator it = msgs.begin();
|
|
|
+ it != msgs.end();
|
|
|
+ ++it) {
|
|
|
++n;
|
|
|
}
|
|
|
if (sigma == 1) {
|
|
@@ -456,7 +493,8 @@ namespace artis {
|
|
|
compute();
|
|
|
}
|
|
|
|
|
|
- typename common::DoubleTime::type start(typename common::DoubleTime::type t) override
|
|
|
+ typename common::DoubleTime::type
|
|
|
+ start(typename common::DoubleTime::type t) override
|
|
|
{
|
|
|
heights = {0, 0, 0, 0, 0};
|
|
|
speeds = {0.21, 0.3, 0.7, 0.56, 0.14};
|
|
@@ -471,7 +509,8 @@ namespace artis {
|
|
|
typename common::DoubleTime::type
|
|
|
ta(typename common::DoubleTime::type /* t */) const override { return sigma; }
|
|
|
|
|
|
- common::Bag<common::DoubleTime> lambda(typename common::DoubleTime::type /* t */) const override
|
|
|
+ common::Bag<common::DoubleTime>
|
|
|
+ lambda(typename common::DoubleTime::type /* t */) const override
|
|
|
{
|
|
|
common::Bag<common::DoubleTime> msgs;
|
|
|
|
|
@@ -560,13 +599,13 @@ namespace artis {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // state
|
|
|
std::vector<double> heights;
|
|
|
std::vector<double> speeds;
|
|
|
std::vector<double> scales;
|
|
|
unsigned int index;
|
|
|
unsigned int n;
|
|
|
typename common::DoubleTime::type sigma;
|
|
|
-
|
|
|
typename common::DoubleTime::type _last_time;
|
|
|
};
|
|
|
|