(翻譯)OMG UML2.5中文譯文 16.12 Expansion Regisons

16.12.1 Summary(概要)

An ExpansionRegion is a StructuredActivityNode that executes its contained elements multiple times corresponding to elements of an input collection.

擴展區域是一個結構化活動節點,它會多次執行內部元素,執行的次數符合輸入元素的聚合。

16.12.2 Abstract Syntax(抽象語法)

16.12.3 Semantics(語義)

An ExpansionRegion is a StructuredActivityNode that takes as input one or more collections of values and executes its contained ActivityNodes and ActivityEdges on each value in those collections. If the computation produces results, these may be collected into output collections. The number of output collections can differ from the number of input collections.

擴展區域是一個結構化活動節點,它接受一個或多個值的聚合,然後對這些聚合中的每一個值執行它包含的活動節點和活動邊。如果計算產生結果,那麼這些結果被收集到輸出聚合中。輸出聚合的個數可以和輸入聚合的個數不同。

An ExpansionNode is an ObjectNode used to indicate a flow across the boundary of an ExpansionRegion. From 「outside」 of the region, the values on these nodes appear as collections. From 「inside」 the region the values appear as elements of the collections. A 「collection」 is defined to be any construct supported by an execution engine that may be treated either as a whole or as a well-defined set of element values.

擴展節點一種對象節點,用於表現流穿過擴展區域的邊界。從區域的外部來看,節點上的值表現為聚合,從區域的內部來看,這些值表現為聚合的元素。聚合可以被定義為任何執行引擎支持的結構,作為整體或定義良好的值的集合被處理。

An execution engine may define various kinds of collection types that it supports (sets, bags, and so on), individual instances of which may be constructed from element values and from which those element values may later be obtained. Such a collection instance is passed as a single value on a single token. An execution engine may alternatively support collections implicitly as the set of values passed in a group of tokens placed together on an ExpansionNode.

執行引擎可以定義多種支持的類型(集合,包等),這些類型的實例可以從元素值構造,後續處理可以從中取得那些值。這樣的聚合實例作為單個值通過一個令牌傳遞。執行引擎也可以支持隱性聚合,它的值被一組擴展節點上的放置在一起的令牌傳遞。

If an ExpansionRegion has multiple input ExpansionNodes, then each one must handle the same kind of collection (set, bag, or so on), although the types of the elements in different collections may vary. If the kind of collection is represented as a collection type, then this is used as the type of the ExpansionNodes. Otherwise, the type of the ExpansionNodes reflects the type of the elements in the collections.

如果擴展區域有多個輸入擴展節點,那麼每個擴展節點必須處理相同種類的聚合(集合,包,等),即使包含在不同聚合中的元素的類型不同時也是這樣。如果這種聚合表現為一個聚合類型,那麼這個類型就會被用作擴展節點的類型。否則就以聚合中元素的類型作為擴展節點的類型。

An ExpansionRegion begins executing according to the normal rules for an Action (see sub clause 16.2.3). In addition,if the input ExpansionNodes for the ExpansionRegion have collection types, then a collection instance must be placed on each ExpansionNode before the ExpansionRegion may begin executing. Otherwise, there is no constraint on whether any input ExpansionNode contains any tokens (as an ExpansionNode with no token is interpreted as the empty collection in this case). When the ExpansionRegion starts executing it removes all tokens in its input ExpansionNodes.

擴展區域按照動作(參見16.2.3)的通常規則開始執行。如果擴展區域的輸入擴展節點是聚合類型,那麼在 擴展區域執行之前,聚合實例必須要傳遞到每個擴展節點。但是並沒有要求每個擴展節點上都存在某種令牌(因為在這種情況下不保有令牌的擴展節點被解釋為一個 空聚合)。當擴展區域開始執行時,會移除所有輸入擴展節點上的令牌。

