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

Lesson 12 - Reading from and Writing to External Files

GPSS World has Blocks that are designed to read from and write to external ASCII files. These Blocks can be very useful if you want to read an external data file, format your own report, or simply collect one or two pieces of data at given time intervals in an external file.

Please take the time now to read the section titled Data Streams in Chapter 4 of the GPSS World Reference Manual. Also, you should refer to Chapter 7 to better understand the use of the I/O Stream Blocks, OPEN, READ, SEEK, WRITE and CLOSE. When used in conjunction with the string procedures in GPSS World, you can accomplish powerful data handling and formatting tasks.

In this lesson, we will use some very simple models that are designed to do nothing other than exercise the actions of the Data Stream Blocks. Each model is supplied with a matching data file with which it interacts. In the case of the files that are used for writing, we have provided you with a file TSTTEMPL.TXT that can be used to restore each of the files to its original state, if you or others wish to use this lesson again.

Another way to restore the changed files is to copy the TST*.TXT files to a safe place before you start this lesson. They are located in the Sample Models folder.

When you are done with the lesson, either copy back the TST*.TXT files or copy the TSTTEMPL.TXT file to the following files.

TSTSKINW.TXT

TSTAPPW.TXT

TSTSKRW.TXT

TSTSQRW.TXT

TSTSQR2W.TXT

Next, delete these two files. TSTCATW.TXT TSTSTW.TXT

The TSTRD.TXT file and the TSTSTRD file are only used to read data. They will not be altered and do not have to be initialized before you use this lesson again.

The names of the test files used in this lesson are created by a code. Here are the letters and the I/O actions that they represent.

CAT = Catenate (String Procedure) SK = Seek

IN = Insert SQ = Sequential

R = Replace ST = String

RD = Read W = Write

You will notice in the OPEN Blocks of these sample models, that there is no

path specified. That means that GPSS World will use the Sample Folder as the destination for all files that are written to disk.

Let’s start by reading a file sequentially and storing the values in a GPSS World Matrix. We’ll use the model TSTRD.GPS and the data file TSTRD.TXT shown below.

Model: TSTRD.GPS

;GPSS World Sample File - TSTRD.GPS

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

;Reads a file sequentially and stores

;the values in a matrix.

;At end of file goes to label Finis

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

Total MATRIX ,10,1 GENERATE ,,,1

OPEN ("TSTRD.TXT"),,flag Again READ Numero,,Finis SAVEVALUE Nrow+,1

ASSIGN Numrow,X$Nrow

MSAVEVALUE Total,P$Numrow,1,P$Numero TRANSFER ,Again

Finis CLOSE Prob,,Flag1 TERMINATE 1

Flag TERMINATE 1 Flag1 TERMINATE 1

Datafile: TSTRD.TXT

1

2

3

4

5

6

7

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTRD

and

SELECT Open

Now, create the simulation and open the Matrix Window so we can watch it as

the simulation reads the data file and updates the Matrix.

CHOOSE Command / Create Simulation

and

CHOOSE Window / Simulation Window / Matrix Window

Then in the Open Matrix dialog box you will see the Matrix "Total" in the drop-down box since it is the only one in this model.

SELECT OK

and size the window to a comfortable viewing size.

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Figure 12—1. The Total Matrix.

The simulation will run very quickly filling the Matrix with the values 1 through 7 that are found in the data file. Let’s briefly discuss the way the I/O Stream Blocks are working here.

The OPEN Block is placed in a separate segment of the model since the file only needs to be opened once. A high priority Transaction opens the file to be read as the first action in the running of the simulation.

Then the Transaction that will be doing the reading of the files begins to read the file sequentially looping through the READ Block and the four Blocks that follow it. Each value read is placed into the Transaction Parameter "Numero". The next three Blocks update a SAVEVALUE counter that is then moved to a Parameter and used as the row number in the matrix. Then in the MSAVEVALUE Block, the value that has been read into P$Numero is placed in the appropriate row of the Matrix, Total. When the end of file is reached, the Transaction is sent to the CLOSE Block labeled Finis, closing the data file. Then the Transaction enters a TERMINATE Block, ending the simulation.

