|
@@ -41,7 +41,8 @@ namespace artis {
|
|
std::map<std::string, bool> initial_states;
|
|
std::map<std::string, bool> initial_states;
|
|
};
|
|
};
|
|
|
|
|
|
- class Cell : public artis::pdevs::Dynamics<common::DoubleTime, Cell, CellParameters> {
|
|
|
|
|
|
+ class Cell
|
|
|
|
+ : public artis::pdevs::Dynamics<common::DoubleTime, Cell, CellParameters> {
|
|
public:
|
|
public:
|
|
enum inputs {
|
|
enum inputs {
|
|
IN
|
|
IN
|
|
@@ -56,8 +57,10 @@ namespace artis {
|
|
Cell(const std::string& name,
|
|
Cell(const std::string& name,
|
|
const artis::pdevs::Context<common::DoubleTime, Cell, CellParameters>& context)
|
|
const artis::pdevs::Context<common::DoubleTime, Cell, CellParameters>& context)
|
|
:
|
|
:
|
|
- artis::pdevs::Dynamics<common::DoubleTime, Cell, CellParameters>(name, context),
|
|
|
|
- _neighbour_number(context.parameters().neighbour_numbers.find(name)->second),
|
|
|
|
|
|
+ artis::pdevs::Dynamics<common::DoubleTime, Cell, CellParameters>(name,
|
|
|
|
+ context),
|
|
|
|
+ _neighbour_number(
|
|
|
|
+ context.parameters().neighbour_numbers.find(name)->second),
|
|
_initial_state(context.parameters().initial_states.find(name)->second)
|
|
_initial_state(context.parameters().initial_states.find(name)->second)
|
|
{
|
|
{
|
|
input_ports({{IN, "in"}});
|
|
input_ports({{IN, "in"}});
|
|
@@ -72,8 +75,9 @@ namespace artis {
|
|
if (_phase == SEND) {
|
|
if (_phase == SEND) {
|
|
_phase = WAIT;
|
|
_phase = WAIT;
|
|
_sigma = common::DoubleTime::infinity;
|
|
_sigma = common::DoubleTime::infinity;
|
|
- } else if (_phase == NEWSTATE) {
|
|
|
|
- if (_state and (_true_neighbour_number < 2 or _true_neighbour_number > 3)) {
|
|
|
|
|
|
+ } else if (_phase == NEW_STATE) {
|
|
|
|
+ if (_state and (_true_neighbour_number < 2
|
|
|
|
+ or _true_neighbour_number > 3)) {
|
|
_state = false;
|
|
_state = false;
|
|
} else if (not _state and (_true_neighbour_number == 3)) {
|
|
} else if (not _state and (_true_neighbour_number == 3)) {
|
|
_state = true;
|
|
_state = true;
|
|
@@ -85,7 +89,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>& bag) override
|
|
const common::Bag<common::DoubleTime>& bag) override
|
|
{
|
|
{
|
|
std::for_each(bag.begin(), bag.end(),
|
|
std::for_each(bag.begin(), bag.end(),
|
|
@@ -101,7 +106,7 @@ namespace artis {
|
|
}
|
|
}
|
|
});
|
|
});
|
|
if (_received == _neighbour_number) {
|
|
if (_received == _neighbour_number) {
|
|
- _phase = NEWSTATE;
|
|
|
|
|
|
+ _phase = NEW_STATE;
|
|
_sigma = 0;
|
|
_sigma = 0;
|
|
} else {
|
|
} else {
|
|
_phase = WAIT;
|
|
_phase = WAIT;
|
|
@@ -109,7 +114,8 @@ namespace artis {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- 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>& bag) override
|
|
const common::Bag<common::DoubleTime>& bag) override
|
|
{
|
|
{
|
|
dext(t, e, bag);
|
|
dext(t, e, bag);
|
|
@@ -126,22 +132,26 @@ namespace artis {
|
|
_received = 0;
|
|
_received = 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
|
|
{
|
|
{
|
|
return _sigma;
|
|
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> bag;
|
|
common::Bag<common::DoubleTime> bag;
|
|
|
|
|
|
if (_phase == SEND) {
|
|
if (_phase == SEND) {
|
|
- bag.push_back(artis::common::ExternalEvent<common::DoubleTime>(OUT, _state));
|
|
|
|
|
|
+ bag.push_back(
|
|
|
|
+ artis::common::ExternalEvent<common::DoubleTime>(OUT, _state));
|
|
}
|
|
}
|
|
return bag;
|
|
return bag;
|
|
}
|
|
}
|
|
|
|
|
|
- common::Value observe(const common::DoubleTime::type& /* t */, unsigned int index) const override
|
|
|
|
|
|
+ common::Value observe(const common::DoubleTime::type& /* t */,
|
|
|
|
+ unsigned int index) const override
|
|
{
|
|
{
|
|
if (index == STATE) {
|
|
if (index == STATE) {
|
|
return _state;
|
|
return _state;
|
|
@@ -151,7 +161,7 @@ namespace artis {
|
|
|
|
|
|
private:
|
|
private:
|
|
enum Phase {
|
|
enum Phase {
|
|
- SEND, WAIT, NEWSTATE
|
|
|
|
|
|
+ SEND, WAIT, NEW_STATE
|
|
};
|
|
};
|
|
|
|
|
|
// parameters
|
|
// parameters
|