Then the group of ActivityNodes and ActivityEdges contained in the ExpansionRegion is executed once for each element of the input collections. These will be referred to as the expansion executions for the ExpansionRegion. If the

collections have different numbers of elements, then the number of expansion executions is equal to the size of the smallest collection (except in the case of mode=stream, in which case there is only one expansion execution, as discussed later). Each of the expansion executions proceeds independently from the other executions, with the same semantics as the execution of a general StructureActivityNode, except for the following special rules:

接下來,對於輸入聚合的每個元素,包含在擴展區域中的活動節點和活動邊 被執行一次。這就是所謂的擴展區域的擴展執行。如果聚合中元素的個數不相同,那麼擴展執行的次數等於最小聚合的大小(node=stream的情況除外, 這時只有一次擴展執行,將在後面討論)。每次擴展執行都獨立於其他的執行,它的語義和通常的結構化活動節點的執行相同,但是下面的特殊規則除外:

· Within each expansion execution, a single token is offered on each ActivityEdge with an input ExpansionNode as its source and its target inside the ExpansionRegion. This token contains as its value an individual element of the collection on the input ExpansionNode. For each collection on each such input ExpansionNode, a different element is offered for each expansion execution. If the collection is not a set (non-unique), duplicate values are considered to be different elements. If the collections are ordered, then the elements from each collection are aligned in order for each execution (one execution gets all elements from position 1 in the input collections, another gets all elements from position 2, and so on), up to the number of executions (this provides an effective ordering of the expansion executions). If the collections are not ordered, then it is undefined which individual elements of a collection are delivered to which execution (except that no element is delivered to more than one execution).

在每次擴展執行內部,單獨的 令牌會發送給每個源節點為輸入擴展節點,且目標節點在擴展區域以內的活動邊。該令牌以包含的輸入擴展節點聚合中的一個元素作為它的值。對於每一個輸入擴展 節點上的每一個聚合,都會為每一次執行發送一個不同的令牌。如果聚合不是集合(允許重複),重複的值被看作不同的元素。如果聚合是有序的,那麼來自每個聚 合的元素被有序對齊提供給每次執行(一次執行取得位置1上的元素,下一次驅動位置2上的元素,以此類推),直到達到執行次數(這種方式提供一種有效的擴展 執行次序)。如果聚合是無序的,那麼聚合的哪個獨立的元素傳遞給哪次執行是無定義的(除非沒有元素分傳遞給多於一次執行)。

· Each expansion execution may result in tokens offered to an ActivityEdge with its source inside the ExpansionRegion and with an output ExpansionNode as its target. Such tokens are immediately accepted by the ExpansionNode and inserted into the output collection for that ExpansionNode. If the input and output collections are both ordered, then the values provided by each execution are concatenated in the same order as is induced on the executions by the input collections. If each execution produces a single value, then the output collection will have the same number of elements as the smallest input collection, and, if the output collection is ordered, it will have an output at each position corresponding to the input at the same position of the input collections. On the other hand, if each execution may or may not produce a value, then the output collection will have fewer elements than the input collections and the ExpansionRegion will act as a kind of filter. Finally, if each execution can produce more than one value, then the output collection may end up with a greater number of elements than the input collections.

每次擴展執行都可能導致令牌被發送給一個源節點在擴展區域內而目標節點為輸出擴展節點的活動邊。這樣 的令牌被擴展節點立即接受並插入到該擴展節點的輸出聚合中。如果輸入聚合和輸出聚合都是有序的,那麼每次執行產生的值會被按照被輸入聚合引導的執行次序相 同的次序連接。如果每次執行處理一個單值,那麼輸出聚合會和最小的輸入聚合擁有相同數目的元素。並且,如果輸出聚合是有序的,會在每個位置上保存和輸入聚 合相同位置上對應的輸出。另一方面,如果執行可能產生,也能不產生值,那麼輸出聚合的元素就會少於輸入聚合,這時擴展區域作為一種過濾器工作。最後,如果 每次執行可以產生的值多於一個,那麼結束是輸出聚合中元素的個數會大於輸入聚合。

