Google
 

Trailing-Edge - PDP-10 Archives - decuslib10-05 - 43,50337/27/stat2e.sim
There is 1 other file named stat2e.sim in the archive. Click here to see a list.
BEGIN
  simulation CLASS statisticssimulation;
  COMMENT same as "simulation" plus automatic tracing
  and production of queue statistics;
  BEGIN

    PROCEDURE write_time;
    BEGIN
      outtext(" TIME:"); outfix(time,0,4);
      outchar('.'); outimage;
    END;

    process CLASS s_process(nameid, number);
    COMMENT same as "process" but has name and
    number to be used in output messages;
    VALUE nameid;
    TEXT nameid; INTEGER number;
    BEGIN
      REF(s_queue) my_queue;
      PROCEDURE s_out;
      INSPECT my_queue DO
      BEGIN
        increase_queuelength(-1);
        out; my_queue:- NONE;
      END of s_out;
    END of s_process;

    head CLASS s_queue(nameid);
    COMMENT same as "head" but trace messages
    are given when the queue length is changed,
    and queue length statistics are collected;
    VALUE nameid; TEXT nameid;
    BEGIN
      INTEGER queuelength;
      REAL previous_time, length_integral;

      PROCEDURE increase_queuelength(plus); INTEGER plus;
      BEGIN
        length_integral:=
        length_integral+queuelength*(time-previous_time);
        previous_time:= time;
        queuelength:= queuelength+plus;
        outtext("QUEUE AT "); outtext(nameid);
        outtext(" SIZE");
        outint(queuelength,3); write_time;
      END of increase_queuelength;

      PROCEDURE write_mean_length;
      BEGIN
        increase_queuelength(0);
        outtext("QUEUE AT "); outtext(nameid);
        outtext(" MEAN LENGTH ");
        outfix(length_integral/time,1,5);
        outtext(" UNTIL"); write_time;
      END;
    END;
    

    PROCEDURE s_hold(the_time, place);
    COMMENT same as "hold" but writes a trace message
    for every event during the simulation;
    NAME place; REAL the_time; TEXT place;
    BEGIN
      INSPECT current WHEN s_process DO
      BEGIN
        outtext(nameid); outtext(" NO.");
        outint(number,3);
        outtext(" WILL BE "); outtext(place);
        write_time;
      END;
      hold(the_time);
    END of s_hold;

    PROCEDURE s_wait(queue);
    COMMENT same as "wait" but writes trace message
    when a queue is entered, and updates queue statistics;
    REF(s_queue) queue;
    BEGIN
      INSPECT current WHEN s_process DO
      BEGIN
        my_queue:- queue;
        outtext(nameid); outtext(" NO.");
        outint(number,3);
      END;
      INSPECT queue DO
      BEGIN
        outtext(" INTO QUEUE AT "); outtext(nameid);
        write_time;
        increase_queuelength(1);
      END;
      wait(queue);
    END of s_wait;
  END of statisticssimulation;
  

  

  REAL simulation_duration;
  simulation_duration:= 200;
  statisticssimulation BEGIN
    REF (platform) harbour, store, factory;
    INTEGER i, u;
    s_process CLASS truck;
    BEGIN
      WHILE TRUE DO
      BEGIN
        s_hold(harbour.travel_time,"LEAVING FOR HARBOUR");
        ACTIVATE harbour DELAY 0; s_wait(harbour.queue);
        IF draw(0.5,u) THEN
        BEGIN
          s_hold(store.travel_time,"LEAVING FOR STORE");
          ACTIVATE store DELAY 0; s_wait(store.queue);
        END ELSE
        BEGIN
          s_hold(factory.travel_time,
          "LEAVING FOR FACTORY");
          ACTIVATE factory DELAY 0; s_wait(factory.queue);
        END;
      END;
    END of truck;
    s_process CLASS platform(platform_time, travel_time);
    REAL platform_time, travel_time;
    BEGIN
      REF (s_queue) queue;
      queue:- NEW s_queue(nameid);
      WHILE TRUE DO
      BEGIN
        INSPECT queue.first WHEN truck DO
        BEGIN
          s_out;
          s_hold(platform_time,"LOADING OR UNLOADING");
          ACTIVATE THIS truck;
        END OTHERWISE passivate;
      END;
    END of platform;
    harbour:- NEW platform("HARBOUR",1,10,20);
    ACTIVATE harbour;
    store:- NEW platform("STORE",1,15,20);
    ACTIVATE store;
    factory:- NEW platform("FACTORY",1,17,20);
    ACTIVATE factory;
    FOR i:= 1 STEP 1 UNTIL 5 DO
    ACTIVATE NEW truck("TRUCK",i);
    hold(simulation_duration);
    outimage;
    outtext("END OF SIMULATION"); write_time;
    outimage;
    harbour.queue.write_mean_length;
    store.queue.write_mean_length;
    factory.queue.write_mean_length;
  END of simulation;
END of program;