Module Simula

Class RTS_Simulation

All Implemented Interfaces:
Runnable

public class RTS_Simulation extends RTS_Simset
System class Simulation.

The system class "simulation" may be considered an "application package" oriented towards simulation problems. It has the class "simset" as prefix, and set-handling facilities are thus immediately available.

The concepts defined in "simulation" are explained with respect to a prefixed block, whose prefix part is an instance of the body of "simulation" or of a subclass. The prefixed block instance acts as the head of a quasi-parallel system which may represent a "discrete event" simulation model.

 simset class simulation;
        begin  ref (head) SQS;
      link class EVENT_NOTICE (EVTIME, PROC);
                     long real EVTIME; ref (process) PROC;
           begin
              ref (EVENT_NOTICE) procedure suc;
                 suc:- if SUC is EVENT_NOTICE then SUC else none;

              ref (EVENT_NOTICE) procedure pred;   pred:- PRED;

              procedure RANK_IN_SQS (afore); Boolean afore;
              begin ref (EVENT_NOTICE) evt;
                 evt:- SQS.last;
                 while evt.EVTIME > EVTIME do    evt :- evt.pred;
                 if afore then
                    while evt.EVTIME = EVTIME do evt :- evt.pred;
                 follow(evt)
              end RANK_IN_SQS;
           end EVENT_NOTICE;

           ref (MAIN_PROGRAM) main;

           ref (EVENT_NOTICE) procedure FIRSTEV;  FIRSTEV :- SQS.first;
           ref (process) procedure current; current :- FIRSTEV.PROC;
           long real procedure time; time := FIRSTEV.EVTIME;

      link class process;  .................... 12.1;
           procedure ACTIVAT .................. 12.3;
           procedure hold ..................... 12.4;
           procedure passivate ................ 12.4;
           procedure wait ..................... 12.4;
           procedure cancel ................... 12.4;
   process class MAIN_PROGRAM ................. 12.5;
           procedure accum .................... 12.6;

           SQS        :- new head;
           main       :- new MAIN_PROGRAM;
           main.EVENT :- new EVENT_NOTICE(0,main);
           main.EVENT.into(SQS)
        end simulation;
 
When used as a prefix to a block or a class, "simulation" introduces simulation-oriented features through the class "process" and associated procedures.

The variable SQS refers to a set which is called the "sequencing set", and serves to represent the system time axis. The members of the sequencing set are event notices ranked according to increasing value of the attribute "EVTIME". An event notice refers through its attribute PROC to a "process" object and represents an event which is the next active phase of that object, scheduled to take place at system time EVTIME. There may be at most one event notice referencing any given process object.

The event notice at the lower end of the sequencing set refers to the currently active process object. The object can be referenced through the procedure "current". The value of EVTIME for this event notice is identified as the current value of system time. It may be accessed through the procedure "time".

Note: Since the statements and procedures introduced by "simulation" make implicit use of the sequencing procedures (detach, call and resume) explicit sequencing by these procedures should be done with care.

Link to GitHub: Source File.