· Tokens placed on the InputPins of an ExpansionRegion are duplicated for each expansion execution, so that each execution is offered a different copy of the tokens on outgoing ActivityEdges from the InputPins. In this way, tokens consumed from an InputPin in one expansion execution do not affect the tokens available from the InputPin in other executions (the tokens on the InputPin effectively appear to be 「constant」 across the executions). Similarly, tokens offered on ActivityEdges that cross into an ExpansionRegion from outside it (other than those to or from ExpansionNodes of the ExpansionRegion) are duplicated for each expansion execution (the target of each ActivityEdge is offered a separate copy of the tokens within each expansion execution).

放置到擴展區域的輸入引腳上的令牌在每 次擴展執行是被複制,以便每次執行都從連接在輸入引腳上的輸出活動邊上得到令牌的不同拷貝。通過這種方式,在一次擴展執行中被消費的輸入引腳上的令牌不會 影響到其他的擴展執行中輸入引腳上可用的令牌(在執行過程中輸入引腳上的令牌事實上好像是常量)。類似的,發送給從外向內穿入活動區域的活動邊的令牌(進 出擴展區域的擴展節點的活動邊除外)會在每次擴展執行時被複制(每次擴展執行時活動邊的目標節點每次都會得到一個令牌的單獨拷貝)。

· ExpansionRegions may also have OutputPins and ActivityEdges that cross out of the ExpansionRegion from inside it. However, the semantics are undefined for offering tokens to such OutputPins or ActivityEdges from within the expansion executions of the ExpansionRegion (other than for ActivityEdges to or from ExpansionNodes of the ExpansionRegion).

擴展區域也可以擁有從內向外穿出活動區域的輸出引腳和活動邊。但是從擴展區域的擴展執行中向這樣的輸出引腳和活動邊發送令牌的語義沒有被定義(進出擴展區域的擴展節點的活動邊除外)。

When the ExpansionRegion completes all expansion executions, it offers the output collections on its output ExpansionNodes on any ActivityEdges outgoing from those nodes (they are not offered during the execution of the ExpansionRegion). If the ExpansionRegion contains an ActivityFinalNode immediately within it, then, if the ActivityFinalNode accepts a token within any expansion execution, all currently ongoing expansion executions are terminated and the ExpansionRegion as a whole completes its execution. In this case, output collections are still offered from the output ExpansionNodes, though the collections may only be partially filled.

當擴展區域結束了所有的擴展執行以後,擴展區域將所有輸出擴展節點上的輸入聚合發送到各節點的輸 出活動邊(在擴展區間執行期間它們不會被發送)。如果擴展區域直接包含活動終止節點,那麼,如果活動終止節點在擴展執行期間接受到一個令牌,所有正在進行 的擴展執行會被終止,而且擴展區域整體的執行也會結束。這種情況下,輸出聚合還是會被發送到輸出擴展節點上,雖然它們可能只是被部分填充了。

The mode of an ExpansionRegion controls how its expansion executions proceed.

擴展區間的模式控制擴展執行如何進行。

· If the value is parallel, the expansion executions proceed concurrently. This allows an execution engine to run the executions in parallel, or otherwise overlapping in time, but this is not required. However, if the executions are run sequentially, then the order in which they are run is not defined.

如果設定值為parallel,則擴展執行會並行處理。這時允許執行引擎並行執行處理,或者在時間上重疊,但這並不是必須的。如果執行被順序地處理,則處理的次序無定義。

· If the value is iterative, the expansion executions must occur in an iterative sequence, with one completing before another can begin. The first expansion execution begins immediately when the ExpansionRegion starts executing, with subsequent executions starting when the previous execution is completed. If the input collections are ordered, then the expansion executions are sequenced in the order induced by the input collection. Otherwise, the order of the expansion executions is not defined.

