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

This Expression results in 1, if there are less than 6 customers waiting, or 100 otherwise.

Remember that # is used to represent multiplication, not*, which is reserved for SNA indirect addressing.

Now let’s look at a random number stream.

CHOOSE Command / SHOW

and when the dialog box opens

TYPE RN1000

SELECT OK

The RN SNA returns a random integer from 0 to 999 in the Status line and in the Journal Window. Use the Command again. When the dialog box opens

TYPE RN1000

SELECT OK

A second call to the same random number generator returns a different result. If the result took some time in returning, remember, we have a lot of windows open. You may want to close all but the Model and Journal / Simulation Windows now since their continuing update slows the running of the simulation and the response to interactive commands.

But wait a minute! We didn’t have to type in the SHOW command again. We could have loaded it into a function key. Let’s do it.

CHOOSE Edit / Settings

and select the Function Keys Page and enter the SHOW Command next to F9.

TYPE SHOW RN1000

then

SELECT OK

and

PRESS t

several times. As you can see, a random number stream returns a different random number on successive calls. This happens when you call SNAs that access random numbers within a simulation, too.

Time for a break. Let’s review. This lesson was an introduction to the entry and correction of statements from the keyboard. In this lesson we used the On-line Help facility, used the Assignable Function Key feature, investigated Expressions in GPSS World, and worked with the Facilities and Expressions Windows.

In the next lesson, we look at the full screen text editor in. Now end the Session.

CLICK ON The X-Upper Right All Open Windows

and when asked if you want to save the changes in any of the Windows

SELECT No

Lesson 4 - The Text Editor

The integrated editor is a powerful full screen text editor with many of the features of word processors such as Cut, Paste, Copy, and Search. In addition, there are features that allow you to find model Translation errors quickly. It is discussed in detail in Chapter 3 of the GPSS World Reference Manual.

Let’s open a new model and do some editing.

CHOOSE File / Open

then in the dialog box

SELECT SAMPLE1

and

SELECT Open

Now let’s Edit the Model File.

Highlight the line that begins with ADVANCE by placing the cursor at the beginning of the line and dragging it across the page using the mouse with the left button continually depressed while moving it. The highlighted text is said to be selected. This is "swipe" selection.

There’s a second way to select text, as well. Click just to the left of the first letter of ADVANCE.

This removes the selection you just did. Now press and hold j while you click just to the right of

the last letter of ADVANCE. You have just selected text using "enhanced" selection. Sometimes this method is more convenient. Yet another selection method is to double click to select a single word.

Now, lets place a copy of the selected text into the clipboard.

CHOOSE Edit / Copy

Now you can paste in another ADVANCE Block after the RELEASE. Place the cursor in the RELEASE Block line and

CHOOSE Edit / Insert Line

and

CHOOSE Edit / Paste

You can also use the keystrokes b+ X, b+ C and b+ V for Cut, Copy and Paste, respectively after you have selected text.

We now have additional ADVANCE Block right before the TERMINATE. You can change the time in the A operand by highlighting the 400 by placing the mouse pointer in front of the 4 and dragging it over the number and then releasing it and then typing in a new value. You do not have to specifically delete the 400, that is automatically done as soon as you start to type a new value.

TYPE 200

Explore other options of the Edit menu. Make a change and then choose Undo to restore the file to its state just before the change was made. Delete and insert lines. Delete deletes the line in which the cursor is positioned. Insert puts a new line after the line where the cursor is

positioned. The Font option lets you change the font and color of your display. Remember,

Courier New is a monospaced font that lets you line up columns in your model easily since all characters take up the same amount of space.

Now let’s take a look at the Search commands. Find / Replace and the Find / Replace Box are similar to those commands found in common text editors and word processors. You

can find, change or do mass changes on text in your model. When using the Find / Replace Window, you should note that the Search only operates in one direction and will stop when it reaches the end of the file. It is best to position the cursor at the beginning of the file when doing a search. The Find / Replace Box is shown below.

CHOOSE Search / Find / Replace

Figure 4—1. The Find / Replace Dialog Box

As with all the windows, you can move it to a more convenient place by clicking on the title bar and dragging the window to a new location. To do this just place the mouse pointer over the Title Bar of the window, click and hold mouse button 1 while you drag the window, then release.

