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

imit_model / AnyLogic / UsersManual(AnyLogic)

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

AnyLogic V User’s Manual

Entry action – [optional] sequence of Java statements to be executed when the statechart enters the state.

Exit action – [optional] sequence of Java statements to be executed when the statechart exits the state.

Exclude from build – if set, the state is excluded from the model.

Show name – if set, the name of the state is shown on the statechart diagram.

9.2.1.2 Transition

A transition (see Figure 116) denotes a switch from one state to another. A transition indicates that if the specified trigger event occurs and the specified guard condition is true, the statechart switches from one state to another and performs the specified action. When this occurs, we say that the transition is taken.

The starting point of a transition lies on the border of the transition’s source state. The end point of a transition lies on the border of the transition’s destination state. A transition may freely cross simple state and composite state borders. If the source of a transition lies either on or inside a state, and the destination of that transition lies outside of the state, then that state is considered exited by the transition. If such a transition is taken, the exit action of the exited state is executed. If the source of a transition lies outside a state, and the destination of that transition lies either on or inside the state, then that state is considered entered by the transition. If such a transition is taken, the entry action of the entered state is executed. In case a part of a transition lies inside a state, but both source and destination are outside the state, this state is considered neither entered nor exited.

There is a special type of transition called internal transition. An internal transition lies inside a state, and both start and end points of the transition lie on the border of this state (see Figure 116). Since an internal transition does not exit the enclosing state, neither exit nor entry actions are executed when the transition is taken. Moreover, the current simple state within the state is not exited too. Therefore, the internal transition is very useful for implementing simple background jobs, which should not interrupt the main activity of the composite state.

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

227

Chapter 9. Statecharts

Transition

Transition

Internal transition

Figure 116. Transitions

To draw a transition

1.Click the Transition toolbar button, or

Choose Draw|Statechart|Transition from the main menu.

2.Click the starting point of the transition (the border of a state or pseudo state).

3.Click the points where the transition should turn.

4.Click the ending point of the transition (the border of a state or pseudo state).

Properties

Name – name of the transition.

Fire – the trigger type.

Immediately – the transition is triggered immediately.

After timeout – the transition is triggered after the specified timeout elapses. If signal event occurs – the transition is triggered on the specified signal event occurrence.

If change event occurs – the transition is triggered on the specified change event occurrence.

If event occurs – the transition is triggered on the specified custom event occurrence.

All these trigger types are described in section 9.4, “Triggering a transition”.

228

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

AnyLogic V User’s Manual

Timeout – [for transitions triggered After timeout only] specifies a timeout that triggers the transition.

Signal event – [for transitions triggered If signal event occurs only] specifies signal event that triggers the transition.

Change event – [for transitions triggered If change event occurs only] specifies change event that triggers the transition.

Trigger – [for transitions triggered If event occurs only] specifies custom event that triggers the transition.

Guard – [optional] boolean expression that allows (if true) or prohibits (if false) the transition. If not specified, true is assumed.

Action – [optional] sequence of Java statements executed when the transition is taken.

Exclude from build – if set, the transition is excluded from the model.

Show name – if set, the name of the transition is shown on the statechart diagram.

To move a point of a transition

1.Drag the point.

To add a salient point to a transition

1.Select the transition.

2.Click the Edit Points toolbar button, or Choose Draw|Edit Points from the main menu, or

Right-click the transition and choose Edit Points from the popup menu. The points of the transition should turn yellow.

3.Drag a segment of the transition to create a salient point, or

Right-click the segment and choose Add Point from the popup menu.

To remove a salient point from a transition

1.Select the transition.

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

229

Chapter 9. Statecharts

2.Click the Edit Points toolbar button, or Choose Draw|Edit Points from the main menu, or

Right-click the transition and choose Edit Points from the popup menu.

3.Right-click the point and choose Delete Point from the popup menu, or Drag the point to an adjacent point of the transition.

The dragged point disappears.

9.2.1.3 Initial state pointer

Initial state pointer (see Figure 117) points to the initial state within a particular level of state hierarchy.

If the control is passed to a composite state, a simple state is found inside it by following the initial state pointers down the state hierarchy, and this state becomes current. There should be exactly one initial state on each level – i.e., on the upper level and in each composite state.

Initial state

 

Initial state

pointer

 

pointer

 

Figure 117. Initial state pointer

To draw an initial state pointer

1.Click the Initial State Pointer toolbar button, or

Choose Draw|Statechart|Initial State Pointer from the main menu.

2.Click the starting point of the initial state pointer.

3.Click the points where the initial state pointer should turn.

230

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

AnyLogic V User’s Manual

4.Click the ending point of the initial state pointer (the border of a state or pseudo state).

The generic transition editing operations (see section 9.2.1.2, “Transition”) can be applied to initial state pointers.

Properties

Name – name of the initial state pointer.

Action – [optional] sequence of Java statements executed when the initial state pointer forwards the control to an initial state.

