HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' k% F# n: W0 G5 o
R+ b" y2 \" K
public Object buildActions () {/ t% p6 c* t9 l# }/ F" Z& [9 i
super.buildActions();
) ]( h. }5 x; [$ u) a ; @. ~! C0 W! H: a% S8 a
// Create the list of simulation actions. We put these in7 n$ x+ X! v- Q" E; ^
// an action group, because we want these actions to be) O9 U) x4 M+ H* O' @# x
// executed in a specific order, but these steps should
+ Z+ S! M$ F# f O5 I" z- e- f // take no (simulated) time. The M(foo) means "The message7 L: X) R- f" s9 d2 W# M) [7 u5 B
// called <foo>". You can send a message To a particular
6 C/ N. U( K' u+ q$ V. ]6 p$ [ // object, or ForEach object in a collection.
$ H6 O1 D. M- m0 k% h , Z( \( y$ f3 F, `! B; h! K! ?
// Note we update the heatspace in two phases: first run' _: i! B6 d3 a( s9 S% m# s8 N
// diffusion, then run "updateWorld" to actually enact the
& s. N) }, k# r( c2 C# t& \/ B // changes the heatbugs have made. The ordering here is
! q' ~1 G- f% y Q2 A2 r! W // significant!
' U5 W+ O! c) l [ 9 _# ~, w3 F B0 C) |0 [. D; j
// Note also, that with the additional$ V/ |* X4 h( E) ~# B* R
// `randomizeHeatbugUpdateOrder' Boolean flag we can
}. S5 \( j* h2 L, W // randomize the order in which the bugs actually run
7 N; v! y* g5 l" U# r% ?0 c6 \ // their step rule. This has the effect of removing any
, ~6 g/ I- r4 y' h8 P // systematic bias in the iteration throught the heatbug
7 w2 K G% E( q7 C4 K0 g* v+ C // list from timestep to timestep( e$ P, Z8 f, w
' W! }0 ^9 ^+ T
// By default, all `createActionForEach' modelActions have
! B$ f2 p& W* @+ I' C // a default order of `Sequential', which means that the
& i( \$ q4 w9 a( @8 E/ W ]3 J% w // order of iteration through the `heatbugList' will be( i1 a8 o3 B9 {/ p. a
// identical (assuming the list order is not changed- Z' N! b% [* f J5 s
// indirectly by some other process).! N- }9 |" n( I# S
; ]5 z/ C7 R3 S( V, @) f) ^( X" W
modelActions = new ActionGroupImpl (getZone ());
9 ]7 K% l, A; s/ |* x
- E' P2 |8 {$ ?- S: R try {
) X$ `3 J* V0 I& h9 t5 i" t5 B modelActions.createActionTo$message
: H, ^+ S* U+ _- m8 T (heat, new Selector (heat.getClass (), "stepRule", false));
2 K3 q$ g( ^/ @! \2 S } catch (Exception e) {! Y# u% k. ~% a( T
System.err.println ("Exception stepRule: " + e.getMessage ());
& v6 L% W8 ], M) ` }4 V3 t: B+ U# d+ k5 _9 q
. o/ [. q8 J' f. \6 H" r try {
! q# h0 [8 u9 e6 g9 D, U Heatbug proto = (Heatbug) heatbugList.get (0);
9 q" e5 n2 @8 z6 ]3 j/ u3 d) l Selector sel =
: W0 ~$ l# Q. k) F* S/ E0 D new Selector (proto.getClass (), "heatbugStep", false);3 E( o- O. R! Y! n1 X, q" ]; r
actionForEach =' I% A! F9 p: ^" x5 \
modelActions.createFActionForEachHomogeneous$call
( _- V8 Q2 P# D% L (heatbugList,
5 n" U. ~0 m: d9 r5 S new FCallImpl (this, proto, sel,
5 K$ A5 K' d# z( N* q Y3 [- V new FArgumentsImpl (this, sel)));0 _! B5 F! I! ]1 e3 j: z
} catch (Exception e) {+ @" b0 [! l! Z, A
e.printStackTrace (System.err);
+ u$ ~9 F& y8 \* U3 B/ A! f }; g3 Q5 S0 T1 F" `7 k) R
2 j6 @4 A& x9 P7 r+ u0 s& W$ H syncUpdateOrder ();) f3 P) b) V9 P e: B
3 @0 r) m( D! S& o try {5 [: R% }6 I% K& e6 V
modelActions.createActionTo$message 3 @- f' ~3 K; E: k6 |2 K# Q
(heat, new Selector (heat.getClass (), "updateLattice", false));
5 F; _ P' l( j2 f } catch (Exception e) {
7 }6 Q |# x3 t5 s4 H; J7 H System.err.println("Exception updateLattice: " + e.getMessage ());% T$ @: H6 g# o8 B
}
4 l6 {. ^; z4 i
5 K# B4 `3 p" H& y" w // Then we create a schedule that executes the
2 S" y* D: c Z; e; d6 P, w // modelActions. modelActions is an ActionGroup, by itself it
6 w6 T7 V+ q% Z ]7 P" G* S. z // has no notion of time. In order to have it executed in
3 W# c% g, v8 B. b$ U. _+ Y) p // time, we create a Schedule that says to use the5 i% Q( B4 }$ ^' g/ f0 o
// modelActions ActionGroup at particular times. This
; X; j8 Y5 B4 E9 X# E // schedule has a repeat interval of 1, it will loop every
: m: G, \4 p9 d. G // time step. The action is executed at time 0 relative to% L2 ?$ i5 {1 r: F3 V6 v/ l
// the beginning of the loop.
. j& v$ y# T5 W$ y \9 n8 D- X* L# A. R8 F$ L9 O
// This is a simple schedule, with only one action that is
; x4 I# |6 t$ `" c9 Z4 c+ G // just repeated every time. See jmousetrap for more
2 N" k6 e+ T$ O. @. s9 o // complicated schedules.% x" y- h" w7 l+ q
% K6 e0 A- ]8 y6 Y9 Y$ X2 N
modelSchedule = new ScheduleImpl (getZone (), 1);
4 F( t% ?' S: m2 a; y7 v% S modelSchedule.at$createAction (0, modelActions);( n: p7 X; @% X, E* v
$ v# y5 L# e" s
return this;
( D5 n7 E' r8 B; _( l+ @ } |