HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
# ]4 T* w' ~/ x) \4 J2 E* }9 E: @4 `1 ^% X& r4 T
public Object buildActions () {
$ m; a" g2 f+ ]# t6 S& g7 C super.buildActions();& A. q( V0 ]4 T7 v
9 z8 n. B5 c! h // Create the list of simulation actions. We put these in! f8 w! A0 }3 b7 q9 x
// an action group, because we want these actions to be
) @& u5 J4 G0 R& b8 U' z" n // executed in a specific order, but these steps should9 q$ U" V5 T, f
// take no (simulated) time. The M(foo) means "The message1 \) R# D7 J8 ]1 q; F3 c
// called <foo>". You can send a message To a particular* ]; n. ^$ n4 w8 f. r/ F; A
// object, or ForEach object in a collection.+ d% s/ W" f7 E; e
5 F1 C4 Q9 l7 L+ w8 G3 W // Note we update the heatspace in two phases: first run
$ S6 i/ c$ Q! M- a/ j8 Z% t9 @( X$ o // diffusion, then run "updateWorld" to actually enact the
0 t$ }; E; ^! t; W) O6 ~ // changes the heatbugs have made. The ordering here is; O" p$ C8 l# p
// significant!
% v% ?# n; y# u+ B0 u , {! w# A: C$ s; i% V
// Note also, that with the additional
' E1 M- P* P/ m5 l2 F& f // `randomizeHeatbugUpdateOrder' Boolean flag we can
, u, h/ }9 ?0 l. z" l // randomize the order in which the bugs actually run+ M2 ]" X ]0 b
// their step rule. This has the effect of removing any
8 M2 U+ X5 w7 j- q // systematic bias in the iteration throught the heatbug0 p+ p( H6 \5 L* T; N
// list from timestep to timestep
: Y4 y9 x2 f, s, \ 1 O/ ^* N. I1 O, z% c- Z/ \
// By default, all `createActionForEach' modelActions have
" N2 V [) I7 m7 y4 q# B // a default order of `Sequential', which means that the+ c' |0 S% v3 s4 \: b W, D& U3 k
// order of iteration through the `heatbugList' will be$ [6 r4 {4 i7 t- V. K
// identical (assuming the list order is not changed
' v0 d% C! b( B) S9 Q // indirectly by some other process).5 h c1 C* _6 |" o7 d \
/ m* w F* a9 c" B. ^; a3 p0 B modelActions = new ActionGroupImpl (getZone ());7 n1 H4 ^. Z4 j, r
: _8 \& e* w5 V( P- ?
try {% W* U. \) V3 T& i7 T2 \) V8 O( |- [
modelActions.createActionTo$message. E( U* G3 q0 m k9 ^3 }$ }* W
(heat, new Selector (heat.getClass (), "stepRule", false));' P7 h( h* `# r; p! L( b7 h
} catch (Exception e) {
9 F# l6 k1 H. V9 k+ S1 n System.err.println ("Exception stepRule: " + e.getMessage ());
9 D+ Z' P: D. J- T; n }( y5 x1 N. }7 o' [) V4 r) k! s
3 [, e, a# U3 m
try {6 H4 j8 A: {/ v7 r) g
Heatbug proto = (Heatbug) heatbugList.get (0);; y8 r+ o O2 F4 s) |5 |! j
Selector sel =
& z$ k& m/ \- R8 G; j9 O6 l0 z new Selector (proto.getClass (), "heatbugStep", false);0 V4 p7 S6 P$ D1 h0 A
actionForEach =8 ~, O4 f# M( e& L
modelActions.createFActionForEachHomogeneous$call
t4 R4 L7 ^2 n% u" }1 a (heatbugList,
4 ^% u; N( n, T t# w new FCallImpl (this, proto, sel,
" {! {: M' B; e2 f& B new FArgumentsImpl (this, sel)));
9 W/ ]* H+ A; p2 @ [ ~6 d } catch (Exception e) {
2 Y2 V( F! H% S2 |; h9 ` e.printStackTrace (System.err);- x$ I/ F' z( s6 M, y) s
}4 z0 t5 b' B0 {
z! F3 _, s; s- Y! U syncUpdateOrder ();
2 M8 c5 N8 z0 C% x8 h# D9 _6 [( u2 q( F7 C8 T
try { X# c- `5 M; R# Q5 E" i/ J
modelActions.createActionTo$message " x7 t3 ^* k0 g" y" D6 L! d# V
(heat, new Selector (heat.getClass (), "updateLattice", false));5 _. a6 ^7 ^8 h
} catch (Exception e) {
( G7 Y. {4 V( m" d7 O System.err.println("Exception updateLattice: " + e.getMessage ());
- A8 s/ E0 A& T5 _5 d }* h& k( S7 D1 j' l# v) M2 Y7 y
, S0 [( z+ H: O3 Q
// Then we create a schedule that executes the" b$ P+ C6 `# N3 j7 e+ H& ]7 I- P
// modelActions. modelActions is an ActionGroup, by itself it
# |' V8 R/ w4 j, s4 B& T4 V // has no notion of time. In order to have it executed in
" R' e0 _8 l' \! n! r$ m // time, we create a Schedule that says to use the. l& m& B7 W- y- G
// modelActions ActionGroup at particular times. This/ b* g( T' f: X% I' V
// schedule has a repeat interval of 1, it will loop every- B: q% h# J1 W
// time step. The action is executed at time 0 relative to
7 o' x0 Y m1 f: u: d // the beginning of the loop.
$ u/ A' S+ ?$ r$ v0 l- M
8 |0 o9 W1 ^! B7 m# K/ N; E // This is a simple schedule, with only one action that is- `1 w( k; L! f7 m( D2 v& f3 d
// just repeated every time. See jmousetrap for more; Q Y/ }5 D0 c# h6 p/ i% @
// complicated schedules.( P4 W( H9 H- m# {1 b) H7 z5 {
4 F( r3 _- t# j" x0 k6 y modelSchedule = new ScheduleImpl (getZone (), 1);
8 x" p0 e! c; x8 h' F& U& {8 C modelSchedule.at$createAction (0, modelActions);
5 a- s# m+ x, b+ m& z' p
" v7 E3 |9 O2 P2 [ r return this;5 y+ A% x, p1 H4 U0 w
} |