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

gpss_manual

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

of LINK and UNLINK Blocks in Chapter 7.

Related Blocks

There are two GPSS Blocks which can be used with Userchain Entities:

LINK Blocks conditionally place a Transaction on a User Chain.

UNLINK Blocks remove Transactions from a User Chain.

Related SNAs

The SNAs associated with Userchain Entities are:

CAEntnum - Average Userchain content. The time weighted average number of chained Transactions for Userchain Entity Entnum.

CCEntnum - Total Userchain entries. The count of all Transactions that have been chained to to the User Chain of Userchain Entity Entnum.

CHEntnum - Current Userchain content. The current number of Transactions chained at User Chainentity

Entnum.

CMEntnum - Maximum Userchain content. The maximum number of Transactions chained at Userchain Entity Entnum. The "high water mark".

CTEntnum - Average Userchain residence time. The average duration of Transactions at Userchain Entity

Entnum.

4.12. Variable Entities

A Variable Entity is a complex expression which can be calculated on demand. All Variable Entities may be defined from Expressions which include constants, SNAs, arithmetic library functions and arithmetic and logical operators. Expressions are discussed in Chapter 8.

A variable is defined by a VARIABLE, FVARIABLE, or BVARIABLE Command.

VARIABLE creates a GPSS arithmetic variable entity which, when evaluated by an SNA call, evaluates the Expression and returns the overall result. In GPSS/PC Compatibility Mode, intermediate results are truncated.

FVARIABLE creates a GPSS "floating point" variable entity which, when evaluated by an SNA call, evaluates the Expression and returns the result.

BVARIABLE creates a GPSS Boolean variable entity which, when evaluated by an SNA call, evaluates the Expression, then returns 1 if the result is non zero, 0 otherwise. BVARIABLES return 1 if true, 0 if false.

Related SNAs

The SNAs associated with variables are:

BVEntnum - Result of evaluating Boolean Variable Entity

Entnum.

VEntnum - Result of evaluating arithmetic or floating point Variable Entity Entnum.

4.13. Numeric Group Entities

A Numeric Group Entity is a set of numeric values. Numeric Groups are useful for recording events or for describing the state of a process which you are simulating.

Numeric Group operations are faster for integers than for real values.

Related Blocks

There are several GPSS Block s which can be used with Numeric Groups Entities:

JOIN Blocks place a value into a Numeric Group.

REMOVE Blocks take a value out of a Numeric Group.

EXAMINE Blocks test values in a Numeric Group.

Related SNA

The SNA associated with Numeric Groups is:

GNEntnum - Numeric Group count. GNEntnum returns the membership count of Numeric Group Entity Entnum.

4.14. Transaction Group

Entities

A Transaction Group is a set of Transactions. There is no limit to the number of Transaction groups you may have, and no limit to the number of groups to which a single Transaction may belong. Transaction Groups are useful for classifying and accessing Transactions. The active Transaction can test the Transaction Parameters of the members of any Transaction Group.

Related Blocks

There are several GPSS Blocks which can be used with Transaction Groups:

JOIN Blocks place the entering Transaction into a

Transaction Group.

REMOVE Blocks take some group members out of a Transaction Group.

EXAMINE Blocks test members of a Transaction Group.

SCAN Blocks test and/or modify members of a Transaction Group.

ALTER Blocks test and/or modify members of a Transaction Group.

Related SNA

The SNA associated with Transaction Groups is:

GTEntnum - Transaction Group count. GTEntnum returns the membership count of Transaction Group Entnum.

The GPSS World random number streams are generated by a maximal period 32 bit multiplicative congruential algorithm. The period is 231-2 and does not include 0. You may include any number of random number generators in the simulation without declaring them. The initial seed of the random number generator is the same as the entity number of the random number generator entity. However, only random number generators numbered 1 through 7 can be controlled by an RMULT statement.

4.15. Random Number

Generators

The GPSS World Pseudo-random number generation algorithm is based on Lehmer’s Multiplicative-Congruential algorithm, with a maximal period. The algorithm produces pseudo-random numbers in the open interval 0 to 2,147,483,647 and it generates 2,147,483,646 unique random numbers before repeating itself. There is an additional shuffling step used by GPSS World. The RN class SNA returns 0-999, inclusively and the evaluation of random functions uses a random number drawn from 0-.999999, inclusively.

The important attributes of random number generators are:

