HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:5 ~% N" T9 V; T4 a
5 z: r' q: j$ u3 D public Object buildActions () {$ C8 R/ r- [2 ~+ u% Q( V
super.buildActions();3 }1 K. A/ Q' l' R) b
9 i3 x( a$ W' o: U" R% o
// Create the list of simulation actions. We put these in6 k8 s( z4 T+ g" P5 A" Z. T
// an action group, because we want these actions to be1 U* U! ^1 L2 M6 W: \, j# C* S
// executed in a specific order, but these steps should
7 @7 r, E. O; j: Q4 @8 q0 [) w // take no (simulated) time. The M(foo) means "The message' ~/ x* n: [2 M
// called <foo>". You can send a message To a particular
- A: Y8 V2 c/ J# P; F8 f; { // object, or ForEach object in a collection.
, B# `, o! f; c( W `7 V
. F$ m( t9 E6 F) p2 j# v8 e3 V // Note we update the heatspace in two phases: first run# k6 p2 I7 I) |! s( D. U- y! I0 A
// diffusion, then run "updateWorld" to actually enact the e: J' r$ b0 V4 |: {8 x8 X
// changes the heatbugs have made. The ordering here is+ E3 h" b1 I! I! g' `
// significant!
# l$ N5 {9 B' V. C
4 ~3 f. O* Z# P! R* E // Note also, that with the additional) R# ?0 T/ |8 z
// `randomizeHeatbugUpdateOrder' Boolean flag we can
- ]* \, g0 p; L' t // randomize the order in which the bugs actually run
* w' ^- i" n% S- b2 i8 f7 s6 [: K // their step rule. This has the effect of removing any3 G/ m1 h/ U7 d6 b7 F1 ]
// systematic bias in the iteration throught the heatbug8 u8 N% F2 t6 j) l5 p
// list from timestep to timestep
$ e1 m* I! c( a- @( n 6 B( {# ]: S0 Q9 ~' q
// By default, all `createActionForEach' modelActions have5 v6 g) O" u" n/ ~8 V+ _' Q
// a default order of `Sequential', which means that the% y( C# t8 ^, z6 s5 Q, B
// order of iteration through the `heatbugList' will be" U' t5 G* C0 O% W, M7 F! W
// identical (assuming the list order is not changed. t3 ~; Z- P, h; b) o: ~% S" u" B
// indirectly by some other process).
$ F8 W! z8 c" v5 L% D7 q# Y 1 k9 I# W7 @+ ]- f1 _# u
modelActions = new ActionGroupImpl (getZone ());% b4 u7 `3 s0 G7 B, ^
o- f5 V0 H/ ?
try {# T0 ~( t: E; Y- T+ \+ l
modelActions.createActionTo$message0 M; X! x; g8 s1 M
(heat, new Selector (heat.getClass (), "stepRule", false));
0 _0 I, ~' g4 f% E; C- ~ } catch (Exception e) {; E! k5 Q5 i' l0 v2 S
System.err.println ("Exception stepRule: " + e.getMessage ());2 ~; q/ ^3 c4 Q$ x
}3 v) |; \9 T9 _" c+ g; N* m. e
7 g- t: T% a- s" l try {1 K) O1 @- z1 v
Heatbug proto = (Heatbug) heatbugList.get (0);
5 R. d( o8 T4 L/ }' g5 j) p* l- v Selector sel = / ]- M( I6 U; Q
new Selector (proto.getClass (), "heatbugStep", false);5 P# m% x" T( P% a- [
actionForEach =
0 i* v: z" `# \+ u modelActions.createFActionForEachHomogeneous$call' V3 }9 k! U6 L, s4 s7 B$ H
(heatbugList,
; z. E' U- q9 ] new FCallImpl (this, proto, sel,
. ]; f/ [, n( O& P0 z" M. p new FArgumentsImpl (this, sel)));9 f' m4 g$ z) B& }9 d0 Q. q! C: N
} catch (Exception e) {1 O' j: j5 R& p& {% b1 U6 J6 ^/ u
e.printStackTrace (System.err);. N7 G7 l3 O1 Y4 o
}
4 v" N. i9 U0 u- i7 m+ y. }1 m 6 Q( x$ ^5 w+ m4 T
syncUpdateOrder ();! a# Q2 ^3 a! ?& p
3 h( G( J- o/ C! { try {2 u6 P& J) `+ k" d5 v1 J) G Z
modelActions.createActionTo$message
f1 F+ z7 g$ \6 o$ _; @$ n$ u (heat, new Selector (heat.getClass (), "updateLattice", false));
3 h4 D8 _+ r0 Q: r } catch (Exception e) {' @7 ~4 X! q Y% t8 b
System.err.println("Exception updateLattice: " + e.getMessage ());! G' p1 ]9 m1 j5 s7 ~
}2 Q7 W2 o3 `- u1 ~
1 s3 W4 f" ?9 d" c // Then we create a schedule that executes the6 C) j* O* P7 G1 i' K; x. V
// modelActions. modelActions is an ActionGroup, by itself it
9 {) n7 a! Y( ~$ X1 S // has no notion of time. In order to have it executed in
$ |+ ^2 p4 Q% ]/ j) C" k! C8 O // time, we create a Schedule that says to use the K4 _8 w- S; N) H( l- ~. _
// modelActions ActionGroup at particular times. This. X( `2 N; n* p, S4 m# f2 Q# s
// schedule has a repeat interval of 1, it will loop every3 d2 R8 y; n& y* N3 {( w
// time step. The action is executed at time 0 relative to
4 ]0 K' f p- G* Z // the beginning of the loop.- Z3 z& p% ` E& }! V
6 L8 j W1 X2 }2 H5 E // This is a simple schedule, with only one action that is
$ K7 g5 U: P* Z* J9 f8 U // just repeated every time. See jmousetrap for more. a7 q' w9 X& l3 W
// complicated schedules.0 m. R3 a3 i3 U: { l1 P M) r: W# n5 T3 L
; z) u4 t" R' [) o) [$ q" U
modelSchedule = new ScheduleImpl (getZone (), 1); g8 ~2 V6 h9 |9 Y/ @
modelSchedule.at$createAction (0, modelActions);
' t8 L! v; L3 i5 V8 T! P
1 G$ w ? u9 c* j A: g7 F$ J1 Y return this;
4 Z9 s) Q9 Y6 v A" x; X: ] } |