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

imit_model / AnyLogic / UsersManual(AnyLogic)

.pdf
Скачиваний:
125
Добавлен:
06.06.2015
Размер:
4.28 Mб
Скачать

AnyLogic V User’s Manual

SocialGroup, Age, Gender

{

{

 

 

 

 

// SocialGroup: wealthy

{

1

,

1.2

},

// Age: child

{

0.8

,

0.75

},

// Age: teenager

{

0.62

,

0.5

},

// Age: adult

{

0.2

,

0.1

}

// Age: aged

} ,

 

 

 

 

 

{

 

 

 

 

// SocialGroup: middleclass

{

1.3

,

1.4

},

// Age: child

{

0.3

,

0.96

},

// Age: teenager

{

0.6

,

0.52

},

// Age: adult

{

0.2

,

0.05

}

// Age: aged

} ,

 

 

 

 

 

{

 

 

 

 

// SocialGroup: deprived

{

1.6

,

1.5

},

// Age: child

{

0.3

,

0.81

},

// Age: teenager

{

0.35

,

0.4

},

// Age: adult

{

0.05

,

0.15

}

// Age: aged

}

 

 

 

 

 

}

To initialize hyper-array elements with a single scalar constant, just type the desired scalar number in the Initial value property.

If you need an array with elements distributed by some law, you create an appropriate distribution object (see Chapter 10, “Stochastic modeling”) and pass it to the method random() of the hyper-array.

© 1992-2004 XJ Technologies http://www.xjtek.com

137

Chapter 6. Matrices and hyper-arrays

For instance, if you need array A initialized with elements, uniformly distributed in interval [min,max), you type the following string in its Initial value property:

random( new DistrUniform(min,max) )

Or you can initialize it in the Startup code code section of the active object class with the following string:

A.random( new DistrUniform(min,max) );

6.2.3.1 Setting specified elements of a hyper-array

Sometimes, you need setting some group of elements of a hyper-array separately.

Therefore call method set() in the Startup code or in the event handler:

<hyper-array>.set([<list of subscripts>,] <value>);

The <list of subscripts> identifies, which element(s) of the <hyper-array> should get the <value>. For example, hyper-array variable SmokingRate has the dimensions: SocialGroup, Age, Gender. The examples of possible subscript lists for this array are listed in Table 9.

Subscript lists

Description

 

 

wealthy,

One element gets the <value> - smoking rate for wealthy male

teenagers, male

teenagers.

 

 

wealthy,

Vector of two elements gets the <value> - smoking rate for wealthy

teenagers

teenagers of both genders.

 

 

teenagers

A sub-array of elements gets the <value> - smoking rate for

teenagers of both genders and of all social groups.

 

 

 

<empty list>

All array elements get the <value>.

 

 

 

Table 9.

138

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

6.2.4Aggregation functions

Sometimes you need performing aggregation operations on elements of hyper-arrays. Aggregation functions are listed in Table 10. ‘N’ is the size of the set of the aggregated elements {xi}.

Function

Description

 

 

 

 

 

 

 

 

 

 

 

 

 

N

Sum

The sum of the aggregated elements: S = xi

 

 

 

 

 

i=1

 

 

 

 

 

 

 

 

1

N

 

 

Avg

Average value: x =

xi

 

 

 

N i=1

 

 

 

 

 

max,min

Maximum/minimum value of the aggregated elements.

 

 

 

 

 

 

 

 

 

 

 

N

Prod

The product of the elements: P = xi

 

 

 

 

 

i=1

 

 

 

 

 

 

 

 

 

 

1

N

Stddev

Standard deviation: σ =

(xi x)2

 

 

 

 

 

N i=1

 

 

 

 

 

 

Table 10. Aggregation functions for hyper-arrays

The function syntax is:

<hyper-array>.<function name>()

Sometimes it is necessary to perform aggregation on a sub-array. You can do it with the following call:

<hyper-array>.get(<list of subscripts>).<function name>()

The <list of subscripts> defines the sub-array to aggregate in the same manner as for set() method (see section 6.2.3.1, “Setting specified elements of a hyper-array”).

© 1992-2004 XJ Technologies http://www.xjtek.com

139

Chapter 6. Matrices and hyper-arrays

6.2.5Using hyper-arrays in equations

AnyLogic supports hyper-arrays as well as primitive types in equations. See Chapter 5, “Equations” to know how to define equations. You can define differential equations or formulas for hyper-array variables in a way similar to scalar variables. However, there are some specifics that we describe in the current section.

6.2.5.1 Arithmetic operations with hyper-arrays