If any errors occur in the OPEN or CLOSE Blocks, the Transaction will go to the Blocks labeled Flag or Flag1 respectively. Such an error would be easy to spot since normally those two Blocks should have an entry count of 0.

If we were doing multiple reads and writes, we could use a high priority Transaction to open the file. After all the data is read, the file is CLOSEd. In general, you should keep files open no longer than necessary, in case multiple replications of the same simulation want to use them.

Now, close the Matrix Window and open the next file. It will demonstrate seeking data from selected locations in a file and placing it in specific locations in a matrix.

CLICK ON The X-Upper Right of the Matrix Window

Model: TSTSKRD.GPS

;GPSS World Sample File - TSTSKRD.GPS

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

;Read two separate text lines of a file

;using SEEK and stores the values

;in a matrix. Close file after second value

;is read and stored.

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

Total MATRIX ,10,1 GENERATE ,,,1

OPEN ("TSTRD.TXT"),,Flag SEEK 4

TRANSFER ,DoRead

Again SEEK 6

DoRead READ Numero,,Finis

MSAVEVALUE Total,P$numero,1,P$numero

TEST E P$Numero,4,Finis

TRANSFER ,Again

Finis CLOSE Prob,,Flag1

TERMINATE 1

Flag TERMINATE 1

Flag1 TERMINATE 1

Datafile: TSTRD.TXT

1

2

3

4

5

6

7

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTSKRD

and

SELECT Open

Now, create a simulation and open the Matrix Window. We can watch as the simulation reads the data file and updates the Matrix.

CHOOSE Command / Create Simulation

and

CHOOSE Window / Simulation Window / Matrix Window

The Open Matrix dialog box has the correct name in the drop-down box.

SELECT OK

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Figure 12—2. The Total Matrix.

The simulation will run very quickly, but this time only the values 4 and 6 will be entered into the Matrix in rows 4 and 6. Let’s briefly discuss the way the I/O Stream Blocks are working.

The OPEN Block is placed in a separate segment of the model since the file only needs to be opened once. First, a high priority Transaction opens the file to be read.

Then, the Transaction that will cause the reading of the files enters a SEEK Block that places the Current Line Position at line 4. Next, entry into a READ Block causes the fourth text line to be read. The value that has been read is put into the matrix and then a test is performed to see if another read should be done. Another READ is done and the second number retrieved and loaded into the Matrix. Finally, the file is closed and the simulation ended.

If any errors occur in the OPEN or CLOSE Blocks, the Transaction will go to Flag, or Flag1, respectively. Such an error would be easy to spot, since normally those two Blocks should have and entry count of 0.

Now, close the Matrix Window. The next test file will demonstrate writing to a selected line in a file using random access.

CLICK ON The X-Upper Right of the Matrix Window

Model: TSTSKINW.GPS

;GPSS World Sample File - TSTSKINW.GPS

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

;Test for random write.

;Inserts 123456 before line 3 of data

;file TSTSKINW.TXT

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

GENERATE ,,,1

OPEN ("TSTSKINW.TXT"),,Flag

SEEK 3

WRITE 123456,,Flag1,On

CLOSE Prob,,Flag2

TERMINATE 1

Flag TERMINATE 1

Flag1 TERMINATE 1

Flag2 TERMINATE 1

Datafile: TSTSKINW.TXT

This is line1

This is the info on line 2

This is line 3

Line 4

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTSKINW

and

SELECT Open

Now, create a simulation and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Now, let’s look at the altered data file.

CHOOSE File / Open and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box CHOOSE <Text File>

then from the list

SELECT TSTSKINW

and

SELECT Open

