Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Gpss tutorial.pdf
Скачиваний:
321
Добавлен:
15.04.2015
Размер:
1.4 Mб
Скачать

World.

In the next lesson, we turn to the final lesson of this series. We will look at how an Experiment, a special type of PLUS Procedure, can be crafted to perform multiple simulations and analyze the results automatically. See you then.

Lesson 19 - Experiments

By the time you get to this point, you will have used the methods in previous lessons to debug your simulation under all the conditions you will subject it to while generating the final results. Now is a good time to reflect on the status of your project. If you have any doubts about what your simulation is doing internally, it might be a good idea to initiate an additional verification and/or stress-test subproject before continuing with the experimentation phase. Normally, you will have done some planning about the experiments you want to run. After all, the simulation must be built to deliver the results used in the analysis of the experiment.

In GPSS World, experiments are defined when you translate a special PLUS Procedure called an Experiment. Other than the replacement of the keyword ‘PROCEDURE’ with ‘EXPERIMENT’ there is no difference between the syntax of an Experiment and that of a Procedure. Actually, there is one extra thing you can do in an Experiment (or in a Procedure called by an Experiment). That is the use the DoCommand library procedure. But more on that later. The bottom line is that Experiments inherit all the power of PLUS, making them fully programmable and automatic. Your computer can be grinding out results and exploring response surfaces even while you sleep. Just as with PLUS Procedures, you can insert EXPERIMENT definitions into your Model or you can send them to existing simulations using a Custom Command. In either case, you may find the INCLUDE Command useful, which can be used to point to a Text Object containing lengthy PLUS PROCEDUREs and/or EXPERIMENTS.

To actually run a previously defined Experiment you must introduce a CONDUCT Command to the Simulation Object. If your Simulation has only a single EXPERIMENT with no arguments, a simple CONDUCT will get things started without even declaring the name of the Experiment. On the other hand, if you have defined arguments in your EXPERIMENT, you can control it from the CONDUCT Command.

Once you have begun an Experiment with a CONDUCT Command, your ability to interact with the simulation is somewhat 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. That’s another reason why it is best to have your testing done before you begin the experimentation. More on this later.

Let’s now look at an Experiment we defined for the TELEPHON.GPS sample model. But before we do, you should skip ahead to Chapter 2 Section 2 to study the internal structure of the Model. See you when you get back.

As you can see, the purpose of the model is to find the best configuration of telephone lines under a predefined set of load factors. We now turn to the ONEWAY.GPS Model which has defined an experiment for the Telephone system model. Go ahead and Open the Model

CHOOSE File / Open

and in the dialog box

SELECT OneWay

CHOOSE Open

You should see the following Model Statements

; GPSS World Sample File - ONEWAY.GPS

***********************************************************************

**

*Balanced Telephone System Experiment with *

*One-Way Analysis of Variance. *

**

*To Determine the Optimal Number of Telephone Lines. *

**

**

**

*BestLines() places results in a Global MATRIX MainResult, *

*and in a Results File named RESULT.TXT and then performs *

*a One Way Analysis of Variance. *

**

*To Create an EXPERIMENT that can be HALTed, saved, *

*and resumed, you would need to use Global SAVEVALUE *

*and/or MATRIX Entities to control the Runs. Also, *

*when you use the CLEAR Command, you must use the OFF *

*option to preserve control variables and results. *

**

***********************************************************************

*Define the Global Experimental Result Matrix *

*Max of 4 Levels of Factor 1, Max of 3 Replicates per cell * MainResult MATRIX ,4,3

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 Journal. */ 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;

; From GPSS World Sample File - TELEPHON.GPS, by Gerard F. Cummings

**************************************************************

**

**

*Telephone System Model *

**

**************************************************************

*Simple Telephone Simulation *

*Time Unit is one minute *

Sets STORAGE 2

Transit TABLE M1,.5,1,20 ;Transit times

GENERATE 1.667,1 ;Calls arrive

Again GATE SNF Sets,Occupied ;Try for a line

ENTER Sets ;Connect call

ADVANCE 3,1 ;Speak for 3+/-1 min

LEAVE Sets ;Free a line

TABULATE Transit ;Tabulate transit time TERMINATE 1 ;Remove a transaction Occupied ADVANCE 5,1 ;Wait 5 minutes TRANSFER ,Again ;Try again

**************************************************************

First, notice that the PLUS Experiment named BestLines calls a second PLUS Procedure called DoTheRun. Both are defined here by including them in the Model. When you create a Simulation from this Model, the Procedures will be Translated along with the GPSS Statements and will be registered in the Simulation. Alternately, we could have sent these PLUS Procedures to an existing Simulation, using a Custom Command and/or an INCLUDE Command.

When we interact with this Simulation we can ignore the BestLines experiment, because it does nothing until a CONDUCT Command is sent to the Simulation. But now, let’s take a closer look at the statements in the EXPERIMENT.

The BestLines Experiment is designed to fill up a Global Matrix with results and pass it to the ANOVA library procedure, which creates a statistical analysis and report. Notice that there is an inner and outer WHILE/DO loop which perform all the simulations needed by the experiment. There is a single experimental factor, namely, the number of telephone lines, with 4 treatment levels. At each treatment level we perform 3 replicates changing only the random number seeds. This improves the estimate of the Standard Error of the Experiment.

