HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:- f8 Z7 |4 ^1 _! f* T% \
6 ^5 C' J" [/ W6 i& c
public Object buildActions () {) L7 k; T6 n E. v
super.buildActions();
9 `1 Z0 I. j2 V* q! K" K " v$ ^' b7 I1 ?. j r; y! {# d
// Create the list of simulation actions. We put these in% M* v2 ^' v. M! J
// an action group, because we want these actions to be% V! {& m+ d! u) D b. b" a
// executed in a specific order, but these steps should
& }0 a) H$ C! F! b! o4 C; u# y3 V // take no (simulated) time. The M(foo) means "The message
0 A1 _$ g3 U7 ~ // called <foo>". You can send a message To a particular
3 \ d$ o$ |0 W" M // object, or ForEach object in a collection.' e5 r" b S/ C1 ]( [; U" K
w1 x' f/ \0 W9 V
// Note we update the heatspace in two phases: first run
3 D: F6 P# W& j b7 [ // diffusion, then run "updateWorld" to actually enact the
* Z6 N* u% T0 H0 Y# O7 t9 F // changes the heatbugs have made. The ordering here is
4 ]1 Q. g3 {8 \+ p7 |: n/ a // significant!
# d1 |$ n, e7 A/ @& s8 T
- d) G5 _, l U$ k/ Z+ `, D // Note also, that with the additional% E; {7 l- b( e5 F4 s
// `randomizeHeatbugUpdateOrder' Boolean flag we can
+ G: J8 D, \" {" y // randomize the order in which the bugs actually run
4 a- {) P5 e' ?+ @2 U J% ]/ a4 W // their step rule. This has the effect of removing any" C& k7 d1 j8 j5 _
// systematic bias in the iteration throught the heatbug
' d- Y/ `& e& U( h( I9 c // list from timestep to timestep2 j# V* {: a1 l9 @
- C/ w( L4 Q7 q. c. P% N // By default, all `createActionForEach' modelActions have
7 b9 d1 k) E/ t9 v // a default order of `Sequential', which means that the# i& L* Z( ~6 e
// order of iteration through the `heatbugList' will be
+ W8 f6 Y5 j; }/ z$ z4 n // identical (assuming the list order is not changed
3 k. P3 e8 B/ j/ V0 Y // indirectly by some other process).0 g0 i) Y2 |4 U3 c8 u2 l1 v# P
$ S$ e+ w5 a; W7 } modelActions = new ActionGroupImpl (getZone ());0 {9 u5 i% x* u, N
5 O9 a1 q8 e& L) `/ k* U3 c8 W try {
8 \9 B# l K1 H, S) V7 [% j: _" H modelActions.createActionTo$message6 R' l" { ~% A0 B1 s7 e" f" h
(heat, new Selector (heat.getClass (), "stepRule", false));9 T2 u9 N5 y0 ?2 N: B, [
} catch (Exception e) {
, R9 j" F" i3 Z7 b8 U: R; ^# K System.err.println ("Exception stepRule: " + e.getMessage ());9 p* O* A' d9 e" h7 w. l0 _
}* b* N" ]0 O% Y7 d3 k( v* O8 N
h' o3 ?9 Q! n
try {
5 t( D0 q9 D6 M3 d2 R Heatbug proto = (Heatbug) heatbugList.get (0);+ v/ t4 C3 }. \- G. K6 _
Selector sel =
6 N9 p* c! t8 }, J new Selector (proto.getClass (), "heatbugStep", false); R h8 R6 ]8 q
actionForEach =* }$ o7 }' T/ G
modelActions.createFActionForEachHomogeneous$call
) M0 y! W/ o1 @* W# w (heatbugList,
7 Q2 j# H! I4 s% r5 J new FCallImpl (this, proto, sel,
$ {) A: Z5 M$ v new FArgumentsImpl (this, sel)));3 y5 B$ L, H- p$ u5 @" N
} catch (Exception e) { J/ y3 L m+ f' V, L8 b; Q
e.printStackTrace (System.err);% t- h* e u: i0 {7 R4 F O
}
- B" C& t* c; D1 }
# P' J8 ~/ k5 Z- ] syncUpdateOrder ();
6 X% {6 b3 K: E1 T: h. v5 z, E& W/ n+ _: S4 v1 g3 j H4 Y! \# T/ V
try {* H5 u: U. P+ T& \& b- Z9 ^
modelActions.createActionTo$message # Z6 D- u m x
(heat, new Selector (heat.getClass (), "updateLattice", false));
0 w2 y0 F1 b S1 U } catch (Exception e) {, j8 D! A1 V: V, j- D1 ~
System.err.println("Exception updateLattice: " + e.getMessage ());( K2 }9 \" F; c* J% W9 ~) I
}; T$ d) E# b4 q* b4 n! u/ g
! J" d6 [& K8 Z% a
// Then we create a schedule that executes the @3 j" Q2 a/ A+ L7 l
// modelActions. modelActions is an ActionGroup, by itself it$ }( n% R0 d" s" S2 j
// has no notion of time. In order to have it executed in" Q5 A0 N* f$ _3 C/ B
// time, we create a Schedule that says to use the0 i9 V$ k+ U w% Q0 A/ K
// modelActions ActionGroup at particular times. This
& w/ z; z/ T0 h" A // schedule has a repeat interval of 1, it will loop every
; e" D+ Y" Q: f2 v, |3 m& `/ h1 i // time step. The action is executed at time 0 relative to, G( D2 A3 ~% |6 a! r/ C: C
// the beginning of the loop." K/ X2 g& E I/ i% v( C
: j5 i/ M8 e! M/ Q2 S5 j9 W // This is a simple schedule, with only one action that is
- i5 `: E4 p6 }; d; c# t // just repeated every time. See jmousetrap for more% n7 ^1 O9 x `% y2 @, Z
// complicated schedules.& @1 E. x5 r" g6 r0 g* y, Z5 W
" D v8 m; i( g0 _3 ?) o modelSchedule = new ScheduleImpl (getZone (), 1);. e( g1 i. k* A& x3 U* i
modelSchedule.at$createAction (0, modelActions);
& K3 Z5 t8 W; P4 B6 C2 d$ l" i - B4 [$ S+ M1 ^$ K# E$ N8 j
return this;
2 A/ b; d" \/ t: H: E/ i } |