Author:
SIMULA Standards Group, Øystein Myhre Andersen
  • Field Details

  • Constructor Details

    • RTS_Simulation

      public RTS_Simulation(RTS_RTObject SL)
      Create a new Simulation.
      Parameters:
      SL - staticLink
  • Method Details

    • isDetachUsed

      public boolean isDetachUsed()
      Always true in this class.
      Overrides:
      isDetachUsed in class RTS_RTObject
      Returns:
      true: this object is a QPS System block
    • _STM

      public RTS_Simulation _STM()
      Description copied from class: RTS_RTObject
      Method representing the Statements in this Block
      This method is virtual and must be redefined in blocks.
      Overrides:
      _STM in class RTS_Simset
      Returns:
      a pointer to this _RTObject
    • SQS_FIRST

      private RTS_EVENT_NOTICE SQS_FIRST()
      Utility: Returns the first event in the SQS.
      Returns:
      the first event in the SQS
    • time

      public double time()
      Returns the current simulation time.
                      long real procedure time; time := FIRSTEV.EVTIME;
       
      Returns:
      the current simulation time
    • current

      public RTS_Process current()
      Returns the current process.
                      ref (process) procedure current; current :- FIRSTEV.PROC;
       
      Returns:
      the current process
    • hold

      public void hold(double time)
      Procedure hold.

      The statement "hold(T)", where T is a long real number greater than or equal to zero, halts the active phase of the currently active process object, and schedules its next active phase at the system time "time + T". The statement thus represents an inactive period of duration T. During the inactive period the reactivation point is positioned within the "hold" statement. The process object becomes suspended.

                      procedure hold(T); long real T;
                      inspect FIRSTEV do begin
                              if T > 0 then EVTIME:= EVTIME + T;
                              if suc =/= none and then suc.EVTIME <= EVTIME
                              then begin out; RANK_IN_SQS(false);
                                      resume(current)
                              end if
                      end hold;
       
      Parameters:
      time - holding time
    • passivate

      public void passivate()
      The procedure passivate. It stops the active phase of the currently active process object and deletes its event notice. The process object becomes passive. Its next active phase must be scheduled from outside the process object. The statement thus represents an inactive period of indefinite duration. The reactivation point of the process object is positioned within the "passivate" statement.
                      procedure passivate; begin
                              inspect current do begin
                                      EVENT.out; EVENT :- none
                              end;
                              if SQS.empty then error("...") else resume(current)
                      end passivate;
       
    • passivate1

      RTS_Process passivate1()
      Special version of 'passivate'
      Returns:
      next Process
    • wait

      public void wait(RTS_Head S)
      The procedure wait. It includes the currently active process object in a referenced set, and then calls the procedure "passivate".
                      procedure wait(S); ref (head) S;
                      begin current.into(S); passivate end wait;
       
      Parameters:
      S - the head of the set
    • cancel

      public void cancel(RTS_Process x)
      The Procedure cancel.
      The statement "cancel(X)", where X is a reference to a process object, deletes the corresponding event notice, if any. If the process object is currently active or suspended, it becomes passive. Otherwise, the statement has no effect. The statement "cancel(current)" is equivalent to "passivate".
                      procedure cancel(X); ref (process) X;
                      if X == current then passivate
                      else inspect X do
                              if EVENT =/= none
                              then begin EVENT.out; EVENT :- none
                      end cancel;
       
      Parameters:
      x - the argument process
    • accum

      Utility procedure accum.
                      procedure accum (a,b,c,d);  name a,b,c;  long real a,b,c,d;
                      begin
                              a:= a + c * (time-b);  b:= time;  c:= c + d
                      end accum;
       
      A statement of the form "accum (A,B,C,D)" may be used to accumulate the "system time integral" of the variable C, interpreted as a step function of system time. The integral is accumulated in the variable A. The variable B contains the system time at which the variables were last updated. The value of D is the current increment of the step function.
      Parameters:
      a - argument a
      b - argument b
      c - argument c
      d - argument d
    • ActivateDirect

      public void ActivateDirect(boolean REAC, RTS_Process X)
      Direct activation: (re)activate x
      Parameters:
      REAC - signals reactivation
      X - the Process to avtivate
    • removeEvent

      private void removeEvent(RTS_EVENT_NOTICE EV)
      Utility: Remove event from SQS
      Parameters:
      EV - the event
      Throws:
      RTS_SimulaRuntimeError - if this action empties SQS.
    • ActivateDelay

      public void ActivateDelay(boolean REAC, RTS_Process X, double T, boolean PRIO)
      Delayed activation: (re)activate x delay t [ prior ]
      Parameters:
      REAC - signals reactivation
      X - the Process to activate
      T - the delay time
      PRIO - indicates priority
    • ActivateAt

      public void ActivateAt(boolean REAC, RTS_Process X, double T, boolean PRIO)
      Activate at: (re)activate x at t [ prior ]
      Parameters:
      REAC - signals reactivation
      X - the Process to activate
      T - the activation time
      PRIO - indicates priority
    • ActivateBefore

      public void ActivateBefore(boolean REAC, RTS_Process X, RTS_Process Y)
      Activate before: (re)Activate x before y
      Parameters:
      REAC - signals reactivation
      X - the Process to activate
      Y - the Process to precede
    • ActivateAfter

      public void ActivateAfter(boolean REAC, RTS_Process X, RTS_Process Y)
      Activate after: (re)Activate x after y
      Parameters:
      REAC - signals reactivation
      X - the Process to activate
      Y - the Process to succeed
    • ACTIVATE3

      private void ACTIVATE3(boolean REAC, RTS_Process X, boolean BEFORE, RTS_Process Y)
      Utility: Activate after: (re)Activate x after or after y
      Parameters:
      REAC - signals reactivation
      X - the Process to activate
      BEFORE - indicates before/after
      Y - the other process
    • TRACE_ACTIVATE

      private void TRACE_ACTIVATE(boolean REAC, String msg)
      Utility: Trace (re)activate
      Parameters:
      REAC - true if Reactivate
      msg - trace message
    • SIM_TRACE

      private void SIM_TRACE(String msg)
      Utility: Trace Simulation event
      Parameters:
      msg - the event message
    • toString

      public String toString()
      Description copied from class: RTS_RTObject
      Returns a string representation of the object.
      Overrides:
      toString in class RTS_BASICIO