HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:% I* W" R3 f/ x# X# ]0 L
# m% {/ U/ d/ ^, l$ d& P4 F1 k public Object buildActions () {; e% n' l" X3 x0 D
super.buildActions();
5 h! B+ {( u- Q9 l! K* a 6 t" D2 ^% i% s7 k/ V
// Create the list of simulation actions. We put these in
& ]/ A2 `8 @2 M3 ^* } // an action group, because we want these actions to be
/ n7 T) r# \! ?: \9 P // executed in a specific order, but these steps should, [8 t5 D9 T! x
// take no (simulated) time. The M(foo) means "The message
! Y; s/ D- ^5 r) L: F# v // called <foo>". You can send a message To a particular8 ~% @* t* F# I( P8 Y- u& Y9 X& x/ b
// object, or ForEach object in a collection.( c3 L1 ?0 o2 C6 I
* g( W7 z9 w% d3 f' ^5 ? // Note we update the heatspace in two phases: first run
* k8 W3 E; W/ I/ E; K4 a2 P! _# t* u( B // diffusion, then run "updateWorld" to actually enact the K$ E1 n8 E/ W( L
// changes the heatbugs have made. The ordering here is% ]# R9 I5 u6 o2 i D: g- H
// significant! F: I0 Z6 Y2 B+ ]) X6 d# ~( t* Z
% }7 E$ d" ]( S7 o
// Note also, that with the additional6 }% U5 f8 v! w; f
// `randomizeHeatbugUpdateOrder' Boolean flag we can2 I* Z; k. T/ L4 F1 A$ [, x! C
// randomize the order in which the bugs actually run& K5 l$ c, Y5 H ]. `
// their step rule. This has the effect of removing any
# o$ N6 k5 b- v // systematic bias in the iteration throught the heatbug
: c8 O; ?7 C0 B( M3 V" a // list from timestep to timestep
! f1 X. u& j; b6 e
" R- J# Y3 U: V- d1 p# I+ c3 U" i // By default, all `createActionForEach' modelActions have& j# p. A% `$ F
// a default order of `Sequential', which means that the
" }. ^* f& M/ e; u8 {% \. j // order of iteration through the `heatbugList' will be
0 `5 @. g" E o* _% O3 x // identical (assuming the list order is not changed% r; m$ C; x0 j) g
// indirectly by some other process).2 j( W; K+ E1 d2 x
- T$ B2 A/ C4 G: Z2 k; H modelActions = new ActionGroupImpl (getZone ());$ Z6 J2 U5 K3 K& p* A% b4 g
6 W5 @' @# B0 v2 o( L: ?! x- |
try {
; Q2 V5 y7 M, x, [ modelActions.createActionTo$message
- \+ v$ y" G; X (heat, new Selector (heat.getClass (), "stepRule", false));
. F. y6 i! H7 F1 s( W } catch (Exception e) {
" j- l: E, n' t System.err.println ("Exception stepRule: " + e.getMessage ());4 D- O8 y' u8 I. X' z( l1 Z7 W
}
. ?" {0 F% Z2 G8 f( [, F5 o1 p# o+ z+ c/ m
try {% s0 y# A* z6 f3 r2 I1 X
Heatbug proto = (Heatbug) heatbugList.get (0);
: ~- k4 `. _, D( I/ W Selector sel = & Z4 D, _2 M2 D" s; ^
new Selector (proto.getClass (), "heatbugStep", false);) s4 P8 [! c9 x% A2 ~
actionForEach =5 _: s* u. I1 j! m
modelActions.createFActionForEachHomogeneous$call
5 W; x; J0 O4 R d9 S- S (heatbugList,
: ~: m& v/ D& W5 Q new FCallImpl (this, proto, sel,
+ j% D4 ~7 m0 F$ A. d( l3 I* _ new FArgumentsImpl (this, sel)));0 y. i* D5 J8 N$ w
} catch (Exception e) {0 b! V8 W" R1 Y0 p; K5 \* l0 n' L
e.printStackTrace (System.err);' r% L4 m% s2 }
}( f& U. x9 d- X+ A
1 U3 ?6 b; p+ t2 @4 }) { syncUpdateOrder ();6 X$ c5 O( c [( }8 V
% j" ^, b8 K- F n5 _ {, u q( H
try {
- J/ B$ n/ j5 { modelActions.createActionTo$message : z' O* C) T& b( s: Y& q# O& m
(heat, new Selector (heat.getClass (), "updateLattice", false));; d; R* M, D. z3 t% M: ~
} catch (Exception e) {1 Z3 G' P J, k; o
System.err.println("Exception updateLattice: " + e.getMessage ());4 C3 x* Y6 W% a3 I( n5 ~
}
y9 u7 d" O( E% N% ~4 ]& K
3 p3 u. p# K) ?, Q& z3 U8 n4 } // Then we create a schedule that executes the& ^9 d& o: j2 C! T, J
// modelActions. modelActions is an ActionGroup, by itself it9 F9 J9 T0 S! U* T
// has no notion of time. In order to have it executed in
7 E1 ]& K. \6 N. B$ Z // time, we create a Schedule that says to use the
) e+ v2 [5 O, R' p& B! ^ // modelActions ActionGroup at particular times. This
! b; b, Z: v; J! a& @4 V% y& n' |' ]8 s // schedule has a repeat interval of 1, it will loop every
8 T! @* b& y* o // time step. The action is executed at time 0 relative to! [: w) `% }8 j8 d
// the beginning of the loop.1 h7 K0 l2 r4 M. ^1 o
9 o8 k2 z7 k- j" v( n( G
// This is a simple schedule, with only one action that is7 I: G/ a' j# g9 @0 V5 ~2 J5 A1 ^
// just repeated every time. See jmousetrap for more
2 i+ C. _' h2 {$ t! j" G // complicated schedules.% Q8 k6 |0 o# X) Z. e+ G/ q
( o5 _8 H' X' z, J G+ _
modelSchedule = new ScheduleImpl (getZone (), 1);, Y) H$ ]+ S9 }
modelSchedule.at$createAction (0, modelActions);
* I# f7 `: i! D H# V9 `; j
7 N7 Z$ A \# u return this;
2 l. Z% C7 H* W( {' H: a: Q& L- Q) G } |