net.simplace.sim.components.util.SimpleCounter

Provides a resettable counter of simulation days.

Counting

Counter is incremented, if the input variable iDoCount is true.

Resetting the counter

If iReset is true, the counter is reset before an potential increment.

Customization

Increment and start value are customizable. Default increment is 1, start value is 0.

Cyclic counting

If cMin and cMax are set and cMax is bigger than cMin, then the counter counts cyclic (like a clock). The value of Counter will always be shifted between cMix and cMax (both inclusive).

If the Counter equals the (possibly shifted) cStartValue, a cycle is completed and the CycleNumber is incremented.

Examples

Example 1

For cStartValue=1, cIncrement=1, cMin=1, cMax=10 the counter will start with 1 and give following sequence:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, ...

Example 2 - Countdown

For cStartValue=3, cIncrement=-1, cMin=0, cMax=10 the counter will start with 1 and give following sequence:

3, 2, 1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 10, 9 ...

Example 2 - Clock

For cStartValue=18, cIncrement=5, cMin=1, cMax=12 the counter will start with 6 and give following sequence:

6, 11, 4, 9, 2, 7, 12, 5, 10, 3, 8, 1, 6, 11, 4, ...

(18 corresponds to 6 p.m., five hours later it will be 11 p.m, another five hours later 4 a.m. etc.)

Component Variables

Content TypeNameDescriptionData TypeUnitMin ValueMax ValueDefault Value
constantcIncrementincrement of counterINT--1
constantcMaxmaximal value of the counter of a cyclic counterINT---
constantcMinminimal value of the counter of a cyclic counterINT---
constantcStartValuestart value of counterINT--0
inputiDoCountcounter is incremented if trueBOOLEAN--false
inputiResetresets the counter to its start value if trueBOOLEAN--false
outCounteractual value of the counterINT--1
outCycleNumbernumber of cycles when counting between cMin and cMaxINT--0
outNumberOfResetsnumber of resetsINT--0
outTotalCounttotal count starting from 0 and incremented by 1INT--0



public class SimpleCounter extends net.simplace.sim.model.FWSimComponent {
// Public Constructors
public SimpleCounter();


// Public Instance Methods
public HashMap createVariables(); // Defines
net.simplace.sim.model.FWSimComponent


Create the FWSimVariables as interface for this SimComponent

// Protected Instance Methods
protected void init(); // Defines net.simplace.sim.model.FWSimComponent

Initializes the fields by getting input and output FWSimVariables from VarMap
protected void process(); // Defines net.simplace.sim.model.FWSimComponent

Process the algorithm and write the results back to VarMap
protected Integer cyclic(Integer value, Integer min, Integer max);

protected FWSimComponent clone(FWSimVarMap aVarMap);
// Defines net.simplace.sim.model.FWSimComponent


creates a clone from this SimComponent for use in other threads


}



Hierarchy: java.lang.Object - net.simplace.sim.model.FWSimComponent (net.simplace.sim.util.FWSimFieldContainer) - SimpleCounter