You will see that 123456 has been inserted before the third line of the file. If we had not used a SEEK Block, the data would have been inserted before the first line of the file. In this example, we have not isolated the OPEN Block since we are only doing one write and then closing the file and ending the simulation. You will see that the SEEK Block is used to position the Current Line Position to the location in the data file before text line 3 where the information in the WRITE Block is to be written.

OPEN, WRITE and CLOSE all have alternate exits in case an I/O error occurs. Not only will the Transaction go to the indicated Block, when an error occurs, but a subsequent CLOSE retrieves the Error Code, and places it into a Transaction Parameter.

Next, we’ll look at a write operation that appends data to the end of a file.

Model: TSTAPPW.GPS

;GPSS World Sample File - TSTAPPW.GPS

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

;Appends 123456 at end of data file TSTAPPW.TXT.

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

GENERATE ,,,1

OPEN ("TSTAPPW.TXT"),,Flag SEEK 10000

WRITE 123456,,Flag1,On CLOSE Prob,,Flag2 TERMINATE 1

Flag TERMINATE 1 Flag1 TERMINATE 1 Flag2 TERMINATE 1

Datafile: TSTAPPW.TXT

This is line1

This is the info on line 2

This is line 3

Line 4

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTAPPW

and

SELECT Open

Now, create a simulation and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Now, let’s look at the altered data file.

CHOOSE File / Open and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box

CHOOSE <Text File>

then from the list

SELECT TSTAPPW

and

SELECT Open

The only way that this use of the WRITE Block differs from the previous one is that we have chosen to append a value to the end of the file. You will see that the value 123456 has been added to the end of the file. We have done two things differently here. First, the SEEK Block has the value 10000 in it and the WRITE Block is in insert mode (indicated by the on). In Insert mode when the Current Line Position is set past the end of the file, the data will be appended to the end of the file.

Although we will not show it here, if Insert mode is off, meaning that the WRITE Block is operating in Replace mode, then GPSS World would fill any empty gaps with null text lines up to the line number in the SEEK, and add the data at that position.

Next on the agenda is a model that uses the WRITE Replace mode. We’ve used the code SKRW in the name to indicate Seek, Replace, and Write. The SEEK Block is used to place the Current Line Position at a chosen location.

Model: TSTSKRW.GPS

;GPSS World Sample File - TSTSKRW.GPS

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

;Writes 123456 on line 2 of data file

;TSTSKRW.TXT replacing original line.

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

GENERATE ,,,1

OPEN ("TSTSKRW.TXT"),,Flag SEEK 2

WRITE 123456,,Flag1,Off CLOSE Prob,,Flag2 TERMINATE 1

Flag TERMINATE 1 Flag1 TERMINATE 1 Flag2 TERMINATE 1

Datafile: TSTSKRW.TXT

This is line1

This is the info on line 2

This is line 3

Line 4

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTSKRW

and

SELECT Open

Now, translate the model and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Now, let’s look at the altered data file.

CHOOSE File / Open and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box

CHOOSE <Text File>

CHOOSE File / Open

then from the list

SELECT TSTSKRW

and

SELECT Open

What happened? Line two of the data file was overwritten with the value 123456. Once again, we did not need to isolate the OPEN or the CLOSE Blocks since we were only going once through the model. The difference here from the previous model is that the WRITE Block is in Replace mode. You have to

specify OFF for replace mode. In this example, we also used the SEEK Block to

choose the line that we wanted to be overwritten. Next let’s look at how Replace mode works if there is no line position specified in a SEEK Block.

Model: TSTSQRW.GPS

; GPSS World Sample File - TSTSQRW.GPS

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

;Writes 123456 on line 1 of data file

;TSTSQRW.TXT replacing original line.

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

GENERATE ,,,1

OPEN ("TSTSQRW.TXT"),,Flag WRITE 123456,,Flag1,Off CLOSE Prob,,Flag2 TERMINATE 1

Flag TERMINATE 1 Flag1 TERMINATE 1 Flag2 TERMINATE 1

Datafile: TSTSQRW.TXT

This is line1

This is the info on line 2

