Binary Counter

Code explanation
Model's attributs

As the model Generator,mDuration is a parameter that will allow us to store the time step between the reception of an event and its replication. mSigma will allow us to calculate the remaining time between each event received to continue to replicate the first entry received. . And mLastTime used to store the date of the last event. mCounter will serve to retrieve the entry and it will allow us to see if is an 1 or not. ''mCounter will be equal to 1 if two 1 were recovred during the periode of time.

Constructor / Destructor

There are exactly the same as for the model Generator, the constructor retrieves the duration parameter, and the destructor is empty but obligatory.

Init

We init the attribute mSigma at parameter duration, mLastime at the start. At the begining of the simulation, we wait an input so we init mState to PASSIVE. We init mCounter and mCounter2 to 0. Finaly, we return infinity to wait indefinitely until a reception of an entry.

Output

If mCounter is equal to 1, it's because we retrieve two 1 in entry during the period of time, so we can return an 1, else we return nothing.

TimeAdvance (Ta)

If we have'nt recieved anything, we're just waiting the time given with the parameter mduration. If we already have recieved a 1, we only wait the remaning time before the end of the duration given by the user with mDuration

InternalTransition

The internalTransition happens every time step given in parameter. It attributes the value time to mLastTime, that will allow us the possibility to update mSigma if is an externalTransition. It then resets mSigma with the parameter mduration, sets back mState to PASSIVE and reset mCounter and mCounter2 to 0. L'internalTransition a lieu à chaque laps de temps donné en paramètre. Elle attribut la valeur time à mLastTime ce qui va ensuite nous offrir la possibilité de mettre à jour mSigma si c'est une externalTransition. Il réinitialise ensuite sigma avec le paramètre mduration défini par l'utilisateur et repasse mState à PASSIVE et réinitialise mCounter et mCounter2 à 0.

ExternalTransition

If we have'nt yet received a 1, we're in the state PASSIVE. Once we receive something, we check if is a one and if so we go in the ACTIVE state. If we recieve or not a 1, we uptade mSigma and mlastTime

if we already received a 1 we're in the state ACTIVE. So we look if we receive an other one and if so we set mCounter to 1. Here again, if we receive an 1 or not, we update mSigma and mLastTime.