HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下: B4 T1 D9 O$ w! g
3 [ S# h2 j) `: \5 ^9 V' G1 x
public Object buildActions () {
+ A' b' ^& y7 j! ]: r7 \ super.buildActions();+ N$ c$ h) M: K
9 L8 K. B, c! B, D9 f# H$ ]
// Create the list of simulation actions. We put these in
s* E9 u0 N7 @- v: m // an action group, because we want these actions to be
: O- }+ l/ ] P6 r7 { // executed in a specific order, but these steps should
- r- A' x0 ^1 [# Z // take no (simulated) time. The M(foo) means "The message, d6 [' G1 y6 X0 r4 E4 g0 G- c
// called <foo>". You can send a message To a particular
) a3 t7 `8 \' F // object, or ForEach object in a collection.- C h8 o7 u. D% J- C
2 g0 u. E6 J5 k5 r // Note we update the heatspace in two phases: first run
9 D" M0 b- C& g // diffusion, then run "updateWorld" to actually enact the
9 C$ ~% k- w; z' C( o" J; z5 t2 U // changes the heatbugs have made. The ordering here is
, X1 N3 N N) J1 O& z9 N // significant!
6 \; a5 ^8 {- l; ^
5 q1 _# @, o2 E3 \ // Note also, that with the additional
7 Z8 S' ^- P7 U6 \ // `randomizeHeatbugUpdateOrder' Boolean flag we can {" R( e3 L' z9 n
// randomize the order in which the bugs actually run, \! B+ x5 l; [& A( x
// their step rule. This has the effect of removing any! B! g+ @0 n1 S- ]+ ^5 `/ l) z, G
// systematic bias in the iteration throught the heatbug
& l* N) P/ Z! y2 k- B4 E7 p! Q // list from timestep to timestep
' a }# b) Q! u* g% D l; e9 j ; Y; g( A* S& T8 l! d8 X" b
// By default, all `createActionForEach' modelActions have. F9 S# U: P0 A& J: ~: K9 ]# v! S* g
// a default order of `Sequential', which means that the" `$ Y$ j* Q1 ^( J; w, g
// order of iteration through the `heatbugList' will be9 e6 k/ u) b7 M; J2 h. L
// identical (assuming the list order is not changed
0 H b E6 j/ C* o# x+ O) @# W // indirectly by some other process).* k& Y+ u7 R' O* \
: n9 a. ?6 A% b7 p, m+ o x modelActions = new ActionGroupImpl (getZone ());" y) P2 K+ R7 t1 j$ `# x6 C
& i, o/ I6 U7 O+ j& M
try {' [- v3 Z4 _, ?5 e0 o* w
modelActions.createActionTo$message, v$ ^1 V# S v j* ?# Y
(heat, new Selector (heat.getClass (), "stepRule", false));0 V R0 u4 ?$ x6 K; Z. I" a' ]) X
} catch (Exception e) {4 a4 L- }' S0 N" q: t- Q
System.err.println ("Exception stepRule: " + e.getMessage ());
0 q- E! z1 n+ A/ }# g }; u- {! N/ B0 ?' B
* H6 D l- x, r& a' i6 N* @% f
try {) X7 ?8 w% S$ Y n/ d6 s4 K* E
Heatbug proto = (Heatbug) heatbugList.get (0);5 o4 U* Q4 a; o3 r7 ]
Selector sel =
6 K. z& l$ [9 L- h new Selector (proto.getClass (), "heatbugStep", false);0 l3 u) B8 n: n4 G+ G/ U! Y4 e' K" t
actionForEach =0 N i6 t$ V) ?1 p) i1 _ l, l
modelActions.createFActionForEachHomogeneous$call
; U k3 B: ?. V4 L( s2 G8 }, H (heatbugList,* H" x, J0 T# P, |
new FCallImpl (this, proto, sel, p, i: X, C1 {; ^& C) O( g
new FArgumentsImpl (this, sel)));
3 _" s% y2 ?3 L2 ?0 X: _" ~ } catch (Exception e) {7 ]0 H0 [' i1 Y/ w) d9 h3 `
e.printStackTrace (System.err);, T2 K" \! s) W& z# O
}( M; N& M% i# _& s
+ |9 I7 ^: |5 {, W1 o) {* }
syncUpdateOrder ();% L- d( B9 x3 @! H- [+ D
' G2 o+ t. \( n& E( {8 H4 [, V
try {# g3 @& U0 N% r( V S
modelActions.createActionTo$message ; y7 \1 l& `, Y7 u9 S) O
(heat, new Selector (heat.getClass (), "updateLattice", false));3 s8 _1 T7 H' f/ S0 {+ b) }' Z6 E
} catch (Exception e) {+ K. L7 r: U( I! E u4 S
System.err.println("Exception updateLattice: " + e.getMessage ());) o- a1 ~$ H" A
}9 P& f; j( g$ K$ t8 e$ {; C8 x7 K$ i- A
4 A9 E [( c/ @+ c8 \6 W* N% m // Then we create a schedule that executes the" x: e( ^+ q, O2 L
// modelActions. modelActions is an ActionGroup, by itself it
1 u+ @$ s* B) z/ E# H3 k" ~/ H2 X, @ // has no notion of time. In order to have it executed in
' @1 _: X! z5 Z // time, we create a Schedule that says to use the
# R+ ~# g* r j! N' Q F# T // modelActions ActionGroup at particular times. This
% J6 |' v" Y) Z4 C! ?, X) O // schedule has a repeat interval of 1, it will loop every
& V6 D, o% u+ z5 q // time step. The action is executed at time 0 relative to7 l+ k# ]% ~+ g0 J" ]0 Q+ l% T
// the beginning of the loop.
/ P9 r" x9 @( i! X e" m2 y9 H5 ~4 c. K& i5 f9 W* t y
// This is a simple schedule, with only one action that is8 u: n$ _7 `# B
// just repeated every time. See jmousetrap for more' N. |7 A+ f. ~# A8 z- {* G/ w9 h
// complicated schedules.! S( n# O' X: k6 E
" |6 C; L, V3 I& { ?0 z
modelSchedule = new ScheduleImpl (getZone (), 1);
% k/ u' U9 r$ o modelSchedule.at$createAction (0, modelActions);! H; m: C! ?# a1 B4 w
7 S ?* o8 D9 J return this;7 V L4 z, s# E- D# b8 w& u
} |