This is line 3

Line 4

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTSQRW

and

SELECT Open

Now, create a simulation and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Now, let’s look at the altered data file.

CHOOSE File / Open

and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box CHOOSE <Text File>

then from the list

SELECT TSTSQRW

and

SELECT Open

As you might have guessed, this works just like the last model, but this time the Current Line Position has not been relocated so it is line number 1 that is replaced. Next, we’ll replace two lines, one with a text string and one with a calculation result. You can put any values in the string that you want. In a minute we’ll show you how to combine multiple values from different sources in a string. Now let’s try the multiple sequential WRITEs in replace mode.

Model: TSTSQR2W.GPS

;GPSS World Sample File - TSTSQR2W.GPS

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

;Does 2 sequential writes in replace mode

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

GENERATE ,,,1

OPEN ("TSTSQR2W.TXT"),,Flag

WRITE ("This is fun."),,Flag1,Off WRITE (5+5),,Flag2,Off

CLOSE Prob,,Flag3 TERMINATE 1

Flag TERMINATE 1 Flag1 TERMINATE 1 Flag2 TERMINATE 1 Flag3 TERMINATE 1

Datafile: TSTSQR2W.TXT

This is line1

This is the info on line 2

This is line 3

Line 4

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTSQR2W

and

SELECT Open

Now, create a simulation and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START

and in the dialog box since START 1 is what we want.

SELECT OK

Now, let’s look at the altered data file.

CHOOSE File / Open and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box

CHOOSE <Text File>

then from the list

SELECT TSTSQR2W

and

SELECT Open

The only difference here is that after each WRITE Block entry, the Current Line Position is increased one line. Hence, text lines 1 and 2 are replaced. We have also included an error flag for each WRITE so that if an I/O error occurs, we will know which Block is the cause of the problem.

In our final two examples, we will work with strings. You can manipulate data in powerful ways using String Procedures with data that has been read in or data that you may wish to write. You can format report headers and data as well as read in and extract portions of data from a file. You might want to read further about Strings in Chapter 8 of the GPSS World Reference Manual.

Model: TSTCATW.GPS

;GPSS World Sample File - TSTCATW.GPS

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

* *

* Barber Shop Simulation * * Time is in Minutes *

* *

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

GENERATE 5,2.5 ;Create next customer. SAVEVALUE Custnum+,1 ;Total customers who stay

ASSIGN Custno,X$Custnum ;Assign number to customer QUEUE Barber ;Begin queue time.

SEIZE Barber ;Own or wait for barber. DEPART Barber ;End queue time.

ADVANCE 10,2.5 ;Haircut takes a few minutes. RELEASE Barber ;Haircut done.

;Give up the barber.

TEST G TG1,1,Fin ;Write final Avg. Queue Residence TERMINATE 1 ;Customer leaves.

Fin OPEN ("TSTCATW.TXT"),,Flg1

WRITE (Catenate("Avg. Barber Queue Time Is ",QT$Barber)),,Flg

CLOSE Prob,,Flg2

TERMINATE 1

Flg TERMINATE 1

Flg1 TERMINATE 1

Flg2 TERMINATE 1

Datafile: TSTCATW.TXT

This file is to be created.

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTCATW

and

SELECT Open

Now, create a simulation and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

Now, let’s look at the altered data file.

CHOOSE File / Open and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box

CHOOSE <Text File>

then from the list

SELECT TSTCATW

and

SELECT Open

In the WRITE Block in this model, we’ve used the String Procedure "Catenate" to take text data and mix it with actual data from the simulation run. You can see that this would be most valuable in formatting reports or putting out selected information at given time intervals in a simulation run. You could have a segment of your model with the sole purpose of generating Transactions to write simulation statistics. The values from the simulation could be labeled as we have done here for easy interpretation after the simulation run is complete.

Now, let’s see how we can manipulate data that we read in from a file. Model: TSTSTRDW.GPS

; GPSS World Sample File - TSTSTRDW.GPS

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