In counterpart to matrices, operations with hyper-arrays do not go by the linear algebra rules, but are applied to array elements one-by-one. The operands may be of different dimensions. The result of the operation is a hyper-array with the dimensions that the operand subscripts union has. The following figures illustrate some cases [symbol # is the operation sign placeholder – it can be addition (+), subtraction (-), multiplication (*), or division (/) symbol].

If both operands have the same dimensions, the resulting hyper-array is of the same dimensions also. Each element of the resulting hyper-array is the result of operation with two co-indexed elements of A and B.

Gender

 

Gender

 

 

#

Age

 

Age

C

=

A

Gender

#

Age

#

#B

Figure 60. Operation with hyper-arrays having the same dimensions

Another case: the dimension set of one operand (A) contains all the dimensions of the other one (B). In other words, the intersection of the dimension sets equals the dimension set of B and their union equals the set of A.

140

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

Gender

 

Gender

 

 

#

Age

 

Age

C

=

A

#

Age

#

#B

Figure 61. Operation with hyper-arrays, where one has less dimensions

The operation with the integer or real scalar value (x) is applied to each element of the hyper-array A (Figure 62).

Gender

 

Gender

#

 

 

 

#

 

 

 

 

 

 

 

 

 

Age

 

Age

 

 

 

 

 

 

 

 

#

 

C

=

A

#

x

Figure 62. Operation with a hyper-array and a scalar

In the case shown in Figure 63, the resulting dimension set is the union of subscripts. One can describe the operation as a sequence of operations with the first array and vectors extracted from the second one (as shown in the Figure 61). Regarding the figure example, “wealthy” sub-array of resulting hyper-array (where ‘social group’ subscript is ‘wealthy’, marked with red color) is calculated in the same way, as by operation with hyper-array A and vector extracted from B where ‘social group’ is ‘wealthy.’

© 1992-2004 XJ Technologies http://www.xjtek.com

141

Chapter 6. Matrices and hyper-arrays

Gender

 

Gender

 

groupSocial

#

Age

Age

 

C

=

A

Social group

 

#

 

Age

#

B

Figure 63. Operation with arrays having different dimensions

6.2.5.2 Array functions

All the predefined functions and all the lookup tables you define within your project accept both scalar and hyper-array arguments. In case of hyper-array, unary function is applied to all the elements of the array argument, similar to arithmetic operations with a scalar. Binary functions are applied to two hyper-arrays in the same way as operation with hyper-arrays having the same subscripts.

6.2.5.3 Getting array elements and sub-arrays

Sometimes you need to access only some specific element or a sub-array. In equations you get the desired element or sub-array by the following expression:

<hyper-array> ‘[’ <list of subscripts> ‘]’

The <list of subscripts> identifies the array to get in the same manner as in set() method (see section 6.2.3.1, “Setting specified elements of a hyper-array”).

For instance, there is a hyper-array Smoking_Rate, which holds the average smoking rate of people in respect to gender, age, and social group.

To get the value of an element of a hyper-array in an equation, you type the following code in an equation expression. You should specify subscripts for all the dimensions.

142

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

SmokingRate[female, teenagers, middleclass]

To get a sub-array in an equation, specify subscripts not for all dimensions. For example, you are interested in smoking rate for all people, pertained to the deprived social group. You get the corresponding sub-array having (gender, age) dimensions this way:

SmokingRate[deprived]

You can perform conditioned extraction. Therefore you define a parameter whose type is an enumeration. For instance, it is of type Age, is named ageParam, and has child as default value.

SmokingRate[Female, ageParam]

Then you can change the value of this parameter on some event (e.g. on timer expiry action):

ageParam = Teenagers;

© 1992-2004 XJ Technologies http://www.xjtek.com

143

Chapter 7. Message passing

7. Message passing

Commonly you may need to send some information from one active object to another. In AnyLogic you can establish active object interaction by passing messages – data units, carrying some useful information. Messages can model various objects of the real world. You may implement notification or signaling mechanism in your system – in this case, messages may represent commands or signals passed in a control system. Or you may need to model entity flow in your system, where messages represent entities – the items that are being served, produced, or otherwise acted on by your process: documents in business processes, customers in service systems, parts and products in manufacturing models. You may have different types of entities in the same model.

Messages are sent and received via the special elements of active objects – ports. Message passing is enabled only between ports connected by connectors – paths used by messages to flow through the model.

This chapter gives the detailed description of the message passing mechanism. It is organized as follows:

Section 7.1, “Ports”, describes how to create ports and add them to your own active object classes. This section also contains the detailed explanation of message routing rules.

Section 7.2, “Messages”, describes how to define your own message classes. You should read it if you need to carry some data in messages being passed between active objects in your model.

Section 7.3, “Defining custom port classes”, gives the detailed description of the predefined AnyLogic port classes. This section describes how to create your own port classes with customized behavior to change the semantics of message passing.

Consider the chapter organization to study sections meeting your requirements.

If you create your model from AnyLogic library objects, please refer to section 1.5.8, “Active objects interaction” to know how to connect objects and establish message passing.

144

© 1992-2004 XJ Technologies http://www.xjtek.com

AnyLogic V User’s Manual

7.1 Ports

Ports play the central role in the message passing mechanism. Messages are sent and received through ports. Ports are bi-directional and can serve both for input and output. Ports may be public – i.e., accessible from outside the class; or private – accessible only inside an active object. To communicate with other objects, you need to add a public port to the active object; and to establish a communication inside the object, you can use a private port.

7.1.1Adding a port to an active object class

To add a public port to an active object class

1.Click the Port toolbar button, or

Choose Draw|Structure|Port from the main menu.

2.Click the class border on the structure diagram.

A new port appears, displayed as the small square, see Figure 64.

Public port

Figure 64. A public port

Placing a port on the class border makes it public.

To add a private port to an active object class

1.Click the Port toolbar button, or

Choose Draw|Structure|Port from the main menu.

2.Click inside the class border on the structure diagram.

A new port appears, displayed as the small square, see Figure 65.

© 1992-2004 XJ Technologies http://www.xjtek.com

145

Chapter 7. Message passing

Private port

Figure 65. A private port

Once the new port is created, you can specify the port name in the text line editor opened on the right of the port in the structure diagram.

7.1.1.1 Moving, copying and deleting ports

There are some common operations you can perform with ports on the class structure diagram. You can copy, move and delete ports just as any other class elements. First, you should select the port by clicking it.

To move a port

1.Drag the port with the mouse or use arrow keys.

To copy a port

1.Ctrl-drag the port.

To delete a port

1.Click the Delete toolbar button, or Choose Edit|Delete from the main menu, or

Right-click the port and choose Delete from the popup menu, or Press Del.

146

© 1992-2004 XJ Technologies http://www.xjtek.com

Соседние файлы в папке AnyLogic