Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

gpss_manual

.pdf
Скачиваний:
49
Добавлен:
05.06.2015
Размер:
1.88 Mб
Скачать

Statement - Procedure body. A PLUS statement. Must be

Statement.

Intended Use

An Experiment is a special kind of PLUS Procedure. EXPERIMENT Statements are used to define special User Procedures used to control multiple runs of a Simulation. Normally, the statement used as the Experiment body is a Compound Statement.

Experiments are generally used in connection with the DoCommand() Library Procedure, to control the Simulations, and the ANOVA Library Procedure to automatically analyze results. Normally, the Experiment fills a Global Matrix Entity with results and passes it to the ANOVA procedure.

Example

The following example of an Experiment is discussed in more detail in Lesson 19 of the

GPSS World Tutorial Manual.

In this example, an EXPERIMENT Statement is used to define a User Procedure. When Translated, the Experiment is integrated into the Procedure Library of the simulation. Thereafter, it can be invoked by an appropriate CONDUCT Command.

EXPERIMENT BestLines(LeastLinesToRun, MostLinesToRun, Increment) BEGIN /* Each Result Matrix has the following dimensions:

1.Each of up to 5 Factors requires a dimension, where each dimension indicates the number of levels used for that factor.

(The ONEWAY DoCommand used here supports only 1 factor)

2.The last dimension indicates the maximum number of replicates within each cell.

There may be up to a total of 6 dimensions. */

/* Put a Header into the Journal */ DoCommand("SHOW """" ");

DoCommand("SHOW (""**** Balanced Telephone-System Experiment with One-way ANOVA ****"")");

DoCommand("SHOW """" ");

/* Optionally, save data to a Result file for later processing. */

DoCommand("OPEN (""RESULT.TXT""),2"); /* Open Stream 2 For Statistical data */

DoCommand("SEEK 10000,2"); /* Append the Results */

DoCommand("WRITE ""**** EXPERIMENT BestLines() ****"",2"); /* Header for this Experiment */ LevelOfFactor1 = 1; /* Levels are 1-4, incl.*/

CurrentLines = LeastLinesToRun; /* Set the number of telephone lines to use */

WHILE ((CurrentLines <= MostLinesToRun) ‘AND’ (LevelOfFactor1<=4)) DO BEGIN

Replicate = 1;

WHILE (Replicate <= 3) DO BEGIN

/* Run the Simulation by calling a PROCEDURE (defined below) */

DoTheRun(CurrentLines,Replicate);