Now Close the SAMPLE2.GPS Model Window

CLICK ON The X-Upper Right of Model Window

and when the unsaved changes box appears

SELECT No

The Bookmark feature is a little more complex so we’ll do some practice with it. Open the model BOOKMRK.GPS. This is really the model TELEPHON.GPS.

CHOOSE File / Open

and in the open model box

SELECT BOOKMRK

and

SELECT Open

; GPSS World Sample File - BOOKMRK.GPS

100 *****************************************************

110 * *

120 * *

130 * Telephone System Model *

140 * by Gerard F. Cummings *

150 * *

160 *****************************************************

170 * Simple Telephone Simulation *

180 * Time Unit is one second *

200 Sets STORAGE 2

210 Transit TABLE M1,100,100,20 ;Transit times

220 GENERATE 100,60 ;Calls arrive

230 Again GATE SNF Sets,Occupied ;Try for a line

240 ENTER Sets ;Connect call

250 ADVANCE 180,60 ;Speak for 3+/-1 min

260 LEAVE Sets ;Free a line

270 TABULATE Transit ;Tabulate transit time

280 TERMINATE 1 ;Remove a Transaction

290 Occupied ADVANCE 300,60 ;Wait 5 minutes

300 TRANSFER ,Again ;Try again

310 *******************************************************

Now, place the cursor in line 210. We have added line numbers to the TELEPHON.GPS sample model so that it will be easier to see how BOOKMARKing works. Your GPSS World models do not need to have line numbers.

CHOOSE Search / Mark

Now, position the cursor in line 300 and again

CHOOSE Search / Mark

You have now set two Bookmarks in the file. Place the cursor in the middle of line 260.

CHOOSE Search / Select to Bookmark

What happened? The text from the cursor position to the last mark visited was highlighted. You should see the highlighting to just before line 300. Remember if you try to move the cursor with the arrow keys, the text will be deselected. Bookmarks can be very helpful in moving around your Model File or in deleting a large portion of text or for cutting and pasting large sections of text.

Now try moving around the file using the To Next Bookmark command.

CHOOSE Search / Next Bookmark

a number of times. Notice that the search moves through the Bookmark list in an orderly fashion. When the end of the list is reached, the search for the next bookmark goes back to the beginning. Remember, no matter where you are in the file (even if you have used other commands such as Find Next) the To Next Bookmark Command will always go to the Bookmark that is next in the list after the last bookmark visited or the last bookmark created.

If you save a file after inserting Bookmarks, they will also be saved.

Close the BOOKMRK.GPS File using the method described for the last file that we closed. Finally, let’s address finding and correcting translation errors.

CHOOSE File / Open

From the open model dialog selection box

SELECT ERROR

in the files list box, then

SELECT Open

CHOOSE Command / Create Simulation

Well, we knew there were going to be errors in this model. Let’s use the editing features to find and correct them.

Position and size the Journal and Model Windows so that the model text and Status Line in the Main Window and the Journal Window are all visible. Make sure the Model Window has the focus.

CLICK ON The Title Bar of the Model Window

Let’s use the Next Error search. This menu item will place the cursor in the line at the place of the error and show the error in the Status Line of the Model Window.

CHOOSE Search / Next Error

The cursor has been placed in the line that uses the Exponential Distribution where we have neglected to add the final right parenthesis. You will see that the error message appears in the Status Line of the Main Window.

Figure 4—2. Translation Error

You can now insert the missing right parenthesis. Notice that the invocation of the Exponential() procedure is enclosed in parentheses. This is an important rule to remember: In general, PLUS expressions occurring outside a PLUS Procedure must be parenthesized! The good news is that you can use parenthesized expressions just about anywhere.

Search / Previous Error allows you to scroll backwards through an error list.

The error message in the Journal File tells us that the second error is at line 13. Use Search / Go To Line to find the line.

CHOOSE Search / Go To Line

and in the dialog box

TYPE 13

SELECT OK

The cursor has been placed at the beginning of line 13. Insert the semicolon that is missing in front of the comment. Then, we should be ready to run the simulation, once it is retranslated.

CHOOSE Command / Retranslate

Now, try to run it. You will see a runtime error immediately.

CHOOSE Command / START

