HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:# [) c' N3 B) A4 y
/ M% y, w! H6 C3 C public Object buildActions () {
, b# S9 s) r" \5 p super.buildActions();
7 @: a9 h6 t) l1 X' h+ f$ R
$ U G% ?: L( _# Q4 X2 D // Create the list of simulation actions. We put these in- _# g% z& H E. r* ?
// an action group, because we want these actions to be9 v7 E/ B6 b# x( p* l# N6 J
// executed in a specific order, but these steps should3 d/ F5 U" r' w: b
// take no (simulated) time. The M(foo) means "The message: B6 i: J" r* U1 j8 F: Q# q
// called <foo>". You can send a message To a particular
6 M) Q ?4 V+ c, z; U- O // object, or ForEach object in a collection.
1 ^! L; ~- l/ F# X
/ q. L0 D; K' t4 F% u+ z& m // Note we update the heatspace in two phases: first run0 g, R P' T8 O0 o
// diffusion, then run "updateWorld" to actually enact the% _+ H' _+ \6 e4 a
// changes the heatbugs have made. The ordering here is! n) p" t9 [. W, A4 c# Q
// significant!- |& K! W2 v# {9 l2 h8 }
) h( C$ Y, R: p' } X* p+ I // Note also, that with the additional' X7 o7 j$ U% u. m/ I& y
// `randomizeHeatbugUpdateOrder' Boolean flag we can
- l' P# c9 M% e // randomize the order in which the bugs actually run: F$ x$ ?% e! i) Y* a8 |) |
// their step rule. This has the effect of removing any
3 h) @# S+ k8 T // systematic bias in the iteration throught the heatbug! m1 F. {8 k7 y; z$ T8 d
// list from timestep to timestep6 a6 p/ q- E* k* F" T% }
0 o7 h. x/ C" q // By default, all `createActionForEach' modelActions have
% N1 S+ c( a6 M7 M# K // a default order of `Sequential', which means that the& i& s A& L4 D8 P# k
// order of iteration through the `heatbugList' will be
/ O H- X4 B. Q6 p/ t& ` // identical (assuming the list order is not changed
7 l3 Z7 R) k2 C* g x // indirectly by some other process).
$ ]& ?; x& P! p$ a! P 7 H- S3 Y5 }: j) j
modelActions = new ActionGroupImpl (getZone ());
: {3 n! H- I4 G8 w6 h+ n! v
; z5 ]' n0 T1 H; i3 |# X try {
3 J2 t& H7 G1 Q$ Z. l modelActions.createActionTo$message/ f( a9 T" z7 z& G
(heat, new Selector (heat.getClass (), "stepRule", false));1 F3 l% Y' k$ G4 N0 a C' C2 ^
} catch (Exception e) {
1 @2 h6 |* a/ X2 n! l7 R) w System.err.println ("Exception stepRule: " + e.getMessage ());0 M0 u$ r6 [* a# @
}0 C* _! I! X" }9 V3 o
3 w/ \- C3 z/ ^& E
try {
5 `; J1 V0 [" u1 N$ N Heatbug proto = (Heatbug) heatbugList.get (0);
: K* a' o+ y x* Y Selector sel = : V( m0 X; k& H' U0 ?4 o+ s
new Selector (proto.getClass (), "heatbugStep", false);
8 Y( T9 v5 Y6 p actionForEach =3 g! m' t1 e8 S" y V) {, X
modelActions.createFActionForEachHomogeneous$call V- a2 E3 P. D/ M
(heatbugList,/ P# U- J* a0 B9 ^$ j |% j) X3 g9 N
new FCallImpl (this, proto, sel,
( e- Z( a# T6 a# X! O) b' ^ new FArgumentsImpl (this, sel)));
6 [ f" O* E* ^) z; U } catch (Exception e) {0 c" Q" l! p3 d* [7 l/ W: G
e.printStackTrace (System.err);
3 T2 O4 L" J' ]1 W1 {9 @ }; T: Z8 H$ O- _" G
2 f% z/ l7 x8 N) P; Z8 B
syncUpdateOrder ();( n* j2 Q7 S4 M- A5 p# U8 h4 B0 S5 |
4 v( ]* }1 M9 P# j7 E4 |
try {8 z& l# e8 `5 w& I, a' t
modelActions.createActionTo$message
+ {1 S- {$ s) S (heat, new Selector (heat.getClass (), "updateLattice", false));) f: n0 d4 D$ b+ Z! `
} catch (Exception e) {: h: ^6 v9 ^7 V7 c a) s- q
System.err.println("Exception updateLattice: " + e.getMessage ());# j5 {+ r3 i! D6 W& J% `, D
}1 I) H7 f- p+ |( p, s1 P* i/ L' q8 N6 m
; E6 A4 k+ U ~) R // Then we create a schedule that executes the
3 c/ L4 V( q3 g' ?8 Z' c1 ~ // modelActions. modelActions is an ActionGroup, by itself it2 c% |+ L2 E* P3 {% B2 |& F
// has no notion of time. In order to have it executed in
7 ~2 z1 l9 S1 D0 a- b" s // time, we create a Schedule that says to use the
5 ^; i7 ~6 W F2 G0 ^+ k // modelActions ActionGroup at particular times. This
1 t) K4 m* Y' {9 n i% o. @ // schedule has a repeat interval of 1, it will loop every' Z- x& I1 g* O1 J7 ~% ~
// time step. The action is executed at time 0 relative to% P0 Q, C" A/ P O# {: H) r
// the beginning of the loop.% o6 o8 }# L- I. n4 B, Q& }
7 Y8 Q+ }; m- W6 @8 X- [% l
// This is a simple schedule, with only one action that is/ |7 r B5 P5 a! N- o9 g6 u
// just repeated every time. See jmousetrap for more
, w2 W/ Q/ Z* ~$ x+ \) r5 b // complicated schedules.
+ l4 v f1 z7 B. @$ I4 `+ C
9 U Z! w+ J7 s* [+ j, ] modelSchedule = new ScheduleImpl (getZone (), 1);( T* o3 ^3 n" w2 e
modelSchedule.at$createAction (0, modelActions);0 M8 S; x- b: S7 T2 H
& ]3 v [& h9 U+ K" F2 E1 l return this;
7 X1 B- X0 e ^/ U/ I+ k } |