HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:* F5 D1 `7 C% G; S1 V
/ S" q! C/ ^- w- t, D; M public Object buildActions () {% t5 i' z+ M" A
super.buildActions();
2 Z/ `9 R2 e; u6 s% g' m
- s4 L- S- I: Y# b% s // Create the list of simulation actions. We put these in
! L$ J, k( h7 u // an action group, because we want these actions to be
) w c% S, M3 e, D% b, B4 m0 w // executed in a specific order, but these steps should" J" X! f0 z. P) X, c
// take no (simulated) time. The M(foo) means "The message
q j6 c3 S4 ~& v // called <foo>". You can send a message To a particular. F+ s# M4 S7 w0 c6 G, y! J4 N
// object, or ForEach object in a collection.8 J) b' @4 l1 ^
4 K: i+ Y7 ^4 t1 `+ l! [2 g3 h // Note we update the heatspace in two phases: first run: x1 S8 S1 n* B3 F3 t0 e) p
// diffusion, then run "updateWorld" to actually enact the Q i; N: y. I
// changes the heatbugs have made. The ordering here is
6 n/ P% v( g1 R6 d" R* b // significant!! R* x% h4 V2 F2 F
+ `! h. a' ^* e3 {: ?( ]
// Note also, that with the additional% F. ^# B3 L" m
// `randomizeHeatbugUpdateOrder' Boolean flag we can
d; f' p# `$ v) K9 o/ g // randomize the order in which the bugs actually run
0 G" c$ ]3 k# \& m8 q3 u // their step rule. This has the effect of removing any% E: ?- {# p2 |9 a. B; R
// systematic bias in the iteration throught the heatbug
) f- |! J1 q. | v {; [) Y* Z" O // list from timestep to timestep
* ?- R' v, l" Z2 h& k% G
$ L6 d2 b0 @; ]0 T; \ // By default, all `createActionForEach' modelActions have; W$ ?- u0 K7 V- \9 ]3 ?+ z m
// a default order of `Sequential', which means that the
$ c+ }, P1 U. n6 M$ A // order of iteration through the `heatbugList' will be
, C# s* J8 q* e H* f8 |. ? // identical (assuming the list order is not changed
' k4 f/ U# i; e# T, ] // indirectly by some other process).9 L6 S. x4 B" c. m2 _
( c3 l4 o7 c2 M; ?0 ]0 ]( \4 r
modelActions = new ActionGroupImpl (getZone ());) N3 c* {. `( i5 p9 T" Z
" X+ w1 v# W: l- u: C( A2 H( m# \ try {) N C t( E* ^+ b5 I
modelActions.createActionTo$message* x) x, m; c6 ^
(heat, new Selector (heat.getClass (), "stepRule", false));: l$ {/ C0 R2 R5 l1 T+ W
} catch (Exception e) {0 v# T. z8 }: P- l" ?, g" h
System.err.println ("Exception stepRule: " + e.getMessage ());
. |3 ~% M; \) N% m3 k }. }- C7 X4 n' d' E6 A! d. e
- [! k8 }8 t! h# R" V. ?( q try {3 @* r+ G& f" U
Heatbug proto = (Heatbug) heatbugList.get (0);
U( C7 _* V$ h$ k! a1 t6 T6 _ Selector sel =
0 L- u" I4 ~, I" \7 W3 D new Selector (proto.getClass (), "heatbugStep", false);
8 S/ U7 H& Y' {6 r; P9 `1 q+ z actionForEach =
0 A7 a* [- H& u/ Y3 ^! t$ x modelActions.createFActionForEachHomogeneous$call
" p3 s. v6 B/ d% S! | (heatbugList,0 i/ [# [+ E4 u
new FCallImpl (this, proto, sel,8 n' f7 D' V9 v n! c B
new FArgumentsImpl (this, sel)));
# C: D" i& L8 J9 d, j P } catch (Exception e) {0 {) Z# S+ g; M
e.printStackTrace (System.err);
" `. I" O$ ?& j8 ^, `' } }
C: T7 I8 r# a6 U2 j) K: V 8 S5 l& Z* m9 C7 Z; N" Q
syncUpdateOrder ();# C7 P/ e+ {6 u9 x4 @
# o; s6 e- `" D& E8 \
try {0 L# _. m+ w/ P' L
modelActions.createActionTo$message
. D, ^4 q! O4 r! z- h (heat, new Selector (heat.getClass (), "updateLattice", false));; H/ t; {4 N/ |2 y, S
} catch (Exception e) {8 D6 ]) E: V4 B7 I6 N, X
System.err.println("Exception updateLattice: " + e.getMessage ());" `% u! E. y) `$ t/ `6 [
}( n( j" t- ?. `, a6 h( @) D) T
& L- U f5 L m. @) T // Then we create a schedule that executes the
) K1 F* K3 i; `$ g" p# y // modelActions. modelActions is an ActionGroup, by itself it
, \% J( W# J5 ~ // has no notion of time. In order to have it executed in
" e0 Y/ o: @; F8 Q // time, we create a Schedule that says to use the
* P# B- L: `) d- V4 g5 j$ ~3 `$ n // modelActions ActionGroup at particular times. This& Z6 u8 x. S0 ]
// schedule has a repeat interval of 1, it will loop every
# u9 y7 H0 ~* I* P4 m // time step. The action is executed at time 0 relative to! H! e& y0 n5 f0 @, F
// the beginning of the loop.
% \7 I8 k+ s4 ^% R) g& j2 e1 k2 c1 R% A. _
// This is a simple schedule, with only one action that is# W' ]; X; ?/ m" X
// just repeated every time. See jmousetrap for more" E+ T) l4 J# P& ]2 Z
// complicated schedules.% U, S5 I. w! J2 Y
+ l$ u% z$ a9 ?. Y/ C e' k9 y
modelSchedule = new ScheduleImpl (getZone (), 1);
* o1 q/ H7 U8 _/ r/ u modelSchedule.at$createAction (0, modelActions);
. |( \' P" J; F# Y, \: E3 [# G 8 K# S& q# Q+ Z
return this;9 z' y4 h) g! b8 [; `4 D/ q& f
} |