Within the innermost loop of the BestLines Experiment Calls the DoTheRun procedure, which uses a set of Commands to initialize and actually run the simulations. Since DoTheRun is called by an EXPERIMENT, it can make calls to the DoCommand library procedure. In this way it sends CLEAR OFF, RESET and START Commands to the Simulation. Each time DoTheRun completes, the BestLines Experiment stores the result of the simulation into the corresponding element of the MainResult Global Matrix, which is defined just after BestLines() in the listing. There could be any number of Result Matrices, but each one must have a dimension for each of the experimental factors (up to 5) plus one more for indexing replicates. Since we are doing a One Way ANOVA, the first index of the Result Matrix if for the treatment level, each with a distinct number of phone lines, and a second index allows multiple replicates to be run under each treatment. Thus, our Result Matrix has two dimensions. When the Experiment is complete, BestLines calls the ANOVA library procedure which writes the statistical report to the Simulation Journal.

Here are some tips for using the DoCommand library procedure. Use 4 double quotes around stings 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. Why? Well, the argument string is translated in global scope where TEMPORARY PLUS variables are not accessible.

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 through the DoCommand library procedure returns to the calling Procedure, the simulation has completed and is ready for the results to be extracted.

Notice that our sample PLUS Procedure DoTheRun uses the OFF option of the CLEAR Command. If it didn’t, the ResultMatrix Global Matrix would be zeroed and data would be lost. We will be able to open a window on all the results after the experiment completes. But before we do that, take a look at a few other things that are done.

Notice how the SHOW Commands are used to put messages in the Simulation Journal. This is a handy way to keep track of what the Experiment is currently working on. All it takes is a glance at Journal.

The BestLines Experiment also creates a separate plain text results file in the form of a Text Object. Using Manual Simulation mode, the EXPERIMENT sends OPEN, SEEK, WRITE, and CLOSE Block Statements to the Simulation creating Result.Txt.. The resulting file can be read by other statistical and data analysis programs, or it can be used simply to make a permanent record of the experimental results.

Well, enough of the preliminaries, let’s run the experiment.

CHOOSE Command / Create Simulation

Now we have the OneWay Simulation Object. We now want to begin the Experiment with a CONDUCT BestLines(1,4,1) Command. For your convenience we have already loaded the command into a Function Key, as part of the Model Settings. So just

PRESS u

Now take a look at the Journal. The Experiment is running automatically! If we wanted to get fancy, we could run multiple Experiments simultaneously, by creating more than one Simulation Object.

Let’s take a closer look at the System Clock of the running simulation.

CHOOSE View / Show Clock

That puts a running display of the clock down in the lower right corner of the Main Window. Interesting, but it makes the Experiment run a little slower, so let’s turn it off. So

CHOOSE View / Show Clock

Doing this again while the Clock is displayed, turns it off.

Now let the Experiment run to completion. This will take a few minutes, so you may want to take a short break.

Welcome back. Wasn’t that easy? We have completed an experiment and done a statistical analysis. First, look at the Results Matrix.

CHOOSE Window / Simulation Window / Matrix Window

And, since there’s only one Matrix

CHOOSE OK

In the Matrix Window you should be able to see all the results neatly tabulated. Next, look at the Result File.

CHOOSE File / Open

and in the dialog box go to the ‘Files of type:’ drop-down box and

SELECT Text File (*.txt)

Then in the main box

SELECT Result

and

CHOOSE Open

Again, we see the individual results of the experiment that were placed in the file by the WRITE Command.

Now let’s take a look at the ANOVA table in the Journal. It should look like this.

_____________________________________________________________________________

ANOVA

_____________________________________________________________________________

Source of

Sum of

Degrees of

Mean

F

Variance

Squares

Freedom

Square

 

_____________________________________________________________________________

Treatments

733101.343

2

366550.671 59995.882

Error

54.986

9

6.110

Total

733156.329

11

 

_____________________________________________________________________________

 

Count

Mean

Std. Dev.

Min

Max

95% Conf.

1

3

580.22

4.78

575.31

584.87

11.88

2

3

22.80

2.15

21.27

25.26

5.34

3

3

3.32

0.05

3.27

3.36

0.12

4

3

3.02

0.01

3.01

3.03

0.02

_____________________________________________________________________________

From the ANOVA Table we see that the F statistic is so large that there is no question of the line number being a determining factor. For less impressive effects we would normally consult a table of critical values of the F statistic, such as that in the GPSS World Reference Manual.

We move on to the descriptive statistics following the ANOVA table. Here we see that there is only a small improvement in adding more than 3 lines in the configuration. Commonly we would find that the expense of the fourth line would not be justified. We therefore conclude that this system should be configured with three telephone lines, under these load conditions.

The BestLines Experiment we used here is relatively simple. We did not pay attention to creating a restartable experiment. Notice that the Result Matrix gets filled from the bottom no matter what arguments we use in the CONDUCT Command. It would not be difficult to use the CONDUCT command to start filling the Result Matrix where we left off. We would have to change how the arguments of BestLines are used. We could even use Global Variables to save the conditions of the last completed simulation. (Recall that Global Variables continue to exist after PLUS Procedures using them have completed). Such an Experiment could be HALTed, and saved for completion at a future time. For the sake of simplicity, we did not do this here.

Well, that’s all for this series of tutorial lessons. Go ahead and end the Session. We hope we have been able to give you a few glimpses of the true simulation power available to you through GPSS World. Much remains to be explored, however, and we suggest that you continue your studies by reading, understanding and running the examples in Chapter 2 of this manual.

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