如果設定值為iterative,那麼擴展執行必須按照循環次序發生,另一次開始之前結束前一次執行。當擴展區域執行開始 後第一次擴展執行馬上開始,當前一次執行結束後下一次執行開始。如果輸入聚合是有序的,那麼擴展執行會按照輸入聚合的引導而順序進行。否則擴展執行的順序 無定義。

· If the value is stream, there is exactly one expansion execution, and element values are offered to this execution in a stream from each collection. That is, each element of a collection on an input ElementNode is offered separately as a token, one by one, on all outgoing ActivityEdges from the ExpansionRegion (up to a number of tokens equal to the size of the smallest input collection). If the input collections are ordered, then this sequence of offers is made in the same order as the elements of each collection; otherwise the order is not defined. During the course of the single expansion execution, multiple tokens may be accepted by each output ExpansionNode in order to construct the output collections from the ExpansionRegion. If an output collection is ordered, then the elements of the collection are ordered corresponding to the order in which tokens are received by the ExpansionNode.

如果設定值為stream,那麼只會有一次擴展執行,而且發送給執行的來自每個聚合中的元素會被寫到流中。也 就是說,輸入節點上的聚合中的每個元素,會被作為令牌單獨地,一個接一個地發送到擴展區域的輸入活動邊上(直到令牌的數量等於最小輸入聚合的大小)。如果 輸入聚合是有序的,那麼發送的順序就會和每個聚合中元素的順序一致;否則順序無定義。在一次擴展執行過程中,每個輸出擴展節點可以接受多個令牌,目的是創 建擴展區域的輸出聚合。如果輸入聚合是有序的,那麼元素會按照令牌被擴展節點接受的次序排列。

16.12.4 Notation(記法)

An ExpansionRegion is shown as a dashed rounded box with one of the keywords ?parallel?, ?iterative? or ?stream? in the upper left corner (see Figure 16.48). Input and output ExpansionNodes are drawn as small rectangles divided by vertical bars into small compartments. (The symbol is meant to suggest a list of elements.) The ExpansionNode symbols are placed on the boundary of the dashed box. Usually, ActivityEdge arrows inside and outside the ExpansionRegion will distinguish input and output expansion nodes. If not, then a small arrow can be used as with Pins (Figure 16.5).

擴展區域表示為一個圓角虛線框,在它的左上角(參見圖16.48)標註 ?parallel?, ?iterative? 或?stream?這三個關鍵字的某一個。輸入和輸出擴展節點表示為被豎線分割成若干區間的小矩形。(這個符號希望讓人聯想到元素的列表。)擴展節點符號 被放置在虛線框的邊界上。通過活動區域內部,外部的活動邊的箭頭會區別輸入和輸出擴展節點。如果沒有,可以向引腳一樣可以使用一個小箭頭來區分(圖 16.5)。

Figure 16.48 Expansion Region

As a shorthand notation, the ExpansionNode 「list box」 notation may be placed directly on an Action symbol, replacing the pins of the action (Figure 16.49). This indicates an expansion region containing a single Action. The equivalent full form is shown in Figure 16.50. In the shorthand notation, there must be one input ExpansionNode corresponding to each in or inout parameter of the behavior (which must have at least one such parameter) and one output ExpansionNode corresponding to each out, inout, or return parameter of the behavior.

作為簡略記法,擴展節點列表框符號可以直接放到一個動作符號上以代替動作的引腳(圖16.49)。這表示擴展區域包含一個唯一的動作。等價的完整形式如圖 16.50。

Figure 16.49 Shorthand notation for expansion region containing single node

Figure 16.50 Full form of previous shorthand notation

圖 16.51顯示了一個更加簡略的方式,來表示一個包含單個調用行為動作的擴展區域。這裡使用了圖16.49中的記法,但是沒有模式關鍵詞,而是在符號的右 上角記入了一個「*」(目的是表明「多次執行」)。這個記法等價於一個包含調用行為動作的擴展區域(如圖16.50),外加模式值為parallel。