In the dialog box, replace the 1.

TYPE 10,NP

SELECT OK

The runtime error appeared in the Journal Window telling us that we are trying to release an unowned Facility. Now use Search / Go To Line to find and correct the name of the Facility

used in the RELEASE Block. Make sure the Model Window has the focus when you do this search. Runtime errors do not create an error list like the one produced by a translation.

Therefore, you can’t use Next Error. Instead, a runtime error is called an Error Stop. The

simulation halts and sends several messages that identify and locate the single error.

If you wish to retranslate the model and test that it will run successfully to completion you can do so on your own now.

In this lesson we have explored the EDIT and SEARCH command menus. We have also addressed correction of errors. These commands are quite useful for modifying individual lines or large portions of text. You can enter your entire model by typing it in and using the editing command to alter or duplicate sections of you file.

Now end the Session.

CLICK ON The X-Upper Right of All Windows

and when asked if you want to save the changes

SELECT No

In the next lesson we will begin to study the most important of the GPSS Block statements.

Lesson 5 - The GENERATE and TERMINATE Blocks:

Transaction Entities

A GPSS Transaction is an object with a set of attributes. Each Transaction is distinct in that it can be identified by a unique Transaction number. Transactions created in a simulation are numbered consecutively starting with 1. In addition, you can change the attributes associated with each Transaction. Attributes are in the form of priority, scheduled time, Assembly Set, and "Transaction Parameters", which are given user ASSIGNed names or numbers. Transaction Parameters are like the letters in the mail carrier’s bag that are addressed to one person. The Parameters carry information about the Transaction that is unique to that Transaction only. You can use Snapshot Windows to look at information that is carried in these parameters. Transactions pass from Block to Block in a simulation, acting on, and being acted upon by other GPSS entities.

Unlike general purpose programming languages, each Transaction in GPSS maintains a place marker. Whereas there is only one place in a computer program to be remembered, in a GPSS simulation there may be thousands, with thousands of Transactions located in many different Blocks. Transactions do not necessarily start at the top of the program. A GPSS simulation may have many GENERATE statements, each of which creates many Transactions, each of which has a place marker.

Transactions can be created in a batch, or at spaced out time intervals by a GENERATE Block. All simulations must have at least one GENERATE Block. Let’s consider the case where a new Transaction is created every 60 time units. The specific unit of time does not matter as long as we are consistent throughout. Let’s say that one time unit represents a second. Then, the appropriate form of the GENERATE statement for a Block which creates a new Transaction every minute is:

GENERATE 60 ;Create a new Transaction

Since GPSS World has a floating point clock, we could also represent generation of Transactions at one minute intervals by

GENERATE 1 ;Create a new Transaction

Then if we needed to represent a one second interval it could be represented by 1/60 of a minute or 0.16666667. You should choose the representation that is most meaningful in your model. If you use an expression here, it must be parenthesized.

Start a GPSS World Session as we have before.

CHOOSE File / New and since the model is already selected

SELECT OK

and type the GENERATE statement from the previous page in the Model Window that appears. Then, translate your one line model. Start by pressing the Tab Key.

PRESS v

TYPE GENERATE

PRESS v

TYPE 60

PRESS v

TYPE ;Create a new Transaction

We have only used tabs so the model will line up. It is not necessary for the parts of your GPSS model line to be in certain columns, but it does make it easier to read.

Now,

CHOOSE Save As

and in the dialog box in the highlighted area

TYPE MYMODEL

and

SELECT OK

CHOOSE Command /Create Simulation

and

CHOOSE Window / Simulation Window / Blocks Window

You should see your GENERATE Block in the Blocks Window. Blocks are always numbered starting with 1.

In the Blocks Window, succeeding Blocks are generally placed beneath their predecessors. When the next Block won’t fit beneath its predecessor, it is moved up to the top of the next column to the right. The arrangement of the Blocks is also due to the size of the window and will change if you resize the window.

TERMINATE Blocks remove Transactions from the simulation. When a Transaction enters a TERMINATE Block, the Transaction is destroyed. Also, there is an optional operand that will decrement a special number called the "Termination Count". When you type START 123, you are setting the Termination Count to 123. This controls how long the simulation should run by itself. If you place a 1 in operand A of a TERMINATE Block, every time a Transaction is destroyed by that Block, the Termination Count is reduced by 1. When the Termination Count becomes 0 or less, the simulation ends and, unless suppressed by Operand B of START, a Standard Report is written automatically. The Termination Count can be less than zero when the simulation ends if Operand A of the TERMINATE Block is greater than 1.