*Movie Theater Food Buying Analysis *

*Takes info on age and sex, reads it in and analyzes *

*how mix of people will influence needs at concession *

*stand. Then writes a report on wait times, queue size *

*and total people served. *

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

Fem EQU 1 Male EQU 2 GENERATE 1

TEST E X$Finish,0,In ;After End of File-destroy next xact READ Info,1,Fin ;Get Cust Age and Sex

SAVEVALUE Info1,(Substring(P$Info,1,2)) SAVEVALUE Info2,(Substring(P$Info,3,1)) SAVEVALUE Counter+,1

TEST G X$Info1,8,In ;Older than 8 may buy TEST LE X$Info1,17,In ;Older than 17 don’t buy TEST E X$Info2,Male,Ques ;All Males buy

Ques TRANSFER .50,In ;50% of Females are dieting-don’t buy QUEUE Wait ;Begin queue time.

SEIZE Salesperson ;Customer gets salesperson DEPART Wait ;End queue time.

ADVANCE 6,1 ;Get service

SAVEVALUE Served+,1 ;Keep track of number served RELEASE Salesperson ;Done with Salesperson

In TERMINATE ;Enter the viewing area

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

GENERATE ,,,1,10 ;Make this first Transaction OPEN ("TSTSTRD.TXT"),1,Er ;Read file

OPEN ("TSTSTW.TXT"),2,Er1 ;Write file TERMINATE

Fin SAVEVALUE Finish,1 ;Signal EOF to new xacts WRITE (Catenate("Average "," Average ")),2,Er2 WRITE (Catenate(" Wait ","Line Size")),2,Er3

WRITE (Polycatenate(" ",INT(QT$Wait)," ",INT(QA$Wait))),2,Er4 WRITE "Total People Served",2,Er7

WRITE (Catenate(" ",X$Served)),2,Er8 CLOSE Prob,1,Er9

CLOSE Prob1,2,Er10 TERMINATE 1

Er TERMINATE 1

Er1 TERMINATE 1

Er2 TERMINATE 1

Er3 TERMINATE 1

Er4 TERMINATE 1

Er5 TERMINATE 1

Er6 TERMINATE 1

Er7 TERMINATE 1

Er8 TERMINATE 1

Er9 TERMINATE 1

Er10 TERMINATE 1

Datafile: TSTSTRD.TXT

161

021

252

162

151

131

172

172

182

352

341

152

152

162

151

131

172

172

182

352

341

202

141

161

171

151

112

142

142

122

132

142

152

Datafile: TSTSTW.TXT

This file is to be created.

Now, let’s run the simulation

CHOOSE File / Open

In the dialog box

SELECT TSTSTRDW

and

SELECT Open

Now, create a simulation and run it.

CHOOSE Command / Create Simulation

and

CHOOSE Command / START and in the dialog box since START 1 is what we want.

SELECT OK

and wait for the simulation to run. Now, let’s look at the altered data file.

CHOOSE File / Open and in the dialog box you must first

CLICK ON The Down Arrow at the End of the Files of type box

CHOOSE <Text File>

then from the list

SELECT TSTSTW

and

SELECT Open

In this final model, we have read in values from the file TSTRDST.TXT, manipulated them first by dividing them into smaller pieces and second by taking only a portion of the information that we read at a given location in the data string. You can see how powerful String Procedures can be. Take some time to examine the String Procedures in Chapter 8 of the GPSS World Reference Manual. Also, you may want to take a breather before you tackle the ANOVA Command.

Don’t forget to initialize the data files as described in the beginning of this lesson and delete the two string output files. You may also want to delete the reports that we have created along the way. You can do that in the Windows file management system. See you when you’re ready for the next lesson.

Lesson 13 - The ANOVA Library

Procedure

You have probably noticed that changing nothing other than the random number seeds in a simulation can cause what appear to be large differences in output. If we are to use simulation in real problems, how can we tell which effects are random and which are real? The GPSS World ANOVA command provides a way.

