HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:) @8 Z$ a! v, V
0 n4 Q5 e' s( ?' L8 R public Object buildActions () {
( J ~; v: n& Z l8 K super.buildActions();
5 i, ? z3 m) X& z+ T
( _' t! U! o2 ?, b* s- y5 R // Create the list of simulation actions. We put these in
- I, @/ m- E, j0 ` // an action group, because we want these actions to be t. U3 R' ?! }* F3 |: I- p
// executed in a specific order, but these steps should% v( y, A" R2 h/ K( v
// take no (simulated) time. The M(foo) means "The message
% k8 Y- b+ u. Z+ z) } // called <foo>". You can send a message To a particular/ k! `1 p7 c! e2 A! ^
// object, or ForEach object in a collection.
0 m* E4 }: s h. j
; F0 T% R( A- Q2 _, A // Note we update the heatspace in two phases: first run4 V2 j, o: b6 X4 B" r% M- V4 n
// diffusion, then run "updateWorld" to actually enact the7 n, {* [' v. q2 S
// changes the heatbugs have made. The ordering here is. p5 t- G; c$ P: }
// significant!
" y: D9 Q) }/ u% W3 h; I % F+ T- _' u. N7 Q
// Note also, that with the additional
' S5 ~, }; D+ K+ Z // `randomizeHeatbugUpdateOrder' Boolean flag we can
4 e3 t. i, t" o# @' y4 p/ r# h // randomize the order in which the bugs actually run
% _0 x* g8 v+ M, b3 Q // their step rule. This has the effect of removing any# e( e$ |- N& ]6 B# o7 I
// systematic bias in the iteration throught the heatbug
& w, E9 ~ O5 ~; S // list from timestep to timestep1 Y) Z/ T2 v& i) {+ s
0 a; q3 k! K: p- r t& {
// By default, all `createActionForEach' modelActions have! c+ K/ r5 a& y! u& i' F ^" p; u
// a default order of `Sequential', which means that the: d6 X. ?8 c. a+ G* v
// order of iteration through the `heatbugList' will be5 ?1 U, @/ ^% a9 P6 U1 g: ~, ?
// identical (assuming the list order is not changed
7 V2 r9 c" M: h# |, L( R // indirectly by some other process).
2 N8 X5 M l/ Z* |' G! J " P5 t# Y$ `9 H' H0 S, f
modelActions = new ActionGroupImpl (getZone ());5 D5 C/ Q9 d8 T4 A7 V* m
+ `" F+ B% t% Y6 `) S: `- S8 ^+ ?
try {6 u: c% F; B9 e [# G# m
modelActions.createActionTo$message
7 t: ^* o3 b3 x (heat, new Selector (heat.getClass (), "stepRule", false));
5 k6 |+ @3 r8 v; _ } catch (Exception e) {, @. [5 n9 V- Z0 p+ W
System.err.println ("Exception stepRule: " + e.getMessage ());
" `. c y( B8 p" W7 ~& X }. e* x9 h8 H q. r8 i& R- _; ~
' Y! V7 c; k7 U; ?8 t
try { A) s. ~. d0 `5 m% n1 V
Heatbug proto = (Heatbug) heatbugList.get (0);
9 H/ p4 @) P1 j3 A5 m Selector sel = C( {9 l5 ?8 b+ @8 i4 Z* V
new Selector (proto.getClass (), "heatbugStep", false);7 A1 X0 B3 J3 r7 H1 w! w, R
actionForEach =
$ _& g% y: @* A. o modelActions.createFActionForEachHomogeneous$call
6 F X, R) i6 r4 O. D. O+ i (heatbugList,' p0 r9 E {& O1 x6 S
new FCallImpl (this, proto, sel, h3 p, T5 H l5 J0 j: f
new FArgumentsImpl (this, sel)));
$ S T. h' ~1 B2 G/ G } catch (Exception e) {* l+ W, w; S6 C. I/ ~1 |' Z
e.printStackTrace (System.err);6 h, ]0 S g; N1 B' r
}" l0 M) `$ F3 O
% Y0 Q) _- {, T) u9 d( W1 \ syncUpdateOrder ();
) t7 X. A' I5 T- X. m# T0 w$ Z2 U
6 H; k7 _2 i, e D: m! H F try {0 r& Q) {! L0 h- f- Y! M& q& A
modelActions.createActionTo$message ) q% d A: X; b) {! \) I- h, h
(heat, new Selector (heat.getClass (), "updateLattice", false));
% F U1 d+ S/ H8 k1 B' M8 U. e* G } catch (Exception e) { w6 K7 O) X7 E& U6 ^8 }
System.err.println("Exception updateLattice: " + e.getMessage ());
- e7 K4 K* Y2 W J# y! u' m }, r: V) }9 w4 ^0 l
6 T; s1 m6 @- w# P y // Then we create a schedule that executes the
/ ?9 M. x. z3 \8 r // modelActions. modelActions is an ActionGroup, by itself it6 i6 f6 u2 W# n- C- F/ h
// has no notion of time. In order to have it executed in2 N9 s Z- J' Y" ]; w
// time, we create a Schedule that says to use the! x4 W$ w q8 S& Z* S
// modelActions ActionGroup at particular times. This4 o; q# v% Y2 I) |0 v, V
// schedule has a repeat interval of 1, it will loop every$ ~, Y# Q5 F7 n! A+ u
// time step. The action is executed at time 0 relative to: d6 A. I0 s* D: a1 y/ n( N
// the beginning of the loop.( l2 C# z6 Q. |
0 h4 Q7 n8 k s8 Y0 x8 J- @7 a // This is a simple schedule, with only one action that is
' |! m q, Q0 c/ t% C) s // just repeated every time. See jmousetrap for more
5 U, R0 d8 Y4 I' t // complicated schedules." r/ i# k, R( o U0 Y1 K! m
{/ r; {: d+ A) A4 A0 n$ Q modelSchedule = new ScheduleImpl (getZone (), 1);
+ e# j7 |/ U. ^5 A4 `$ c4 W modelSchedule.at$createAction (0, modelActions);. Y2 [5 ]" l, R! f x. t A" @! I8 G
" X4 I4 ^; ^, k$ F+ `1 ]' _$ G return this;, y" T, C9 f8 x+ M* r
} |