Seeds. Unless changed by an RMULT statement, the initial seed is equal to the entity number of the random number generator. For example, RN2 starts with a seed of 2.

System usage. GPSS World uses Random Number Generators in the scheduling of time ties, in Fractional Mode TRANSFER Blocks and to sample random numbers for GENERATE and ADVANCE Blocks. You can select which random number generator number is to be used as the source of the random number. This is set in the "Random" page of the Model Settings Notebook.

SNA Values. When accessed as an SNA, a random integer value 0-999 is returned. You may build larger random numbers by using Expressions such as 1000#RN2+RN2 to define a new variable entity. The newly defined random numbers are returned by calls to a V class

SNA. You may find it more convenient to use the built-in probability distributions in the Procedure Library. They are discussed in Chapter 8.

Interpolation values. Fractional values 0-.999999 are drawn from the random number stream when used for interpolation in a continuous random Function.

Related SNAs

The SNAs associated with Random Number Generator Entities are:

RNEntnum - Random number. RNEntnum returns a random integer 0-999 from Random Number Generator Entity Entnum.

4.16. Data Streams

A Data Stream is a sequence of text lines used by a GPSS World simulation. Each Data Stream is identified by a unique number, so that many can be processed at the same time within in a single simulation. Data Stream numbers are arbitrary positive integers, assigned by you.

You can use a Data Stream to read and write to a file, or to maintain a set of directly accessible data in the memory of your computer.

The basic unit of a Data Stream is the text line, which is a string of printable characters, including blanks. The built-in library of string Procedures can be used to manipulate text lines. When a string is used as a text line, unprintable characters encountered by a READ or WRITE operations cause the line to be truncated.

Elementary operations involving Data Streams, such as READ, WRITE, and SEEK each involve a single line of text. Data read from a file is stripped of any terminating CR or LF character before being brought into the simulation. Similarly, a CR/LF sequence is added automatically to any text string written by the simulation. Therefore, you do not need to add control characters within your simulation. You will pass a text string with no CR or LF to a WRITE Block, and you will receive a text string with no CR or LF from a READ Block.

There are twotypes of Data Streams:

1.Input/Output (or just, I/O) Streams for accessing files,

2.In-Memory Streams for testing, and for direct access of internal data.

Each Data Stream has a Current Line Position. This is a 1-relative index to the next line position to be read or written. For example, if a READ is issued when the Current Line Position is 1, the first text line in the Data Stream is retrieved. The SEEK Block can be used to change the Current Line Position in I/O Streams and In-Memory Streams.

A WRITE to an I/O Stream or to an In-Memory Stream is operated in either Insert Mode or Replace Mode. The Current Line Position is used

slightly differently in these two modes.

There are 5 GPSS Blocks used to process Data Streams: OPEN and CLOSE, which initialize and complete Data Stream processing, respectively. READ and WRITE, which add to and retrieve text lines from the Data Stream, respectively. SEEK is used to set the Current Line Position in I/O Streams and In-Memory Streams.

4.16.1 GPSS Blocks for Data Streams

OPEN

The OPEN Block initializes the Data Stream and sets the Current Line Position to 1.

You determine which type of Data Stream is to be used by how you specify Operand A of OPEN. This operand requires a string constant to describe the Data Stream. Remember that String constants are PLUS Expressions. You must parenthesize any PLUS Expression when you use it as a GPSS Block Operand.

An I/O Stream is described by a file specification and an In-Memory Stream is described by a null string.

For example, in the OPEN Block Statement, you could specify

OPEN ("MYFILE.TXT")

to open an I/O Stream, or

OPEN ("")

to open an In-Memory Stream.

If, when you create an I/O Stream, you use a file name without a path, the directory of the Simulation Object is assumed to be the location of the file. When an existing file is found, it is completely loaded into virtual memory during the processing of the OPEN Block. If no file is found, it is assumed that you are creating one, and processing continues.

CLOSE

The CLOSE Block releases resources used by the Data Stream, and returns the error code. For IO Streams, it writes the data from virtual memory to the disk file.

READ

The READ Block retrieves the next text line. In IO and In-Memory Streams it retrieves the text line at the Current Line Position, and increments the Current Line Position. If no text line is there, the Active Transaction takes the Alternate Destination but does NOT store an error code internally.

WRITE

The WRITE Block passes a line of text to the Data Stream.