Let’s add a TERMINATE Block to our model. In the Model Window start a new line after the GENERATE Block line. With the cursor at the end of the GENERATE Block line

PRESS e

then

PRESS v

TYPE TERMINATE

PRESS v

TYPE 1

PRESS v

TYPE ;Destroy a Transaction

CHOOSE Command / Retranslate

Figure 5—1. The Blocks Window with a two Block Model

These two Blocks represent a tiny simulation. They could represent a situation where a customer arrives at a store every minute, precisely on the minute. Not very likely, but later you will see how to change the model to match your specific situation. For now, let’s use this model to study what happens in a simulation.

The clipboard operations of Cut, Copy and Paste are available as you build your model. Large segments of blocks can be selected and then replicated, moved, or deleted this way. Feel free to experiment with this powerful feature. Multiple Block selection and the clipboard operations are discussed in the GPSS World Reference Manual.

Before we begin the simulation, you must know about two sets of Transactions called the Current Events Chain, and the Future Events Chain. To understand these chains, you must keep in mind the "system clock", which tells what the current simulated time is. Each Transaction has an attribute that indicates when it must attempt its next Block entry. If the current simulated clock time has not yet reached that time, the Transaction must be put aside until the simulation is ready for it. That’s what the Future Events Chain is for. The Future Events Chain is a holding area for Transactions that are scheduled to do something in the future.

Every time a Transaction enters a GENERATE Block, a second Transaction is created. This new Transaction does not enter the GENERATE Block right away. Instead, it is placed on the Future Events Chain according to the arrival time interval you specified in the GENERATE Block.

The Current Events Chain is the set of Transactions that still have Blocks to be entered at the current system clock time. Transactions are taken from the front of the Current Events Chain, one at a time, to enter as many Blocks as possible. When there are no more Transactions on the Current Events Chain, GPSS World will advance the system clock.

Let’s take a look at the Current Events Chain and the Future Events Chain in our Current Model. First set up a Stop Condition that will cause the simulation to stop on each attempted Block entry.

Make sure the Blocks Window has the focus. You should now see two blocks

CLICK ON The Generate Block

In the debugging icons in the Debug Toolbar at the top of the Blocks Window, you will see a place icon in the form of a stop light.

CLICK ON The Place Icon in the Debug Toolbar at the Top of the Window

This will place a STOP on the Generate Block. The Simulation will stop on an attempted entry into the GENERATE Block. The STOP command is discussed in Chapter 6 of the GPSS World Reference Manual. Before we even start, let’s see what’s on the Current Events Chain and the Future Events Chain.

Please note: If you are using a Student Version, you will have to use the following to view the contents of the CEC and FEC. The Student Version does not have access to Snapshot Windows other than the User Stops Window.

CHOOSE Command / Custom

TYPE Report ,Now

The Current Events and Future Events Chains are listed at the bottom of the Report.

Now, we will go back to accessing the Snapshots of the FEC and CEC in the full version of the software.

CHOOSE Window / Simulation Snapshot / FEC Snapshot CHOOSE Window / Simulation Snapshot / CEC Snapshot

Nothing on the CEC, but there is one Transaction on the FEC! That’s because the GENERATE Block was "primed", thereby creating its first Transaction when we issued the STOP Command. Once we issue a START Command, Transaction 1 will be moved to the Current Events Chain and the time will be set to 60. Close each of the Snapshot Windows.

CLICK ON The X-Upper Right of Each Window

These windows are not like the windows that you select under Window / Simulation Window. Snapshots are static views of the current condition and will not change as the

simulation runs. They can be refreshed by halting the simulation and opening the window when you are ready for current information. Although you don't have to halt the simulation, it keeps the information consistent with the current state of the simulation.

Make sure you can see all of the Journal Window.

CHOOSE Command / START

and in the dialog box, replace the 1

TYPE 100

SELECT OK

