HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
* D+ u" d+ E" @- Z
* F# J) g3 p$ Z \& u$ W public Object buildActions () {/ p9 y7 r8 @- p7 b/ Y
super.buildActions();
# d* u* J: D' G' |
. V' x/ L3 m7 t8 a3 J7 j& A* m D // Create the list of simulation actions. We put these in% r% Z `. A4 p7 ?- @
// an action group, because we want these actions to be
/ Y& e' r7 D; w+ a. ^: [) u // executed in a specific order, but these steps should
6 x' _8 e1 g# g* k // take no (simulated) time. The M(foo) means "The message( C. F& @- i4 i- U2 q! V
// called <foo>". You can send a message To a particular+ B2 u6 j5 [. y1 c7 J
// object, or ForEach object in a collection.) E- R) }+ V) W/ C7 Y% r
+ q0 d W7 R$ y3 v
// Note we update the heatspace in two phases: first run6 T2 T6 x+ [$ z2 S$ |' K
// diffusion, then run "updateWorld" to actually enact the
5 x2 T1 b, q3 m4 J, u1 o N // changes the heatbugs have made. The ordering here is, t+ v7 s. c6 v, k4 h
// significant!1 K; A/ X' b# x) y+ N9 R( g1 b5 j; ?
9 v7 i! _1 M* U) g. P* _ // Note also, that with the additional9 ~$ f2 U) \5 F G2 o
// `randomizeHeatbugUpdateOrder' Boolean flag we can7 O" C" l+ Y# X' f. N3 y/ T4 l# I- ]
// randomize the order in which the bugs actually run
- Z1 w3 H7 ?6 ]6 A1 S; t2 @ // their step rule. This has the effect of removing any5 ?% I8 U% ^+ ]$ g6 J- f0 i
// systematic bias in the iteration throught the heatbug; I o7 K. K* f, J3 _
// list from timestep to timestep
$ Q0 L# h! f, B3 M 7 f( H4 ^8 y4 h6 Y' g' A- V5 U
// By default, all `createActionForEach' modelActions have2 H2 J# e5 b8 y4 S- M, C
// a default order of `Sequential', which means that the
& [' Y& v4 E5 z& @& s // order of iteration through the `heatbugList' will be
% d. D. j. V3 [% ^' G // identical (assuming the list order is not changed
8 }3 Q4 Q- L4 m8 ], N // indirectly by some other process).
$ H9 x: H$ O3 p3 l0 {8 d4 k
* {' ^' |6 U" r R, C) X# L" \ modelActions = new ActionGroupImpl (getZone ());: _1 a+ l" Y! V; s
: E2 s* b* T. L6 ]1 B try {' G) f+ z. p% |/ O
modelActions.createActionTo$message6 B' Q5 r4 S" X d t7 p; Y
(heat, new Selector (heat.getClass (), "stepRule", false));
; H' k: N$ u4 k( I/ ?9 o- H } catch (Exception e) {: q- y% ?- D8 @- P5 E( B: i+ y( B/ V
System.err.println ("Exception stepRule: " + e.getMessage ());
/ V7 |( P" L0 m+ {; k1 i N& I }
; h4 M# t& W! |9 E6 {3 I y% V/ p/ {+ G1 b. p$ _+ J8 F
try { d$ |5 c* A) c
Heatbug proto = (Heatbug) heatbugList.get (0);
# E$ {: k9 p) W \# W2 \" \( j Selector sel =
3 N; b# b5 L2 t! \% J' m new Selector (proto.getClass (), "heatbugStep", false);
4 y' S0 X7 y3 n1 I7 T actionForEach =; [, V' i6 v% o- F0 s2 ~. J' T W- V
modelActions.createFActionForEachHomogeneous$call( Y, C; c1 K; R: Q ~7 b
(heatbugList,8 f% }; G) m+ |; |; k1 c" b$ m
new FCallImpl (this, proto, sel,
j5 H) y$ u! U$ O5 R7 N/ {& v. w new FArgumentsImpl (this, sel)));
) }1 D$ v+ H5 d+ Z } catch (Exception e) {+ `# Y, ~ w6 j" k' O2 M& K7 _) Q
e.printStackTrace (System.err);
0 H: H# J4 o* ~4 u0 r8 S3 } }
8 p6 S) r! c- C6 W3 e
8 [' O2 j* K( R8 j- e- ? syncUpdateOrder ();" T' F, H H5 ]5 ?5 }7 x
# k% k$ x9 I9 ^* q6 Z. | try {
' r$ _5 d: c. U$ u2 G8 ^ modelActions.createActionTo$message
0 R7 Y9 w) M: Q e: b0 z1 P3 M (heat, new Selector (heat.getClass (), "updateLattice", false));0 Q( {" T: ~+ I4 A
} catch (Exception e) {* V7 f5 y- u. k2 J# H# x7 c
System.err.println("Exception updateLattice: " + e.getMessage ());
2 c) g' x. }# |0 A, J }
& A( a6 G1 ?2 m% J - A3 o: Z1 m( M6 k+ v+ b2 N* f6 t
// Then we create a schedule that executes the
" U/ k& Q# q, W* Z // modelActions. modelActions is an ActionGroup, by itself it6 w7 A- Y, r- U( y0 Y' s$ ^ _
// has no notion of time. In order to have it executed in
: H I, O4 U) p! G c" a0 R9 I // time, we create a Schedule that says to use the
' ?' b) u5 l2 S5 ~5 }6 K // modelActions ActionGroup at particular times. This
" T& o4 z( A) l' S2 c // schedule has a repeat interval of 1, it will loop every$ V, ~; W1 i, U4 z# W3 M* R5 Q1 @
// time step. The action is executed at time 0 relative to
1 ~% Q1 D0 |% Y, y // the beginning of the loop.
- {: l9 C7 B8 q
0 q& t% Y/ w. ]( Z; j' n // This is a simple schedule, with only one action that is6 X* P* z1 U5 D7 H
// just repeated every time. See jmousetrap for more
. v1 H+ |, P, D- G6 k // complicated schedules.
H. H/ C7 {* }" n; F& k 3 J/ A# M5 y9 O$ S, `
modelSchedule = new ScheduleImpl (getZone (), 1);# H# R( s( v7 {) G, k, L# V
modelSchedule.at$createAction (0, modelActions);
2 b0 A1 w! X# u4 p9 J6 b4 Y . z( z7 ]' q! c6 k: P
return this;
: o/ Z' r5 B* t3 L' I. h" a. l } |