HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:% l# B0 f1 s2 v" v7 U. U1 m) }. x, l
& O( J) s3 t6 A' ] V
public Object buildActions () { Q0 ~6 `5 ]. p" y" O
super.buildActions();
: h3 z8 t9 ]: @9 \
H( T! ]& p2 B, |5 P& b- a // Create the list of simulation actions. We put these in. a% v3 z& x- z9 o
// an action group, because we want these actions to be9 U; V6 N; L& B; V
// executed in a specific order, but these steps should
8 z2 } W6 F7 B( [# t% _ // take no (simulated) time. The M(foo) means "The message
0 Q- r/ |1 [6 F# Y // called <foo>". You can send a message To a particular; `8 ?9 o) a$ q% @; a0 U
// object, or ForEach object in a collection.( X0 F" p9 t7 U2 u! o9 k# H/ \
) s l) J( _) f/ Y4 a9 i
// Note we update the heatspace in two phases: first run- l7 L( N7 F9 N) a+ J' w
// diffusion, then run "updateWorld" to actually enact the
0 b* |9 B9 L1 O( T0 o // changes the heatbugs have made. The ordering here is
6 C; t' I. M8 B# ^$ l // significant!
: Y7 P# [" E, N4 Q + `9 p8 u/ H, M3 W$ i
// Note also, that with the additional: R" V6 `% ~- q# B
// `randomizeHeatbugUpdateOrder' Boolean flag we can
! j' C* x, s, q3 C2 d1 m0 r // randomize the order in which the bugs actually run
) F: e3 [0 W: ]* b3 z) J5 k6 `4 z+ W // their step rule. This has the effect of removing any, d M. k! u( @+ X
// systematic bias in the iteration throught the heatbug4 o& X2 x s6 d j; g
// list from timestep to timestep, O0 v& L$ F/ {* v
" k1 y3 u* R$ ~, b/ O7 \
// By default, all `createActionForEach' modelActions have
& `3 J% Z( f- t f% h- y. m5 d // a default order of `Sequential', which means that the2 ?3 F- s+ f3 S
// order of iteration through the `heatbugList' will be
. [. a( E' I* S% N q& g // identical (assuming the list order is not changed
5 u. g% H0 ~& C$ K! `, ]0 a // indirectly by some other process).
' Q$ p9 v: ^1 d1 O* O/ e1 x6 y6 y
& U% R9 A, U" @) k+ W9 q; m4 P ` modelActions = new ActionGroupImpl (getZone ());
3 \% H/ _% C g. i0 N6 X' ?# B+ v1 u+ N! N! S6 e0 A4 c j5 |& ~
try {+ _) Z8 h3 p$ {; b
modelActions.createActionTo$message% s& @% J& i" ?$ N% Y& v9 U
(heat, new Selector (heat.getClass (), "stepRule", false));
( a5 R5 d5 K9 H7 D z2 G0 S2 \ } catch (Exception e) {. `) ^; }* T0 M. ?0 E( s5 r! G1 W
System.err.println ("Exception stepRule: " + e.getMessage ());
& B5 a# `0 T5 O ?: | }: I* o# x; k4 s, A& S7 o
" y8 Y6 ~& X' A( z try {
9 A$ R: S4 O- k' e' A8 s Heatbug proto = (Heatbug) heatbugList.get (0);
+ u4 y( I1 ~3 E" p. @4 c# `* W Selector sel = ! v" F: T+ l8 v* b3 ^
new Selector (proto.getClass (), "heatbugStep", false);: f0 K: z) k1 [6 Y: T
actionForEach =
' S5 F6 P2 \& q1 a) ~% A' }' X modelActions.createFActionForEachHomogeneous$call6 g1 U. o! }) o' W7 Y/ ^# R1 l3 J% Y
(heatbugList,
7 r# I2 ?# j F; u$ a+ H6 e) v" k new FCallImpl (this, proto, sel,) o3 P: w& t3 ]% ~/ w/ `, N- ]* j
new FArgumentsImpl (this, sel)));# V2 U9 [; D$ ?8 ]' J% I
} catch (Exception e) {
5 |/ B! i' a; X& Z e.printStackTrace (System.err);
8 a$ I9 N$ g5 E, l }
3 f1 i* M8 H1 s! z0 w# V8 P0 G # b+ I% Q, j6 q0 _, q
syncUpdateOrder ();
9 u" G& N( X% h0 g, A; h" X
/ X% o# R6 \4 m, O/ T8 Q try {7 |, ~5 b/ l& q% i" s0 e
modelActions.createActionTo$message
/ L5 E+ _9 H) P$ F/ ~$ r+ h- d (heat, new Selector (heat.getClass (), "updateLattice", false));% I) V6 U: n/ n! Z, m
} catch (Exception e) {
7 Y) O( s! I* \% B* Q6 o3 T System.err.println("Exception updateLattice: " + e.getMessage ());
& A6 k7 a9 a0 Q7 k$ R2 p6 R }9 u7 c# v0 M/ \1 K' R- J6 w8 V/ a
6 f' |$ ]* E4 a8 U5 r // Then we create a schedule that executes the
6 `2 j e$ e/ x) ` // modelActions. modelActions is an ActionGroup, by itself it
; z. S* Z, J! u; ]" R // has no notion of time. In order to have it executed in
m1 _& q) M/ [ // time, we create a Schedule that says to use the& ~, w- b* R. o8 t ^6 d
// modelActions ActionGroup at particular times. This
! m: c8 }' ^5 B7 f // schedule has a repeat interval of 1, it will loop every. Q3 L) K+ ~( L1 k0 p4 i! w' t1 ?
// time step. The action is executed at time 0 relative to8 ?4 v0 a+ o6 C7 O8 G
// the beginning of the loop.
+ K4 D/ T4 i" `3 b& f8 Q4 @ }
! M8 b3 @6 b$ _$ i1 `- S& D( R; ?9 M // This is a simple schedule, with only one action that is
- s" q; S' B7 \$ T% A" L // just repeated every time. See jmousetrap for more
. I$ O8 r H }4 u C // complicated schedules.
x" e/ j% R5 m: B ) w) t4 Y7 |1 d* V1 D5 f2 h I
modelSchedule = new ScheduleImpl (getZone (), 1);# H# T$ R, L6 Z3 |, |
modelSchedule.at$createAction (0, modelActions);
& C1 O( W) [! g0 X/ r1 R . f% a7 g2 o1 Z: V
return this;
8 c6 M0 H& v9 W } |