Figure 16.51 Notation for expansion region with one behavior invocation

16.12.5 Examples(示例)

Figure 16.52 shows an ExpansionRegion with two inputs and one output that is executed in parallel. Execution of the ExpansionRegion does not begin until both input collections are available. Both collections are expected to have the

same number of elements. The interior of the ExpansionRegion is executed once for each element in the input collections. During each execution of the region, a pair of values, one from each collection, is available to the interior

from the input ExpansionNodes. Each expansion execution produces a result value on the output ExpansionNode. All of the result values are formed into a collection of the same size as the input collections. This output collection is available outside the ExpansionRegion on the output ExpansionNode after all the parallel expansion executions have completed.

圖16.52表示一個並發執行的擴展區域,有兩個輸入和一個輸出。擴展區域直到每個輸入聚合都給可用時才會開始執行。 這裡希望每個聚合擁有同樣數量的元素。對於輸入聚合的每個元素,擴展區域的內部都會執行一次。在每次執行期間,從輸入擴展節點取得一對值(每個聚合一個) 以供內部使用。每次擴展執行在輸出擴展節點上產生一個結果值。所有的結果值組成與輸入聚合相同大小的輸出聚合。當所有的並發擴展執行結束後,輸出擴展節點 上的輸出聚合可以被擴展區域的外部使用。

Figure 16.52 Expansion region with two inputs and one output

Figure 16.53 shows a fragment of a Fast Fourier Transform (FFT) computation containing an ExpansionRegion. Outside the ExpansionRegion, there are operations on arrays of complex numbers. S, Slower, Supper, and V are arrays.

Cut and shuffle are operations on arrays. Inside the region, two arithmetic operations are performed on elements of the three input arrays, yielding two output arrays. Different positions in the arrays do not interact, therefore the ExpansionRegion can be executed in parallel on all positions.

圖16.53展示了快速傅里葉變換(FFT)處理的一個片段,它包含了一個擴展區域。在擴展區域的外 面,有個針對複數數組的操作,S,Slower,Supper和V都是數組,操作的內容是分割和打亂數組。在擴展區域內部,對三個輸入數組進行兩個數學計 算後,產生兩個輸出數組。數組中的不同位置的數據不會相互影響,所以這個擴展區域可以對所有位置上的數據進行並行處理。

Figure 16.53 Expansion Region

Figure 16.54 shows a use of the shorthand notation for an ExpansionRegion with a single Action. In this example, the Specify Trip Route action outputs sets of flights and sets of hotels to book. The hotels may be booked independently and in parallel with each other and with booking the flight.

圖16.54展示了包含一個單獨動作的擴展區域的簡略記法的使用方法。在這個例子中,Specify Trip Route動作輸出航班和酒店的集合用於預訂,一家酒店可以獨立地和其他酒店或航班並行預訂。

Figure 16.54 Examples of expansion region shorthand

In Figure 16.55, Specify Trip Route can result in multiple flight segments, each of which must be booked separately. The Book Flight action will invoke the Book Flight Behavior multiple times, once for each flight segment in the set passed to Book Flight.

在圖16.55中,SpecifyTripRoute動作可以給生成多個航段,每個必須獨立預定,預定航班動作將會調用預定航班行為多次,對傳遞給BookFlight擴展區域的每個航段執行一次。

Figure 16.55 Shorthand notation for expansion region

推薦閱讀:

我對面向對象編程的一些理解
大話設計模式之簡單工廠模式與策略模式
EA&UML日拱一卒--序列圖(Sequence Diagram)::交互和交互使用
EA&UML日拱一卒--序列圖(Sequence Diagram)::同步/非同步
EA&UML日拱一卒--活動圖::活動(續)

TAG:面向對象編程 | 面向對象分析與設計 | UML建模 |