Home

SIMSCRIPT III Programming Manual

image

Contents

1. loop MEAN SERVICE TIME MST end method SELECT define TELLER CHOICE as TELLER reference variables for each TELLER in TELLER POOL with ACQUIRED UNITS TELLER 0 find the first case if found return with TELLER otherwise for each TELLER in TELLER POOL compute CHOICE as the minimum TELLER of N QUEUE TELLER return with CHOICE end method PRINT STATISTICS define TELLER as a TELLER reference variable print 4 lines thus TELLER UTILIZATION QUEUE LENGTH AVERAGE MAXIMU for each TELLER in TELLER POOL print 1 line with ID NUMBER TELLER UTILIZATION TELLER AVG QLEN TELLER MAX QLEN TELLER thus x x KK main define NO OF TELLERS as an integer variable define MEAN INTERARRIVAL TIME MEAN SERVICE TIME DAY LENGTH as real variables open unit 1 for input name is ed ex3 dat use unit 1 for input read NO OF TELLERS MEAN INTERARRIVAL TIME EAN SERVICE TIME DAY LENGTH call TELLER INITIALIZE NO
2. print 3 lines with AVG QLEN MAX QLEN 100 AVG BUSY TOTAL UNITS thus AVERAGE CUSTOMER QUEUE LENGTH IS OLOR KK MAXIMUM CUSTOMER QUEUE LENGTH IS THE ATTENDANTS WERE BUSY PER CENT OF THE TIME end main create ATTENDANT reference value stored in global variable TOTAL UNITS ATTENDANT 2 schedule a CUSTOMER GENERATOR now start simulation print 1 line thus SIMPLE GAS STATION MODEL WITH 2 ATTENDANTS call PRINT STATISTICS ATTENDANT Read as using unit 5 end 75 public preamble for the RESOURCE subsystem begin class RESOURCE every RESOURCFE has TOTAL UNITS an ACQUIRED UNITS an AVAILABLE UNITS method WAIT FOR method and CLEAN UP method and owns a REQUEST QUEUE define TOTAL UNITS as an integer variable define ACQUIRED UNITS as an integer variable monitored on the left define AVAILABLE UNITS as an integer method define WAIT FOR as a method given 2 integer values requested units and priority before destroying a RESOURCE call CLEAN UP end begin class REQUEST every REQUES has a UNITS a PRIORITY and a PROCESS NOTICE and belongs to a QUEUE define UNITS PRIORITY as integer variables define PROCESS NOTICE a
3. EQUIREMENT gt 0 UNITS CPU JOB PRIORITY UI RE EMORY REQ from ACQ UI RED ENT from ACQUIRE UNITS CPU JOB TIM end process me given M until T do tho TIME V STA d JOB GEN EA IME INTERARR V gt STO Schedule a JOB given MIN F EXPON wait loop end process method STOP SIMULATION skip print 9 lines with TIM RANDI F 1 ERATO IVAL RT TIME MINUTES PROCESSING TIME ENT and EMORY UNITS MEMORY JOB PRIORITY D UNITS MEMORY EAN PROC TIME TIM LJ 10 1 EXPON ENTIAL F M EAN PROC TIME STOP TIME RANDI F 1 4 ENTIAL M KAN INT ERARRIVAL TIME 3 6 lines AVG QLE 55 ED AVG JOB E E V UTILIZATION CPU M EMORY AVG QLE N CPU IS P t nus 107 TOTAL UNITS 2 MEAN UTILIZATION EMORY PROC TIME minutes MAX QLI lt JOB PRIORITY 2 now AFTER ee AX HOURS HE CPU UTILIZATION WAS LEE HE MEMORY UTILIZATION WAS i
4. move from ACQ end I method AVAILABLE UNITS return with TOTAL UNITS ACQUIRED UNITS 104 method WAIT FOR REQ UNITS REQ PRIORITY define REQ as a REQUEST reference variable create REQ UNITS REQ REQ UNITS PRIORITY REQ REQ PRIORITY PROCESS NOTICE REQ PROCESS V file REQ in QUEU suspend end method CLEAN UP define REQ as a REQUEST reference variable while QUEUE is not empty do remove first REQ from QUEUE destroy PROCESS NOTICE REQ destroy REQ loop end 105 6 07 Example 7 A Computer Center Study Input data in file ex7 dat Input data in file ex7 x dat JOB 1 0031 5 00 JOB 2 46 12 7 00 JOB 3 78 3 3 10 00 JOB 9 28 22 30 00 JOB 10 48 1 4 40 00 JOB 24 22 1 5 60 00 preamble for the COMPUTER CENTER system Example 7 importing the RESOURCE subsystem begin class COMPUTER the class has a CPU a MEMORY JOB TIME in minutes JOB process method JOB GENERATOR process method STOP SIMULATION process method define CPU MEMORY COMPUTER RESOURCE reference variables define JOB TIME as a real variable tally NO PROCESSED as the number AVG JOB TIME as the average of JOB TIME define JOB as a process method given 2 in
5. loop end method PRINT PROBABILITIES define I as an integer variable define JOB as a JOB reference variable print 3 lines thus THE JOBS WERE DISTRIBUTED AS FOLLOWS NAME PROBABILITY for 1 to NO OF JOBS do JOB REPERTOIRE I print 1 line with NAME JOB PROBABILITY JOB thus Ck Ck ck ck ckckckckckckck ck KK KKK KKK kk loop end method PRINT STATISTICS define I as an integer variable define JOB as a JOB reference variable print 4 lines with TIME V thus 102 RESULTS AFTER HOURS OF CONTINUOUS OPERATIO JOB TYPE NO COMPLETED AVERAGE DELAY HOURS for 1 to NO OF JOBS do JOB REPERTOIRE I print 1 line with NAME JOB NO COMPLETED JOB AVG DELAY JOB thus Ckck ck ck ck ck ck ck ck k ck kk loop call MACHINE PRINT STATISTICS end main define MEAN INTERARRIVAL TIME STOP TIME as real variables open unit 1 for input name is ex6 dat use unit 1 for input call MACHINE READ SHOP call JOB READ REPERTOIRE read MEAN INTERARRIVAL TIME STOP TIME call JOB READ PROBABILITIES print 1 line thus EXAMPLE JOB SHOP SIMULATION call JOB PRINT REPERTOIRE call JOB PRINT PROBABILITIES Schedule a JOB GEN start simulation
6. a Se define QUEU end hods for the R ESOURCE t method ACQUI RI ED UNITS P class define as an integer variable define REQ as a R enter with ACQ while QU do EUE is remove first RI add UNITS EQU Schedule the P destroy loop move from ACQ hod AVAILABLE not empty UNITS F QU EQ from QUEUE EQ to ROCESS NOTICE REQ now an integer variable an integer variable monitored on the left an integer method requested units and priority call CLEAN UP RITY as integer variables as a pointer variable ranked by high PRIORITY EST reference variable UNITS return with TOTAL UNITS EU E lt TOTAL UNITS ACQ ACQUIRED UNITS 8l method WAIT FOR REQ define create REQ as UNITS a REQUEST reference variable UNITS REQ R EQ UNITS PRIORI TY REQ PROCESS file R NOTICE EQ in QU suspend end method CL define while QUEUE do EAN UP REQ as is REQ EU a REQUEST reference variable not empty remove first REQ from destroy P destroy loop end REQ PRIORITY ESS V QUEUE ROCESS NOTIC RE
7. A one dimensional double array named Y is declared by define Y as a 1 dimensional double array An array is dynamically allocated and its number of elements determined at run time by executing a reserve statement e g reserve Y as 100 The number of elements in an array can be obtained by calling the built in function dim f for example dim f Y returns 100 The first element of the array is stored at index 1 The elements of Y therefore are Y 1 Y 2 Y 100 Each element is automatically initialized to zero Multi dimensional arrays may also be declared The release statement de allocates an array i e frees its storage Arrays can also be reserve with an arbitrary low boundary other than 17 This is employed by replacing the number of elements in the reserve statement with low bound to high bound For example suppose we wanted to reserve a 2 dimensional double array indexed from 10 to 10 in the first dimension and from 0 to 20 in the second dimension define Z as a 2 dimensional double array reserve Z as 10 to 10 by 0 to 20 The lower and upper index boundaries can be retrieved using the built in functions low f and high f In the above example calling low f Z would return 10 Calling high f Z 0 would return 20 1 09 Expressions Arithmetic expressions may use any combination of arithmetic operators unary and binary and exponentiation Built in functions may be called t
8. RATOR MEAN INTERARRIVAL TIME STOP TIME now read as using unit 5 keep text window open end 103 public preamble for the RESOURCE subsystem begin class RESOURCE every RESOURCFE has TOTAL UNITS an ACQUIRED UNITS an AVAILABLE UNITS method WAIT FOR method and CLEAN UP method and owns a REQUEST QUEUE define TOTAL UNITS as an integer variable define ACQUIRED UNITS as an integer variable monitored on the left define AVAILABLE UNITS as an integer method define WAIT FOR as a method given 2 integer values requested units and priority before destroying a RESOURCE call CLEAN UP end begin class REQUEST every REQUES has a UNITS a PRIORITY and a PROCESS NOTICE and belongs to a QUEUE define UNITS PRIORITY as integer variables define PROCESS NOTICE as a pointer variable define QUEUE as a set ranked by high PRIORITY end end methods for the RESOURCE class left method ACQUIRED UNITS define ACQ as an integer variable define REQ as a REQUEST reference variable enter with ACQ while QUEUE is not empty and UNITS F QUEUE lt TOTAL UNITS ACQ do remove first REQ from QUEUF add UNITS REQ to schedule the PROCESS NOTICE REQ now destroy loop
9. 30 Statistical attributes may be defined by accumulate and tally statements appearing within a begin class block A statistical attribute is an object attribute or class attribute whose value is computed based on the values assigned to another object attribute or class attribute We add to our example an object attribute named Trip Distance and a statistical attribute named Odometer containing the sum of the values assigned to Trip Distance 20 begin class Vehicle every Vehicle has a Trip Distance define Trip Distance as a real variable tally Odometer as the sum of Trip Distance end Object attributes and class attributes may be reference variables random variables and monitored variables 21 2 03 Methods A method is a routine associated with a class It may have given arguments and it may be a function which returns a function result or a subroutine which does not return a function result but may have yielded arguments An object method is invoked on behalf of an object and performs some operation using the object A class method is related to the class but is not invoked on behalf of an object Object methods are declared in every statements and class methods are declared in the class statements within begin class blocks The mode and dimensionality of a method s arguments and the mode of the method s function result if the method is a function are specified by a define method statement after the method s decl
10. A left usage text function that can be assigned a text value if a critical runtime error has occurred in the simulation If this function is assigned the assigned message is displayed the program is halted and SIMSCRIPT III debugger will be activated if the program was compiled WITHOUT optimization For example if number operations pending 0 let err message f ERROR Negative number of pending operations always exit r integer A subroutine that terminates the program with an exit status of integer arg high f array arg Returns the upper bound of the given array The return value will be identical to that returned by DIM F unless the array was reserved with an upper and lower boundary Zero is returned if the given array pointer is zero A runtime error is generated if the given argument is not an array low f array arg 72 Returns the lower bound of the given array The return value will be 1 if the array was not reserved with an upper and lower boundary Zero is returned if the given array pointer is Zero runtime error is generated if the given argument is not an array parm v A one dimensional text array that contains the command line arguments given to the program when it was invoked Dim f parm v is the number of command line arguments and is zero if no arguments were provided snap r A subroutine that may be provided by the program which is invoked when a runtim
11. method CL define while QUEUE do EAN UP REQ as is REQ EU a REQUEST reference variable not empty remove first REQ from destroy P destroy loop end REQ PRIORITY ESS V QUEUE ROCESS NOTIC REQ REQ PRIORITY 88 6 04 Example 4 Harbor Model preamble for the HARBOR system Example 4 begin class SHIP every SHIP has an UNLOAD process method and DONE WAITING method and RESCHEDULE UNLOAD method and belongs to a QUEUE and a DOCK define RESCHEDULE UNLOAD as a method given a real argument time scale factor the class has a CYCLE TIME a GENERATOR process method and a STOP SIMULATION process method and owns the QUEUE and the DOCK define CYCLE TIME as a real variable tally NO OF SHIPS as the number MIN CYCLE TIME as the minimum MAX CYCLE TIME as the maximum MEAN CYCLE TIME as the mean of CYCLE TIME accumulate MAX QLENGTH as the maximum MEAN QLENGTH as the mean of N QUEUE end end methods for the SHIP class process method UNLOAD define ARRIVE TIME UNLOADING TIME as real variables ARRIVE TIME TIME V UNLOADING TIME UNIFORM F 0 5 1 5 2 if N DOCK lt 2 if N
12. predefined array named seed v contains ten seed values equally spaced throughout the period of the LCG however any seed values may be assigned by the program to this array A stream number between 1 and 10 selects a seed value from this array The values from the LCG are transformed by built in functions into pseudo random numbers from the following probability distributions beta binomial Erlang exponential gamma lognormal normal Poisson triangular uniform continuous and discrete and Weibull 3 03 Statistics An accumulate or tally statement specifies one or more statistics to compute automatically from the values assigned to an object attribute or class attribute A name is given to each statistic and an object method or class method by that name is generated that returns the value of the statistic Any of the following statistics may be computed the maximum minimum number sum mean mean square sum of squares variance and standard deviation of the values assigned to the attribute A histogram of the values may also be computed The statistics are weighted by simulation time if specified by an accumulate statement and are unweighted if the tally statement is used The statistics can be computed for the entire simulation or for particular time intervals for example every day or every week of simulation time The reset statement is used to initialize the statistics at the beginning of a time interval Suppose in
13. If the argument is positive the rounded value is computed by adding 0 5 to the argument and truncating the result If the argument is negative the value is obtained by subtracting 0 5 from the argument and truncating For example int f 3 5 returns 4 and int f 3 5 returns 4 itoa f integer An alpha function that returns the character representation of integer arg The argument must be in the range 0 to 9 The return value is in the range 0 to 9 itot f integer A text function that returns the text representation of integer arg For example itot f 100 returns 100 and itot f 5 returns 5 real f integer A double function that returns the floating point representation of integer arg For example real f 3 returns 3 0 rtot f double arg total width integer frac width integer use exponential integer A text function that returns textual representation of double arg Given as arguments are the total number of places the number of places to the right of the decimal point and a flag to use exponential notation For example rtot f 65 01369 10 4 0 returns the text string 65 0137 50 trunc f double An integer function that returns the value obtained by truncating double arg to remove its fractional part For example trunc f 3 5 returns 3 and trunc f 3 5 returns 3 51 ttoa f text An alpha function that returns the first
14. but cannot refer to class Moving Object access the private attributes of Vehicle such as Vehicle Last ID call the private methods of Vehicle access the private subsystem attribute Z methods for the City_Vehicle class main end 44 4 02 Source Code Organization A SIMSCRIPT III program consists of a main module or a main module and several subordinate modules called subsystems keywords subsystem module and package are synonymous A main module may have an optional preamble followed by one or more routines and methods headings One of the routines must be named main The preamble contains definitions of data structures used in the program like classes entities global variables constants and sets All statements in a preamble are non executable The main module can be given a name and can import subsystems but cannot BE imported by a subsystem Begin file anyname sim Preamble for the Y system importing the A subsystem define routine1 as a routine end main end routine routine1 end End file anyname sim A subsystem begins with a public preamble and is followed by an optional private preamble and zero or more routines and methods headings The file containing a public preamble must be named after the subsystem In the following example the subsystem called X must appear within the file X sim Begin file X sim Public preamble for the X subsystem
15. ioi eer ete 7 1 075 7 1 08 VARIABLES AND 5 0 0 040 000000000000 8 1 092 EXPRESSIONS zc AER LLENAS P 8 1 10 BASIC STATEMENTS ere secedere dere PhD ee eese derat 10 11 1 12 FUNCTIONS AND 85 2 0022 2 2 0 00000000 11 1 13 ARGUMENT CHECKING 2 3 13 LIA rene e teer eee 14 OBJECT ORIENTED PROGRAMM ING eeeeeee ee eene eee eee eee eee e e e 17 2701 CEASSES AND OBJEGTS cre cioe ib eee teet ege 17 2 02 ATTRIBUTES del celer 18 2 03 METHODS teet rte e e tc tenere re e ree 22 2 04 GROUPING OBJECTS IN SETS hehehe nenne e 26 2 054 ARRA YSOF SEIS erede es esee MAE Bass Ee 28 2 06 29 OBJECT ORIENTED DISCRETE 86 2 22 222 114 0 34 2 01 PROCE
16. return with REGULAR otherwise return with PREMIUM end main create ATTENDANT TOTAL UNITS ATTENDANT 2 create PUMP REGULAR create PUMP PREMIU TOTAL UNITS PUMP REGULAR 1 TOTAL UNITS PUMP PREMIUM 3 schedule a CUSTOMER GENERATOR now start simulation print 2 line thus SIMPLE GAS STATION WITH TWO ATTENDANTS AND TWO GRADES OF GASOLINE call PRINT STATISTICS ATTENDANT call PUMP PRINT ALL STATISTICS Read as using unit 5 end 80 public preamble for the end met lef end met end ESOURCE ESO URCE begin class R ESO a an an a and a owns a every R has define define define AVAI URCE TOTAI ACQUIR WAIT CLI TOTAL ACQUI Li EAN ABLE FOR met UP met UNITS ED UNITS UNITS method hod hod and REQU EST QU UNITS RI define WAIT given 2 integer values before destroying a R end FOR ED UNITS E UNITS as as as as a method subsystem EQU EST begin class R every REQU has a U define UNITS ES LTS RIO ROCI belongs to a QU RITY ESOURCE ESS NOTICE and EU PRIO define PROCI ESS NOTIC
17. the program is terminated with a runtime error However if the value of the variable is nonzero typically the program sets it to 1 the variable is assigned a value of 2 to indicate that end of file has been reached Each input unit has its own copy of this variable heading v A subprogram variable that specifies a routine to be called for each new page written to the current output unit when pagination is enabled lines v is greater than zero or contains zero which is the default if no routine is to be called The routine typically writes a page heading but may perform other tasks Each output unit has its own copy of this variable line v An integer variable that contains the number of the current line for the current output unit It is initialized to 1 If pagination is enabled lines v is greater than zero then the first line of each page is number 1 Each output unit has its own of this variable 60 lines v An integer variable that enables pagination for the current output unit if containing a positive value indicating the maximum number of lines per page or disables pagination if zero which is the default or negative Each output unit has its own copy of this variable mark v An alpha variable that specifies the character that marks the end of input data describing an external process or random variable Its default value is asterisk out f integer arg An alpha function that
18. A double function that returns the fractional part of double arg It is computed by subtracting the truncated value of the argument from the original value If the argument is positive the return value is positive If the argument is negative the return value is negative For example frac f 3 45 returns 0 45 and frac f 3 45 returns 0 45 inf c An integer constant equal to the largest integer value On 32 bit computers this value is 2 1 2 447 483 647 The smallest integer value is inf c 1 log e f double A double function that returns the natural logarithm i e the base e logarithm of double arg The argument must be positive 54 log 10 f double A double function that returns the base 10 logarithm of double arg The argument must be positive max f numeric arg1 numeric 2 A function that returns the maximum value of two or more integer or double arguments If every argument is integer the function returns an integer result otherwise the function returns a double result numeric arg1 numeric arg2 A function that returns the minimum value of two or more integer or double arguments If every argument is integer the function returns an integer result otherwise the function returns a double result mod f numeric arg1 numeric arg2 A function that computes numeric arg1 divided by numeric arg2 and returns the remainder If both arg
19. AND HAVE A AN PROCESSING TIME OF Wk SR MINUTI JOBS ARE UPPLIED AS EXTERNAL DATA THE SIMULATIO ERIOD IS eK KE HOURS Gl TORNE HOURS V 1 one hour per simulation time unit Schedule a COMPUTER JOB GENERATOR given MEAN INTERARRIVAL TIME MEAN PROCESSING TIME STOP TIME now schedule a COMPUTER STOP SIMULATION in STOP TIME hours start simulation read as using unit 5 to keep text window open 108 end 109 public preamble for the RESOURCE subsystem begin class RESOURCE every RESOURCFE has TOTAL UNITS an ACQUIRED UNITS an AVAILABLE UNITS method WAIT FOR method and CLEAN UP method and owns a REQUEST QUEUE define TOTAL UNITS as an integer variable define ACQUIRED UNITS as an integer variable monitored on the left define AVAILABLE UNITS as an integer method define WAIT FOR as a method given 2 integer values requested units and priority before destroying a RESOURCE call CLEAN UP end begin class REQUEST every REQUES has a UNITS a PRIORITY and a PROCESS NOTICE and belongs to a QUEUE define UNITS PRIORITY as integer va
20. Capacity and a Current Gallons define Miles Per Gallon Fuel Capacity and Current Gallons as real variables end A derived class also inherits the object methods of each of its base classes This means that each object method defined or inherited by its base classes may be invoked on behalf of an object of the derived class In addition the derived class may define object methods of its own our example the object methods of the Vehicle class such as Initialize Flat Tires etc may be invoked on behalf of a Gas Vehicle object This is appropriate because the Gas Vehicle is a Vehicle it has all of the object attributes of a Vehicle and can be operated upon by these methods as if it were a Vehicle object The Gas Vehicle class may define object methods of its own for example a Fuel Level method that returns the value of Current Gallons Fuel Capacity Note that an object method defined by the Gas Vehicle class may not be invoked on behalf of a Vehicle object because a Vehicle object lacks the object attributes defined by the Gas Vehicle class A Vehicle is not Gas Vehicle A derived class cannot alter the definition of an inherited object attribute or object method For example the Gas Vehicle class cannot change the mode of the inherited ID 29 attribute A derived class may define an attribute or method having the same name as an inherited attribute or method but it does not replace or change the inherited attribute or
21. DOCK 1 an existing ship is using both cranes call RESCHEDULE UNLOAD F DOCK 2 give up one cran else no existing ships so this ship will use both cranes UNLOADING TIME UNLOADING TIME 2 always file SHIP in DOCK else no room at the dock must wait in the queue file SHIP in QUEU suspend always work UNLOADING TIME days remove SHIP from DOCK 89 destroy SHIP CYCLE TIME TIME V ARRIV if QUEUE is not empty call DONE WAITING F QUEU else if N DOCK 1 call RESCHEDUL always always end method DONE WAITING E TIM remove SHIP from QU EU file SHIP in DOCK Schedule the UNLOAD now E UNLOAD F DOCK 0 5 E gain a crane end method RESCHEDULE UNLOAD SCALE FACTOR interrupt UNLOAD TIME A UNLOAD TIME A UNLOAD SCALE FACTOR resume UNLOAD end process method GENERATOR define SHIP as a SHIP reference variable until TIME V 80 do create SHIP Schedule an UNLOAD SHIP now wait EXPONENTIAL F 4 3 1 days loop end process method STOP SIMULATION print 5 lines with NO OF SHIPS TIME V MIN CYCLE TIME MAX CYCLE TIME MEAN CYCLE TIME thus SHIP AND CRANE MODEL SHIPS WERE UNLOADED IN DAYS TH
22. JOB reference array define SELECTION as an integer stream 9 variable define GENERATOR as a process method given 2 real arguments end begin class TASK every TASK has a MACHINE and a MEAN TIME and belongs to a SEQUENCE define MACHINE as a MACHIN define MEAN TIME as a real end define HOURS to mean units end methods for the MACHINE class method USE UNIT given MEAN TIME if AVAILABLE UNITS 0 define START TIME as a rea mean interarrival time and stop time P reference variable variable E WAIT yielding TIM l variable 99 5 TIME V call WAIT FOR 1 0 TIME WAITED TIME V START TIME else add 1 to ACQUIRED UNITS always work EXPONENTIAL F MEAN TIME STREAM HOURS subtract 1 from ACQUIRED UNITS end method LOOKUP MACHIN E NAM E define MACHINE for each MACHINE find the fir if found return with otherwise return with 0 end method READ SHOP define NO OF define MACHINE AC read NO OF MACHIN 1 to NO do create MACHIN read TOTAL STREAM MAC file MACHI loop end HIN as a MACHINE in S st ACHINE ES ES OF MACHIN method PRINT STATISTICS NAM define MACHINE print 5 lines thus as a MACHIN
23. OF TELLERS MEAN SERVICE TIME schedule a CUSTOMER GENERATOR DAY LENGTH MEAN INTERARRIVAL TIME now start simulation print 10 lines with NO OF TELLERS EAN INTERARRIVAL TIME EAN SERVICE TIME DAY LENGTH TIME V HOURS V CUSTOMER MEAN WAITING TIME thus SIMULATION OF A BANK WITH TELLERS EACH WITH A SEPARATE QUEUE CUSTOMERS ARRIVE ACCORDING TO AN EXPONENTIAL DISTRIBUTION OF INTER ARRIVAL TIMES WITH A MEAN OF i MINUTES SERVICE IME IS ALSO EXPONENTIALLY DISTRIBUTED WITH A MEAN OF INUTES 85 BANK DOORS ARE CLOSED AFTER HOURS BUT ALL CUSTOMERS INSIDE ARE SERVED HE LAST CUSTOMER LEFT THE BANK AT HOURS HE AVERAGE CUSTOMER DELAY WAS MINUTES I call TELLER PRINT STATISTICS Read as using unit 5 to keep the window open end 86 public preamble for the end met lef end met end ESOURCE ESO URCE begin class R ESO a an an a and a owns a every R has define define define AVAI URCE TOTAI ACQUIR WAIT CLI TOTAL ACQUI Li EAN ABLE FOR met UP met UNITS ED UNITS UNITS method hod hod and REQU EST QU UNITS RI define WAIT given 2 integer values before destroying a R end FOR ED UNI
24. TIME MEAN SERVICE TIME DAY LENGTH as real variables 94 open unit 1 for input name is ex5 dat use unit 1 for input read MIN TELLERS MAX TELLERS NO OF REPLICATIONS T MEAN INTERARRIVAL TIME EAN SERVICE TIME DAY LENG MEAN INTERARRIVAL TIME EAN SERVICE TIME DAY LENG SIMULATION OF A SINGLE QUEUE BANK THE NO OF TELLERS RANGES FROM TO REPLICATIONS FOR EACH NO OF TELLERS print 9 lines with MIN TELLERS MAX TELLERS NO OF REPLICATIONS H thus CUSTOMERS ARRIVE ACCORDING TO AN EXPONENTIAL DISTRIBUTION SERVICE TIME IS ALSO EXPONENTIALLY DISTRIBUTED WITH A MEAN OF ro RUE INUTES BUT ALL CUSTOMERS INSIDE ARE SERVED SEED1 SEED V 1 SEED2 SEED V 2 for NO OF TELI do H RS MIN TE ERS to MAX TELLERS SEED2 MEAN INTERARRIVAL TIME MEAN SERVICE TIME OF INTER ARRIVAL TIMES WITH A MEAN OF MINUTES THE BANK DOORS ARE CLOSED AFTER HOURS EACH DAY call SIMULATE BANK given NO OF TELLERS NO OF REPLICATIONS SEEDI DAY LENGTH start new page loop read as using unit 5 to
25. The class attributes class methods and class constants of a base class may be accessed without qualification within a method of a derived class A class method cannot be overridden Substitutions defined by define to mean and substitute statements within a begin class block of a base class are not inherited Cyclic inheritance is not permitted for example every A is a B and every B is an A or every A is a B every B is a C and every C is an A Suppose class D is derived from classes B and C and that class A is a base class of both B and C That is every D is a B and a C every B is an A and every C is an A This is known as diamond shaped inheritance There is only one occurrence of A s object attributes in a D object If both B and C override an object method M inherited from A then D must override M the implementation of D M may invoke any combination of A M B M and C M 33 3 Object Oriented Discrete Simulation 34 3 01 Process Method Any method that is a subroutine may be declared as a process method which can be invoked directly by a call statement or scheduled by a schedule statement for execution at some future simulation time In our example let us define a process method named Trip given the trip distance and average speed and yielding the duration of the trip begin class Vehicle every Vehicle has a Trip process method define Trip as a process method given 2 double arguments trip distance in miles an
26. character of text arg or returns a blank if text arg is the null string For example ttoa f yes returns y and ttoa f returns ttoi f text arg An integer function that returns an integer value that is represented in a text string If for some reason the conversion cannot take place zero is returned ttor f text arg A double function that returns the floating point value that has been converted from a text string If for some reason the conversion cannot take place zero is returned 32 5 02 Numeric Operations abs f numeric A function that returns the absolute value of an integer or double argument If the argument is integer the function returns an integer result If the argument is double the function returns a double result For example abs f 5 returns 5 and abs f 12 3 returns 12 3 and f integer arg1 integer arg2 An integer function that returns the value obtained by performing a bitwise AND of integer arg1 and integer arg2 For example and f 23 51 returns 19 because the bitwise AND of binary 010111 23 and binary 110011 51 is binary 010011 19 arccos f double arg A double function that returns the arc cosine of double arg in radians The argument must be in the range 1 to 1 The return value is in the range zero to arcsin f double arg A double function that returns the arc sine of double arg in radians The argument must be in
27. class method Construct called after a Vehicle object has been created add 1 to Count add 1 to Last ID ID Last ID Manufacturer Unknown reserve Tire Pressure as Num Tires end method Initialize given Maker Max Speed Initial Pressure Manufacturer Maker Maximum Speed Max Speed define J as an integer variable for J 1 to Num Tires Tire Pressure J Initial Pressure end 24 method Flat Tires Min Pressure define Count and J as integer variables for J 1 to Num Tires with Tire Pressure J Min Pressure add 1 to Count increment local variable return with Count return number of under inflated tires end method Print print 3 lines with ID Manufacturer Current Speed Maximum Speed Odometer Flat Tires 10 thus Vehicle manufactured by Its current and maximum speeds are and mph Its odometer reads miles It has flat tires end method Destruct called before a Vehicle object is destroyed write as Destroying call Print release Tire Pressure subtract 1 from Count end method Print Count write Count as There are i Vehicle objects in existence end A method that is a function may have left and or right implementations left implementation begins with the keywords left method whereas a right implementation begins with the keywords method or right method An object method or class method that is a function is implicitly defined for a mo
28. effect at the beginning of the private preamble of the subsystem and those in effect at the end of the private preamble apply to the routines 42 of the subsystem A module that imports the subsystem however does not import nor is affected by the substitutions and settings defined by the subsystem Although it is not possible to import substitutions named constants defined in the public preamble of the subsystem are imported In subsystems each public routine whether function or subroutine must be defined in a public preamble and each private function and subroutine must be defined in a private preamble Full definition is encouraged including specification of the mode and dimensionality of its arguments System attributes are defined by the system statements in the preamble of a main module Subsystem attributes are analogously defined by the subsystem statements appearing in the public and private preambles of a subsystem A subsystem may provide a special initialize routine which is called once automatically before the main routine is executed This routine can be used to initialize subsystem attributes global variables and class attributes defined by the subsystem If more than one subsystem in a program has an initialize routine the sequence in which these routines are executed is undefined The following example shows a subsystem and a main module that imports the subsystem public preamble for the Transportation
29. importing the A subsystem define routine1 as a routine end optional private preamble Private preamble for the X subsystem importing the B subsystem define routine2 as a routine End optional implementation routine routine1 end routine routine2 45 End file X sim A separate source file can contain the private preamble for a subsystem followed by optional implementation code for the subsystem There are no naming restrictions on this file Keep in mind that constructs defined in the private preamble of a subsystem are never imported Begin file anyname sim Private preamble for the X subsystem importing the B subsystem define routine3 as a routine End optional implementation routine routine3 end End file anyname sim A separate source file can contain solely implementation code without any public private or system preamble If the file contains code for a subsystem it must have the heading Implementation for the subsystem Begin file anyname sim Implementation for the X subsystem routine routine3 end End file anyname sim A separate file containing implementation code for the system should NOT have the implementation for header Basically any code found in a source file that does not have any preamble or implementation for headings is assumed to be part of the main module or system 1 Begin fi
30. keep text window open 95 public preamble for the RESOURCE subsystem begin class RESOURCE every RESOURCFE has TOTAL UNITS an ACQUIRED UNITS an AVAILABLE UNITS method WAIT FOR method and CLEAN UP method and owns a REQUEST QUEUE define TOTAL UNITS as an integer variable define ACQUIRED UNITS as an integer variable monitored on the left define AVAILABLE UNITS as an integer method define WAIT FOR as a method given 2 integer values requested units and priority before destroying a RESOURCE call CLEAN UP end begin class REQUEST every REQUES has a UNITS a PRIORITY and a PROCESS NOTICE and belongs to a QUEUE define UNITS PRIORITY as integer variables define PROCESS NOTICE as a pointer variable define QUEUE as a set ranked by high PRIORITY end end methods for the RESOURCE class left method ACQUIRED UNITS define ACQ as an integer variable define REQ as a REQUEST reference variable enter with ACQ while QUEUE is not empty and UNITS F QUEUE lt TOTAL UNITS ACQ do remove first REQ from QUEUF add UNITS REQ to schedule the PROCESS NOTICE REQ now destroy loop move from ACQ end I method AVAILABLE UNITS return w
31. method given a yielding a real argument accumulate AVG BUSY as the mean of ACQUIR amp HO a the SHOP P real argument Example 6 subsystem IT method and as a text variable EAM as an integer variable mean tim n ded using a unit time waiting for a unit ED UNITS accumulate AVG BACK MAX BACK the class LOG as the mean LOG as the maximum of N QUEU has a LOOKUP met hod a READ SHOP method and a P RINT STATISTICS method and 98 owns the SHOP define LOOKUP as a MACHINI given a text argument begin class JOB every JOB has NAME a PROBABILITY a DELAY TIME and PERFORM process owns a TASK SEQUENCE define NAME as a text vari reference method machine name method and able as real variables define PROBABILITY DELAY TIME tally NO COMPLETED as the AVG DELAY as the the class number mean of D has a NO OF JOBS a REPERTOIRE a SELECTION random step variable a GENERATOR process method a READ REPERTOIRE method a READ PROBABILITIES method a PRINT REPERTOIRE method a PRINT PROBABILITIES method and a PRINT STATISTICS method define NO OF JOBS as an integer variable define REPERTOIRE as a 1
32. method The result is that the derived class has two definitions of the name one defined by the class and the other inherited from a base class In the following example the Gas Vehicle defines a text object attribute named ID and an object method named Initialize which accepts three more given arguments than the inherited Initialize method begin class Gas Vehicle every Gas Vehicle has an ID and an Initialize method define ID as a text variable define Initialize as a method given 2 text arguments VIN and manufacturer name 1 double argument maximum speed and 3 real arguments initial tire pressure mpg and fuel capacity end When a name has been inherited from two or more base classes or has been defined by the derived class and inherited from one or more base classes each inherited definition must be accessed using its qualified name A Gas Vehicle object has an inherited integer attribute named Vehicle ID and a defined text attribute named ID or Gas Vehicle ID The Initialize method defined by the Gas Vehicle class is called on behalf of a Gas Vehicle object The following implementation of this method calls the inherited Initialize method on behalf of the Gas Vehicle object to initialize its inherited attributes Manufacturer Maximum Speed and Tire Pressure It then initializes three of its defined attributes ID Miles Per Gallon and Fuel Capacity methods for the Gas Vehicle class method Initialize given VIN
33. of the class Member attributes p set name s set name and m set name are implicitly defined as O dimensional scalar object attributes A define set statement may appear inside the block after the belongs phrase to specify the ordering of members of the set either FIFO first in first out which is the default LIFO last in first out or ranked based on the values of one or more 0 dimensional object attributes and values returned by object methods that are functions with no arguments An owns phrase in an every statement or the class statement appearing inside a begin class block refers to a set of entities or set of objects owned by an object of the class or owned by the class Owner attributes f set name l set and n set name are implicitly defined as object attributes or class attributes with the background dimensionality If the background dimensionality is nonzero the owner attributes are array attributes and the object or class owns an array of sets Unless the owner and member class are the same class an owns phrase must refer to a set of objects by its qualified name i e the name of the member class followed by an apostrophe and the set name However only the set name appears in the name of owner attributes In the following example the owns phrase indicates that every Repair Shop object owns a set of Vehicle objects named Service Queue The set of objects is defined by the belongs phrase and define set state
34. only of main module preamble and implementation but larger models should be designed with modularity in mind as a main module with a set of subsystems to facilitate code reuse and team work development Modularity can be easily added to an existing SIMSCRIPT IL5 model defining it as a main module system and adding new subordinate modules subsystems packages SIMSCRIPT III includes all standard language elements and can be used as a general purpose object oriented programming language with English like syntax In addition it includes powerful support for building simulation models with interactive GUI presentation graphics and animation Building SIMSCRIPT III graphical models is explained in the SIMSCRIPT III Graphics Manual The SIMSCRIPT models are developed inside the Simstudio integrated development environment IDE which incorporates an automated project builder syntax colored text editors a class browser and graphical editors for GUI elements dialog boxes menus palettes icons graphs Building SIMSCRIPT III projects using Simstudio is described in SIMSCRIPT III User s Manual This chapter describes basic language elements and related enhancements like support for the Latin 1 character set named constants argument type checking multiple line comments and reference modes Chapter 2 introduces classes objects multiple inheritance object and class methods all used for object oriented programming Chapter 3 de
35. pointer variable define QUEUE as a set ranked by high PRIORITY end end methods for the RESOURCE class left method ACQUIRED UNITS define as an integer variable define REQ as a REQUEST reference variable enter with ACQ while QUEUE is not empty UNITS F QUEUE lt TOTAL UNITS do remove first REQ from QUEUE add UNITS REQ to ACQ schedule the PROCESS NOTICE REQ now destroy REQ loop move from ACQ end method AVAILABLE UNITS return with TOTAL UNITS ACQUIRED UNITS 76 method WAIT FOR REQ UNITS REQ PRIORITY define REQ as a REQUEST reference variable create REQ UNITS REQ REQ UNITS PRIORITY REQ REQ PRIORITY PROCESS NOTICE REQ PROCESS V file REQ in QUEU suspend end method CLEAN UP define REQ as a REQUEST reference variable while QUEUE is not empty do remove first REQ from QUEUE destroy PROCESS NOTICE REQ destroy REQ loop end 77 6 02 Example 2 Simple Gas Station with 2 attendants preamble for the GAS STATION system Example 2 importing the RESOURCE subsystem begin class CUSTOMER the class has a FILL UP process method and a GENERATOR process method end begi
36. process notice and the process method is permitted to suspend execution using a wait suspend or request statement However if process v is zero then no simulation is running and it is a runtime error to suspend execution Note that resources are requested and owned by the current process notice A process method can call or schedule itself or other process methods A process method that is an object method is invoked on behalf of an object and can be thought of as an activity of the object The event set can contain more than one scheduled invocation of the same or different process methods on behalf of a single object to model concurrent activities of the object A method can be invoked automatically before after scheduling canceling a process method process methods are scheduled internally endogenously however an externally scheduled process routine can call a process method to achieve the effect of exogenous scheduling A priority statement inside a begin class block specifies the priority order of the process methods of the class A priority statement outside a begin class block may specify the priority order of process methods in different classes and the priority order of processes A break ties statement may not be specified for a process method 37 3 02 Random Number Generation SIMSCRIPT III utilizes a linear congruential generator LCG to produce uniform pseudo random 31 bit values ranging from zero to 2 147 483 647
37. returns zero repeat f text_arg integer_arg A text function that returns the concatenation of integer_arg copies of text_arg For example repeat f AB 3 returns ABABAB Integer_arg must be nonnegative A null string is returned if text_arg is a null string or integer_arg is zero 58 substr f text arg integer 1 integer arg2 A text function that returns a substring of text arg when called as a right function or modifies a substring of text arg when called as a left function The substring begins with the character at position integer arg1 and continues until the substring is integer arg2 characters long or until the end of text arg is reached The first character of text arg is at position 1 For example the statement T substr f Philadelphia 6 5 assigns delph to T When called as a left function the text value assigned to the function replaces the specified substring of text arg which must be an unmonitored text variable The following assignment changes the value of T from delph to delta substr f T 4 2 z ta If the value assigned to the substring is not the same length as the substring then space characters are appended to or trailing characters are removed from the assigned value Integer arg1 must be positive and integer arg2 must be nonnegative If integer arg1 is greater than the length of text arg or integer arg2 is zero then a null string is returned when substr f is called
38. specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate If equals 1 the Weibull distribution is the same as the exponential distribution If equals 2 the Weibull distribution is the same as the Rayleigh distribution 67 5 06 Simulation between v A subprogram variable that specifies a routine to be called by the timing routine before each process method or process routine is executed or contains zero which is the default if none is to be called The process notice is removed from the event set ev s and the simulation time time v and event set index event v are updated before this routine is called however the pointer to the process notice process v is not yet assigned date f integer arg1 integer arg2 integer arg3 An integer function that returns the number of days from the origin date established by a prior call of origin r to the specified date where month m equals integer 1 day d equals integer arg2 and year y equals integer arg3 The arguments must satisfy 1 lt lt 12 1 lt 4 lt 31 y 2100 day f double arg An integer function that returns the day of the month in the range 1 to 31 for the date that is double arg days after the origin date established by a prior call of origin r The argument must be nonnegative ev s A one dimensional array of sets called the event set Each process meth
39. the range 1 to 1 The return value is in the range 2 to T arctan f double argY double argX A double function that returns the arc tangent of double argY double argX in radians Either argument may be zero but not both If double argY is positive the return value is in the range zero to If double argY is negative the return value is in the range to zero If double argY is zero and double argX is positive the return value is zero If double argY is zero and double argX is negative the return value is cos f double A double function that returns the cosine of double arg argument is specified in radians The return value is in the range 1 to 1 53 dim f array arg An integer function that returns the number of elements in array arg The argument is normally an array pointer However if the argument names an array of sets then the f set array pointer is implicitly passed in its place If the argument is zero then zero is returned div f integer arg1 integer arg2 An integer function that returns the truncated result of integer arg1 integer arg 2 Integer arg2 must be nonzero For example div f 17 5 returns 3 and 12 8 returns exp c A double constant equal to the value of e 2 718281828459045 exp f double arg A double function that returns the value of where double arg is the exponent frac f double arg
40. An integer function that returns the value of integer arg1 shifted right by integer arg2 bit positions For example shr f 23 2 returns 5 because binary 010111 23 shifted right two positions is binary 000101 5 An arithmetic shift is performed with the sign bit copied to the most significant bit positions The value of integer arg1 is returned if integer arg2is zero result is undefined if integer arg2 is negative sign f double An integer function that returns the sign of double arg 1 if the argument is positive 1 if the argument is negative and zero if the argument is zero sin f double arg A double function that returns the sine of double arg The argument is specified in radians The return value is in the range 1 to 1 56 sqrt f double A double function that returns the square root of double arg The argument must be nonnegative tan f double arg A double function that returns the tangent of double arg The argument is specified in radians xor f integer arg1 integer arg2 An integer function that returns the value obtained by performing a bitwise exclusive OR of integer arg1 and integer arg2 For example xor f 23 51 returns 36 because the bitwise exclusive OR of binary 010111 23 and binary 110011 51 is binary 100100 36 57 5 03 Text Operations concat f text argt text arg2 A text function that returns the concatenation of tw
41. E HOP with NAME MACHINE reference variable MACHINE NAME as integer variables as a MACHINE Lu E MACHIN LH reference variable reference variable DEPARTMENT INFORMATION E NO OF MACHINES UTILIZATION AVG NO OF JOBS MAXIMUM IN BACKLOG BACKLOG for each MACHINE in SHOP print 1 line with NAME MACHINE TOTAL UNITS MACHINE AVG BUSY MACHINE TOTAL UNITS MACHINE AVG BACKLOG MACHINE MAX BACKLOG MACHINE thus Kk ck Ckckckckckck ck ck ck ck kckck methods for the JOB class 100 process method ERFORM define TASK as a TASK reference variable define TOTAL WAIT WAIT as real variables for each TASK in SEQUENCE do call USE UNIT MACHINE TASK given MEAN TIME TASK yielding WAIT add WAIT to TOTAL WAIT loop DELAY TIME TOTAL WAIT end process method GENERATOR MEAN INTERARRIVAL TIME STOP TIME until TIME V gt STOP TIME do schedule a PERFORM REPERTOIRE SELECTION now wait EXPONENTIAL F MEAN INTERARRIVAL TIME 10 HOURS loop call PRINT STATISTICS stop end method READ REPERTOIRE define I as an integer variable define JOB as a JOB reference variable define TASK as a
42. E MINIMUM TIME TO UNLOAD A SHIP WAS A Meee MEAN X Skip 3 lines print 2 lines with MEAN QLENGTH MAX QLENGTH thus HE AVERAGE QUEUE OF SHIPS WAITING TO BE UNLOADED WAS MC RIK HE MAXIMUM QUEUE WAS stop end main 90 end Schedule a SHIP GEN Schedule a SHIP STO start simulation read as using unit 5 ERATOR now P SIMULATION in 80 days to keep text window open 91 6 05 Example 5 Modern Bank Single Queue Multiple Server Input data in file ex5 dat 00 24 97 58 251 57 92 4 61 28 2553294 67 60 6 299 XI di a ww w m preamble for the BANK system Example 5 importing the RESOURCE subsystem begin class CUSTOMER the class has a WAITING TIME in minutes a BANK VISIT process method and a GENERATOR process method define WAITING TIME as a real variable tally DAILY MEAN WAITING TIME as the DAILY mean MEAN WAITING TIME as the mean WAIT HISTOGRAM 0 to 100 by 5 as the histogram of WAITING TIME define GENERATOR as a process method given 2 real values day length in hours and mean interarrival time in minutes end begin class TELLER every TELLER is a RESOURCE and has an ENGAGE method define ENGAGE as a method yielding 1 real v
43. For example write Vehicle Count as The number of vehicles is i 18 Object attributes and class attributes are automatically initialized to zero Their names must be unique within the class The mode of an object attribute or class attribute must be specified by a define variable statement after the has phrase that names the attribute and within the same begin class block begin class Vehicle every Vehicle has an ID a Manufacturer a Maximum Speed and a Current Speed define ID Manufacturer Maximum Speed and Current Speed as integer variables define Manufacturer as a text variable the class has a Count and a Last ID define Count and a Last ID as integer variables end Statement normally mode is may appear within a begin class block to establish a background mode and attributes defined by subsequent has phrases will have the background mode if their mode is not specified by a define variable statement In the following example all of the attributes have the background mode of integer except Manufacturer begin class Vehicle normally mode is integer every Vehicle has an ID a Manufacturer a Maximum Speed and a Current Speed define Manufacturer as a text variable the class has a Count and a Last ID end After the begin class block the background mode reverts to its setting before the block The background settings inside the block are independent of the background settings outside the block Substit
44. INTERARRIVAL TIME 1 minutes loop end method TELLER ENGAGE yielding WAIT if AVAILABLE UNITS 0 define START TIME as a real variable START TIME TIME V call WAIT FOR 1 0 WAIT TIME V START TIME HOURS V MINUTES V else add 1 to ACQUIRED UNITS always work EXPONENTIAL F MEAN SERVICE TIME 2 minutes subtract 1 from ACQUIRED UNITS free the teller end routine SIMULATE BANK given NO OF TELLERS NO OF REPLICATIONS SEED1 SEED2 MEAN INTERARRIVAL TIME MEAN SERVICE TIME DAY LENGTH define I as an integer variable define START IM m as a real variable 93 TIME V 0 SEED V 1 SEED1 SEED V 2 SEED2 reset totals of CUSTOMER WAITING TIME create TELLER TOTAL UNITS TELLER NO OF TELLERS TELLER MEAN SERVICE TI
45. ME MEAN SERVICE TIME skip 2 lines print 5 lines with NO OF TELLERS thus NUMBER OF TELLERS FINISH TELLER QUEUE LENGTH AVERAGE CUSTOMER TIME UTILIZATION AVERAGE AX IMUM WAITING TIME HOURS MINUTES for I 1 to NO OF REPLICATIONS do START TIME TIME V reset DAILY totals of CUSTOMER WAITING TIME ACQUIRED UNITS TELLER N QUEUE TELLER schedule a CUSTOMER GENERATOR DAY LENGTH EAN INTERARRIVAL TIME now start simulation print 1 line with TIME V START TIME HOURS V DAILY AVG BUSY TELLER NO OF TELLERS DAILY AVG QLEN TELLER DAILY MAX QLEN TELLER CUSTOMER DAILY MEAN WAITING TIME thus x x KK x KK loop print 4 lines with AVG BUSY TELLER NO OF TELLERS AVG QLEN TELLER MAX QLEN TELLER CUSTOMER MEAN WAITING TIME thus AVERAGE OVER ALL REPLICATIONS KK x KK Skip 3 lines print 3 lines with CUSTOMER WAIT HISTOGRAM 1 QLEN HISTOGRAM TELLER 1 TIME V thus WAITING TIME NO WHO WAITED QUEUE LENGTH PERCENTAGE MINUTES THIS TIME OF TIME Sq uem 5 0 for 2 to 20 print 1 line with 5 I 1 5 I CUSTOMER WAIT HISTOGRAM I 1 QLEN HISTOGRAM TELLER I TIME V thus lt lt KK KK print 1 line with CUSTOMER WAIT HISTOGRAM 21 QLEN HISTOGRAM TELLER 21 TIME V thus 100 lt T 20 destroy TELLER end main define MIN TELLERS MAX TELLERS NO OF TELLERS NO OF REPLICATIONS SEED1 SEED2 as integer variables define MEAN INTERARRIVAL
46. Maker Max Speed Initial Pressure MPG Tank Size call Vehicle Initialize given Maker Max Speed Initial Pressure ID VIN Miles Per Gallon MPG Fuel Capacity Tank Size end 30 The inherited after creating and before destroying methods Construct and Destruct are invoked implicitly define Buick as a Gas Vehicle reference variable create Buick Vehicle Construct call Initialize Buick invokes Gas Vehicle Initialize given 5 2 461 Buick 95 35 22 5 15 call Print Buick Vehicle Print destroy Buick Vehicle Destruct A derived class can provide an object method implementation that overrides inherited one For example the Gas Vehicle class can override the inherited Print method begin class Gas Vehicle every Gas Vehicle overrides the Print end The new implementation calls the overridden implementation to print attributes inherited from the Vehicle class It then prints attributes defined by the Gas Vehicle class methods for the Gas Vehicle class method Print call Vehicle Print invoke the overridden implementation print 2 lines with ID Miles Per Gallon Fuel Capacity Current Gallons thus gets miles per gallon Its gallon tank contains gallons end 3l Because a Gas Vehicle object can be treated as Vehicle object a Gas Vehicle reference value can be assigned or passed to a Vehicle reference variable or ar
47. Q REQ PRIORITY 82 6 03 Example 3 A Bank with Separate Queue for Each Teller Input data in file ex3 dat preamble for the BANK system Example 3 importing the RESOURCE subsystem begin class CUSTOMER the class has a WAITING TIME in minutes a BANK VISIT process method and a GENERATOR process method define WAITING TIME as a real variable tally MEAN WAITING TIME as the mean of WAITING TIM EJ define GENERATOR as a process method given 2 real values day length in hours and mean interarrival time in minutes end begin class TELLER every TELLER is a RESOURCE has an ID NUMBER and an ENGAGE method and belongs to the TELLER POOL define ID NUMBER as an integer variable define ENGAGE as a method yielding 1 real value waiting time in minutes accumulate UTILIZATION as the mean of ACQUIRED UNITS accumulate AVG QLEN the mean AX QLEN as the maximum of N QUEUE the class has a MEAN SERVICE TIME in minutes an INITIALIZE method a SELECT method and PRINT STATISTICS method and owns the TELLER POOL 83 define define I given 1 integer value and 1 real value EAN S ERVIC as a real variable E TIM 121 as a method ITIA n
48. SIMSCRIPT Programming Manual CACI SIMSCRIPT III Programming Manual contains parts from the book SIMSCRIPT III by Stephen V Rice Ana K Marjanski Harry M Markowitz and Stephen M Bailey Copyright O 2007 CACI Products Company All rights reserved part of this publication may be reproduced by any means without written permission from CACI For product information or technical support contact CACI Products Company 1455 Frazee Road Suite 700 San Diego CA 92108 Phone 619 881 5806 Email simscript caci com The information in this publication is believed to be accurate in all respects However CACI cannot assume the responsibility for any consequences resulting from the use thereof The information contained herein is subject to change Revisions to this publication or new editions of it may be issued to incorporate such change ii Table of Content 1 INTRODUCTION TO SIMSCRIPT 1 1 01 JIANGUAGEDBASIGS 3 1 027 CHARACTER SET Cai 4 1 03 2 arte beret rete eee va tina ve ee NEMUS 4 1 04 SCIENTIFIC NOTATION AND 5 1 05 NAMED AND ENUMERATED 5 5 1 6 1 06
49. SS METHOD reete PEU ee ee dara 35 3 02 RANDOM NUMBER GENERATION 4 38 3 037 S EASISTIGS 38 MODULARITY 2 5 5 2 6 cuc oso ae ec esae a 41 AL SUBSYSTEMS RTL Ee E E 41 4 02 SOURCE CODE 45 LIBRARY M s sene seno e cene sh sas 49 5 01 MODE setae stesse sena setae erstes ae 50 5 02 NUMERIC 53 5 03 TEXT OPERATIONS Creo eee eee ena eee eek ea 58 9 04 INPUT OUTBUT ie doeet ce CHO 60 5 05 RANDOM NUMBER 2 2 1 1 20 64 5 06 SIMULATION ed ed e Ure Ded 68 5 075 2 MISCEEEANEOUS 47 55 ect oeste een cete eee teen 72 EXAMPLE 74 6 01 EXAMPLE 1 GAS 5 74 6 02 EXAMPLE 2 SIMPLE GAS STATION WITH 2 8 78 iii 6 03 EXAMPLE 3 A BANK WITH SEPARATE QUEUE FOR EACH TELLER 83 6 04 EXAMPLE 4 A HARBOR MODEL cccscssccsc
50. Shop as a Repair_Shop reference variable define V as a Vehicle reference variable define GV as a Gas_Vehicle reference variable create Shop V GV file V in Service_Queue Shop file GV in Service_Queue Shop for each V in Service_Queue Shop call Print V The body of the loop invokes Vehicle Print or Gas Vehicle Print depending on whether reference variable V holds the reference value of a Vehicle Gas Vehicle object This capability is called polymorphism and is one of the properties of Object Oriented languages 32 Suppose each vehicle in the service queue must be driven to another repair shop ten miles away for each V in Service Queue Shop schedule a Trip V given 10 30 in 0 days If the Gas Vehicle class overrides the Trip process method then Gas Vehicle Trip is scheduled for each Gas Vehicle object in the queue and Vehicle Trip is scheduled for each Vehicle object A class derived from the Repair Shop class inherits the ability to own a Service Queue set It inherits the owner attributes f Service Queue 1 Queue n Service Queue A derived class may specify accumulate and tally statements that compute statistics based on the values assigned to inherited object attributes An inherited object method that is a function including the method associated with a monitored object attribute is overridden by naming it an overrides phrase and providing left and or right implementations of the method
51. TASK reference variable define MACHINE NAME as a text variable read NO OF JOBS reserve REPERTOIRE as NO OF JOBS for I 1 to NO OF JOBS do create JOB read NAME JOB until mode is alpha do create TASK read MEAN TIME TASK NAME MACHINE LOOKUP MACHINE NAME if MACHINE TASK 0 print 1 line with MACHINE NAME JOB thus m TASK Dk ck ck ck ck ck kk ck kckckckckck ck kc kck FOR JOB TYPE destroy TASK else file TASK in SEQUENCE JOB always loop REPERTOIRE I JOB loop start new input line end 101 KKKKKKKKKKKKKKKKKKKK IS NOT D EFIN method READ PROBABILITIES define I J as integer variables for I 1 to NO OF JOBS read PROBABILITY REPERTOIRE I J read as B 1 to reread the current input line read SELECTION end method PRINT REPERTOIRE define I as an integer variable define JOB as a JOB reference variable define TASK as a TASK reference variable print 2 lines thus THE JOB TYPE DESCRIPTIONS for 1 to NO OF JOBS do JOB REPERTOIRE I print 3 lines with NAME JOB thus JOB NAME KKK KK KKK KKK KKKKKKK kk TASK SEQUENCE ACHINE MEAN TIME for each TASK in SEQUENCE JOB print 1 line with MACHINE TASK MEAN TIME TASK thus KKKKKKKKKKKKKKKKKKKK
52. TS E UNITS as as as as a method subsystem EQU EST begin class R every REQU has a U define UNITS ES LTS RIO ROCI belongs to a QU RITY ESOURCE ESS NOTICE and EU PRIO define PROCI ESS NOTIC a Se define QUEU end hods for the R ESOURCE t method ACQUI RI ED UNITS P class define as an integer variable define REQ as a R enter with ACQ while QU do EUE is remove first RI add UNITS EQU Schedule the P destroy loop move from ACQ hod AVAILABLE not empty UNITS F QU EQ from QUEUE EQ to ROCESS NOTICE REQ now an integer variable an integer variable monitored on the left an integer method requested units and priority call CLEAN UP RITY as integer variables as a pointer variable ranked by high PRIORITY EST reference variable UNITS return with TOTAL UNITS EU E lt TOTAL UNITS ACQ ACQUIRED UNITS 87 method WAIT FOR REQ define create REQ as UNITS a REQUEST reference variable UNITS REQ R EQ UNITS PRIORI TY REQ PROCESS file R NOTICE EQ in QU suspend end
53. Vehicle object The object method Flat Tires is a function that returns the number of under inflated tires The object method Print writes a description of a Vehicle and the class method Print Count writes the current number of Vehicle objects 22 begin class Vehicle every Vehicle has a Construct method a Destruct method an Initialize method Flat Tires method and a Print method after creating a Vehicle call Construct before destroying a Vehicle call Destruct define Initialize as a method given a text argument name of manufacturer a double argument maximum speed and a real argument initial tire pressure define Flat Tires as an integer method given a real argument minimum tire pressure the class has a Print Count method end An object method is may be invoked with given and yielded arguments A reference value expression is specified in parentheses after an object method name and before any given arguments A class method name must be qualified The following statements invoke the methods of the Vehicle class and the Chevy object methods define Chevy as a Vehicle reference variable create Chevy implicit call Construct Chevy call Initialize Chevy given Chevrolet 90 32 if Flat Tires Chevy 25 is zero write as Tires are okay always call Print Chevy call Vehicle Print Count destroy Chevy implicit call Destruct Chevy The reference value of an object is passed implicitly
54. a free form read statement using the current input unit or returns zero if there are no more input values wcolumn v An integer variable that contains the column number of the last character written to the current output line or zero if no character has been written Each output unit has its own copy of this variable wopenerr v An integer variable that equals 1 to indicate that an error occurred when opening the file associated with the current output unit or equals zero if no error occurred If the Open statement for the unit specifies the noerror keyword then the program can check the value of this variable after a use statement to determine whether an error occurred when opening the file otherwise such an error causes the program to terminate Each output unit has its own copy of this variable wrecord v An integer variable that contains the number of lines written to the current output unit Each output unit has its own copy of this variable write v An integer variable that contains the unit number of the current output unit Its initial value is 6 because unit 6 standard output is the current output unit when a program begins execution The assignment write v changes the current output unit and has the same effect as the statement use N for output 63 5 05 Random Number Generation beta f double arg1 double arg2 integer A double function that returns a random number in the rang
55. able read v An integer variable that contains the unit number of the current input unit Its initial value is 5 because unit 5 standard input is the current input unit when a program begins execution The assignment read v changes the current input unit and has the same effect as the statement use N for input record v integer An integer function that returns the number of lines read from or written to the specified I O unit Integer arg must be a valid unit number ropenerr v An integer variable that equals 1 to indicate that an error occurred when opening the file associated with the current input unit or equals zero if no error occurred If the Open statement for the unit specifies the noerror keyword then the program can check the value of this variable after a use statement to determine whether an error occurred when opening the file otherwise such an error causes the program to terminate Each input unit has its own copy of this variable rreclen v An integer variable that contains the number of characters read in the current input line excluding the end of line character Each input unit has its own copy of this variable rrecord v An integer variable that contains the number of lines read from the current input unit Each input unit has its own copy of this variable 62 stield f An integer function that returns the starting column number of the next value to be read by
56. ach random number stream stream number is used as an index into the array The number of array elements returned by dim f seed v is the number of streams and is initially 10 however the program may release the array and reserve it to change the number of streams triang f double arg1 double arg2 double arg3 integer arg A double function that returns a random number in the range m to n from the triangular distribution having parameters equal to double arg peak k the mode equal to double arg2 and n equal to double arg3 and mean equal to where m lt k lt n Integer must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate 66 uniform f double arg1 double 2 integer A double function that returns a random number in the range m to from the continuous uniform distribution having parameters equal to double arg1 and n equal to double arg2 and mean u equal to Where m n Integer arg must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate weibull f double arg1 double arg2 integer A double function that returns a nonnegative random number from the Weibull distribution having shape parameter o equal to double arg1 and scale parameter equal to double arg2 where a gt 0 and gt 0 Integer arg must
57. alue waiting time in minutes accumulate DAILY AVG BUSY as the DAILY mean AVG BUSY as the mean of ACQUIRED UNITS accumulate DAILY AVG QLEN as the DAILY mean DAILY MAX QLEN as the DAILY maximum AVG QLEN as the mean 92 the class MAX QLI OLI of N Q EN H T U as the maximum STOGRAM 0 to 20 by 1 EU has 5 define EA 25 define SIMULAT given 4 integer values E BANK as a and 3 real values end process method C USTOM call ENGAG E T ELL ER yie end process method CUSTOM routine nos stream 1 s of tellers d as in minutes no stream 2 s the histogram as a real variable of replications mean servic tim ER BANK VISIT lding WAITING TIM R G EN tal d mean interarrival time in minutes in minutes day length in hours ERATOR DAY LI ENGTH M EAN INT ERARRIVAL TIME define TIME TO CLOSE as a real variable TIME TO CLOSE TIME V DAY LENGTH HOURS V until TIME V TIME TO CLOSE do Schedule a BANK VISIT now wait EXPONENTIAL F MEAN
58. alues 128 to 159 are non printable Latin1 characters Values 160 to 255 are printable Latinl characters and include these letters A A AAAA ECE EIj i iibNO O0 00UU 0 0Ybn a a ece eei ii no o o oguu u ybpy and these special symbols 8 8 2 gt 237 4 1 UAE Words in the following languages can be represented using the Latinl character set Afrikaans Albanian Basque Catalan Danish Dutch Faroese Finnish French German Icelandic Irish Italian Norwegian Portuguese Romansh Scottish Gaelic Spanish Swahili and Swedish Latinl characters can appear in SIMSCRIPT III source code and in program input and output and can be stored in alpha and text variables For example define CAF as a text variable CAFE Le Loir dans la Th i re write CAFE as Le nom du caf est t The character set supported by SIMSCRIPT 5 is ASCII which is a 7 bit character code 1 083 Comments SIMSCRIPT III supports single and multiple line comment single line comment begins with a pair of consecutive apostrophes and terminates at the end of the line or upon reaching another pair of apostrophes on the same line comments are for human readers the compiler ignores them This block of code if N 0 variable is uninitialized read number of elements into N always reserve X as allocate the array is equivalent to if N 0 read N always rese
59. aration and within the same begin class block define method statement is similar to a define routine statement If the define method statement is omitted the method is assumed to be a subroutine with no arguments The names of methods and attributes must be unique within the class however these names may be defined elsewhere in the program including in other classes If an object method is a subroutine with no arguments it may be specified in an after creating statement within a begin class block which causes the method to be invoked implicitly on behalf of an object after a create statement has allocated the object and initialized its attributes to zero Since this method cannot accept arguments the program can define and explicitly call another object method that accepts arguments and uses them to initialize attributes of the new object to nonzero values If an object method is a subroutine with no arguments it may be specified in a before destroying statement within a begin class block which causes the method to be invoked implicitly on behalf of an object before a destroy statement has de allocated the object In our Vehicle example we define five object methods and one class method The object method Construct is invoked automatically after a Vehicle is created and the object method Destruct is invoked automatically before a Vehicle is destroyed The object method Initialize is given three arguments which are used to initialize a
60. ariable read J if 1 lt J lt dim f Y write Y J as The value is d 7 2 else invalid entry write as The index is out of bounds always The select statement is a case statement in which one of several blocks of statements is chosen for execution based on the value of an expression 10 1 11 Loops A loop is specified by one or more control phrases followed by the body of the loop which is either a single statement or a sequence of statements between the keywords do and loop A for phrase causes the body of the loop to be executed once for each value assigned to a control variable for example for 1 to A while or until phrase specifies a logical expression and terminates the loop when the expression is false or true A with or unless phrase specifies a logical expression and executes the body of the loop for the current iteration when the expression is true or false These phrases may be combined to control loop execution In addition leave and cycle statements may be specified in the body of the loop a leave statement terminates the loop and a cycle statement terminates the current iteration of the loop A find or compute statement may be specified in the body of a loop A find statement terminates the loop when the body is executed for the first time and is followed by an if found or if none phrase which evaluates to true if the body of the loop was or was not executed For each execution of th
61. as a right function and no modification is made to text arg when substr f is called as a left function trim f text arg integer A text function that returns the value obtained by removing leading and or trailing blanks if any from the value of text arg If integer arg is zero leading and trailing blanks are removed if integer arg is negative only leading blanks are removed and if integer arg is positive only trailing blanks are removed If text arg is the null string or contains all blanks then a null string is returned For example trim f Hello 0 returns Hello upper f text arg A text function that returns the value of text arg with each lowercase letter converted to uppercase other characters are unchanged For example upper f Chicago returns CHICAGO and upper f caf returns CAF 59 5 04 Input Output buffer v An integer variable that specifies the length of buffer when the first use the buffer statement is executed Its default value is 132 efield f An integer function that returns the ending column number of the next value to be read by a free form read statement using the current input unit or returns zero if there are no more input values eof v An integer variable that specifies the action to take when an attempt is made to read data from the current input unit beyond the end of file If the value of the variable is zero which is the default
62. by value to an object method and must be nonzero It is accessible within the object method in an implicitly defined local reference variable that has the same name as the class Because a class method is not invoked on behalf of an object a reference value is not passed to a class method and this local reference variable is not defined within a class method A method implementation begins with the keyword method The following is an implementation of the Construct object method 23 method Vehicle Construct add 1 to Count add 1 to Last ID ID Vehicle Last ID Manufacturer Vehicle Unknown reserve Tire Pressure Vehicle as Num Tires end As shown above the names of class attributes Count and Last ID and the name of the class constant Num Tires do not need to be qualified within a method of the class However the method name Vehicle Construct must be qualified unless it follows a methods heading that names the class object attributes ID Manufacturer and Tire Pressure are subscripted by the implicitly defined local reference variable named Vehicle that contains the reference value of the Vehicle object for which the method was invoked However these subscripts may be omitted and are implicit when accessing object attributes and calling object methods With these changes here is an equivalent implementation of the Construct method followed by implementations of the other Vehicle methods methods for the Vehicle
63. cecessessceceeeceesesessnseeeeeeceseeesenseaeees 89 6 05 EXAMPLE 5 THE MODERN BANK ccssccsccsccesessessececesececeesessaeceeeeeesesenenseaeees 92 5 een emere ene seen ennt 92 6 06 EXAMPLE 6 A JOB SHOP MODEL eese nennen 98 6 07 EXAMPLE 7 A COMPUTER CENTER STUDY cccssssccssececeesssssseceeesecseesssnseaeees 106 iv 1 Introduction to SIMSCRIPT Ill The SIMSCRIPT III programming language is a superset of SIMSCRIPT 5 with significant new features to support modular object oriented simulation programming It preserves existing world view and the powerful data structures entities attributes and sets process and event oriented discrete simulation of SIMSCRIPT IL5 and adds the new more elaborated data structures and concepts like classes methods objects multiple inheritance and process methods to support object view and object oriented process and event discrete simulation Object types are defined with the class which can be instantiated they may have methods which describe object behavior and may contain special process methods with time elapsing capabilities which can be scheduled for execution in defined instances of time Both world view and object view can exist in the same model or a modeler may decide to use entirely object view or a world view only SIMSCRIPT III model can consist
64. d average speed in mph yielding 1 double argument trip duration in hours end methods for the Vehicle class process method Trip given Distance Average Speed yielding Duration define Start Time as a double variable Start Time time v Current Speed z min f Average Speed Maximum Speed wait Distance Current Speed hours Current Speed 0 Duration z time v Start Time hours v Trip Distance Distance update Odometer end This process method can be called directly for example call Trip Chevy given 600 55 yielding Trip Duration In this case the caller waits for the trip to complete and receives the duration of the trip in the yielded argument However a trip can be scheduled to begin now schedule a Trip Chevy given 600 55 in 0 days or to begin sometime in the future schedule a Trip Chevy given 600 55 in 3 days 35 The routine that executes the schedule statement does not wait for the trip to complete and continues on without delay to the next statement of the routine Upon completion of the trip argument values yielded by the process method are discarded In this example there is no one waiting to receive the duration of the trip however this information could be saved by the process method in an attribute If the process method is an object method then an explicit or implicit reference value subscript must follow the method name If the process method is a class method however the method i
65. dinate modules called subsystems Main module consists of a preamble followed by one or more routines including a main routine The preamble declarations are visible only to the routines of the main module A SIMSCRIPT II 5 program can be viewed as a SIMSCRIPT III main module Subsystem is a named module consisting of a public preamble followed by an optional private preamble and zero or more routines The declarations in the public preamble are visible to the private preamble and routines of the subsystem and to every module that imports this subsystem The declarations in the private preamble are visible only to the routines of the subsystem It is easier to develop and maintain a large program that has been divided into meaningful units Subsystems promote better source code organization and facilitate the reuse of code The public preamble of a subsystem defines the interface to the subsystem and the implementation is hidden in the private preamble and routines of the subsystem A module may import any number of subsystems and a subsystem may be imported by any number of modules A subsystem may be distributed as a source file containing only the public preamble and one or more binary object files obtained by compiling the subsystem The source file documents the subsystem interface and is read by the compiler when compiling a module that imports the subsystem An executable program is built by linking the binary object files that
66. e error occurs and the value of batchtrace v is 1 The subroutine may write to the file named simerr trc by writing to the current output unit wordsize f An integer function that always returns 32 for 32 bit SIMSCRIPT III products or 64 for 64 bit SIMSCRIPT Note that this function does NOT necessarily return with word size of the architecture 73 6 Example Programs 6 01 Example 1 Gas Station preamble for the GAS STATION system Example 1 importing the RESOURCE subsystem begin class CUSTOMER the class has a FILL UP process method and a GENERATOR process method end begin class ATTENDANT every ATTENDANT is RESOURCE and has a PRINT STATISTICS method accumulate AVG QLEN as the average MAX QLEN as the maximum of N QUEUE accumulate AVG BUSY as the average of ACQUIRED UNITS end end process method CUSTOMER FILL UP if AVAILABLE UNITS ATTENDANT 0 no attendants available call WAIT FOR ATTENDANT 1 0 wait for an attendant else add 1 to ACQUIRED UNITS ATTENDANT always work UNIFORM F 5 0 15 0 2 minutes fill up subtract 1 from ACQUIRED UNITS ATTENDANT end process method CUSTOMER GENERATOR define I as an integer variable for I 1 to 1000 do Schedule a FILL UP now wait UNIFORM F 2 0 8 0 1 minutes loop end 74 method ATTENDANT PRINT STATISTICS
67. e body of the loop a compute statement evaluates an arithmetic expression and computes statistics e g sum mean maximum minimum from the values of the expression over the life of the loop 1 12 Functions and Subroutines A subroutine is a block of code which can be written once and invoked from different places in the program In SIMSCRIPT subroutines are recursive which means the same subroutine can be invoked by itself A function is a routine that returns a function result A subroutine does not return a function result Functions and subroutines may have one or more given arguments however only subroutines may have yielded arguments The value of a given argument is an input to the routine whereas the value of a yielded argument is an output from the routine Each function and subroutine is declared by a define statement in the preamble which specifies the number and mode of arguments and the mode of the function result for functions To call a function with n given arguments the function name is followed by a parenthesized list of n expressions for example F I J A subroutine is invoked by a call statement for example call Analyze given A B yielding C D A function is terminated by a return with statement which specifies the function result A subroutine terminates when a return statement is executed or the end of the subroutine is reached 11 The following function has three given arguments a one dimensional a
68. e public preambles of S1 and S2 then the three definitions may be accessed within module M by using the qualified names M C S1 C and S2 C The local definition may be accessed without qualification that is C and M C are synonymous Suppose 1 C is a class that has a class attribute named A This attribute may be accessed within module M by using the qualified name S1 C A If such a name is unwieldy a substitution can be defined for it for example define CA to mean S1 C A The method implementations of a class must appear within the module that defines the class A private class is defined by one or more begin class blocks within the preamble of a main module or within the private preamble of a subsystem private class is visible only to the defining module A public class is defined by one or more begin class blocks within the public preamble of a subsystem and by zero or more begin class blocks within the private preamble of the subsystem The public part of a public class is specified in the public preamble whereas the private part of a public class is hidden in the private preamble This makes it possible for a class to have a public interface yet also have private attributes methods and sets and even private base classes Substitutions defined by define to mean and substitute statements and the settings established by normally and suppress resume statements in effect at the end of the public preamble of a subsystem are in
69. e zero to one from the beta distribution having shape parameters o equal to double arg1 and a equal to a double_arg2 and mean u equal to where gt 0 and gt 0 Integer arg must a a specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate binomial f integer_arg1 double_arg integer_arg2 An integer function that returns a random number in the range zero to n from the binomial distribution having parameters n equal to integer_arg1 and p equal to double arg and mean equal to np where gt 0 and gt 0 The return value represents a random number of successes in n independent trials where p is the probability of success for each trial Integer arg2 must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate If n equals 1 the binomial distribution is the same as the Bernoulli distribution erlang f double arg integer argt integer arg2 A double function that returns a nonnegative random number from the Erlang distribution having mean equal to double arg shape parameter o equal to integer arg1 and scale parameter 2 equal to where gt 0 0 Integer arg2 must specify a random number stream between 1 and dim f seed v or negative stream number to generate the antithetic variate exponential f double arg integer arg A double
70. ement the reference value of the process notice for the least imminent invocation largest time a of a process method or process type or is zero if there are no scheduled invocations The number of elements in this array is contained in events v minute f double An integer function that returns the minute part in the range 0 to minutes v 1 of the number of days specified by double arg which must be nonnegative minutes v A double variable that specifies the number of minutes per hour Its default value is 60 0 69 month f double An integer function that returns the month in the range 1 to 12 for the date that is double arg days after the origin date established by a prior call of origin r argument must be nonnegative n ev s integer arg An integer function that returns the number of process notices in ev s integer arg The argument must be in the range 1 to events v nday f double An integer function that returns the day part of the number of days specified by double arg which must be nonnegative origin r integer 01 integer arg2 integer arg3 A subroutine that establishes the specified date as the origin where month equals integer arg1 day d equals integer arg2 and year y equals integer arg3 The arguments must satisfy 1 lt m x12 1x d lt 31 and y 2100 process v A pointer variable that contains the reference value of the proces
71. ent In the following example a double function named F is declared Its first argument is integer its second argument is double and its third argument is integer define F as a double function given an integer argument a double argument and an integer argument The following statement declares a subroutine named Test given a text value and a one dimensional integer array and yielding two double values define Test as a routine given a text argument and a 1 dimensional integer argument yielding 2 double arguments The compiler checks each routine call to verify that the caller s arguments are compatible with the routine s arguments caller s given value is converted to the mode of the routine s given argument and a routine s yielded value is converted to the mode of the caller s yielded argument if the argument modes differ and mode conversion is possible For example a double value passed to an integer argument is automatically converted to integer If the argument modes differ but mode conversion is not permitted for example passing a text value to a double argument the compiler issues an error message When the mode and dimensionality of a routine s arguments have been declared in a define routine statement it is not necessary to define the mode and dimensionality of the arguments within the routine implementation But if they are defined within the routine implementation their definitions must agree with the definitions in
72. function that returns a nonnegative random number from the exponential distribution having mean equal to double arg where gt 0 Integer arg must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate 64 gamma f double arg1 double arg2 integer arg A double function that returns a nonnegative random number from the gamma distribution having mean equal to double arg shape parameter o equal to double arg2 and scale parameter equal to Ls where gt 0 and gt 0 Integer arg must specify a random number stream between 1 and dim f seed v a negative stream number to generate the antithetic variate equals 1 the gamma distribution is the same as the exponential distribution If is an integer the gamma distribution is the same as the Erlang distribution If is an integer and equals 5 the gamma distribution is the same as the chi square distribution with degrees of freedom log normal f double arg double arg2 integer A double function that returns a nonnegative random number from the lognormal distribution having mean equal to double arg1 and standard deviation o equal to double arg2 where gt 0 and o gt 0 Integer arg must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate normal f double_arg1 double_arg2 i
73. gument However a Vehicle reference value cannot be assigned or passed to a Gas Vehicle reference variable or argument When the Print method is called using a Vehicle reference variable that contains a Gas Vehicle reference value Gas Vehicle Print is invoked For example define V as a Vehicle reference variable create V create a Vehicle object call Print V invoke Vehicle Print destroy V destroy the Vehicle object define GV as a Gas Vehicle reference variable create GV create a Gas Vehicle object call Print GV invoke Gas Vehicle Print V GV assign Gas Vehicle reference value to Vehicle reference variable call Print V invoke Gas Vehicle Print destroy V destroy the Gas Vehicle object create V create a Vehicle object GV V allowed this is flagged by the compiler A variable can be checked at runtime to determine if it contains a reference value of an object belonging to a particular class The following logical condition is true if the variable P refers to a Vehicle object or to an object of a class derived from Vehicle such as a Gas_Vehicle object if P is a Vehicle reference A Service_Queue set may contain not only Vehicle objects but also objects of classes derived from Vehicle A Gas_Vehicle object has inherited the ability to be a member of a Service_Queue set It has inherited the member attributes p Service_Queue s Service_Queue and m Service_Queue from the Vehicle class define
74. ions are used The public preamble of a subsystem is placed in one file say shipping sim for the shipping subsystem and the ied preamble and subsequent implementation code is placed a second file with i appended to its name this case shipping i sim Building SIMSCRIPT III projects is facilitated by the Interactive Development Environment IDE called Simstudio This is fully described in the SIMSCRIPT III User Manual SIMSCRIPT III projects can also be built using the command line interface also described in the User Manual 47 5 Library m Library m is a special module that is implicitly imported by every preamble This module defines routines variables and constants which are accessible to every module These definitions may be accessed without qualification for example time v or with qualification for example library m time v The library m definitions are described in the sections of this chapter 5 01 Mode Conversion 5 02 Numeric Operations 5 03 Text Operations 5 04 Input Output 5 05 Random Number Generation 5 06 Simulation 5 07 Miscellaneous 49 5 01 Mode Conversion atot f alpha arg A text function that returns a text value of length one containing alpha arg as its only character For example atot f B converts an alpha B to a text B int f double arg An integer function that returns the value obtained by rounding double arg to the nearest integer
75. ith TOTAL UNITS ACQUIRED UNITS 96 method WAIT FOR REQ UNITS REQ PRIORITY define REQ as a REQUEST reference variable create REQ UNITS REQ REQ UNITS PRIORITY REQ REQ PRIORITY PROCESS NOTICE REQ PROCESS V file REQ in QUEU suspend end method CLEAN UP define REQ as a REQUEST reference variable while QUEUE is not empty do remove first REQ from QUEUE destroy PROCESS NOTICE REQ destroy REQ loop end 97 6 06 Example 6 Job Shop Model Input data in file ex6 dat 6 14 CASTING UN 5 LATHES 4 PLANES ITS 8 DRILL PRES S 16 SHAPERS 4 POLISHING 3 IRST 0833 5833 222323 0 ECOND 1 75 SHAPE 1 5 DRILL CASTI PLA LAT POI E HE IS Li E 2 0 0 1 5 RS ACHINI Lud G UNITS S S HING MACHINES ESS E 1 0833 LATHE THIRD 3 9166 4 1666 0 8333 CASTI SHAPE DRILL R S RS PR LES ESSES 0 5 0 4166 END 0 16 40 241 1 PLANE POLIS 44 preamble for the importing the begin class every MACH AC S HING MACHINES 2 2253 JOB SHOE RESOURCE system H s is a RE RCE has a as and a U belongs define NA define STR define USE UNIT as a
76. le anyname sim Some code for the system s implementation routine routine1 end main end 46 Eng file anyname sim To formally state the rules on how we can place public preambles private preambles system preambles and implementation code into source files Public preamble 1 Only one public preamble per subsystem is allowed 2 It must appear first in the source file 3 It cannot span multiple files 4 The file containing the public preamble must be named after it The file X sim will contain the public preamble for the X subsystem Private preambles Pi 2 dien pisos per subsystem 7 It appear either preamble first in the source file or immediately after a public Preamble for the main module 8 Only one main module preamble for the entire program is allowed 9 It must appear first in the source file 10 Subsystems cannot import from the ma in module preamble Implementation code 11 Code for a subsystem must appear after a public preamble private preamble or implementation for heading Code can span multiple files 12 Code for the system must appear after the system s preamble or in a file by itself with no heading Code can span multiple files Adopting some sort of convention is regarding the placement of source code in files is advisable For example in many of the demo programs for SIMSCRIPT III the following convent
77. les and arguments can be reference variables A function that returns a reference value has a reference mode The background mode set by a normally statement can be a reference mode Preamble declarations may specify a reference mode before the entity type is declared for example Ship reference may appear in statements that precede the declaration of the Ship entity type 15 2 Object Oriented Programming 2 01 Classes and Objects A class is defined by one or more begin class blocks appearing in a preamble following block defines a class named Vehicle begin class Vehicle end Definitions of attributes methods and sets are placed within these blocks A class also defines reference mode of the same name so a reference variables of that mode can be declared like define Car as a Vehicle reference variable The following statement allocates a Vehicle type object initializes its attributes to zero and assigns its reference value to the reference variable named Car create Car The following statement de allocates the object whose reference value is stored in Car destroy Car An array of objects can be created and destroyed define Fleet as a 1 dimensional Vehicle reference array reserve Fleet as 50 for J 1 to 50 create Fleet J for J 1 to 50 destroy Fleet J release Fleet 17 2 02 Attributes Object attributes are declared in every statement within begin class blocks In the following example e
78. ment begin class Repair Shop every Repair Shop owns a Vehicle Service Queue end begin class Vehicle 26 every Vehicle belongs to a Service Queue define Service Queue as a FIFO set end The implicitly defined member set attributes of a Vehicle object are p Service Queue s Service Queue and m Service Queue The implicitly defined owner set attributes of a Repair Shop object are f Service Queue l Service Queue and n Service Queue mode of attributes Queue s Service Queue f Service Queue l Service Queue is Vehicle reference A file statement inserts an object into a set Variations of this statement permit the object to be inserted first or last in the set or immediately before or after a specified object If the position is unspecified the object is placed into the set according to the set discipline which may be FIFO LIFO or ranked i e ordered according to attribute values of the members The set discipline is declared by a define statement in the begin class block of the member class and is FIFO by default A remove statement removes an object from a set Variations of this statement remove the first or last object or a specific object from the set A for each loop control phrase traverses a set in the forward or reverse direction executing the body of the loop once for each member of the set Special logical expressions test whether an object is in a set and whether a set is em
79. n class GAS STATION RESOURCE every GAS STATION RESOURCE is RESOURCE and has a REQUEST method a RELINQUISH method a UTILIZATION method and accumulate AVG QLI as the average MAX QL I as the maximum of N QUEUE accumulate AVG BUSY as the average of ACQUIRED UNITS P E define UTILIZATION as a double method end begin class ATTENDANT every ATTENDAN is a GAS STATION RESOURCE and has a PRINT STATISTICS method end begin class PUMP every PUMP is a GAS STATION RESOURCE and has a PRINT STATISTICS method define PRINT STATISTICS as a method given a text argument name of grade the class has a REGULAR a PREMIUM a PRINT ALL STATISTICS method and a SELECT method define REGULAR PREMIUM as PUMP reference variables define SELECT as a PUMP reference method end end methods for the CUSTOMER class 78 process met hod FILL UP define PUMP as a PUMP reference variable PUMP PUMP SELECT call EST PUMP call work call ATTENDANT 2 4 2 minutes ISH ATTENDANT insert nozzle work minutes M F 5 9 2 fill up unattended call work call EST ATT NIFORM F 3 ELINQ ENDANT 5 2 ISH ATTENDANT G call QUISH PUM P end method G EN proces
80. nitored object attribute or class attribute This method has the same name and mode as the attribute and is given n integer arguments where n is the dimensionality of the attribute It has left and or right implementations depending on whether the attribute is monitored on the left and or the right A method may not be represented as a subprogram literal and called using a subprogram variable 25 2 04 Grouping Objects Sets Objects as well as entities can be grouped in sets A set is a doubly linked list with a programmer defined name The owner of a set of objects named List has three owner attributes reference variables F List and L List which identify the first and last objects in the set and N List which holds the number of objects in the set A member of this set has three member attributes reference variables P List and S List which identify the predecessor and successor objects in the set and M List which indicates whether this object is in a set named List An object may own and belong to any number of sets Each belongs phrase in an every statement names a set in which an object may be a member Each owns phrase in an every statement names a set owned by an object An owns phrase in the class statement names a set owned by the class The set named in an owns phrase is qualified by the name of the member class A belongs phrase in an every statement appearing inside a begin class block defines a set that contains objects
81. nteger_arg A double function that returns a random number from the normal distribution having mean 4 equal to double arg1 and standard deviation equal to double_arg2 where gt 0 Integer arg must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate poisson f double arg integer An integer function that returns a nonnegative random number from the Poisson distribution having mean equal to double arg where gt 0 Integer arg must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate 65 randi f integer arg1 integer arg2 integer arg3 An integer function that returns a random number in the range to n from the discrete uniform distribution having parameters equal to integer arg1 and n equal to m n integer arg2 and mean equal to Where mn Integer arg3 must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate random f integer A double function that returns a uniform random number in the range 0 to 1 Integer arg must specify a random number stream between 1 and dim f seed v or a negative stream number to generate the antithetic variate equal to 1 random f integer arg seed v A one dimensional integer array that contains the current seed value for e
82. o or more text arguments For example concat f Phi ladelp hia returns Philadelphia Keep in mind that the operator can be used for concatenation For example let philly Phi ladelp hia fixed f text arg integer A text function that returns the value obtained after appending space characters to or removing trailing characters from the value of text arg to make its length equal the value of integer arg For example fixed f abcd 2 returns ab and fixed f abcd 5 returns abcd Integer arg must be nonnegative if it is zero a null string is returned length f text arg An integer function that returns the number of characters in text arg For example length f Chicago returns 7 and length f returns zero lower f text arg A text function that returns the value of text arg with each uppercase letter converted to lowercase other characters are unchanged For example lower f Chicago returns chicago and lower f CAF returns caf match f text arg1 text arg2 integer arg An integer function that returns the position of the first occurrence of text arg2 in text arg1 excluding the first integer arg characters of text arg1 or returns zero if there is no such occurrence Zero is returned if text arg or text arg2 is the null string Integer arg must be nonnegative For example match f Philadelphia hi 2 returns 10 and match f Chicago hi 2
83. o perform other arithmetic operations including logarithms modulus square root and trigonometric functions Logical expressions may use relational operators lt gt lt gt and logical operators and and or Logical negation is specified by appending is false to a logical expression The expression J gt 1 and J lt dim f Y may be abbreviated as 1 lt J lt dim f Y Logical expressions use short circuit evaluation that is if the first operand of and evaluates to false or the first operand of or evaluates to true the second operand is not evaluated 1 10 Basic Statements Multiple statements may appear on one line and one statement may span multiple lines A semicolon is not required but is allowed after a statement The following statement assigns the value 10 to the variable named X X 10 The optional let keyword can be also used let X z 10 The statement add 1 to X is equivalent to X X 1 Likewise X may be decremented by subtract 1 from X The read statement reads free form and formatted input The write and print statements produce formatted output The open and close statements open and close files The if statement specifies a logical expression followed by a sequence of statements to execute if the expression is true and optionally by else and a sequence of statements to execute if the expression is false It is terminated by the keyword always For example define J as an integer v
84. ocess based simulation models SIMSCRIPT program consists of a main module and zero or more imported subordinated modules called subsystems or packages Main module consists of a block of declarations known as the preamble followed by one or more functions and routines one of which is named main The simplest main module without a preamble in SIMSCRIPT would main print 1 line thus Hello World end or with a preamble preamble define Greeting as a text variable end main Greeting Have a nice day write Greeting as T end Declarations in the preamble are global i e they apply to every routine in the module Declarations within a routine are local i e they apply only to the routine in which they are declared Other levels of scope object scope class scope public and private scope of the subsystem will be described in the chapters that follow Program execution begins with the first statement in main and continues until main returns or a stop statement is executed Programmer defined names and language keywords are case insensitive A programmer defined name is a sequence of letters digits periods dollar signs and underscores Except for and there are no reserved words 1 02 Character Set The character set supported by SIMSCRIPT III is Latinl more formally ISO 8859 1 which is 8 bit character encoding that includes ASCII as a subset Values 0 to 127 are defined by ASCII and v
85. od and process type in the program is assigned a unique index into this array A smaller index value gives higher priority to the process method or process type The set at an index contains a process notice for each scheduled invocation of the process method or process type associated with the index The process notices are ranked within the set by increasing time of occurrence time a The number of elements in this array is contained in events v event v An integer variable that contains the event set index in the range 1 to events v of the current process method or process type during a simulation 68 events v An integer variable that contains the largest event set index which is equal to the total number of process methods and process types defined by the program f ev s A one dimensional pointer array that contains in each element the reference value of the process notice for the most imminent invocation smallest time a of a process method or process type or is zero if there are no scheduled invocations The number of elements in this array is contained in events v hour f double arg An integer function that returns the hour part in the range 0 to hours v 1 of the number of days specified by double arg which must be nonnegative hours v A double variable that specifies the number of hours per day Its default value is 24 0 l ev s A one dimensional pointer array that contains in each el
86. of sets can be declared as illustrated by the following example every Ship belongs to a Fleet normally dimension is 1 the system owns the Fleet The following statements reserve and release an array of sets Fleet reserve Fleet as 100 release Fleet The number of elements in this array of sets is obtained by dim f Fleet 28 2 06 Inheritance A new class similar to the existing classes defined in the model can be derived from one or more existing classes by inheriting their attributes and methods This language property is named inheritance In single inheritance a class is derived from one base class In multiple inheritance a class is derived from two or more base classes SIMSCRIPT III supports both single and multiple inheritance A derived class inherits the object attributes of each of its base classes This means that an object of a derived class has a copy of each object attribute defined or inherited by its base classes In addition the derived class may define object attributes of its own In the following example a class named Gas Vehicle is derived from the Vehicle class which is indicated by the is a phrase of the every statement Each Gas Vehicle object has the object attributes of a Vehicle such as ID Manufacturer etc and the object attributes defined here Miles Per Gallon Fuel Capacity and Current Gallons begin class Gas Vehicle every Gas Vehicle is a Vehicle and has a Miles Per Gallon a Fuel
87. our example we wish to measure how well a repair shop is doing its job and assume that after each vehicle is serviced the time required to service the vehicle is assigned to an object attribute named Service Time A tally statement specifies that the average and maximum service time is to be computed from the values assigned to this attribute An accumulate statement indicates that the time weighted average of the length of the service queue is to be computed The number of vehicles in the queue is maintained in the implicitly defined object attribute named N Service Queue which is automatically updated whenever a vehicle is inserted into the queue by a file statement or removed from the queue by a remove statement A Print Statistics method displays the results 38 begin class Repair Shop every Repair Shop has a Service Time and a Print Statistics method and owns a Vehicle Service Queue define Service Time as a double variable tally Avg Service Time as the mean and Max Service Time as the maximum of Service Time accumulate Avg Queue Length as the mean of N Service Queue end methods for the Repair Shop class method Print Statistics print 3 lines with Avg Service Time Max Service Time and Avg Queue Length as follows Average service time is Maximum service time is Average queue length is end 39 4 Modularity 4 01 Subsystems SIMSCRIPT III program consists of main module and zero or more subor
88. piler In this example a period is placed at the end of the define statement and a semicolon after each assignment statement Define X Y and Z as double variables X 3 5026E5 assign 350260 0 to X Y 1 72e 03 assign 0 00172 to Y 27 641 2 assign 2764 1 to Z 1 05 Named and Enumerated Constants Named constants are defined with a specified value in define constant statement More than one constants can be defined in a single statement for example define Max Capacity 100 as a constant Or define Min Capacity 5 and Max Capacity 100 as constants Named constants are not limited to integers for example define cm per inch z 2 54 cm z centimeters as constants write 12 cm per inch cm as d 5 2 t The above write statement writes the number of centimeters in one foot 30 48 centimeters If the value of a named constant is unspecified it is assigned the integer value that is one greater than the value of the preceding integer constant in the statement or assigned a value of one if there is no preceding integer constant In the following example the constants named F D C B and A represent letter grades and are assigned values zero through four and the constants Idle Busy and Terminated are given values one to three define F 0 D C constants define Idle Busy and Terminated as constants Named constants declared in a preamble are global that is they are accessible to eve
89. pty For example The following statements illustrate operations involving the Service Queue set define Car and MyCar as Vehicle reference variables define EZ Auto and Ferrari Depot as Repair Shop reference variables create MyCar EZ Auto and Ferrari Depot for each Car in Service Queue EZ Auto with Manufacturer Car Ferrari do remove Car from Service Queue EZ Auto file Car in Service Queue Ferrari Depot write as Transferred call Print Car loop if Service Queue EZ Auto is empty write as Time for a coffee break always if MyCar is in Service Queue write as My car is in the shop always An object may belong to any number of sets An object or class may own any number of sets and arrays of sets A set contains either objects or entities but not a mixture of the 27 two An object method or class method be invoked automatically before after filing removing an entity or object into a set owned by an object or class A belongs phrase in an every statement appearing outside a begin class block defines a set of entities temporary entities permanent entities and or resources An owns phrase in an every statement or the system statement appearing outside a begin class block refers to a set of entities or set of objects owned by an entity or owned by the system SIMSCRIPT III supports sets of objects and sets of entities It also supports array of sets 2 05 Arrays of Sets An array
90. returns when called as a right function or modifies when called as a left function the specified character of the current output line Integer arg is the column number of the character which must be between 1 and the record size For example the statement A out f 4 assigns the character in column four to the variable A The statement out f 4 s changes the character in column four to s This function may not be used if the current output unit has been opened for writing binary data page v An integer variable that contains the number of the current page for the current output unit It is initialized to 1 and is incremented for each new page when pagination is enabled lines v is greater than zero Each output unit has its own copy of this variable pagecol v An integer variable that specifies for the current output unit a positive starting column number at which the word Page followed by the current page number will be written as the first line of each page preceding lines written by a heading v routine when pagination is enabled lines v is greater than zero or the variable is zero which is the default or negative to disable this feature Each output unit has its own copy of this variable 61 rcolumn v An integer variable that contains the column number of the last character read from the current input line or zero if no character has been read Each input unit has its own copy of this vari
91. riables define PROCESS NOTICE as a pointer variable define QUEUE as a set ranked by high PRIORITY end end methods for the RESOURCE class left method ACQUIRED UNITS define ACQ as an integer variable define REQ as a REQUEST reference variable enter with ACQ while QUEUE is not empty and UNITS F QUEUE lt TOTAL UNITS ACQ do remove first REQ from QUEUF add UNITS REQ to schedule the PROCESS NOTICE REQ now destroy loop move from ACQ end I method AVAILABLE UNITS return with TOTAL UNITS ACQUIRED UNITS 110 method WAIT FOR REQ UNITS REQ PRIORITY define REQ as a REQUEST reference variable create REQ UNITS REQ REQ UNITS PRIORITY REQ REQ PRIORITY PROCESS NOTICE REQ PROCESS V file REQ in QUEU suspend end method CLEAN UP define REQ as a REQUEST reference variable while QUEUE is not empty do remove first REQ from QUEUE destroy PROCESS NOTICE REQ destroy REQ loop end All example programs from this manual are in the SIMSCRIPT sub directory sim3_examples 111
92. rray of text values a text key to look up in the array and a text value describing the order of values in the array The function searches for the key in the array If it is found the index of the array element containing the key is returned otherwise zero is returned to indicate that the key was not found If the third argument is ascending the function uses binary search otherwise the array is searched sequentially function Search T Key Order define First Last and Index as integer variables First 1 Last dim f T if Order ascending binary search Index First Last 2 while First lt Last and Key lt gt T Index do if Key T Index Last Index 1 else First Index 1 always Index First Last 2 loop if First Last Index 0 not found always else sequential search for Index First to Last with Key T Index find the first case if none Index 0 not found always always return with Index end The function must be declared in the preamble define Search as an integer function given a 1 dimensional text argument and 2 text arguments 12 The following is example of a function call if Search A Jim ascending 0 write as Found Jim in array A always 1 13 Argument Checking The define routine statement specifies the number of given and yielded arguments of a routine It 15 also possible to specify the mode and dimensionality of each argum
93. rve X as N Multiple line comment which may span several lines begins with slash tilde and ends with tilde slash It can also be used in a single line as in the example if N 0 variable is uninitialized read number of elements into N always reserve X as allocate the array Single line comments be nested inside multiple line comments This makes it convenient to comment out a block of code which may itself contain comments assume the array is already allocated if N 0 variable is uninitialized read number of elements into N always reserve X as N allocate the array Comments may be nested to any depth 1 04 Scientific Notation and Punctuation A numeric constant is a sequence of digits with an optional period 1 decimal point and optional scientific notation Floating point variables and constants can be expressed in scientific notation For example Define X Y and Z as double variables X 3 5026E5 assign 350260 0 to X Y 1 72e 03 assign 0 00172 to Y 7 27 641 2 assign 2764 1 to Z The letter E may be omitted from an input value e g 4 82 7 but it is required when expressing the value as a constant e g 4 82e 7 Space characters are not permitted within the constant SIMSCRIPT III permits periods and semicolons to enhance the readability of statements When used for this purpose these punctuation characters are ignored by the com
94. ry routine of the module Named constants declared in a routine are local that is they are accessible only within the declaring routine Similar mechanism for creating named constants is define to mean or substitute statement For example after the following statement each occurrence of the name Max Capacity is replaced by the number 100 define Max Capacity to mean 100 1 06 Basic Data Types There are several basic data types called modes integer real double alpha text and pointer Integer is implemented as a signed 32 bit or 64 bit value depending on which SIMSCRIPT III product 32 bit SIMSCRIPT vs 64 bit SIMSCRIPT is being used Real and double are single and double precision floating point values respectively Pointer is a generic untyped reference value implemented as a 32 bit or 64 bit address depending on a platform 1 07 Text and Alpha Alpha holds one 8 bit character an alpha constant is surrounded by quotation marks e g B Text is a dynamic string holding a sequence of zero or more characters a text constant is also surrounded by quotation marks Hello world Built in functions are available for string operations like concat f upper f and type conversions like ttoa f atot f A text expression can be assigned to an alpha variable and passed to an alpha argument and its value is converted automatically by an implicit call of ttoa f Likewise an alpha expression can be assigned to a tex
95. s ERATOR define I as an integer va for I do Schedule a FILL UP now wait UNIFORM F 2 8 1 loop 1 to 1000 end minutes remov nozzl riable minutes methods for the GAS STATION method R EQU EST P 0 if AVAILABLE UNITS call WAIT FOR 1 else add 1 to ACQUIR always 0 ED UNIT end method R ELINQUISH subtract 1 from ACQUIR ED end method UTILIZATION R ESOURC 5 UNITS lass return with 100 AVG BUSY TOTAL UNITS end methods for the ATT method PRINT STATISTICS print 3 lines with AVG QLI ENDANT cla 55 EN MAX QLI UTILIZATION thus 19 AVERAGE QUEUE WAITING FOR ATTENDANTS IS CUSTOMERS MAX T MU THE ATTENDANTS WERE BUSY CENT OF THE TIME end methods for the PUMP class method PRINT STATISTICS GRADI print 1 line with GRADE AVG QLEN MAX QLEN UTILIZATION thus KKK PERCENT method PRINT ALL STATISTICS print 3 lines thus THE QUEUES FOR THE PUMPS WERE AS FOLLOWS GRADE AVERAGE MAXIMUM UTILIZATION call PRINT STATISTICS REGULAR REGULAR call PRINT STATISTICS PREMIUM PREMIUM end method SELECT if RANDOM F 3 0 70
96. s notice for the current process method or process routine during a simulation or zero if no process method or process routine is active time v A double variable that contains the current simulation time Its initial value is zero which corresponds to the start of the day of origin 70 weekday f double arg An integer function that returns the weekday in the range 1 to 7 representing Sunday through Saturday for the date that is double arg days after the origin date If no origin date has been established by a prior call of origin r the origin is assumed to be a Sunday The argument must be nonnegative year f double arg An integer function that returns the year for the date that is double arg days after the origin date established by a prior call of origin r The argument must be nonnegative 71 5 07 Miscellaneous batchtrace v An integer variable that specifies the action to take when a runtime error occurs The debugger is invoked unless the value of the variable is 1 or 2 If the value is 1 a traceback is written to a file named simerr trc and snap r is called If the value is 2 the program exits without a traceback or snap r invocation The default value is zero which invokes the debugger date r yielding text arg1 text arg2 A subroutine that returns the current date in the form MM DD YYYY in text arg1 and the current time in the form HH MM SS in text arg2 left err message f
97. s scheduled without a reference value expression A schedule a statement creates an instance of the process method schedule a Trip Chevy called Midwest Trip given 600 55 in 3 days The given arguments and the reference value of the object are saved in attributes of the process notice for this process method instance The time a attribute of the notice is assigned the simulation time at which the process method is to begin execution The process notice is filed into the event set ev s where it co exists with other process notices The event set is an array of sets and each process method type is assigned a unique index into the array The scheduled execution of a process method can be canceled and rescheduled by cancel and schedule the statements that refer to the process method instance The reference value of the process notice may be stored in the implicitly defined attribute cancel the Trip Chevy schedule the Trip Chevy in 7 days or stored in a pointer variable cancel the Midwest Trip schedule the Midwest Trip in 7 days A process method in a wait state can be interrupted and later resumed interrupt the Trip Chevy resume the Trip Chevy or interrupt the Midwest Trip resume the Midwest Trip A process method can check the value of global variable process v to determine if a simulation is running If process v is nonzero then a simulation is running and process v 36 contains the reference value of the current
98. scribes a process method which can be used for process and event based discrete simulation It also describes the ACCUMULATE and TALLY statements used for statistics collection Chapter 4 explains how SIMSCRIPT III programs be designed as set of modules subsystems and elaborates data scope and name resolution subsystem is composed of public and private declarations and implementation code Public data and function method declaration defines subsystem s interface with the system and other subsystems Data structures and functionality can also be declared privately which can be used to hide implementation details Chapter 5 lists the system routines variables and constants which are defined by SIMSCRIPT IITs library m subsystem and are implicitly imported into every subsystem Other system modules like gui m 3d m 3dshapes m sdbc m and continuous m are imported on demand and described in specialized manuals Chapter 6 provides SIMSCRIPT III example programs rewritten from SIMSCRIPT II 5 Original programs are from the book Building Simulation Models with SIMSCRIPT 5 These examples illustrate use of classes objects subsystems creating simulations with process methods and collection of statistics on object attributes 1 01 Language Basics SIMSCRIPT III is Modular Object Oriented Language which can be used for general purpose program development It is especially suited for building discrete event and pr
99. subsystem begin class Vehicle public part of public class the class has a Count public class attribute end public subroutine define Check as a subroutine given a double argument public subsystem attributes the subsystem has an X and a Y define X and Y as double variables end private preamble for the Transportation subsystem begin class Moving Object private class end begin class Vehicle private part of public class every Vehicle is a Moving Object private base class the class has a Last ID private class attribute end private subsystem attribute 43 the subsystem has 7 define Z as a double variable end methods for the Moving Object class methods for the Vehicle class subroutine Check Arg end initialize called before main 1 0 Y 1 0 2 1 0 Vehicle Last ID 100 end main module preamble for the City system importing the Transportation subsystem begin class City Vehicle every City Vehicle is a Vehicle end the system has a Y define Y as a text variable end p by importing the Transportation subsystem routines of this module can create Vehicle objects access the public attributes of Vehicle such as Vehicle Count call the public methods of Vehicle call the public subroutine Check access the public subsystem attributes X and Transportation Y qualification of Y is required to distinguish it from the system attribute named Y defined by this module
100. t variable and passed to a text argument and its value is converted automatically by an implicit call of atot f This notational convenience permits for example an alpha variable named A to be converted to uppercase by A z upper f A A text expression can be compared with an alpha expression as part of a logical expression alpha expression is automatically converted to text before the comparison is performed For example if T is a text variable the following syntax is valid if T A An alpha constant such as x can appear in and be compared with an arithmetic expression It can also be assigned to an integer or double variable and be used as array subscript For these cases the alpha constant evaluates to its Latin character code which ranges from zero to 255 The binary operator concatenates text and or alpha operands For example define First Name Last Name Full Name as text variables define Middle Initial as an alpha variable Full Name First Name Middle Initial Last Name 1 08 Variables Arrays An integer variable named X is declared by the following statement define X as an integer variable If the statement is specified in the preamble the variable is global for that module if specified within a routine the variable is local to the routine All variables are automatically initialized to zero except text variables which are initialized to the zero length string
101. teger values priority required units of memory and 1 real value processing time in minutes define JOB GENERATOR as a process method given 3 real values mean interarrival time in minutes mean processing time in minutes stop time end begin class COMPUTER RESOURCE every COMPUTER RESOURCE is RESOURCE and has a UTILIZATION method 106 define UTILIZATION as a double method accumulate AVG USI accumulate AVG QL end processes include JOB external process is JOB external process unit is 7 end methods for the COMPUTI process method JOB JOB PRIORITY M define START IME START T if IME V AVAILABLE QUEUE ME add else call WAIT FO always UNITS ME ORY is emp ME ORY REQUIRE R MEMO if AVAILABLE UNITS CP add 1 to ACQUIRE else call WAIT FOR CP always work PROC subtrac subtrac D D U P X ct ct SSING TIME U 1 minutes RY ED as the average of ACQUIR EN as the average MAX QLEN as the maximum of N QU ER class UNITS ORY ty or PRIO ENT to ACQUIRED ek EMORY R EQUIR ENT as a real variable MEMORY REQ RITY F QU UI EU
102. the define routine statement For example function F M X N the following statements are optional because the argument modes have already been declared in a define routine statement define M and N as integer variables define X as a double variable In some cases the mode of routine arguments is known by the compiler without a define routine statement such as the mode of arguments to function attributes monitoring functions and before after routines 13 1 14 Reference Mode In SIMSCRIPT III a reference mode is implicitly defined for each process type temporary entity type The name of the mode is the name of the entity type followed by the keyword reference A reference variable is a typed pointer variable that can hold the reference value or address of an entity For example if Ship is a temporary entity type the mode Ship reference is implicitly defined The following statement defines Tanker to be a reference variable that can hold the reference value of a Ship entity define Tanker as a Ship reference variable The following statement creates a Ship entity initializes its attributes to zero and assigns its reference value to Tanker create Tanker This entity is destroyed by destroy Tanker When a reference variable is used to access an attribute the compiler verifies that the attribute is an attribute of the entity type For example C Capacity Tanker if Ship does not have a Capacit
103. umber of tellers mean service time in minutes define SELECT as a TELLER reference method end end methods for the CUSTOMER class process method BANK VISIT call ENGAGE TELLER SELECT yielding WAITING TIME end process method GENERATOR DAY LENGTH MEAN INTERARRIVAL TIME define TIME TO CLOSE as a real variable TIME TO CLOSE DAY LENGTH HOURS V until TIME V gt TIME TO CLOSFE do Schedule a BANK VISIT now wait EXPONENTIAL F MEAN INTERARRIVAL TIME 1 minutes loop end methods for the TELLER class method ENGAGE yielding WAIT if ACQUIRED UNITS 1 teller is busy define START TIME as a real variable START TIME TIME V call WAIT FOR 1 0 WAIT TIME V START TIME HOURS V MINUTES V else ACQUIRED UNITS 1 always work EXPONENTIAL F MEAN SERVICE TIME 2 minutes ACQUIRED UNITS 0 free the teller end method INITIALIZE NO OF TELLERS MST define ID as an integer variable define TELLER as a TELLER reference variable for ID 1 to NO OF TELLERS do create TELLER ID NUMBER TELLER ID TOTAL UNITS TELLER 1 84 file TELLER TELLER POOL
104. uments are integer the function returns an integer result otherwise the function returns a double result Numeric arg2 must be nonzero If numeric 1 is positive the return value is positive If numeric arg1 is negative the return value is negative For example mod f 14 5 3 returns 2 5 and mod f 14 5 3 returns 2 5 integer arg1 integer arg2 An integer function that returns the value obtained by performing a bitwise inclusive OR of integer arg1 and integer arg2 For example or f 23 51 returns 55 because the bitwise inclusive OR of binary 010111 23 and binary 110011 51 is binary 110111 55 pi c A double constant equal to the value of 7 3 141592653589793 55 radian c A double constant equal to the number of degrees per radian which is 180 or T 57 29577951308232 rinf c A double constant equal to the largest real value On 32 bit computers this value is approximately 3 4 x10 however a double value may be as large as 107 The smallest real value is rinf c shl f integer arg integer arg2 An integer function that returns the value of integer arg1 shifted left by integer arg2 bit positions For example shl f 23 2 returns 92 because binary 00010111 23 shifted left two positions is binary 01011100 92 value of integer arg1 is returned if integer arg2is zero The result is undefined if integer arg2 is negative shr f integer arg1 integer arg2
105. utions defined by define to mean and substitute statements within a begin class block have effect only within the block The dimensionality of an object attribute or class attribute is zero by default which means the attribute contains a scalar value However a dimensionality greater than zero 19 may be specified in define variable statement or normally dimension is statement to define an array attribute Let us add to our example an object attribute named Tire Pressure that is an array of real values where each element of the array contains the air pressure of one tire of the Vehicle begin class Vehicle every Vehicle has a Tire Pressure define Tire Pressure as 1 dimensional real array end When accessing an element of an array attribute of an object the array subscripts appear in parentheses after the parenthesized reference value expression The following statements allocate and initialize the Tire Pressure array for the Vehicle object whose reference value is stored in Car reserve Tire Pressure Car as 4 forJ 1to4 Tire Pressure Car J 30 Suppose that a Vehicle object is assumed to have four tires A named constant may be defined within a begin class block and is called a class constant begin class Vehicle define Num_Tires 4 as a constant end A class constant is accessed by specifying its qualified name reserve Tire Pressure Car as Vehicle Num Tires for 1 to Vehicle Num Tires Tire Pressure Car J
106. very Vehicle object has an integer attribute named ID a text attribute named Manufacturer and double attributes named Maximum Speed and Current Speed begin class Vehicle every Vehicle has an ID a Manufacturer a Maximum Speed and a Current Speed define ID as an integer variable define Manufacturer as a text variable define Maximum Speed and Current Speed as double variables end An object attribute is accessed like an attribute of a temporary entity by placing a reference value expression in parentheses after the attribute name For example ID Car 781 Manufacturer Car Chrysler Maximum Speed Car 100 Current Speed Car Maximum Speed Car 2 It reads ID of Car is 781 Manufacturer of Car is Chrysler etc Class attributes are declared in the class statements within begin class blocks Whereas each object has its own copy of each object attribute there is only one copy of each class attribute in the program In our example a class attribute named Count can be used to keep track of the current number of Vehicle objects in the program and a class attribute named Last ID can hold the ID of the last Vehicle created by the program begin class Vehicle the class has a Count and a Last ID define Count and Last ID as integer variables end A class attribute is accessed by specifying its qualified name which is the class name followed by an apostrophe and the attribute name with no intervening spaces
107. were produced by compiling the main module and each of its subsystems Separate compilation is supported If a subsystem s private preamble or routines are modified only the subsystem needs to be recompiled However each program that uses the subsystem must be re linked A module imports a subsystem by specifying its name in an importing phrase appended to a preamble heading Not only can a main module import a subsystem but a subsystem A can import a subsystem B If the public preamble of subsystem A imports subsystem B then a module that imports subsystem A will automatically import subsystem B public preamble for the X system importing subsystem A end public preamble for the A subsystem 41 importing subsystem end However if the private preamble of subsystem A imports subsystem B then a module that imports subsystem A is unaware of subsystem B public preamble for the X system importing subsystem A end public preamble for the A subsystem end private preamble for the A subsystem importing subsystem B end If the name of an imported definition is the same as a name defined by the importing module or if the same name is imported from two or more subsystems then the name of an imported definition must be qualified by pre pending the name of the defining subsystem followed by a colon with no intervening spaces For example if module M imports subsystems S1 and S2 and the name C is defined in module M and in th
108. y an error is reported The compiler also validates set operations when reference variables are used For example define Captain as a Shiphand reference variable file Captain in Crew Tanker compiler error unless every Shiphand belongs to a Crew and every Ship owns a Crew A reference variable of one entity type cannot be assigned to a reference variable of another entity type For backward compatibility with SIMSCRIPT 5 a reference variable can be assigned to an integer or pointer variable and an integer or pointer variable can be assigned to a reference variable variable can be checked at runtime to determine if it contains a reference value of a particular reference mode For example if P is a pointer variable that refers to a Ship entity the logical condition P is a Ship reference is true 14 if P is a Ship reference it is safe to access a Ship attribute using P C Capacity P and it is safe to assign P to a Ship reference variable Tanker P always More than one Ship entity can be created and destroyed at a time define S1 S2 S3 as Ship reference variables create S1 S2 S3 create three Ships destroy S1 S2 S3 destroy three Ships An array of reference values can be defined and initialized define Armada as a 1 dimensional Ship reference array define J as an integer variable reserve Armada as 1000 for J 1 to 1000 create Armada J Attributes global variables local variab
109. y ROS HE AVG QUEUE FOR MEMORY WAS AX JOBS HE MAX QUEUE FOR MEMORY WAS JOBS HE AVG QUEUE FOR A CPU WAS JOBS HE MAX QUEUE FOR A CPU WAS JOBS HE TOTAL UMBER OF JOBS COMPLETED WAS WITH AN AVERAGE PROCESSING TIME OF COEUR OE MINUTES stop end method COMPUTER RESOURCE UTILIZATION return with 100 AVG USED TOTAL UNITS end process JOB scheduled externally define JOB PRIORITY EMORY REQUIREMENT as integer variables define PROCESSING TIME as a real variable read JOB PRIORITY MEMORY REQUIREMENT PROCESSING TIME call COMPUTER JOB JOB PRIORITY EMORY REQUIREMENT PROCESSING TIME end main define MEAN INTERARRIVAL TIME MEAN PROCESSING TIME STOP TIM as real variables open unit 7 for input name is 7 x dat open unit 1 for input name is ex7 dat use unit 1 for input create COMPUTER CPU create COMPUTER MEMORY read TOTAL UNITS COMPUTER CPU TOTAL UNITS COMPUTER MEMORY MEAN INTERARRIVAL TIME MEAN PROCESSING TIME STOP TIM print 6 lines with TOTAL UNITS COMPUTER CPU TOTAL UNITS COMPUTER MEMORY 60 MEAN INTERARRIVAL TIM EAN PROCESSING TIME TOP TIME thus A C PUT R CENTER ST U po NO OF CPU S 5 RAGE AVAILABLE SMALL JOBS ARRIVE E RATE OF HOUR

Download Pdf Manuals

image

Related Search

Related Contents

A.O. Smith Custom Commercial Solar Water Heating Systems Technical Documents  DICOM User`s Guide  ASeries A1400DLplus User Manual RS-232 Data Logger  Metra 99-3014G car kit  Fujitsu Consumable Kit for FI-4340C  CAUTION - Sparky CNC  Kenmore ENVIROSENSE 85500 User's Manual  ustin 19a 28. on of date. Engine agneto hasers ith Book the Coil  Owner`s Manual QB5 QB6 QT66 QT88 QC  Creda 5kg User's Manual  

Copyright © All rights reserved.
Failed to retrieve file