HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
& o7 F& M E! P, F# @2 a0 b$ _9 h# o( u
public Object buildActions () {
: o6 P; n+ u$ w9 D( L super.buildActions();9 }! p i, A: Y3 D
; ?; {: p8 |5 ^2 Z: a! Q
// Create the list of simulation actions. We put these in
" m, a) y* A9 D1 I: o/ c // an action group, because we want these actions to be
6 d7 O+ g: m1 }2 B // executed in a specific order, but these steps should# ~9 w% s5 r- S
// take no (simulated) time. The M(foo) means "The message+ M N! ]4 H/ A, O" C/ o
// called <foo>". You can send a message To a particular v2 M \/ i. o; o9 Q, S
// object, or ForEach object in a collection.
0 h" }# v0 m0 ^$ M8 M% \
B2 X- r. f# j% r4 I // Note we update the heatspace in two phases: first run J2 Q! H" D4 g8 C) c
// diffusion, then run "updateWorld" to actually enact the2 R. U4 S+ ]$ {: n2 e
// changes the heatbugs have made. The ordering here is
5 a: q' `% H6 K; t& d // significant!
9 q" D8 f p1 u % B) d M, @" P
// Note also, that with the additional3 D5 {* U I7 J. E( K
// `randomizeHeatbugUpdateOrder' Boolean flag we can
9 z G" Q' H# R! a1 j // randomize the order in which the bugs actually run/ w0 w( i5 t9 e" G) i1 q
// their step rule. This has the effect of removing any1 C' n8 D& a, O2 H
// systematic bias in the iteration throught the heatbug
) A( `0 ?4 |4 |) q6 z0 {& C6 q9 M, E! P$ u // list from timestep to timestep
3 q# A4 l" K& k 3 T7 [. m0 p" |2 W5 ~
// By default, all `createActionForEach' modelActions have
5 e, ^9 w6 Z# C5 p) K! y // a default order of `Sequential', which means that the
$ A* q8 U( r; g+ V% f0 t. D' f) S // order of iteration through the `heatbugList' will be
_5 e' U/ T: o/ E; T: j4 J // identical (assuming the list order is not changed
" q z& e" K% Z6 ]# R // indirectly by some other process).
4 ]: U9 r: V) _1 P
9 [2 [3 J+ y8 g) E! {( w modelActions = new ActionGroupImpl (getZone ());3 b9 \2 j3 C7 ?8 C+ ?
9 J6 }6 o+ r7 }5 z/ b& X" T try {# C$ f/ `( I# C" G; g9 ~6 w
modelActions.createActionTo$message4 m8 P) J N( d* h9 Q
(heat, new Selector (heat.getClass (), "stepRule", false));7 b) C. q- A5 F3 O" M( R
} catch (Exception e) {) M2 O5 L# r |; t
System.err.println ("Exception stepRule: " + e.getMessage ());
: d0 T2 `* @8 ]; O }% p$ J- Y2 ^0 V8 [; G
& ]. ~1 l5 x: _8 q) p
try {
7 N4 l' Z. J: e- K- A Heatbug proto = (Heatbug) heatbugList.get (0);8 n6 o4 z/ \6 Z
Selector sel =
& q/ J# Y: P7 ~/ g+ D, m new Selector (proto.getClass (), "heatbugStep", false);1 h0 v. {0 l6 v4 i% d* k+ H9 b" w
actionForEach =
5 P. v ^& b6 ?% @ modelActions.createFActionForEachHomogeneous$call# W$ `; l E$ @! X1 A+ j
(heatbugList,5 L% G% `0 D2 f; B$ d2 H
new FCallImpl (this, proto, sel,7 y1 b) }, M5 H% D8 Y9 n) d, F4 f
new FArgumentsImpl (this, sel)));% p, O0 C! z6 ~0 Y% _6 L( h( S
} catch (Exception e) {
1 |( |, p" b$ U! l0 Z e.printStackTrace (System.err);' i# e+ s( k7 @8 @5 J
}
8 Q$ B( {/ O0 ?: K
1 Y0 ?" e5 r$ N0 C syncUpdateOrder ();
! K: e' l' ]" m$ U) N3 A+ {0 m' f2 \& ?5 l) L' a
try {% t" ` J! p. h" v- l; S- ]0 q
modelActions.createActionTo$message # b2 E y4 }& H$ N! i3 S
(heat, new Selector (heat.getClass (), "updateLattice", false));0 c4 H" P+ z- m/ w& D9 ?
} catch (Exception e) {
8 k+ ~" M" t4 X System.err.println("Exception updateLattice: " + e.getMessage ());
0 l; |- q! J# i }
Z! c8 S7 w# b' d 3 r; ?& h" C; R: J7 j8 S% o
// Then we create a schedule that executes the
8 i! X ~* Y0 b // modelActions. modelActions is an ActionGroup, by itself it
3 L) e5 a3 Q5 l // has no notion of time. In order to have it executed in/ l; {7 m! x+ g5 p. n
// time, we create a Schedule that says to use the
1 y) I% ?1 `, B+ b( D, N // modelActions ActionGroup at particular times. This
8 K* x& X) \: u+ Q // schedule has a repeat interval of 1, it will loop every p5 r3 H, ]6 s2 @% x# l
// time step. The action is executed at time 0 relative to8 v1 K* l* G: Q
// the beginning of the loop.
$ p; Y/ p0 f6 e; q8 R; y6 d! d( @$ x# U% P/ ]. s$ y5 Y
// This is a simple schedule, with only one action that is7 m) T/ g/ l8 x, s& i1 I4 a' B; a
// just repeated every time. See jmousetrap for more+ q1 ~' x0 y& }( }" V2 ]6 Q
// complicated schedules.. E9 g" }5 a4 {$ ^" S0 i
& R. P$ W# ]# B. d/ d8 P modelSchedule = new ScheduleImpl (getZone (), 1);: L" i+ g: O# V, P6 L
modelSchedule.at$createAction (0, modelActions);
6 ^, p9 L& M0 ], a! C1 s; h * [* q: m0 {; B3 |
return this;8 X9 q) |, \4 H [5 i
} |