This lesson is a brief introduction in the use of the statistical method known as analysis of variance. In it, we consider the ANOVA PLUS Library Procedure, which makes a first level of statistical analysis relatively easy. However, to become proficient in the application of simulation methods, you must become familiar with elementary statistical inference and the design of experiments. These topics are not covered in detail here.

When you use statistical methods to see if two alternatives are really different, you must not allow extraneous uncontrolled events to occur during the simulations. It would not be fair to load one run with additional activities at some unknown place in the simulation, and not to do precisely the same thing in all other runs. Therefore, you should generally not use interactive methods when you are running simulations that will be used for the statistics in your final report.

Let’s return now to the example of the barber who cannot keep up with arriving customers. As manager of the barber shop, you want to determine what effect a faster barber will have on the situation. You do not want to hire another barber. You want to see if a barber who can cut hair in an average time of 5 minutes, causes a significant reduction in waiting time for the customers.

The treatment to be tested is that of barber 1 against barber 2. The barbers differ only in their average haircut times. Our experiment, then, consists of two treatment levels: 6.8 minute average haircut time, and 5 minute average haircut time. We will run 3 simulations at each level. In general, you will want to run more.

If our results are in the form of an arithmetic average of many items, we are justified in using the ANOVA command to do a statistical analysis. We can satisfy this criterion by using the average waiting time of customers as the overall measure.

We are going to build a Results Matrix of a special format that can be used by the Anova procedure. Let’s begin.

Since we have 1 treatment with two levels, we need 2 dimensions in our Results Matrix. The last dimension of a results matrix is always for replications, and we will have three of them at each treatment level. Therefore we will use a 2 x 3 matrix.

Now start the GPSS World Session.

CHOOSE File / Open

In the dialog box

SELECT ANOVA

SELECT Open

Here’s a copy of the program that you should now see in the Model Window.

; GPSS World Sample File - ANOVA.GPS

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

* *

*Barber Shop Simulation *

*Time is in minutes *

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

GENERATE 5,1.7 ;Create next customer. QUEUE Barber ;Begin queue time.

SEIZE Barber ;Own or wait for barber. DEPART Barber ;End queue time. ADVANCE Cut_Time ;Cut takes a few min. RELEASE Barber ;Give up the barber. TERMINATE 1 ;Customer leaves.

Notice that our main experimental parameter in the ADVANCE Block is represented by a User Variable, Cut_Time. This will allow us to change the time it takes to complete a haircut. We will use a three digit random number seed varying only the middle digit to indicate which run of the simulation is being executed, run 1, 2 or 3. In the second set of runs with the faster barber, we will use the same random number seeds and change only the speed at which the barber works.

Before starting the simulation, let’s take a look at the INCLUDE File that we will use to execute multiple simulation runs for us.

RESULTS MATRIX ,2,3 ; Set up for 3 replicates of two levels Cut_Time EQU 6.8

Treatment EQU 1 RMULT 411 Start 100,NP

MSAVEVALUE RESULTS,1,1,QT$Barber Clear Off

RMULT 421 Start 100,NP

MSAVEVALUE RESULTS,1,2,QT$Barber Clear Off

RMULT 431 Start 100,NP

MSAVEVALUE RESULTS,1,3,QT$Barber Clear Off

Cut_Time EQU 5

Treatment EQU 2 RMULT 411 Start 100,NP

MSAVEVALUE RESULTS,2,1,QT$Barber Clear Off

RMULT 421 Start 100,NP

MSAVEVALUE RESULTS,2,2,QT$Barber

Clear Off

RMULT 431

Start 100,NP

MSAVEVALUE RESULTS,2,3,QT$Barber

Let’s look at what will happen when we Translate the INCLUDE File. First, it defines a Global Matrix named Results, which will be used to hold the numeric values for the Analysis of Variance. The Matrix has two dimensions, supporting 2 treatment levels, with 3 replicates of each.

