HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' j7 w8 O* a" O3 \& R: N$ L
* T) Y) Q& x4 W2 R3 [, R: v public Object buildActions () {
: c5 R! g( R- `; i% g( i) ` super.buildActions();
& u q, D% a) h& U
5 Y) T5 R" f& c // Create the list of simulation actions. We put these in, s* ]0 y/ s! y/ l) D
// an action group, because we want these actions to be, |4 ^& h& e& W/ i& z- J
// executed in a specific order, but these steps should
. A$ e6 A9 t9 m6 E' p/ w4 X // take no (simulated) time. The M(foo) means "The message
! i* N' o9 X2 |& @" m // called <foo>". You can send a message To a particular
3 J v$ _2 M1 W2 l // object, or ForEach object in a collection.
0 H* \/ g3 V. D + B; i* k$ x6 r
// Note we update the heatspace in two phases: first run/ m% b' ]9 i4 `" p) Y7 x
// diffusion, then run "updateWorld" to actually enact the
0 o4 u1 H d7 s // changes the heatbugs have made. The ordering here is
5 b' u/ l- A( d) H+ \: j# B // significant!
6 o, w+ _7 l# r$ | * w1 C' g+ C) `, n8 j: q
// Note also, that with the additional; D$ B5 g0 B/ T6 T2 |; S
// `randomizeHeatbugUpdateOrder' Boolean flag we can6 B2 K8 k1 Y& S# | J% ?+ V
// randomize the order in which the bugs actually run( W% \7 p; M# N' o; R
// their step rule. This has the effect of removing any
& Q a; p6 z i1 ?, j0 o // systematic bias in the iteration throught the heatbug
0 m- U% f; @8 G) b3 L# y9 C$ j // list from timestep to timestep! V4 Z. r6 C8 V0 K' p( Z" T7 w
2 y& f+ L0 t9 U4 _ // By default, all `createActionForEach' modelActions have# X2 [: V5 n" w' U: y( n# }: L! k7 \3 \
// a default order of `Sequential', which means that the
8 x& T5 P! f, R' L% o) B% M& g // order of iteration through the `heatbugList' will be6 a4 c2 j! q; @# w" G" t
// identical (assuming the list order is not changed
5 f5 [- `! x& N. _6 h. G // indirectly by some other process)." i$ U1 Z$ _9 X$ d* Q% v9 b
! P" x" r, ?/ B: i) B
modelActions = new ActionGroupImpl (getZone ());' d5 b" Y& O: C6 T& v! M0 _2 w
% s! a6 r% K: d! A% V. Y try {9 n5 F& O. k' y
modelActions.createActionTo$message( p. _. e2 m/ e
(heat, new Selector (heat.getClass (), "stepRule", false)); D% o9 c3 J/ k8 T
} catch (Exception e) {# p: T8 _/ M% s4 ~0 _
System.err.println ("Exception stepRule: " + e.getMessage ());
9 S9 m+ s( [0 [! L! n) S0 L6 Y }& T" r2 p0 C* E) u/ d. n- x6 j
' C5 l9 h4 k$ h
try {
& {% t0 m1 U% C: J; Q6 X Heatbug proto = (Heatbug) heatbugList.get (0);
0 }6 a' R' o J4 H$ O Selector sel = " n9 `0 v4 _) z' u* R0 Y( U4 n+ o
new Selector (proto.getClass (), "heatbugStep", false);2 {3 D% u8 f! r c
actionForEach =
, u5 Q7 |) r( i- @1 Y7 t4 o7 @0 g modelActions.createFActionForEachHomogeneous$call2 d m0 C, H1 M3 N! b/ R2 o7 H7 a
(heatbugList,# b+ A8 B% S& \ j' b1 j
new FCallImpl (this, proto, sel,8 b- g6 P: H& l. V h
new FArgumentsImpl (this, sel)));3 ~( ^# `( b; h9 ^1 I6 @+ H
} catch (Exception e) {
1 i0 a: }, t9 n. n- j3 D e.printStackTrace (System.err);. o% |* {( O) Q' p; V
}) U8 R8 s, j( d! i( P3 [
2 v! ?. `1 h* `1 O5 H7 T3 `( I
syncUpdateOrder ();" E7 @# \& G1 f+ |# @) ~3 |
3 z! w! _ G2 a, E. k6 F
try {+ G% `4 i' Q3 L; O$ \4 Y
modelActions.createActionTo$message
% W/ }; P. I4 O( p (heat, new Selector (heat.getClass (), "updateLattice", false));
/ Y. D2 b6 ]+ s' r$ V: d% W } catch (Exception e) {4 O: B! g3 ]2 w9 a0 b! `* W
System.err.println("Exception updateLattice: " + e.getMessage ());8 ^6 z M5 ~$ f0 Q6 b9 B) w
}
3 @# O- [4 m2 B( M4 v- Z: X9 \4 c
" [) w0 e+ l2 }4 [& D% `8 B. x // Then we create a schedule that executes the9 Q% ^! u. a( W$ {- y- Y% y
// modelActions. modelActions is an ActionGroup, by itself it
$ s4 c8 ^" G' u" | A( d3 ? // has no notion of time. In order to have it executed in
' }, \( m% B& V2 V$ O* V- u // time, we create a Schedule that says to use the
+ f! Y3 E! f/ C // modelActions ActionGroup at particular times. This
9 c- |6 ~* }& n // schedule has a repeat interval of 1, it will loop every
" @6 q8 A5 U7 \; u // time step. The action is executed at time 0 relative to
5 E0 v) A) n& i* g% b8 D // the beginning of the loop.7 N+ h& ?: M- K0 H: S' Y+ n
( }4 D4 {& T# l3 Q0 l
// This is a simple schedule, with only one action that is
1 ], L! Y+ s& L& { Y! w // just repeated every time. See jmousetrap for more
9 {0 a3 S& ?% t" O1 R+ I // complicated schedules.
) e7 j3 w5 a" j' I# X0 s) F
+ ~ |( t% y' C/ o P0 _1 U9 a modelSchedule = new ScheduleImpl (getZone (), 1);! C4 }" P1 K4 C
modelSchedule.at$createAction (0, modelActions);' _1 p+ t. M1 c$ }( O
/ M4 @3 w, C3 w/ J2 w return this;
% S4 g' S& N4 q, k# Y- z } |