HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:: L( y& g# U2 R
- Z. S) Z- q' A- E0 E; v8 c
public Object buildActions () {+ U( p3 j- c1 X2 Z _6 C" ~
super.buildActions();% k4 d( D* a) T
1 n4 S1 H2 b+ o3 j& [+ o
// Create the list of simulation actions. We put these in% ]9 D1 c5 u. \" i n; M2 v
// an action group, because we want these actions to be
# Q) A$ v/ U6 g" ?, H( P: _ // executed in a specific order, but these steps should4 V- x4 x, N9 W7 z
// take no (simulated) time. The M(foo) means "The message
/ w, E* T; Z0 F; I // called <foo>". You can send a message To a particular
3 k! q* |6 j, y) v: h // object, or ForEach object in a collection.$ H8 c, T( n6 p# B8 T# t+ q; K0 f, `
# M4 _0 a) V4 m2 U( V0 j3 | // Note we update the heatspace in two phases: first run
3 r, n( W4 e3 b( U // diffusion, then run "updateWorld" to actually enact the8 ^0 x3 L$ p. B$ A+ x( e3 N& T
// changes the heatbugs have made. The ordering here is
5 o: u$ C3 V& ~. |4 E* c // significant!% ^6 _: s6 \1 t# ]3 `
; D8 e4 B2 U& k
// Note also, that with the additional
& K, n9 u* z4 r9 l7 y2 R/ k9 J // `randomizeHeatbugUpdateOrder' Boolean flag we can" d9 N4 N$ k/ _% H% q* ?8 D ?# ]' B) T
// randomize the order in which the bugs actually run! w7 d, }8 z4 g- j. H9 h V
// their step rule. This has the effect of removing any
! D0 g+ ?" C4 F3 g8 z1 X- w! h // systematic bias in the iteration throught the heatbug
9 n: [. F" o! E% Y: T) ]0 M // list from timestep to timestep
6 Y; p" H4 t% g( e' I; w9 P ) s7 ^- [, `/ @& y/ Z# X
// By default, all `createActionForEach' modelActions have3 S" b( ~6 m+ T. y& {4 @
// a default order of `Sequential', which means that the0 ?8 R! Z4 P( P! m- K0 c5 c3 {8 u
// order of iteration through the `heatbugList' will be# U& U: ^9 h- W
// identical (assuming the list order is not changed% U0 n* u) F" r( e2 p+ i& w- M
// indirectly by some other process).5 f6 ?% |: \' Q, L
0 A% k# [8 ~. s7 w
modelActions = new ActionGroupImpl (getZone ());
% J, d$ O) z. g A$ d3 D5 m) j% B: @6 B1 |# A" s2 J/ T( o
try {6 N3 | W4 S! Q6 F& c' v8 k
modelActions.createActionTo$message
: i+ H1 t: n+ n/ X7 y- B& m (heat, new Selector (heat.getClass (), "stepRule", false));
* T6 j- ~4 n; T& f* x+ d8 c9 b+ Z } catch (Exception e) {
2 f3 q+ G, `( e System.err.println ("Exception stepRule: " + e.getMessage ());5 ^, u" R3 }% T/ t0 @4 _
}
4 R) d7 A b6 a2 M7 L8 c6 ~! e# T/ S1 A, X& i
try {
, O; O& ~" v4 ?: @% \ Heatbug proto = (Heatbug) heatbugList.get (0);/ N# V6 j; l2 X
Selector sel =
& G( [ G; s* N, Z new Selector (proto.getClass (), "heatbugStep", false);3 `- x' p! y, e) H
actionForEach =
" ~ g5 x* C6 @: i% `" _* Q. M modelActions.createFActionForEachHomogeneous$call
% a- {/ Q) Y4 L. M+ w6 _5 {& @ (heatbugList,
% L3 V7 C# S6 P; `. p new FCallImpl (this, proto, sel,9 p4 t, v5 s, S' O$ V. B
new FArgumentsImpl (this, sel)));
! |! a- n# b5 i. x# m- { } catch (Exception e) {6 m( B" Q! m/ s$ b
e.printStackTrace (System.err);
0 ?2 w! C" \0 Y$ l6 A0 u/ g% O7 \ }! }, a3 P) A& B, @
0 `3 w2 R% N: w2 Y9 C- c5 c) E; ? syncUpdateOrder ();8 t f( Z( ?# f/ q& L+ |
/ i& U* e- a# \4 b, `% ^ try {
' D& X& ^0 O* S9 q modelActions.createActionTo$message 9 p# S; R. ~* _! f; `, J
(heat, new Selector (heat.getClass (), "updateLattice", false));
7 ]( A* k( T+ ~" B- G# y# D, W" c0 T } catch (Exception e) {
4 i# |) A" a3 J0 E5 l. V2 A' ^ System.err.println("Exception updateLattice: " + e.getMessage ());' z$ t) h9 T/ R5 R5 T5 p, N
}
, ^, `3 L8 n% \& e
7 \: t$ d+ A' n" `1 t/ [$ a. z // Then we create a schedule that executes the6 ?6 t' J6 R( g; i
// modelActions. modelActions is an ActionGroup, by itself it
& @$ n7 z% Q. T1 _1 p. g8 A- r // has no notion of time. In order to have it executed in
( h- z, F/ {! O8 D // time, we create a Schedule that says to use the" a1 U4 }3 c( {" b9 m8 u0 w
// modelActions ActionGroup at particular times. This
! f% R/ m9 Z9 e$ R# w& \/ H4 Q // schedule has a repeat interval of 1, it will loop every/ i0 Y5 H7 S7 B K
// time step. The action is executed at time 0 relative to+ S# [; R9 }( L- I
// the beginning of the loop.
9 ^5 V$ X6 C* Q1 S% ~3 D6 N; `' s7 R: e) J) {& Z
// This is a simple schedule, with only one action that is9 n7 W. H2 p* C5 A! _2 a1 I
// just repeated every time. See jmousetrap for more
( ]% y: _- U b, p2 k // complicated schedules.
& Q2 k- f8 C4 k0 S- g 5 W; w* K3 r4 v& o
modelSchedule = new ScheduleImpl (getZone (), 1);0 o+ J7 [5 w$ Z5 x
modelSchedule.at$createAction (0, modelActions);
) M( G- I0 o, O5 g% _4 K' s 7 c. j& }5 ?% N9 u
return this;
" l$ t" B2 ^0 Y$ p% W, X } |