The action depends on which mode the WRITE Block operates in. If Operand D of WRITE is ON, Insert Mode is used. This is the default. If Operand D is OFF, Replace Mode is used.

Insert Mode

This is the default mode for WRITE Blocks.

Action:

1.Move all text lines at, or after, the Current Line Position down one position.

2.If the Current Line Position is after the last text line, set it to just after the last text line in the Data Stream.

3.Place a copy of the new text line at the Current Line Position.

4.Increment the Current Line Position.

Replace Mode

Action:

1.If the Current Line Position is after the last text line, fill any intervening line positions with null text lines.

2.Delete any text line at the Current Line Position.

3.Place a copy of the new text line at the Current Line Position.

4.Increment the Current Line Position.

SEEK

The SEEK Block sets the Current Line Position. The Current Line Position is never allowed to be less than 1. Attempts to do so, set it to 1.

4.16.2. Using Data Streams

You select the type of Data Stream by the way you specify Operand A of OPEN.

I/O Streams

If you specify a file specification in Operand A of OPEN, an I/O Stream is created. If you do not include a file path in the specification, GPSS World assumes you are using the Simulation Object's directory.

In an I/O Stream, when you issue an OPEN, the whole file is brought into the memory of your computer. When you CLOSE, the whole file is written out to disk. Actual file writing only occurs at CLOSE time.

No error occurs if a file cannot be found. In that case, GPSS World assumes you intend to create one. If you need to verify that the file existed, you should issue a READ before continuing.

Here’s a simple example using an I/O Stream. This is a small GPSS model segment that opens a file, reads the first text line from it, issues a SEEK to text line 20, writes a text line there, and closes.

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

**

*Read and Modify MYFILE.TXT *

**

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

GENERATE 1,,,1

OPEN ("MYFILE.TXT"),1,Done ;Copy the file to memory READ Text_Parm,1,Done ;Place text line in parm

SAVEVALUE Opening_Line,P$Text_Parm ;Text line to safeplace SEEK 20,1 ;Access text line 20

WRITE ("New Line 20"),1,Done ;Replace the line Done CLOSE Error_Parm,1 ;Copy the file to disk

SAVEVALUE File_Error,P$Error_Parm ;Put in Standard Report TERMINATE 1

In-Memory Streams

If you use a null string in Operand A of OPEN, you create an In-Memory Stream. In an In-Memory Stream, all text lines are kept in memory. When you CLOSE, all lines are deleted.

In operation, an In-Memory Stream works exactly like an I/O Stream, except that no data is in the stream when you start to use it, and the data is not saved when you are done. The simulation must load the Stream with text lines before it can read from it.

In-Memory Streams provide the advantage of direct access to data utilizing the SEEK Block and allow you to test the use of Data Streams without actually accessing a file.

4.16.3. How to Test for Errors

You can choose to handle Data Stream Errors yourself within the Simulation or you can force the Simulation to Error Stop when one is encountered. Normally no Error Stop occurs. This is controlled by a Setting on the Simulation Page of the Simulation's Settings. To change this setting choose the Edit / Settings menu item, and check the I/O Stream Error Stops checkbox.

Errors and other unexpected conditions cause a Data Stream Error Code to be stored internally, and cause the Active Transaction entering the Block to take the Alternate Block Destination, if any. A CLOSE Block can retrieve the Data Stream’s error code. Only the first non zero Error Code is remembered. All others are discarded.

An Alternate Destination can be specified as Operand C in OPEN, CLOSE, READ, and WRITE Blocks. The Active Transaction will go to the Alternate Destination Block, instead of the Next Sequential Block, if an error condition occurs. If you do not use these operands, you are essentially ignoring error conditions, for the time being. Normally, you should use the Alternate Destination operands to send the Active Transaction to a CLOSE Block which retrieves the Error Code. You could then place the code in a Savevalue and terminate the simulation.

When the Active Transaction enters a CLOSE Block, the stored Error Code is placed in a Transaction Parameter. In addition, if the error code is non zero, and you have specified CLOSE Operand C, the Alternate Destination will be taken by the Active Transaction.

End of Data

A special case occurs when the Active Transaction enters a READ Block, but there is no text line at the Current Line Position. This happens normally when you have read all the text lines in a file. This condition causes the Alternate Destination to be taken by the Active Transaction, but does NOT cause an error code to be stored internally.

Error Codes