Next, you will see that an EQU Command has been used to set the average haircut time equal to 6.8 minutes. Then, after three runs of the simulation and collection of appropriate data, the time is set to 5 minutes, allowing for a faster barber than in the first series of runs. You will also see that we set a Treatment value before each series of runs. This will differentiate the runs done with the 6.8 minute Cut_Time (Treatment 1) from those done with the 5 minute Cut_Time (Treatment 2).

Notice that we CLEAR OFF statistics between runs to avoid correlation between one simulation and the next. The OFF parameter is necessary to avoid resetting the Results Matrix. Also, in our simple example, we have not built in allowance for an empty barber shop at the start of each simulation. In your own simulation studies, you will want to ensure that startup effects are insignificant. This can be done by ignoring a transient startup period, using the RESET command some time into the simulation. The GPSS World PLOT command is useful for identifying transient periods that you might want to exclude. We could then gather the waittime values for each of the runs based on a start with a full shop. For now, let’s just concentrate on our simpler example.

Finally, we do two additional things. We run with the NP option as the B operand of START. This suppresses the Standard Report. Also, we set the seeds of the random number generators in the Command File. The same seeds are used in the second series of runs so that the only difference in the model is in the time it takes to cut hair. This reduces variance in the results.

Now start a simulation.

CHOOSE Command / Create Simulation

This creates the Simulation Object and opens its Journal View. Next, we’ll use and Include File to run the simulations. Remember, GPSS World will look for the Include file in the same folder where the model object exists, if the simulation has not been saved, as in this case. If the simulation has been saved, it will look in the folder where the simulation object resides. Now do the Commands in the INCLUDE File:

CHOOSE Command / Custom

TYPE INCLUDE "ctlanova.txt"

SELECT OK

What happened? The simulation started to run automatically. You will see that the simulation has run 6 times in a few seconds. Now, let’s look at the Results Matrix we have built for the Analysis of Variance.

CHOOSE Window / Simulation Window / Matrix Window and when the Matrix Window Cross Section Dialog appears,

CHOOSE OK

This opens the Matrix Window on the Results Matrix. You may want to expand the window if all the cells in the Matrix are not visible. Here, we can see the results of each individual simulation.

Figure 13—1. The Results Matrix.

Now its time for the analysis.

CHOOSE Command / Custom

Type

SHOW ANOVA(Results)

and

SELECT OK

The ANOVA Procedure writes an ANOVA Table into the Journal Window and returns the F value of the analysis.

Figure 13—2. An ANOVA Table in the Journal Window.

Please take time now to read the section on the ANOVA Library Procedure in Chapter 12 of the GPSS World Reference Manual. Please note the table of critical values of the F distribution. You will have to use it shortly. See you when you get back.

Welcome back. Let’s now interpret our results. The primary question is whether or not the effect of the faster barber is above the random noise level.

From the F distribution table in Chapter 12 of the GPSS World Reference Manual, we find that the critical value of F for this experiment, at the 95% level, is 7.71. Since our calculated F value is much greater, we conclude that the effect of the faster barber is statistically significant.

Sometimes it is possible to expose real effects by increasing the durations of the simulations and/or the number of replications. We don’t need to worry about that here.

The GPSS World ANOVA feature provides a very easy first level of statistical analysis. However, you may want to do more. In that case you may find that you want to create a results text file for input to a separate statistical analysis program. This is relatively easy using the OPEN, CLOSE, READ, WRITE, and SEEK GPSS Blocks, and the String formatting routines in the PLUS Library.

Also, the powerful GPSS World EXPERIMENT Procedure can be used to automatically direct and analyze the progress of an experiment involving many simulation runs. Lesson 19, below, goes deeper into the subject. We have really only touched the surface here.

As usual, close up all the windows before going on to the next lesson. You can leave the Main Window open if you don’t intend to stop now.

In the next lesson, we turn to an easier topic. We will look at how Reports are handled in GPSS World. See you then.

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