/* Store the first (and only) result of this run.

This will be used by the ONEWAY DoCommand, below. Multiple results would require additional

Results Matrices. */ MainResult[LevelOfFactor1,Replicate] = TB$Transit; /* Log Result in the Journal, too. This is optional. */ RunDescription = Polycatenate(

PolyCatenate("Main Result: ",LevelOfFactor1," ",Replicate),"

TB$Transit=",TB$Transit,"");

DoCommand("SHOW (RunDescription)"); DoCommand("SHOW """" "); /* Space after Result */

/* Optional Example of writing to a Results File for 3rd party Statistics */ DoCommand("WRITE (RunDescription),2");

/* Set up the next Replication */ Replicate = Replicate + 1; END;

/* Move to the next cell of the experiment. */ LevelOfFactor1 = LevelOfFactor1 + 1; CurrentLines = CurrentLines + Increment; END;

/* Put the Statistical Analysis into the Journal */ DoCommand("SHOW """" ");/* Space down a line */ ANOVA(MainResult); /* Perform the One-Way ANOVA */ DoCommand("SHOW """" ");/* Space down a line */ DoCommand("CLOSE ,2"); /* Close the Optional Results File */ /* All outcomes can now be viewed in the MATRIX Window, or the RESULTS.TXT Text Object. The ANOVA is in the Joural. */ END;

PROCEDURE DoTheRun(NumberOfLines, ReplicateNumber) BEGIN /* A PROCEDURE can issue DoCommand()

only if it is called by an EXPERIMENT */ TEMPORARY RandomSeed1;

/* Use a seed distinct from those of other replicates */ RandomSeed1 = 11 # ReplicateNumber; DoCommand("CLEAR OFF"); /* Must use OFF. */

/* Here we only use one RN stream */ DoCommand(Catenate("RMULT ",RandomSeed1)); DoCommand(Catenate("Sets STORAGE ",NumberOfLines));

DoCommand("START 100,NP"); /* Startup Period */

DoCommand("RESET"); /* Begin the Measurement Period */

DoCommand("START 1000,NP"); /* Run the Simulation */

END;

Action

An EXPERIMENT Statement creates a User Defined Procedure. When it is Translated, the Procedure is added to the simulation’s Procedure Library, and is available for invocation by a CONDUCT Command. If your Simulation has only a single EXPERIMENT with no arguments, a simple CONDUCT without reference to the Experiment name is sufficient to start the Experiment.

The optional Formal Argument list passed to the Experiment by the CONDUCT Command is used to create temporary User Variables, addressed by the given names. Each receives a copy of the value resulting from evaluating the actual argument asserted in the Experiment invocation. Later references to the formal argument name refer to the variable created in this manner. The arguments are often used to specify which part of a response surface is to be explored by this invocation of the Experiment. With proper planning, Experiments can be HALTed, Saved, and restarted later.

While running, an Experiment takes control of the Simulation Object. Having begun an Experiment with a CONDUCT Command, your ability to interact with the simulation is limited. You can always display the running Simulation System Clock ( View / Clock ),

but generally you will have to HALT the Experiment in order to examine the Simulation. Then, unless you have planned ahead, you may have to restart the Experiment from the beginning.

5. GOTO Statement

Syntax

GOTO Label ;

Label - A PLUS Statement Label. A unique name appearing on a Labeled Statement, defined below.

Intended Use

GOTO Statements are used to cause the processing sequence of a Procedure to jump abruptly to a specific statement, tagged with a PLUS Statement Label.

Example

GOTO Sanctuary;

In this example, when the PLUS Procedure comes upon the GOTO Statement, it immediately finds the statement with the label, SANCTUARY, and begins there.

6. IF Statement

Syntax

IF ( Expression ) THEN Statement

Expression - A well-formed PLUS Expression, defined above. Must be Expression.

Statement - Conditional statement. A PLUS Statement.

Intended Use

IF Statements are used primarily to conditionally perform a block of statements

Example

IF (Indicator > 0) THEN BEGIN

Alert = "TRUE";

Old_Indicator=Indicator;

END;

In this example, the Expression is evaluated numerically. True logical relations yield an integer 1 result. If the result of the evaluation is nonzero, the block of Assignment Statements is performed.

Action

An IF Statement evaluates an Expression numerically, and determines of the result is nonzero. If so, the Conditional Statement, which may be compound, is performed.

7. IF-ELSE Statement

Syntax

IF ( Expression ) THEN Statement1 ELSE Statement2

Expression - Test Expression. A well-formed PLUS

Expression, defined above. Must be Expression.

Statement1 - True branch statement. A PLUS Statement.

Must be Statement.

Statement2 - False branch statement. A PLUS Statement.

Must be Statement.

Intended Use

IF-ELSE Statements are used primarily to choose between two statement blocks, only one of which is to be performed.

Example

IF (Indicator > 0) THEN BEGIN

Alert = "TRUE";

Old_Indicator=Indicator;

END;

ELSE Alert = "FALSE";

In this example, the Expression is evaluated numerically. True logical relations yield an integer 1 result. If the result of the evaluation is nonzero, the true branch statement is performed. In this case, the block of Assignment Statements is performed. If the result of numerically evaluating the test Expression is zero, the very last Assignment Statement is performed, instead.

Action

An IF-ELSE Statement evaluates an Expression numerically, and determines of the result is nonzero. If so, the true branch statement, which may be compound, is performed. Otherwise, the false branch statement, which may also be compound, is performed.

ELSE clauses pair with the most recent IF clause. If several IF Statements appear in succession just before an ELSE clause, the latest unpaired IF clause is paired with the ELSE clause to form an IF-ELSE Statement. You can avoid ambiguity by using Compound Statements within IF and IF-ELSE Statements.

8. Labeled Statement

Syntax

Label : Statement

Label - A PLUS Statement Label. A unique user-defined name. Must be Name.

Statement - A PLUS Statement. Must be Statement.

Intended Use

Labeled Statements are used as the targets of GOTO Statements.

Example

GOTO Sanctuary;

...

Sanctuary: RETURN 100;

In this example, when the PLUS Procedure comes upon the GOTO Statement, it immediately finds the statement with the label, SANCTUARY, and begins there. In this

case, the Procedure terminates returning a numerical value of 100.

9. PROCEDURE Statement

Syntax

PROCEDURE Name ( ArgumentList ) Statement

Name - A user-defined Procedure Name. Must be Name.

ArgumentList - A sequence of user-defined names,

separated by commas, used a s formal argument list. Instantiated by a list of Name items, possibly null, separated by commas.

Statement - Procedure body. A PLUS statement. Must be

Statement.

Intended Use

PROCEDURE Statements are used to define User Procedures. Normally, the statement used as the Procedure body is a Compound Statement.

Example

PROCEDURE Decision(Indicator)

BEGIN

TEMPORARY Return_Value;

Return_Value = Old_Indicator;

IF (Indicator > 0) THEN BEGIN

Alert = "TRUE";

Old_Indicator=Indicator;

END;

ELSE Alert = "FALSE";

RETURN Return_Value;

END;

In this example, a PROCEDURE Statement is used to define a User Procedure. When Translated, the Procedure is integrated into the Procedure Library of the simulation. Thereafter, it can be invoked by an appropriate Procedure Call, such as:

Result = Decision(200+My_Constant);

Action

A PROCEDURE Statement creates a User Defined Procedure. When it is Translated,

the Procedure is added to the simulation’s Procedure Library, and is available for invocation.

The Formal Argument list is used to create temporary User Variables, addressed by the given names. Each receives a copy of the value resulting from evaluating the actual argument asserted in the Procedure invocation. Later references to the formal argument name refer to the variable created in this manner.

Procedures have global scope. They may be invoked from anywhere within the simulation.

10. Procedure Call Statement

Syntax

ProcedureName ( ExpressionList ) ;

ProcedureName - An name used to define a Procedure in

the Procedure Library. May be a Math Procedure, a String Procedure, a Probability Distribution, or a User Defined PLUS Procedure. Must be Name.

ExpressionList - The argument list of the Procedure One or

more well-formed PLUS Expressions, separated by commas. Must be ExpressionList.

Intended Use

Procedure Call Statements are used to invoke Procedures in the Library.

Example

Real_Value=Beta(1,100,200,2,2);

In this example, a sample is drawn from the Beta probability distribution. Pre defined Procedures are available for math and string functions, and probability distributions. They are discussed later in this Chapter.

Action

A Procedure Call Statement invokes a Procedure in the Library. Pre-defined and User Defined Procedures may be called.

Expressions may be used as arguments to Procedures. They are evaluated at the very beginning of the invocation. The arguments of built-in Procedures are coerced to a specific data type. This is discussed in the documentation of the specify Procedure. The arguments to User Defined Procedures are evaluated normally.

11. RETURN Statement

Syntax

RETURN Expression ;

Expression - Optional. A well-formed PLUS Expression.

Must be Expression or Null.

Intended Use

RETURN Statements are used to terminate the processing of a PLUS Procedure, and to establish the result value to be used as the result of the Procedure invocation.

Example

RETURN "Success";

In this example, a RETURN Statement is used to complete the Procedure and to establish a string constant as the result of the Procedure invocation.

Action

When a RETURN Statement is performed, the Expression in the RETURN Statement, if any, is evaluated normally. The Procedure is terminated, and all temporary Named Variables and temporary Matrices are deleted. If an Expression was asserted in the RETURN Statement, its result is used as the result of the Procedure. If there is no Expression, integer 0 is used.

12. TEMPORARY Statement

Syntax for TEMPORARY Declaration

TEMPORARY NameList ;

NameList - Name List. A list of user defined names to become local User Variables. Namelist is instantiated by a list of Name items separated by commas.

Syntax for TEMPORARY MATRIX Declaration

TEMPORARY MATRIX Name[ IntegerList ] ;

Name - A user defined local Matrix name. Must be Name.

IntegerList - A sequence of 1 to 6 strictly positive integers,

separated by commas. The number of elements in each dimension of the Matrix. IntegerList is instantiated by a list of

up to 6 PosInteger items, separated by commas.

Intended Use

TEMPORARY Statements are used to create Named Values and Matrices which exist only during the invocation of a PLUS Procedure.

Example

TEMPORARY

Return_Value,Accumulator;

TEMPORARY MATRIX

DataArray[2,3,4];

In this example, two TEMPORARY Statements are used in a Procedure. The first creates two Named Values for use within a single Procedure invocation. The second creates a 3 dimensional local Matrix named DataArray.

Temporary data are not automatically initialized. You must assign data to temporary Named Values and Matrix Elements before you can refer to them in Expressions.

Action

A TEMPORARY declaration creates one or more uninitialized Named Values for used during a single Procedure invocation.

A TEMPORARY MATRIX declaration creates a single uninitialized Matrix, of up to 6 dimensions, for use during a single Procedure invocation.

TEMPORARY Named Values and TEMPORARY MATRICIES have local scope. They can be accessed only within their containing Procedure, and not by Procedures invoked from the containing Procedure. Named Variables and Matrices not declared in temporary declarations have global scope, are known throughout the model, and exist for the life of the simulation. A global matrix must be defined in a GPSS MATRIX Statement.

When a Procedure terminates, all of its temporary Named Values and temporary Matrices are freed.

13. WHILE Statement

Syntax

WHILE ( Expression ) DO Statement

Expression - Test Expression. Required. A well-formed

PLUS Expression, defined above. Must be Expression.

Statement - Target statement. Required. A PLUS Statement.

Intended Use

WHILE Statements are used primarily to perform repetitive actions.

Example

Accumulator=1;

Counter=1;

WHILE (Counter<=X_Integer) DO BEGIN

Accumulator=Accumulator#Counter;

Counter=Counter+1;

END;

In this example, a Compound Statement is performed repetitively in a while loop. If X_Integer is a positive integer, the while loop will continue to accumulate the factorial of X_Integer in the Named Value, Accumulator.

Each time the target statement is performed, the Named Value Counter is incremented. When Counter becomes larger than X_Integer, the target statement is not performed, and processing continues with the statement after the WHILE Statement.

Action

When a WHILE Statement is encountered, the test Expression is evaluated numerically. If the result is nonzero, the target statement is performed, and the "Test-Perform" process is repeated. If the test Expression is zero, the target statement is not performed,

and instead, processing continues with the statement following the While Statement.

To avoid a nonterminating loop, you must ensure that the evaluation of the test Expression becomes zero, at some time. Normally, this is done somewhere in the target statement by an Assignment Statement or Procedure call.

8.3. The Procedure Library

A Procedure must be in a Procedure Library for you to invoke it during a simulation. There are two kinds of libraries. The User Library and the GPSS World Library. The User Library is the collection of PLUS Procedures you have included in the model. The GPSS World Library contains a set of ready made mathematical and string Procedures that you can invoke in any PLUS Expression.

The Procedure library is a set of PLUS Procedures that you can call in Expression. Some Procedures are supplied for you, but you can define and add your own Procedures as well.

The built-in part of the Procedure Library includes Utility Procedures, Math Procedures, Probability Distributions, String Procedures, and Query Procedures.

8.3.1. Utility Procedures

The GPSS World Procedure Library includes an important Utility Procedure needed for the control of Experiments.

The Utility Procedure is

DoCommand( String1 ) - Send a Command to the Simulation during the execution of an Experiment.

An Experiment or any Procedure invoked during an Experiment can invoke the DoCommand Library Procedure. It is this powerful procedure which allows the Experiment to control the simulation environment. In its invocations, a string containing a Command or Statement is Translated in the global context and then executed by the Simulation Object.

Here are some tips for using the DoCommand library procedure. Use 4 double quotes around strings within strings. Each inner string should be sandwiched by pairs of double quotes, which get reduced to single quotes when translated. Also, do not pass a string to DoCommand which contains the name of a TEMPORARY variable because they variables are not accessible in global context.

Normally, GPSS World simulations enqueue all commands (except HALT, SHOW, and CONDUCT) on a low priority Command Queue and work on them one at a time until the queue is empty. However, DoCommand behaves a little differently. It does not return to the calling procedure until the low priority Command Queue is empty. This means that after a START Command issued through the DoCommand library procedure returns to the calling Procedure, the simulation has completed and is ready for the results to be extracted.

8.3.2. Math Procedures

The World Procedure Library includes several Mathematical Procedures. In all cases, the argument is coerced to a numeric value before the Procedure performs its operation. Angular data are in radians. Numeric values are returned as real numbers.

The Math Procedures are

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]