HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
: u4 _1 d8 j2 b. r( o0 S1 y4 G3 ~& `( W
public Object buildActions () {- n4 L1 R7 [7 l7 C
super.buildActions();# h& M1 W+ L4 }/ H: _4 x* I% W
% p* a3 e1 l b, B, e5 ~ // Create the list of simulation actions. We put these in
7 u/ z% t5 @- R7 N5 K, k2 H) @ // an action group, because we want these actions to be
7 x" s% ^5 o8 w( M3 p4 v // executed in a specific order, but these steps should
9 S' n2 L, x; \. B& f# @ // take no (simulated) time. The M(foo) means "The message* ]6 v2 g& N7 L! @
// called <foo>". You can send a message To a particular
+ U7 e+ x1 J" R( q0 Y/ } // object, or ForEach object in a collection.- ~& q( k# l" V
# y& E0 C& X# R! ` // Note we update the heatspace in two phases: first run
8 g$ a0 _' N [% `* t: i // diffusion, then run "updateWorld" to actually enact the
0 e' H' C7 w2 m: @- V // changes the heatbugs have made. The ordering here is. g) a! r" k! Q; t7 y6 g4 `3 T
// significant!
4 @' O9 F! \ g
& v' h2 F4 ~. @" ]$ h" I // Note also, that with the additional4 n# Y. e: a7 \) o5 |. o
// `randomizeHeatbugUpdateOrder' Boolean flag we can
5 i% J4 m/ ~. ~: S" U // randomize the order in which the bugs actually run
; f" x3 k* I8 g // their step rule. This has the effect of removing any' h$ v' [; `; ]' S: ] v
// systematic bias in the iteration throught the heatbug) H4 q o) M" ?4 H
// list from timestep to timestep
$ k/ v5 Q/ A$ g' ]8 f* }' u3 r4 Q: M # W7 |/ g$ I& H, j
// By default, all `createActionForEach' modelActions have
, T0 |( \) i1 N: g" V // a default order of `Sequential', which means that the5 K. J, w8 J" q7 U, H( p. Y1 p
// order of iteration through the `heatbugList' will be, O4 c* m2 g+ u) L. L$ [
// identical (assuming the list order is not changed
7 Y" E, p* N5 ~; A" g; v' X // indirectly by some other process)." Z" \2 h) _' d
5 e: r0 x. L6 R6 D2 ^& J% u3 g modelActions = new ActionGroupImpl (getZone ());( ]% w# L7 C3 |# H6 L' I
2 u& E, n/ w4 b
try {
7 I5 E* n0 G& Y# W" | modelActions.createActionTo$message
- R! ]8 I: X( a, ~; B (heat, new Selector (heat.getClass (), "stepRule", false));% p+ |* z2 O! Q+ ^
} catch (Exception e) {
! L8 k5 T+ [ G! R, u3 K System.err.println ("Exception stepRule: " + e.getMessage ());
3 @( v5 X3 Y& O8 J) a }' f$ Z# [" S1 A- j T) [' O
6 q# Z( V6 A. U! T) n+ Z- o: y1 p try {
% p# X$ @0 w8 V2 U Heatbug proto = (Heatbug) heatbugList.get (0);/ r. c% r: B B$ j1 W& d
Selector sel = ' k3 H( M; s: G1 x ]$ @3 k
new Selector (proto.getClass (), "heatbugStep", false);$ }7 @: r7 r2 Q% }# U+ X9 Y
actionForEach =2 @# L8 C" j" c8 @
modelActions.createFActionForEachHomogeneous$call
9 j0 U8 H8 O7 v9 x2 P (heatbugList,9 `0 w5 A* M E7 f, f; R8 ^* P
new FCallImpl (this, proto, sel,) @) A- {. @& N
new FArgumentsImpl (this, sel)));
: j4 V: o! k" ~; B2 |7 ~ } catch (Exception e) {
$ A" s# @5 b: r3 t$ ^8 v+ Y" ^6 u e.printStackTrace (System.err);
/ Q9 v9 D( E0 q; l6 F4 S }. R: Z; @! s9 V0 L% J0 M( l" x
2 q% x9 b! `( x. f0 g1 W2 i syncUpdateOrder ();# R# ?" N$ ~" `; `, A* G
1 T; ^) j$ N$ x% v9 E8 Y8 E try {
" M* Z, J! ^% Y+ ^+ X' }% B% } modelActions.createActionTo$message ! _- [. n6 p% y3 `0 G# R3 y
(heat, new Selector (heat.getClass (), "updateLattice", false)); C. U) B; f* y2 D
} catch (Exception e) {
2 F% U7 s( }" r' q9 `2 N System.err.println("Exception updateLattice: " + e.getMessage ());( x% p; e7 \6 z: N3 x5 K% I
}; o# R6 A* V; [* l/ T
' Z$ P7 }6 Y; o4 z9 z+ [ // Then we create a schedule that executes the
5 Q6 n" k$ Q/ }( B+ x // modelActions. modelActions is an ActionGroup, by itself it
8 ^0 _7 b) _6 n5 _$ l( A3 J' r6 r5 j // has no notion of time. In order to have it executed in. ?1 i/ O! Q. U% O0 p$ P
// time, we create a Schedule that says to use the. q) j3 w" _- Z9 w% x. a
// modelActions ActionGroup at particular times. This
# o7 E; F& N) ~* B( G& i5 z& a // schedule has a repeat interval of 1, it will loop every
" Y3 }1 U3 g$ U4 q5 N# f // time step. The action is executed at time 0 relative to8 J1 G5 D* u* D T
// the beginning of the loop.
/ H- S( W: B' s; E. R" p- W- \0 K% T3 C8 G4 [
// This is a simple schedule, with only one action that is
! p' h" B& X' t: A // just repeated every time. See jmousetrap for more
+ A. J2 I, K$ Y! D- x4 ] // complicated schedules.
- E" l7 y; D+ R: L: q' j/ U
5 _* W5 \. ]( E modelSchedule = new ScheduleImpl (getZone (), 1);
6 i+ G. O( g: R8 B1 C0 m# J modelSchedule.at$createAction (0, modelActions);
% C9 \9 t7 w7 z6 _1 C
- Q4 Q) _" \" Y: |# Y6 j! v return this;
+ N5 s) x. l- l, b1 `& X& | } |