HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
/ f }7 i" b4 M) M" _" L+ F
3 S0 ~: y* ~ f) b public Object buildActions () {
6 J! O( `/ o" u" r, I super.buildActions();" j5 E! A2 I, w
7 S4 G! l) _. u, k+ ^% R4 R
// Create the list of simulation actions. We put these in
' @" J" \4 r: I4 }9 ] // an action group, because we want these actions to be" N( n3 D$ w8 Z& y! g3 k
// executed in a specific order, but these steps should
: l2 r; [: q9 h, H, s, E- s" l // take no (simulated) time. The M(foo) means "The message
3 C3 }: u/ S* X+ b* F7 F# _% p, l2 U // called <foo>". You can send a message To a particular: q' ?: |+ e/ u. I: s/ x
// object, or ForEach object in a collection.% t+ Q o: G! Q8 T* c* g8 ?% d
9 p% s4 O8 U6 Z# w/ a
// Note we update the heatspace in two phases: first run
+ I" K" R0 j8 z. I( v; i! x // diffusion, then run "updateWorld" to actually enact the
1 T+ P- Q' a/ P5 `2 O C% c // changes the heatbugs have made. The ordering here is1 n$ R: [, J( W% h& J! t6 J
// significant!3 q; k( Y- j* w
% D( r% x" W3 O3 a4 n4 O
// Note also, that with the additional
( {1 o* B$ Q7 |1 M# ^9 ~# G // `randomizeHeatbugUpdateOrder' Boolean flag we can) E8 ?2 [6 @( j8 `8 X: w
// randomize the order in which the bugs actually run8 r& x! g H) F5 p+ \
// their step rule. This has the effect of removing any
8 A2 x' U# S6 f1 d4 X% _ // systematic bias in the iteration throught the heatbug
7 |% b& D7 K& G# _ // list from timestep to timestep' a/ R: `( y w; _' ~9 _* f* H
" z& Y5 K' Z' @ // By default, all `createActionForEach' modelActions have
- |# I) i/ I, [" N7 i8 z // a default order of `Sequential', which means that the! a) \9 x2 O1 s v" h2 o C3 A6 E
// order of iteration through the `heatbugList' will be
8 j1 ~8 P: r9 q9 Z // identical (assuming the list order is not changed
) Y1 l6 S7 i1 ? x9 d$ @# H9 H // indirectly by some other process).3 i7 O1 B; ?( Q0 z; ] r6 j
) d) Y! G; f+ ^* O# y8 S1 W$ I modelActions = new ActionGroupImpl (getZone ());
- T0 M2 E! {/ V5 g4 p* r* Z( U
1 E5 \: |/ g( ?" G. @, E try {
. V M0 j; [7 z. d" _1 Q7 \) [ modelActions.createActionTo$message
2 h* h5 q( H; P) O1 q) Y (heat, new Selector (heat.getClass (), "stepRule", false));
' m- l/ H- c# V' _+ i6 j, q } catch (Exception e) {9 _3 X- C! i1 Z( X
System.err.println ("Exception stepRule: " + e.getMessage ());
0 ?) y9 \4 t9 F4 I& C, G4 a }
- [1 W8 ?0 g6 @7 P1 q- N- m+ W( \5 T) v+ s
try {
, a/ g$ H) o% \1 q2 G1 v+ S Heatbug proto = (Heatbug) heatbugList.get (0);' M3 ?/ e+ \1 H C- d, ?) a
Selector sel = ! `, |( a9 y! Y9 p! D
new Selector (proto.getClass (), "heatbugStep", false);6 |3 \* d, Z( ~7 m4 i
actionForEach =! b# j9 d3 U Z7 [9 \0 ]
modelActions.createFActionForEachHomogeneous$call
9 O1 e. i5 v# H, C# n+ Q. _ (heatbugList,0 U! _/ D9 {+ ?, Y6 j4 `
new FCallImpl (this, proto, sel,0 Q7 ]. o v( {# ~
new FArgumentsImpl (this, sel)));
8 i) ]% ]& s$ C3 ] [' }) K } catch (Exception e) {
3 q0 ]$ C/ t* U) S e.printStackTrace (System.err); ]1 R/ f7 t% y) j8 d
}: y5 y9 l0 E; i! x" @% Q. o4 e7 ?
4 _$ t- Y5 J9 y. y0 P- p syncUpdateOrder ();" Z- C0 o: r o& z: h5 j; T" K
) q: D7 `% |) k& P# f& G
try {
2 k) n W1 B0 r/ @5 t, [- C modelActions.createActionTo$message
+ ~. j! F+ W4 \3 k, \ (heat, new Selector (heat.getClass (), "updateLattice", false));
2 C) s* T. x5 k4 ~$ ?$ M! Q; B } catch (Exception e) {. O2 b# \: H. x& d6 j7 P# i3 G
System.err.println("Exception updateLattice: " + e.getMessage ());
& Y. f r: r6 ]$ Q+ ?; p) Z }
) t. W" p' e3 |3 o: |& R) |( D
9 b- ~6 G1 F" ~) p, k$ D! P5 ?0 I // Then we create a schedule that executes the7 k; M# `. S2 w
// modelActions. modelActions is an ActionGroup, by itself it! |7 _7 L" H8 h
// has no notion of time. In order to have it executed in# N0 A( ^! c3 b; V y. k7 H4 E3 O
// time, we create a Schedule that says to use the; x. g T: A' [1 v6 f G% a
// modelActions ActionGroup at particular times. This
. k8 f8 i4 C/ @9 n+ A& x // schedule has a repeat interval of 1, it will loop every
- `; K0 u0 B* y% R. x% l7 j P // time step. The action is executed at time 0 relative to/ o6 `/ d n% D' \7 D7 l
// the beginning of the loop.
: n* F" ] X1 T% e9 S0 u5 m1 j0 u( X" Y: o5 }
// This is a simple schedule, with only one action that is/ q0 q) h% _/ b& }7 R, m4 v
// just repeated every time. See jmousetrap for more3 i D2 \. s3 T
// complicated schedules.. @) J; U, {$ ~: W
8 ]) X6 G5 d! |0 |/ {4 v' L" b& V modelSchedule = new ScheduleImpl (getZone (), 1);/ z* W+ f6 }! [! O$ ~
modelSchedule.at$createAction (0, modelActions);9 V" |0 J' H" t! p' `. j2 d
5 R1 u8 c6 Q& x# }' Y9 |6 s
return this;7 I- L' I) k! P5 ]
} |