HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
5 N+ M& C! F- [% j9 o; e' K6 ? o, F
public Object buildActions () { T$ G/ a* x1 h
super.buildActions();
1 `/ b7 r* Y U3 H( I
& B) r' W5 t. a // Create the list of simulation actions. We put these in$ Z. T! d* h% l
// an action group, because we want these actions to be
6 ~( C. j" f9 x1 d; ]; W/ ]# X // executed in a specific order, but these steps should; `$ ?1 z, D% A# W
// take no (simulated) time. The M(foo) means "The message" w# T; ]/ s$ G4 L, }3 F0 Y/ o
// called <foo>". You can send a message To a particular5 Q8 E- f6 R* l
// object, or ForEach object in a collection.! V: g- [5 ]! x% M- B: T
- w- |, v, I0 a+ o9 s
// Note we update the heatspace in two phases: first run2 k# R! S' V5 r: y! @
// diffusion, then run "updateWorld" to actually enact the2 z0 K7 g& l+ h
// changes the heatbugs have made. The ordering here is4 A( L* J$ Q m4 k6 ?
// significant!. R7 K1 _) k2 R' R# X
. i* n2 z; k2 M4 |0 U // Note also, that with the additional# h% w, ~2 J# e! ?8 R6 T% x
// `randomizeHeatbugUpdateOrder' Boolean flag we can
0 }% i3 |2 F- {' d7 e // randomize the order in which the bugs actually run
! [9 O4 T! C( u" |7 Q$ [ // their step rule. This has the effect of removing any8 B" w; t: _# P8 D" R* y! p; }
// systematic bias in the iteration throught the heatbug
1 N( Y5 J2 @# l7 e2 e& |( h6 ~" d$ F // list from timestep to timestep
' p- L. V* d& z8 H! n$ L1 F5 s 9 ^3 H9 v. k. T8 {
// By default, all `createActionForEach' modelActions have3 I3 }4 o: S. n! E. t) z
// a default order of `Sequential', which means that the+ N2 ~# r% g9 P
// order of iteration through the `heatbugList' will be
P( J4 i7 f# \4 V% p6 S3 K // identical (assuming the list order is not changed1 ]" v& x3 g9 q) m
// indirectly by some other process).
0 ]" p/ S$ _9 H" w( |7 h & n2 b8 r: m6 `. O% m. H: ]
modelActions = new ActionGroupImpl (getZone ());
+ J1 |8 H( X7 M8 v+ k" A, N' ^/ Z O0 T$ O; R
try {
! V. L1 ^6 ~; D$ V# V. G modelActions.createActionTo$message. v0 N" ?# `! T8 | T! @5 z: n
(heat, new Selector (heat.getClass (), "stepRule", false));
; w- l1 r1 U# p1 A4 n* u4 ? } catch (Exception e) {; h% F: ~$ ?; c! O- x6 e, q
System.err.println ("Exception stepRule: " + e.getMessage ());5 v5 ^3 @7 j5 }; W
}
$ F" u) i; s4 {+ o( E/ ^8 f7 V$ ?. f3 g9 W9 Z
try {
* V& o y6 t H) R! T f( k- \ Heatbug proto = (Heatbug) heatbugList.get (0);
0 }$ a- W1 P9 R+ K Selector sel = , Q+ ?8 X' x8 A5 Y
new Selector (proto.getClass (), "heatbugStep", false);
6 U6 A, }& K1 n/ Y actionForEach =
5 e; `( ^8 P7 v! U% q4 \" t; c0 e- X modelActions.createFActionForEachHomogeneous$call2 c; w4 s, I' H; d6 i: e
(heatbugList,
" W8 `3 W& C0 ?: R) Q* [ new FCallImpl (this, proto, sel,* ? E/ V0 y$ r* b
new FArgumentsImpl (this, sel)));
* H- R. Z! i6 b) L% T; _ } catch (Exception e) {
6 A8 n" l$ a) X9 b e.printStackTrace (System.err);3 B! W# S& E r, Y, R
}# ]# a4 w4 S& r6 l8 z
1 h# D3 o' x. T* M9 d: l
syncUpdateOrder ();
8 }, X/ \7 s( \/ m7 }9 E# U5 U$ i% q9 x& l- h. N$ e `
try {2 w! ~8 F1 r$ W6 H' Z/ B9 N* Y
modelActions.createActionTo$message 3 w- p' l/ U4 `% d& ^. T* r; v
(heat, new Selector (heat.getClass (), "updateLattice", false));
7 h/ a" b+ j+ z @7 P% h+ J- P } catch (Exception e) {; W( l: b8 W5 U& z6 s% K
System.err.println("Exception updateLattice: " + e.getMessage ());
; v s% J3 K- S5 f# F }4 w: I* z& ^/ m s
! g( j, e. n4 F7 Y2 u7 T6 D/ R // Then we create a schedule that executes the) m* R! R% `6 T8 T
// modelActions. modelActions is an ActionGroup, by itself it
: P5 @$ c7 o9 ]) G# | // has no notion of time. In order to have it executed in3 V/ j, ~2 C4 \* z- |- H
// time, we create a Schedule that says to use the5 q7 l8 ]( n% z7 f4 |* N0 {
// modelActions ActionGroup at particular times. This
" y2 R; e8 o% I, t. m5 L" Y5 C // schedule has a repeat interval of 1, it will loop every. L+ f! h- ^: ? M& v, e& E, g
// time step. The action is executed at time 0 relative to2 C0 Q s; Q" b# R5 [ Z
// the beginning of the loop.
3 K& X# K* V! P/ Z1 Y
8 c. t. [( B! v$ x6 p; P' } // This is a simple schedule, with only one action that is
$ R) @/ ]! ?0 x$ C2 T# O. x. o // just repeated every time. See jmousetrap for more1 j/ A; r9 ^! z7 L9 r- I8 ~
// complicated schedules./ l4 I( B4 N! ?8 y7 y! Y( @4 P! x: V
! t- \# T/ \& ]( j/ s modelSchedule = new ScheduleImpl (getZone (), 1);
/ Z, p& D; ~' V0 x K& w: v modelSchedule.at$createAction (0, modelActions);
0 u( f" }& u R" V3 V / q$ q: F7 b1 `+ j! G ~8 e2 a
return this;
: h y; w: X/ Z } |