This sets the Termination Count to 100, moves Transaction 1 to the Current Events Chain, and begins the simulation. But remember that we have set up a Stop Condition. That is why the simulation stops before the first Block entry, and writes a 2 line message in the Journal Window. We could also put a Stop Condition on any Block using the Stops menu in the Blocks Window. Let’s make Transaction 1 enter the GENERATE Block. We’ll use the

STEP 1 Command, which has been preloaded into function key p. It will be available until you change it.

PRESS p

Now, look at the Current Events Chain and the Future Events Chain using the same mouse clicks that we did a minute ago in the Window / Simulation Snapshot Menu.

Your windows should look like this.

Figure 5—2. CEC Snapshot-Unexpanded View.

Figure 5—3. FEC Snapshot

.

Now, look at the FEC Snapshot so you can see all the information about the Transaction waiting to enter the simulation. On the FEC the Time is the "Block Departure Time", the system clock time when Transactions on the FEC are scheduled to come back into the simulation. The Next Block column shows the number of the Block to be entered next by each Transaction. Block number 1 is the GENERATE Block and Block number 2 is the TERMINATE Block. Transaction 2 is waiting to enter the GENERATE Block.

Now let’s look at the Expanded View of the CEC. With the focus on the CEC Snapshot Window

CLICK ON The + in the CEC Window

Figure 5—4. CEC Snapshot. Expanded View.

Transaction 1 has entered the GENERATE Block, thereby creating Transaction 2, which goes onto the Future Events Chain. Transaction 1 is on the Current Events Chain, with M1, its time of entry into the simulation at 60 seconds, and Transaction 2 is on the Future Events Chain, ready to enter the GENERATE Block when the simulated clock time becomes 120 seconds. The GENERATE Block’s job is to bring in a new Transaction every 60 simulated seconds. You will see this information in the various views of these windows. Later we will see that Transactions Parameters can be easily accessed in these windows.

Close the Snapshot Windows as we did a few minutes ago.

Let’s see what time it is right now. In the Model Window

CHOOSE Command / SHOW

In the dialog box:

TYPE AC1

CHOOSE OK

AC1 is the SNA that returns the value of the absolute system clock. Transaction number 1 will move as far as it can in the Current Model at time 60. When it can move no further, it is

taken off the Current Events Chain. Let’s load the SHOW command into s.

CHOOSE View / Settings

Then, page forward in the Model Settings Notebook to the Function Keys Page.

Next to F8

TYPE SHOW AC1

SELECT OK

Transaction 1 is about to be destroyed by entering the TERMINATE Block. Let’s let it do so.

PRESS p

The Transaction will move one Block in response to a STEP 1 command that has been caused by the keystroke(s) just executed. Transaction 1 has been destroyed. The next Transaction to move in the simulation is Transaction 2, which has just been taken off the FEC.

Transaction 1 is gone. Since that depleted the Current Events Chain, there was nothing more to be done at time 60. GPSS World then advanced the clock to the next scheduled time of 120. Transaction 2 was then taken off the Future Events Chain and placed on the Current Events Chain. The Future Events Chain is now empty. However, Transaction 2 is about to enter the GENERATE Block. This will create Transaction 3 and schedule it for 60 time units into the future. Then Transaction 2 will go on its way. Let’s allow Transaction 2 to enter the GENERATE Block.

PRESS p

Now look at the chains.

CHOOSE Window / Simulation Snapshot / CEC Snapshot and with the CEC Snapshot Window having the focus

CLICK ON The + Sign

then in the Main Window

CHOOSE Window / Simulation Snapshot / FEC Snapshot

Size the windows and move them one above the other. Then elongate them so you can see all the information. See? Transaction 3 is now on the Future Events Chain at time 180, and Transaction 2 is ready to enter the TERMINATE Block. When it does, it will be destroyed, and the simulation will have nothing more to do at time 120.

Oh yes! Remember that Transaction 1 already entered the TERMINATE Block. That means that the Termination Count was decremented by 1. Let’s check TG1, the SNA that returns the remaining Termination Count. In the Model Window menu

CHOOSE Command / SHOW

then

TYPE TG1

in the dialog box.

SELECT OK

