HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:$ {0 ^7 [) C" u, w
/ i7 l6 g$ d' C; r
public Object buildActions () { f' j4 v, d' k+ W6 W* A
super.buildActions();. r2 S+ J" s ]( U; F4 a
$ F0 y: a; [; H. U2 A
// Create the list of simulation actions. We put these in" _0 w0 D) f6 u# M5 ]# g1 I
// an action group, because we want these actions to be; Z2 i* C& B. ~7 E
// executed in a specific order, but these steps should- J+ H' o9 S# V- j2 v
// take no (simulated) time. The M(foo) means "The message
6 v# `- \" H/ P2 ?( i // called <foo>". You can send a message To a particular4 v- K& [1 d9 \( g% S& C5 Y/ z
// object, or ForEach object in a collection.
$ q, k; w/ |' t ( H3 V$ B# W# ]3 s, b
// Note we update the heatspace in two phases: first run
_- \0 Z8 |+ d. [ // diffusion, then run "updateWorld" to actually enact the: {+ \" U9 A( P3 R* K5 ~; ?
// changes the heatbugs have made. The ordering here is1 O8 `/ m" J% V8 C: a8 c
// significant!" o5 i; x+ Z' i1 y( c
; g/ U2 ]0 C S
// Note also, that with the additional
( `. ~8 i6 D, P W/ X1 Q // `randomizeHeatbugUpdateOrder' Boolean flag we can/ }% R+ U3 t+ S: P' }% C* ^0 g# V
// randomize the order in which the bugs actually run% }0 \# A# y) }! Z* t
// their step rule. This has the effect of removing any
) c# _3 j, m5 Y // systematic bias in the iteration throught the heatbug! C! B- Q. w6 e% [/ u* [
// list from timestep to timestep* }% n5 O6 m& j
' }0 p. P3 q4 f. I! H' @. X: E // By default, all `createActionForEach' modelActions have; |7 k% p$ q/ e$ s- {# P, K
// a default order of `Sequential', which means that the
- _& s ^) O) @* ~. M s1 W$ e // order of iteration through the `heatbugList' will be7 r! ]( O) J$ Q' F
// identical (assuming the list order is not changed+ H% Y0 R1 b( l9 g% p
// indirectly by some other process).
i' S& T- S* [# S & @$ D! i9 ?/ f6 |) [
modelActions = new ActionGroupImpl (getZone ());
. _8 t( r$ ?" @. z% Q: Y$ ^
% `9 ?# R7 R# h+ R$ r try {) ~+ s" R P. O! d3 ~7 F
modelActions.createActionTo$message
9 y( N* C9 b) F. ?' G* l (heat, new Selector (heat.getClass (), "stepRule", false));
, B5 _6 S |6 t1 H0 `( W6 y& I4 r } catch (Exception e) {4 ^1 \$ n, j" L% O: W _6 L- T
System.err.println ("Exception stepRule: " + e.getMessage ());: S A& h" _6 |1 i J! [# E
}8 i- q* C8 P9 k1 C
2 a1 D& P2 v7 H/ c2 I try {
3 o5 M: G# D! z, A# S- j% o' O Heatbug proto = (Heatbug) heatbugList.get (0);* Z! Y- O' W: D) l+ `% ?8 P
Selector sel = ) u6 S$ h1 X! O9 v
new Selector (proto.getClass (), "heatbugStep", false);1 Q* V) l" ~( n7 z) U8 b
actionForEach =
5 P4 Q3 q) M1 F4 {6 a modelActions.createFActionForEachHomogeneous$call. }$ R; k* g& a& y8 }* B
(heatbugList,
2 E2 g9 G( P1 h: G new FCallImpl (this, proto, sel,' E: E; d! Y* |+ Q" B
new FArgumentsImpl (this, sel)));7 K p: ?0 W& b) S5 @* E% G& F, [
} catch (Exception e) {5 g% b# @) I( q5 @+ O* }/ K
e.printStackTrace (System.err);4 r, _# B" {+ t8 Q) F7 q
}3 c/ Q2 j4 m+ y+ O; Z
# C( t) [4 C! H: z$ t
syncUpdateOrder ();! ]2 N! U8 B+ E" S3 M- x' e+ [
7 c# r0 T5 K" E+ M- ]7 l try {: ^4 }' b' b3 S1 S9 y
modelActions.createActionTo$message
! R2 `1 J; ]2 w" F (heat, new Selector (heat.getClass (), "updateLattice", false));4 [! r# H: C4 `/ x0 [
} catch (Exception e) {& x h; L: o {( q- [* x
System.err.println("Exception updateLattice: " + e.getMessage ());
. [- ~/ [) p8 H$ ~ }- D0 {# o M/ J5 M, e/ p! P
: ~; V' M* Y1 k& c8 C* ?' ^) l
// Then we create a schedule that executes the
' a7 Z, x, j4 c9 P // modelActions. modelActions is an ActionGroup, by itself it
# P Q+ {, y/ h2 U O1 t8 e // has no notion of time. In order to have it executed in2 B# l: E" I: b0 ^8 N; L
// time, we create a Schedule that says to use the5 M6 {/ B: x" Z7 r7 F% \. v
// modelActions ActionGroup at particular times. This
* n$ B1 i u9 ]' q2 ^/ t // schedule has a repeat interval of 1, it will loop every
' @. s1 q9 ^9 I9 ]; A7 p // time step. The action is executed at time 0 relative to
+ C# p& p! {8 I# n // the beginning of the loop.1 C8 c6 Z& R7 M! i" u. t U
8 |: w5 `( X: P$ e, i0 M+ I // This is a simple schedule, with only one action that is W& z6 U5 N; i' ^9 h
// just repeated every time. See jmousetrap for more. F4 G0 b! G4 Y" X& ?
// complicated schedules.
& I" F( O/ Y; R [# } 8 S# G$ g0 n3 e; `" X( h9 A
modelSchedule = new ScheduleImpl (getZone (), 1);
& l) q, x# d$ Z2 P& N; \ modelSchedule.at$createAction (0, modelActions);: _& @$ F( I6 R- y
6 m: D' @$ H3 {8 D! ?0 n return this;
& _. N' Q3 v0 K% h$ s } |