Exclude from build – if set, the initial state pointer is excluded from the model.

Show name – if set, the name of the initial state pointer is shown on the statechart diagram.

9.2.1.4 Pseudo states

A pseudo state is a special type of a node on a statechart diagram. Control never stays in a pseudo state; it always passes through. Therefore, triggers cannot be specified for transitions exiting pseudo states. When control passes a pseudo state, pseudo state’s action is executed.

There are four types of pseudo states:

Final state

Branch

Shallow history state

Deep history state

They all have the following set of properties:

Properties

Name – name of the pseudo state.

Exclude from build – if set, the pseudo state is excluded from the model.

Show name – if set, the name of the pseudo state is shown on the statechart diagram.

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

231

Chapter 9. Statecharts

Action – [optional] sequence of Java statements executed when the control passes the pseudo state.

9.2.1.5 Final state

A final state (see Figure 118) is a termination point of a statechart. When control enters a final state, its action is executed, and the statechart terminates. Transitions may not exit a final state.

To draw a final state

1.Click the Final State toolbar button, or

Choose Draw|Statechart|Final State from the main menu.

2.Click the place on the diagram where you want to put the final state.

Final state

Final state

Figure 118. Final states

9.2.1.6 Branch

A branch (see Figure 119) represents a transition branching and/or connection point. Using branches you can create a transition that has more than one destination state, as well as several transitions that merge together to perform a common action.

232

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

AnyLogic V User’s Manual

When control passes a branch, its action is executed, and then the guards of transitions exiting the branch are evaluated. The first enabled transition – i.e., the transition whose guard evaluates to true – is taken.

To draw a branch state

1.Click the Branch toolbar button, or

Choose Draw|Statechart|Branch from the main menu.

2.Click the place on the diagram where you want to put the branch state.

Branch

B

B B

Branch Branch

Figure 119. Branches

A branch may have at most one special outgoing transition marked default branch exit. This transition is taken in case all other outgoing transitions are closed.

Transitions exiting branch states have the following properties, slightly different from other transitions properties.

Properties

Name – the name of the transition.

Fire – the trigger type.

If guard is open – the transition is triggered if the specified guard is open. If all other guards are closed – the transition is the default branch exit.

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

233

Chapter 9. Statecharts

Guard – [for transitions triggered If guard is open only] boolean expression that allows (if true) or prohibits (if false) the transition. If not specified, true is assumed.

Action – [optional] sequence of Java statements executed when the transition is taken.

Exclude from build – if set, the transition is excluded from the model.

Show name – if set, the name of the transition is shown on the statechart diagram.

If all outgoing transitions are closed and there is no default exit from a branch, a runtime error is issued.

9.2.1.7 Shallow history and deep history states

A composite state may contain shallow history and deep history states. A shallow history state is a reference to the most recently visited state on the same hierarchy level within the composite state. Deep history state is a reference to the most recently visited simple state within the composite state. When the control comes to a shallow/deep history state, its action is executed, and the control is immediately passed to the “real” state referred by it.

To draw a history state

1.Click the History state toolbar button, or

Choose Draw|Statechart|History State from the main menu.

2.Click the place on the diagram where you want to put the history state.

3.In the Properties window, choose whether the history state is Deep or Shallow.

234

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

AnyLogic V User’s Manual

Shallow

B

Deep

history state

history state

A

H H’’

C

D E

F

Figure 120. Shallow history and deep history states

Figure 120 illustrates the difference between shallow and deep history states. Suppose E is the most recently visited simple state inside the composite state A. If the control reaches the deep history state H*, it passes to E, whereas shallow history state H passes the control to C – the most recently visited state on the same hierarchy level. Then the standard procedure of finding the initial state within C is invoked, and the statechart ends up in D.

In case there is no visited state at all within the scope of a history state (no history exists yet), the control goes to the corresponding initial state, unless there is a transition exiting the history state and pointing to the so-called default history state (see Figure 121). There may be at most one such transition (with If there is no history trigger type) for a history state.

Implicit default

H

H

history state

 

 

Explicit default

 

 

history state

 

Figure 121. Default history states

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

235

Chapter 9. Statecharts

9.2.1.8 Text box

A text box is used to put a comment on a statechart diagram. It does not affect the model behavior.

To draw a text box

1.Click the Text Box toolbar button, or Choose Draw|Text Box from the main menu.

2.Click the place on the diagram where you want to put the text box. Then drag to choose the size of the shape.

To modify the content of a text box

1.Double-click the text box.

2.Edit the content of the text box.

3.Click the empty area of the diagram or press Esc to store the modified text. You can also modify the text of the text box using its Properties window.

Properties

Text – content of the text box.

9.3 Execution order

It is important to know exactly what the order is of the execution of statechart elements' actions. For this reason we present the following algorithm.

When a transition is taken, transition and state actions are executed in the following order:

1.State exit actions starting with the old simple state up to the outermost exited composite state.

2.Transition action.

236

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

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