HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:) P+ V. {: g2 B2 v* l6 G) H# o2 e
9 x# f& d/ Z# P) l: \, E0 N public Object buildActions () {9 N7 A C' p7 s
super.buildActions();
/ }# f) k; Q+ |% X/ i& W* S6 s $ _. T/ t% ?+ G3 v6 R
// Create the list of simulation actions. We put these in. C! Y1 p2 {. q6 z
// an action group, because we want these actions to be
$ p( }5 s' Z6 r2 b& k, O/ p // executed in a specific order, but these steps should
: K1 B1 `& R3 J( Y, e j( t' O/ x0 D% r7 | // take no (simulated) time. The M(foo) means "The message
! i* V8 n! y8 o/ r // called <foo>". You can send a message To a particular
1 L; ], X$ f5 n6 u. S$ W6 {3 [ // object, or ForEach object in a collection.
8 N# \ a$ _7 P+ T3 X; R: Z 5 m, b- u2 v7 z+ A" X- z
// Note we update the heatspace in two phases: first run" e% O$ H2 E4 g
// diffusion, then run "updateWorld" to actually enact the# S7 a) S; }# R
// changes the heatbugs have made. The ordering here is
' L5 R) ~: D2 Y, h$ c! I // significant!
5 p, t5 d8 U! Q7 Y* V. O" S( g
- _; K# j- e) X% b+ E; Y // Note also, that with the additional" A7 n6 t' W' k1 j+ v; {7 f
// `randomizeHeatbugUpdateOrder' Boolean flag we can7 ~/ o7 }# G6 ]/ B
// randomize the order in which the bugs actually run
0 I7 I: L! S6 H: c3 t& }* o // their step rule. This has the effect of removing any
# j+ x5 m- x3 M2 s // systematic bias in the iteration throught the heatbug
$ E" v; O) y8 r& a* x/ e // list from timestep to timestep1 ?- a8 G7 \/ `+ B6 S) N. N
9 g* G4 L) {9 Y, j# h- s ? // By default, all `createActionForEach' modelActions have
; p; Y) }0 U' U9 l+ o! Z6 ~ // a default order of `Sequential', which means that the
0 ^9 d: Q9 h% c" L( w# {; Y4 u // order of iteration through the `heatbugList' will be
, c$ l. b6 \9 C& k# B! m // identical (assuming the list order is not changed
/ d# g/ b+ D% c$ n // indirectly by some other process).
; t" n+ P2 Q; [" Q3 D" g* K / e: U1 G( l, |( y
modelActions = new ActionGroupImpl (getZone ());7 O9 Y* a+ N& y6 r
0 V# ^, v' F- r- t- V0 u5 Y# h
try {, R; w! `8 Y, ^7 h+ s# M6 h
modelActions.createActionTo$message- M& S8 V1 u: U2 V b0 Y$ c
(heat, new Selector (heat.getClass (), "stepRule", false));9 L. q. D: J# o: j6 r( M6 O: |
} catch (Exception e) {% { m0 w# o3 I2 J5 S! C
System.err.println ("Exception stepRule: " + e.getMessage ());1 L% x, R. l* S
}$ V0 E7 ~' Q, v1 m* {
, |( D) A7 _; J; q) d8 P try {
+ N+ A$ Z0 B' w1 D- c. z2 p Heatbug proto = (Heatbug) heatbugList.get (0);! f0 Q: y1 g6 B5 |
Selector sel = ( z2 S" e! R4 @, o1 y
new Selector (proto.getClass (), "heatbugStep", false);% \! G! c) R( b/ M( h# Y4 l4 U
actionForEach =) e* d9 i: |/ z! [* L2 G$ D# _, F# x
modelActions.createFActionForEachHomogeneous$call
. d2 U3 ~7 o% t0 [; ^7 R, r3 g8 Q (heatbugList,
" g: U. w5 f+ ^2 F- k new FCallImpl (this, proto, sel,
h( k. P3 Z' E4 Z new FArgumentsImpl (this, sel)));
, w8 Z1 b8 x) q ~ } catch (Exception e) {
, s+ ^+ Y% W+ q8 A0 \9 r e.printStackTrace (System.err);
5 Z4 E' q! j* ^7 S$ i3 ` }1 K: W' H4 P. s) Y; {
* D8 E2 ?; U& W2 @: e2 e: Z syncUpdateOrder ();
2 X9 }8 Q0 W8 I% V5 s# N8 y' {" d! c5 o# C' o' W& m% d/ l/ s0 B. _
try {% y& u. M0 n. A3 u ]% R, c
modelActions.createActionTo$message
* N& E5 o$ s6 z* j; R (heat, new Selector (heat.getClass (), "updateLattice", false));
, c8 S( |) X- [ } catch (Exception e) {6 E0 q5 a/ |& `8 B$ Q
System.err.println("Exception updateLattice: " + e.getMessage ());
+ v# ?* h/ g3 E7 ~2 B2 h7 q1 n% y }
! s6 z& X. B) h4 h2 N: x% B( A ' W5 N( |* n; G& E- E8 U
// Then we create a schedule that executes the
6 j. t. M' q; m E, C, p // modelActions. modelActions is an ActionGroup, by itself it
8 W1 \5 n8 Z( k5 C) m1 N8 P$ o( ^$ f // has no notion of time. In order to have it executed in
/ b: ]0 l4 G$ F: l" X) {/ O // time, we create a Schedule that says to use the
) U4 O* n- w$ B$ V( A" W1 M, d // modelActions ActionGroup at particular times. This- v# z( `5 f7 a- ~6 S% H
// schedule has a repeat interval of 1, it will loop every" T( K0 c1 u* M" E+ [
// time step. The action is executed at time 0 relative to$ @! m% w. U' r8 r% z. z$ R
// the beginning of the loop.
, R6 z4 P5 Z8 ~# j2 {* w! s) q# O+ |: U+ S
// This is a simple schedule, with only one action that is
d0 _4 a; q, M // just repeated every time. See jmousetrap for more8 U& `! z; [0 g' E4 G' o
// complicated schedules.
" c5 j2 z, q: a ' f- T! T" `9 k
modelSchedule = new ScheduleImpl (getZone (), 1);
7 [7 m+ L! }& A: e+ L4 u: B$ P* Q& r modelSchedule.at$createAction (0, modelActions);" I$ D8 N {, i9 w3 y7 \1 D; z3 i
( R- s: f7 h, v; g' f
return this;
9 B& C1 f- }" |3 V: _ } |