HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' b/ n P, Y( K/ ~) c- A
5 W. J" i- ~0 c! ` Y public Object buildActions () {
; _( }. \/ d3 d. V9 r7 a super.buildActions();9 \" S# k8 u; M$ W
& J+ l( c6 F* O% B4 V m! M' S
// Create the list of simulation actions. We put these in
' s) L! {8 W* y$ D3 S! L // an action group, because we want these actions to be
r" w) o# Y2 r& ? // executed in a specific order, but these steps should
7 H2 D( p; h2 o5 k! e. { // take no (simulated) time. The M(foo) means "The message
5 T8 O# {6 A0 w // called <foo>". You can send a message To a particular, z/ `* I% e y+ K
// object, or ForEach object in a collection.1 p( j/ r4 {) T: y+ i- Z
: V& }, n* s2 l: y // Note we update the heatspace in two phases: first run. `, r) z' i- y( N# Q7 b
// diffusion, then run "updateWorld" to actually enact the
/ ~% f( L8 w: d K1 _/ I // changes the heatbugs have made. The ordering here is1 ~2 k- U K: k+ t/ b6 a! I" x
// significant!
* V4 L, E, D7 B; K3 F! h
1 E! ?8 Q; d7 ^/ D! a! Z // Note also, that with the additional
1 U5 F6 ]! k, G. x$ m/ R // `randomizeHeatbugUpdateOrder' Boolean flag we can
5 N6 M! x, j' O3 ^4 w# Z // randomize the order in which the bugs actually run1 d" ]2 E3 f1 r4 p
// their step rule. This has the effect of removing any: J$ @8 ]. d0 p* z0 `- l
// systematic bias in the iteration throught the heatbug
$ B) s: ?0 F ~% T# W; j* [* m // list from timestep to timestep
$ h0 o) A* u& b5 t4 {1 ~! O 1 y7 O9 Q! ?! o3 e- U
// By default, all `createActionForEach' modelActions have
4 L; s' K* m# y6 z. \ // a default order of `Sequential', which means that the
; M% T# G5 ^) Q# A7 x* s // order of iteration through the `heatbugList' will be
9 \. t1 [) {6 T! \ // identical (assuming the list order is not changed5 x% g, d! H/ p u% {1 j
// indirectly by some other process).
$ r/ a E4 m. g; V' k+ s
- X2 X; ?4 P1 e+ r2 e modelActions = new ActionGroupImpl (getZone ());
+ L$ K9 P+ [3 L8 }! }* I, M& L/ ^+ [8 z3 H% `# i
try {
5 L. v) h" r' g; h% ~! H% w modelActions.createActionTo$message
8 u! V$ @6 y5 I+ x( Q4 r: P (heat, new Selector (heat.getClass (), "stepRule", false));+ z+ M6 f$ u& E r! j3 S% w
} catch (Exception e) {1 t# i# B# H3 V* P9 t
System.err.println ("Exception stepRule: " + e.getMessage ());
6 G* U' a% U- W }6 b* F' A! U+ `9 E$ \
# [% X5 }# s6 L/ n# q0 Z/ T; O try {/ {. b8 ?) H; E3 f4 v
Heatbug proto = (Heatbug) heatbugList.get (0);
. V( d. |8 v, {* ]' o1 S: T- ^2 a Selector sel =
/ n( u* ^/ U) u2 n4 E new Selector (proto.getClass (), "heatbugStep", false);
9 H; \5 k+ X4 n- m6 k* s actionForEach =4 y: {: ^0 t2 X1 ?
modelActions.createFActionForEachHomogeneous$call0 B6 g6 A1 z) l5 ?
(heatbugList,
( T% ]: a8 [2 G0 W) L+ x new FCallImpl (this, proto, sel,
) P: {/ Q6 O1 m( r S9 ]+ \7 t new FArgumentsImpl (this, sel)));# n. J& j: }! z' c
} catch (Exception e) {9 B3 t9 H# q! q/ D
e.printStackTrace (System.err);
|, U4 y% r' N. R& F3 | }
$ I: _2 f3 P1 ?+ Q% G% T) T. N& a8 V
' G/ z6 G3 H, j: n/ \, L7 J, B( E syncUpdateOrder ();
6 \4 n5 K4 s- Y7 o
: s% K2 y4 Z# t try {0 {! d$ v7 l1 }& L4 K2 u
modelActions.createActionTo$message
) l5 o+ T& n# `0 K (heat, new Selector (heat.getClass (), "updateLattice", false));- l w# z. @" q
} catch (Exception e) {
5 {; [ k+ l4 p$ s9 N System.err.println("Exception updateLattice: " + e.getMessage ());4 {* g+ x$ L. [7 K
}
) Y: o( P. W! m H ( y2 `6 I& X. ]4 _
// Then we create a schedule that executes the
/ L* t/ U% _& X, p // modelActions. modelActions is an ActionGroup, by itself it
- s5 ?& x- H# w# ~$ t // has no notion of time. In order to have it executed in- k2 `5 ?+ A: Y. h* d1 L
// time, we create a Schedule that says to use the
7 T2 e& \! F* d, S& X' ~ // modelActions ActionGroup at particular times. This
/ x. r! v% O, S // schedule has a repeat interval of 1, it will loop every: l/ G7 G- j e
// time step. The action is executed at time 0 relative to
) n. G- p' C7 n: J% T // the beginning of the loop." H t0 L: d% {' s Z: ]1 x
! Y# I% z8 }3 P% v; S, [3 T/ A
// This is a simple schedule, with only one action that is' t. n( z. h* C0 `2 M7 X
// just repeated every time. See jmousetrap for more
* f: e- {; h- i" F' m // complicated schedules. r1 B2 K f( i ~5 q2 H$ V
: c- o) }/ r, K5 x2 k' [. \ c
modelSchedule = new ScheduleImpl (getZone (), 1);
6 K, \' l' K4 S- t! V( U8 w- I, K modelSchedule.at$createAction (0, modelActions);& P3 s( e: `1 @# T* X: z* I
2 _! H$ K3 A% X! Y: p
return this;
- G. |+ x. q+ A4 q- q3 \% k } |