HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下: G% l2 A+ A7 `( g
: \8 |- l) E) ~" K7 f public Object buildActions () {
* @: n8 h( }7 @+ b4 Q super.buildActions();
' i: X0 a {1 b: `: d + \4 `1 Q" V# `% y
// Create the list of simulation actions. We put these in {5 B3 e, m3 \2 |& j* m( q
// an action group, because we want these actions to be) E) b& a( V4 V y- D" y. d
// executed in a specific order, but these steps should
9 w: A d( B, |2 V // take no (simulated) time. The M(foo) means "The message. q7 o1 Y, h0 y# |$ w5 ^7 t
// called <foo>". You can send a message To a particular
! [* [2 f3 H9 s& t7 U$ t // object, or ForEach object in a collection.
9 A& c6 c5 V- Q0 z
4 G8 ]6 {& E" r // Note we update the heatspace in two phases: first run
* G- g- }7 `3 l+ G# G8 @ // diffusion, then run "updateWorld" to actually enact the5 k. F5 T. C8 |: l1 h
// changes the heatbugs have made. The ordering here is
: g' C) s' P9 n( L# t // significant!+ p T: Q4 D5 k0 L5 D/ ]! B9 g3 Z' V0 H
+ ~) p" U! X7 L# v+ ]: x* D/ c
// Note also, that with the additional p0 [" t3 F" x/ M O- q
// `randomizeHeatbugUpdateOrder' Boolean flag we can
- z8 ^( a! m% T0 R // randomize the order in which the bugs actually run% `. E9 s, @' K1 \" \, Z1 s
// their step rule. This has the effect of removing any. p; Z1 H2 p& M6 Z! s
// systematic bias in the iteration throught the heatbug
0 C6 X( Y) ?0 p% f2 O+ T // list from timestep to timestep5 }+ n$ h: B, n2 A5 Y
3 Y9 R( q% b X7 U+ }% R7 w' X // By default, all `createActionForEach' modelActions have5 M7 ^3 R3 Q8 F
// a default order of `Sequential', which means that the/ y- _; |0 S* ?% l+ B0 T9 l0 N
// order of iteration through the `heatbugList' will be
' B& g5 X& g& P- N; b, k" M4 d // identical (assuming the list order is not changed
4 [9 z, S+ ? G // indirectly by some other process).7 l' a/ l7 D7 ?4 d
) a, g+ Z8 J( x* w: [% e3 C4 u- K
modelActions = new ActionGroupImpl (getZone ());
& q/ E& [& O0 {7 |0 c8 F& |3 _
1 s3 E) y7 T9 D: J try {$ k6 i' J; {$ N3 h* `- ^; V. H
modelActions.createActionTo$message; f) n5 B& J9 Y' @7 k4 ~
(heat, new Selector (heat.getClass (), "stepRule", false));
' F* v+ N* N# `. k. b0 J } catch (Exception e) {( n& E& v& ~1 l
System.err.println ("Exception stepRule: " + e.getMessage ());
9 A& d' _) n! O3 w H }4 R: \6 e. I$ l0 S( P" Q/ i7 X: L! ^
: w+ j* C. G1 `) S
try {- h6 e K' p' X( B" ?/ [! d
Heatbug proto = (Heatbug) heatbugList.get (0);
) S0 _4 z8 b9 y0 N Selector sel = 2 u- I! J1 p, o; E' x6 C0 G
new Selector (proto.getClass (), "heatbugStep", false);
: W3 w, r0 y L# H( j/ N actionForEach =) p. c* X+ S% {* ` G
modelActions.createFActionForEachHomogeneous$call/ v) d$ f% e7 \: P
(heatbugList,
9 W5 t% b- q1 R; Z# \8 ]' H new FCallImpl (this, proto, sel,
q' Z6 ~" K' Y- ~; o new FArgumentsImpl (this, sel)));
5 O0 s% m+ Y0 p% P# ]% I0 i9 s } catch (Exception e) {$ F7 ]/ t, X* E. i- S. ?
e.printStackTrace (System.err);
1 B5 A+ m$ C |' F. E* V }: |3 |# O. v2 u1 t' C1 }9 y
' l, j' X& j. X6 e- Y7 k syncUpdateOrder ();
! N. o2 L3 X0 K0 V3 I: j. D# T; _* t7 t r
try {7 O* D" I/ B. @+ Y) ]! R
modelActions.createActionTo$message " b$ y* S7 T( |4 v/ V7 |4 X
(heat, new Selector (heat.getClass (), "updateLattice", false));# y3 t$ a+ D( o! O+ t0 [3 W3 Y
} catch (Exception e) {3 o) u! s( O. J2 A
System.err.println("Exception updateLattice: " + e.getMessage ());
) T. D8 Y4 y# n3 a" _( F }
( L. v+ F$ Q9 {) }6 N, r! J3 N. s) |
) r$ B" B' d- I1 \; M- y // Then we create a schedule that executes the- r* }; Q; \1 @1 z
// modelActions. modelActions is an ActionGroup, by itself it
$ r( X- x: j: f5 N // has no notion of time. In order to have it executed in& R' B$ Z( h- L2 U/ P
// time, we create a Schedule that says to use the% b1 E4 }! |" j2 g- L/ n3 P
// modelActions ActionGroup at particular times. This
5 ~1 A. |# f% T Y1 }0 V- U // schedule has a repeat interval of 1, it will loop every7 W( J5 R5 p$ b) j0 b
// time step. The action is executed at time 0 relative to9 |- p9 k5 d# I7 j1 ]$ F
// the beginning of the loop.
3 G; r4 A& A" D4 c" O+ _: D* w4 h
@; Y. H% ?+ W // This is a simple schedule, with only one action that is
1 F4 g: M$ L1 k9 w; e$ Y9 S* }: b // just repeated every time. See jmousetrap for more
6 H. M. k/ @7 f% d9 y+ u3 E! L // complicated schedules.
2 ^$ [0 }" ?/ R% |; U ; r. s6 u( a0 [6 C, A2 y
modelSchedule = new ScheduleImpl (getZone (), 1);
* V7 n9 I: ^3 z9 Z modelSchedule.at$createAction (0, modelActions);
$ b0 y$ g( \' p% p
" B+ t( m( w- Y return this;
4 \ h% ~* |) x } |