HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
4 i7 F3 I" S9 I; K# a+ K
! |2 G. y9 I; R) F5 \ ~ public Object buildActions () {5 L0 b3 f" o. \6 o8 `) z+ X
super.buildActions();/ H+ s. v) j2 [
0 j: {& o2 L9 m" c
// Create the list of simulation actions. We put these in3 T4 A8 J6 N: g; ?# t: R
// an action group, because we want these actions to be
5 S: g6 d& U" M8 b! e // executed in a specific order, but these steps should
( u$ w c- T& W // take no (simulated) time. The M(foo) means "The message$ I! ~% _8 \! j+ \5 Z1 f' P* A6 h
// called <foo>". You can send a message To a particular
( {( Z5 l+ f8 \( ~ // object, or ForEach object in a collection.
+ Z) d0 {5 p6 b$ M. O * _/ v# H1 v" v w
// Note we update the heatspace in two phases: first run6 T1 c: ^9 Z- @: J
// diffusion, then run "updateWorld" to actually enact the4 s0 \# V: i G9 V5 x
// changes the heatbugs have made. The ordering here is# Y( c; x& I. G( L3 K- k1 C' W
// significant!" T H3 Q3 G! Q% ]& \# v* Z2 i( L
+ e7 F" \) k& h" f7 O3 [* q
// Note also, that with the additional! z# ^: n% p" V1 \' L v
// `randomizeHeatbugUpdateOrder' Boolean flag we can
+ {. [" s4 e7 C# H( _ // randomize the order in which the bugs actually run
4 [) _9 l: S4 T3 b // their step rule. This has the effect of removing any
4 a# X5 Q: B/ i0 B, y // systematic bias in the iteration throught the heatbug
: c6 B" d7 b$ \3 M: s8 k3 n // list from timestep to timestep
5 c4 K) j1 N/ S1 } * A% m( v! d7 y
// By default, all `createActionForEach' modelActions have; Y3 x7 N+ Y7 v
// a default order of `Sequential', which means that the" e- _$ i' A! E4 [5 u
// order of iteration through the `heatbugList' will be
- x) q/ l) i6 p0 K* M) r0 |1 U // identical (assuming the list order is not changed" d$ @( e6 `3 k, x6 O5 f
// indirectly by some other process).
) L& _, F9 q' V( v( V9 G7 I ' D! n1 `0 d' ^
modelActions = new ActionGroupImpl (getZone ());3 H, M' ~' l0 V" N0 i
$ L% ~0 ]# D9 F
try {, N- [5 G5 d8 ^# K4 v+ ?" n. J
modelActions.createActionTo$message4 k' V& O$ s: ]: j' m
(heat, new Selector (heat.getClass (), "stepRule", false));
% a0 m g% E7 C/ _0 I } catch (Exception e) {. `$ \1 p) n0 Y1 Q
System.err.println ("Exception stepRule: " + e.getMessage ());2 ?6 C8 X' Y s. T
}
( W) C5 _8 o* g9 R6 }% b0 J5 G9 g
' j( C- A' O8 d, K! T try {
/ n5 ?; ?- n0 F+ l9 \' z3 q Heatbug proto = (Heatbug) heatbugList.get (0);
. Y/ m1 W* B; O7 Z+ z& ?: ` Selector sel =
" p& i1 q; `" C8 t% A. G new Selector (proto.getClass (), "heatbugStep", false);! M- [, V$ d4 ]8 [, F
actionForEach =
3 F, X9 x7 p5 v% ^$ [/ e9 D modelActions.createFActionForEachHomogeneous$call
* R4 J6 S O* }- H! F1 L (heatbugList,
; ]& h: ]7 T: t new FCallImpl (this, proto, sel,
* _( y: f* g! {, r3 F new FArgumentsImpl (this, sel)));' ~" Q$ l% }- K3 _( c
} catch (Exception e) {- t3 s7 i# Q. Y9 K
e.printStackTrace (System.err);4 b; D. [" A3 A0 ]* ]$ p
}
$ ^- C# D3 Z/ [8 w6 }/ {
- n+ N3 M Z$ O syncUpdateOrder ();$ o. d, L, J. w: k. f0 Z
8 m9 e" i9 W/ c! [
try {3 b' a. n& W$ `; D) r
modelActions.createActionTo$message 0 R) W; j7 }3 ~3 g' x
(heat, new Selector (heat.getClass (), "updateLattice", false));. w) u: s1 W( X( G0 }0 p: x
} catch (Exception e) {6 T# N( g: I$ o8 j* _; c
System.err.println("Exception updateLattice: " + e.getMessage ());
4 q8 d& g; V; E$ I6 k/ d8 u# N4 ^ }
( f4 m" ^0 L( f . c/ R, X) D2 \' }/ V- H7 @- t* H: D) \
// Then we create a schedule that executes the
% C; I+ l* g# f/ d // modelActions. modelActions is an ActionGroup, by itself it6 v8 K: U& a3 t( h4 X
// has no notion of time. In order to have it executed in
- B9 e8 @- j/ l: S1 `" X( a k/ H // time, we create a Schedule that says to use the
- ]4 C! m R7 \% F/ g6 v* b- f9 t // modelActions ActionGroup at particular times. This
E2 q5 g/ e4 i. ~5 D1 w! n // schedule has a repeat interval of 1, it will loop every
4 J2 ~! `" {5 ?) v // time step. The action is executed at time 0 relative to
/ C7 C! u5 c4 j; A; [' O // the beginning of the loop.) C; A9 M2 O9 Q* o3 f
3 b9 P0 ?8 |1 @, U, j // This is a simple schedule, with only one action that is8 o/ M+ Y3 o+ ~: r. s5 E( R) [
// just repeated every time. See jmousetrap for more
/ J( @* N+ S4 V' R1 z // complicated schedules.6 M2 e N" R- U# }, H( O2 w
% K1 v( r1 ]2 \% r2 x1 Y1 D+ J
modelSchedule = new ScheduleImpl (getZone (), 1);
* s6 F, G( a. t6 R# j8 } modelSchedule.at$createAction (0, modelActions);2 J% O& F, U! ?0 j0 h- [
5 r" I+ W4 o, V4 |" P# I, m
return this;/ J4 s5 ~/ P8 j% W7 X7 @
} |