0 - No Errors.

10 - OPEN Error. Filename too long.

11 - OPEN Error. Error while reading an external file.

12 - OPEN Error. Memory request was denied while trying to read an existing file.

13 - OPEN Error. Stream is already open.

21 - READ Error. A memory request was denied while trying to perform a READ.

22 - READ Error. Data Stream has not been successfully opened.

31 - WRITE Error, A memory request was denied while trying to

perform a WRITE.

32 - WRITE Error. Data Stream has not been successfully opened.

41 - CLOSE Error. An I/O Error prevented the file from being written to disk.

43 - CLOSE Error. Data Stream has not been successfully opened.

51 - SEEK Error. Data Stream has not been successfully opened.

4.17. Continuous Simulation

GPSS World can automatically integrate systems of ordinary differential equations. Integration of User Variables in GPSS World is extremely easy. One or more INTEGRATE statements, and variable initialization, is all that is needed. Integration is done automatically by a modified variable step 5th order Runge-Kutta-Fehlberg method, RKF4(5).

Systems of ordinary differential equations, of any order, can be simulated. Plot and Expressions Windows are available for online viewing of the states of variables.

4.17.1. How to Set up an Integration

There are two things to do in order to set up the automatic integration of a User Variable. You must assert an INTEGRATE Command and you must give the variable an initial value.

Let us assume you have a simple ordinary differential equation of the form y’ = f(-)

where f(-) is an Expression, possibly involving the System Time, i.e. the AC1 System Numeric Attribute, and other User Variables. f(-) is the derivative of y with respect to time.

First, put the derivative in parentheses and set up the INTEGRATE Command as

Y_ INTEGRATE ( f(-) )

Second, make sure Y_ has a starting value, such as

Y_ EQU 100.3

Then, when the simulation advances the clock, it automatically sees to it that the value of the User Variable Y is kept current.

Since several single letter names clash with SNA classes, here we append an underscore to be sure that the name is unique. All other User Variables involved in the derivative, must be initialized, as well. PLUS Assignment Statements can also be used to assign values to User Variables.

Integrations are automatically begun in the active, or "enabled" state. However, you can turn an integration ON or OFF while a simulation is running by using one or more INTEGRATION Blocks. This is discussed in Chapter 7.

4.17.2. Basic Concepts

A derivative states how fast a variable is changing. For example, if your inventory is building up at a rate of 2 units an hour, and your simulation is in units of seconds, all you need to do is add

Inventory INTEGRATE ( 2.0 / 3600 )

and

Inventory EQU 1 00

or whatever the starting Inventory value is.

The rate of change (the derivative) leads GPSS World to automatically increase the numeric value of Inventory throughout the simulation. When sales occur, you can simply decease the Inventory using a PLUS Procedure. The discrete sales event differs fundamentally in that it occurs with no simulated time duration, reducing the value of Inventory instantly.

Integration takes a lot more computer time than the evaluation of a closed form expression. In an example as simple as this one where the variable can be calculated as a function of time, it is much faster to simply calculate the value of the variable given the simulated time, than to integrate the User Variable. Integration should generally be reserved for those cases where you don’t have the solution of the differential equation.

4.17.3. Threshholds

Integrated User Variables create Transactions when they cross thresholds. This makes it easy to use a continuously modeled value to trigger discrete events.

Each INTEGRATE Command may have zero, one, or two numeric thresholds. Operands B and C can be used to specify threshold 1, and/or operands D and E can be used to specify threshold 2. In either case, the first operand of the pair determines the value of the threshold, the second indicates the Block which will receive generated Transactions.

During the integration, if the value of the integrated variable crosses the value of a threshold, from either direction, a new Transaction is created. It is given a priority of 0, and is scheduled to enter the Block associated with that threshold in the INTEGRATE Command. The Transaction’s time of entry into the model is estimated by a linear interpolation. To improve accuracy, the integration ministep is decreased when a threshold is imminent.

Thresholds may be constants, parenthesized Expressions, or even Procedure Calls. In addition, the Transactions generated by a threshold crossing may be used to move the threshold.

Both thresholds behave identically; there is no need to specify one as upper and the other as lower. It is the crossing of the threshold (in either direction) that triggers a Transaction arrival. If the direction of crossing is meaningful to your model, you will have to either keep track of the state of the integrated variable, or test for the direction of crossing when the Threshold Event occurs.

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