Of course! We set up the TERMINATE Block to subtract 1 from the Termination Count every time it is entered by a Transaction. Since it has been entered once, the Termination Count is now 99. You should see the value in the Status Line at the bottom of the Main Window. You will also see the value in the Journal Window. If we would remove the Stop Condition, and let the simulation run, it would stop automatically when the Termination Count reached 0.

Now you’re on your own for a minute. Your assignment is to load other commands into the function keys; to become totally familiar with the creation of Transactions, movement of Transactions to the Current Events Chain, and the update of the system clock. Please take some time now to study these things. Use the Snapshot Windows to study these changes. When you’re done, please close up any Snapshot Windows that are open.

Welcome back. I hope you feel good about the Current Events Chain and the Future Events Chain.

Now let’s open an Expressions Window on the Clock, the Termination Count, and the Active Transaction number.

CHOOSE Window / Simulation Window / Expressions Window

in the dialog box, for the Label

TYPE Clock

and for the Expression

TYPE AC1

CLICK ON View

CLICK ON Memorize

View allows you to see the expression in the current Expressions Window, and Memorize will allow you to save the information with the simulation so you will not have to enter the information the next time you run it. You can also enter expressions that you wish to save with a model by using View / Settings and Clicking on the Expressions tab. You must save the model in order for expressions that are entered here to be saved These expressions will be memorized and will be available to be viewed the next time you create a simulation from this model.

Now, add the next Expression. Type in the next Label and Expression in the dialog box.

TYPE Act. Xact

and

TYPE XN1

CLICK ON View

CLICK ON Memorize

and repeat the procedure for the third Expression. In the dialog box for the Label and Expression,

TYPE Term Ct.

and

TYPE TG1

CLICK ON View

CLICK ON Memorize

Now let’s speed things up a bit. Let's remove all Stop Conditions.

CHOOSE Window / Simulation Snapshot / User Stops

CLICK ON Remove All

Let’s look at the Blocks Window again.

CLICK ON Anyplace on the Blocks Window

Now,

PRESS p

several times to observe the effects of the movement of Transactions on the system clock and the Termination Count. Notice, in the Blocks Window, that each Block flashes after it has been entered by a Transaction, not before.

When you are ready, use either the Continue icon in the Debug Toolbar at the top of the Blocks Window or the loaded Function Key to continue the run.

CLICK ON The Continue Icon in the Debug Toolbar at the Top of the Window

or

PRESS m

The simulation will end soon and write a report. You can examine the report later, if you like.

We have covered a lot of ground. Let’s review. To schedule a Transaction to come into the simulation at some future time, GPSS World places the Transaction on a chain of Transactions called the Future Events Chain, or FEC. The FEC is ordered by increasing values of scheduled time. In other words, a Transaction scheduled at time 200 will precede a Transaction scheduled at time 300. When there is nothing more to do at any given simulated clock time, GPSS World takes Transaction(s) off the Future Events Chain that have the lowest scheduled time value. It is precisely this action that causes the system clock to advance. Since the system clock jumps over time durations where no events occur, it is often possible for a discrete event simulation to run much faster than the real process being simulated.

The Current Events Chain, or CEC, is used as a holding area for Transactions that still have things to do at the current simulated clock time. When there are no more Transactions on the CEC, it means that there is nothing more to do at the current simulated time instant, and that the clock can be advanced by taking the most imminent Transaction(s) from the FEC and updating the clock to the lowest scheduled time represented on the FEC. GPSS World then moves all Transactions scheduled at the lowest time on the FEC to the CEC, and advances the system clock to the new value.

Please note that when Transactions scheduled to reenter the simulation at the same time are moved from the FEC to the CEC, their order is randomized. This prevents certain unintended synchronization sequences from developing. You can prevent this randomization by setting time tie randomization to zero in the Random Page of the Model Settings Notebook. If you wish to view this setting

CHOOSE View / Settings

to move to the Random Page.

An important rule to remember is that the simulated clock time advances every time a Transaction or Transactions must be taken from the Future Events Chain. As you can see, time in a digital computer simulation does not flow smoothly. A simulation usually consists of many Block entries at a given clock time, followed by a sudden jump to the next clock time. As far as the interpretation of the simulation goes, all GPSS Block entries occurring at a given clock time are occurring instantaneously! The quick jumps to each new time instant often allow simulations to run much faster than the real time process being modeled. A

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