gpss_manual
.pdfReturnInteger = STRINGCOMPARE( String1, String2 )
Arguments
String1 - The first of two strings to be compared. Required. Coerced to string. The argument must be Expression.
String2 - The second of two strings to be compared. Required. Coerced to string. The argument must be Expression.
Return Value
ReturnInteger - Integer -1, 0, or 1 as String1 precedes, equals, or succeeds String2.
Example
SHOW Stringcompare("ABC","abc") -1.0000000
This example uses a SHOW Command to demonstrate how the stringcompare( ) string Procedure compares the two string constants and returns the result of the comparison.
Action
StringCompare( ) coerces the first and second arguments to strings. It then compares them lexicographically.
If the two strings are identical, an integer 0 is returned. Otherwise the strings are compared character by character until a difference is detected.
If the first difference occurs because one string is shorter than the other, the shorter string is said to precede the longer one. If the shorter string is String1, -1 is returned. If
the shorter string is String2, 1 is returned.
If the first difference occurs because the character from String1 precedes that from String2 in the ASCII collating sequence, String1 is said to precede String2, and -1 is returned. Otherwise, String2 is said to precede String1, and 1 is returned.
14. SubString - Return part of a string.
Syntax
ReturnString = SUBSTRING( SourceString, Offset, MaxCount )
Arguments
SourceString - The string to be used as the source of the substring. Required. Coerced to string. The argument must be Expression.
Offset - The 1-relative offset in SourceString of the first character of the substring. Required. Coerced to integer. The argument must be Expression.
MaxCount - The maximum number of characters from SourceString to use in the substring. Required. Coerced to integer. The argument must be Expression.
Return Value
ReturnString - The string created as a result of creating a copy of a substring derived from SourceString.
Example
SHOW Substring("123456789",3,4) "3456"
This example uses a SHOW Command to demonstrate how the substring() string Procedure copies 4 characters from the string constant "123456789" to form a new string.
Action
Substring( ) coerces the first argument to a string, and the second and third to integers. If the Offset argument is less than 1, it is set to 1. Substring ( ) then creates a string large
enough to canteen the lesser of the MaxCount argument or the number of characters
remaining after the offset in the source string. Substring( ) then copies the characters from the substring, if any, into the result string.
15. Trim - Remove leading and trailing white space.
Syntax
ReturnString = TRIM( SourceString )
Arguments
SourceString - The string to be used as the source of characters. Required. Coerced to string. The argument must be Expression.
Return Value
ReturnString - The string created as a result of trimming blanks and tabs from SourceString.
Example
SHOW Trim(" A B C ")
"A B C"
This example uses a SHOW Command to demonstrate how the Trim( ) string Procedure creates a new string by removing leading and trailing blanks from a string continuing them.
Action
Trim( ) coerces the arguments to a string. It then creates a string large enough to contain the result, and copies the source string into the result string, omitting leading and trailing blank or tab characters.
16. Uppercase - Convert a string to upper case.
Syntax
ReturnString = UPPERCASE(
SourceString )
Arguments
SourceString - The string to be converted. Required. Coerced to string. The argument must be Expression.
Return Value
ReturnString - The string created as a result of converting SourceString to upper case.
Example
SHOW Uppercase("123 aBc")
"123 ABC"
This example uses a SHOW Command to demonstrate how the uppercase( ) string Procedure copies a string and converts the lower case letters to upper case.
Action
Uppercase( ) coerces the argument to a string, and creates a copy of the string. It then converts the lower case letters in the copy to upper case and returns it as the result string.
1.7 Value - Convert to numeric equivalent.
Syntax
ReturnReal = VALUE( Datum )
Arguments
Datum - The data item to be converted. Required. The argument must be Expression.
Return Value
ReturnReal - The double precision real numeric value equivalent to Datum. A real value.
Example
SHOW Value("123.4") 123.4000000
This example uses a SHOW Command to demonstrate how the value( ) string Procedure converts the string "123.4" to its numeric value.
Action
Value( ) determines the data type of the argument. Integers or stings are converted to their real numeric equivalent, and returned. Real arguments are returned without
modification.
18. Word - Extract a word from a string.
Syntax
ReturnString = WORD( SourceString, WordNumber )
Arguments
SourceString - The string to be examined. Required. Coerced to string. The argument must be Expression.
WordNumber - The 1-relative cardinal number of the word in SourceString to be returned. The argument must be Expression.
Return Value
ReturnString - The string containing the word extracted from SourceString.
Example
SHOW Word("My country ’tis of thee.",2) "country"
This example uses a SHOW Command to demonstrate how the word( ) string Procedure extracts the second word of a source string.
Action
Word( ) coerces the first argument to a string, and the second to an integer. It then finds the word corresponding to the second argument, and creates a string large enough to contain it. Finally, it copies the characters of the word, if any, into the result string.
Words are consecutive printable characters other than tabs or blanks. If the corresponding word does not exist in the source string, a null string is returned.
8.3.5. Probability Distributions
This chapter contains the information you need to use the theoretical probability distributions in the Procedure Library. Empirical distributions, on the other hand, are normally created by using the GPSS FUNCTION Command, using D or C type random Functions. This is discussed in Chapter 6. As other alternatives, it is easy to create your own random variate generators by defining your own PLUS Procedures, or to read empirical data from a file.
Over 20 built in probability distributions are included in the Procedure Library. These distributions are applicable to a wide range of practical situations. [For an excellent detailed discussion, see Law, A.M. and W.D. Kelton: Simulation Modeling and Analysis, 2nd Ed., McGraw-Hill, New York (1991)].
Each Procedure call to a probability distribution requires that you specify a stream argument. In this position, you are to assert an Expression that evaluates to a Random Number Generator Entity number. Random Number Generator Entities are created, as needed, so you need not predefine them. Several Random Number Generators are used by GPSS World for GENERATE, ADVANCE, and TRANSFER blocks. These are
specified in the "Random" page of the Model Settings notebook. This is discussed in
Chapter 2.
Most of the probability distributions are specified by parameters that select from a family of functions. Procedure arguments denoted locate, scale, and shape are often used for this purpose. The locate argument acts like a post-hoc adder, that is applied after the draw from the distribution. It allows you to move the distribution horizontally, to any position on the x axis. The scale and shape arguments, if used, select a member from the family of distributions.
The built-in Procedure Library contains the following probability distributions:
∙ Beta |
∙ LogLaplace |
∙ Binomial |
∙ LogLogistic |
∙ Discrete Uniform |
∙ LogNormal |
∙ Exponential |
∙ Negative Binomial |
∙ Extreme Value A |
∙ Normal |
∙ Extreme Value B |
∙ Pareto |
∙ Gamma |
∙ Pearson Type V |
∙ Geometric |
∙ Pearson Type VI |
∙ Inverse Gaussian |
∙ Poisson |
∙ Inverse Weibull |
∙ Triangular |
∙ Laplace |
∙ Uniform |
∙ Logistic |
∙ Weibull |
1. Beta
Syntax
Real = BETA( Stream, Min, Max, Shape1, Shape2 )
Arguments
Stream - The random number generator entity number. Required. Coerced to integer. Must be greater than or equal to 1. The argument must be Expression.
Min- The smallest sample to be generated. Required. Coerced to real. Must be less than max. The argument must be Expression.
Max- The largest sample to be generated. Required. Coerced to real. Must be greater than min. The argument must be Expression.
Shape1 - The first selection value used to choose from a family of shapes. Required. Coerced to real. Must be strictly positive. The argument must be Expression.
Shape2 - The second selection value used to choose from a family of shapes. Required. Coerced to real. Must be strictly positive. The argument must be Expression.
Return Value
Real - The real value generated as a single instance of the probability distribution.
Probability Density Function
Figure 8—1. The Beta Distribution
Notes
The Beta Distribution degenerates to the Uniform when the Shape1 and Shape2 arguments are 1. That is, Beta( Stream, Min, Max, 1, 1 ) is distributed as Uniform(
Stream, Min, Max ).
Beta( Stream, Min, Max, 1, 2 ) is a left triangle; Beta( Stream, Min, Max, 2, 1) is a right triangle.
2. Binomial
Syntax
Integer = BINOMIAL( Stream, TrialCount, Probability )
Arguments
Stream - The random number generator entity number. Required. Coerced to integer. Must be greater than or equal to 1. The argument must be Expression.
TrialCount - The number of Bernoulli trials in a sample. Required. Coerced to integer. Must be strictly positive. The argument must be Expression.
Probability - The success probability of a Bernoulli trial. Must be between 0 and 1. Required. Coerced to real. The argument must be Expression.
Return Value
Integer - The integer value generated as a single instance of the probability distribution.
Probability Mass Function
Figure 8—2. The Binomial Distribution
3. Discrete Uniform
Syntax
Integer = DUNIFORM( Stream, Min,
Max )
Arguments
Stream - The random number generator entity number. Required. Coerced to integer. Must be greater than or equal to 1. The argument must be Expression.
Min- The smallest sample to be generated. Required. Coerced to integer. Must be less than or equal to max. The argument must be Expression.
Max- The largest sample to be generated. Required. Coerced to integer. Must be greater than or equal to min. The argument must be Expression.
Return Value
Integer - The integer value generated as a single instance of the probability distribution.
Probability Mass Function
Figure 8—3. The Discrete Uniform Distribution
4. Exponential
Syntax
Real = EXPONENTIAL( Stream,
Locate, Scale )
Arguments
Stream - The random number generator entity number. Required. Coerced to integer. Must be greater than or equal to 1. The argument must be Expression.
Locate - The shift value used to position the distribution. Required. Coerced to real. The argument must be Expression.
Scale - The compression value used to expand or contract the distribution. Must be strictly positive. Required. Coerced to real. The argument must be Expression.
Return Value
Real - The real value generated as a single instance of the probability distribution.
Probability Density Function
Figure 8—4. The Exponential Distribution
Notes
The Weibull Distribution degenerates to the Exponential when the shape argument is 1. That is, Weibull( Stream, Locate, Scale, 1 ) is distributed as Exponential( Stream, Locate, Scale ).
The Gamma Distribution degenerates to the Exponential when the shape argument is 1. That is, Gamma( Stream, Locate, Scale, 1 ) is distributed as Exponential( Stream, Locate, Scale ).
5. Extreme Value A
Syntax
Real = EXTVALA( Stream, Locate,
Scale )
Arguments
Stream - The random number generator entity number. Required. Coerced to integer. Must be greater than or equal to 1. The argument must be Expression.
Locate - The shift value used to position the distribution. Required. Coerced to real. The argument must be Expression.
Scale - The compression value used to expand or contract the distribution. Must be strictly positive. Required. Coerced to real. The argument must be Expression.
Return Value
Real - The real value generated as a single instance of the probability distribution.
Probability Density Function
Figure 8—5. The Extreme Value A Distribution