HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
( H# o, G F2 l) N
. d7 M$ B: p, V, d. Y public Object buildActions () {
; C3 {8 t% @4 s; a2 R: A super.buildActions();
/ ]* e: o0 J: g6 x. Z 7 _# d. {& C" D7 B. S) k
// Create the list of simulation actions. We put these in( u4 K# e: q" X4 y' v+ ]1 A
// an action group, because we want these actions to be+ x, k+ v: e, C3 `5 a( z
// executed in a specific order, but these steps should
0 f, D7 R7 z3 b+ f7 B // take no (simulated) time. The M(foo) means "The message! S: m' F- c0 _' t
// called <foo>". You can send a message To a particular
0 h4 l- N, k6 h/ p8 } // object, or ForEach object in a collection.& j4 V- G1 H0 s% j7 y
( W; \3 `4 h- v( S' X' w1 Y5 w* }
// Note we update the heatspace in two phases: first run% u8 D0 w; j( R G3 g% L$ G
// diffusion, then run "updateWorld" to actually enact the
% b$ z6 y. N5 H3 X; l! u // changes the heatbugs have made. The ordering here is
" z+ N5 b6 L; _* E1 H // significant!, ]: t) \' t1 x, {: r
! `$ D* A5 @% M9 S. U7 V2 W f/ L- }
// Note also, that with the additional [7 A; U. X+ l# E; K: q
// `randomizeHeatbugUpdateOrder' Boolean flag we can" f( @ j& F$ a/ m
// randomize the order in which the bugs actually run/ C. _ E! H$ [+ y
// their step rule. This has the effect of removing any& M* u k( S1 y
// systematic bias in the iteration throught the heatbug
1 `+ _/ P2 L1 M) B7 z // list from timestep to timestep1 I/ |1 U; f! G9 Z
" M6 H& w4 d3 c6 O0 [- t* x6 j // By default, all `createActionForEach' modelActions have3 m! F; d; s' v) b2 j
// a default order of `Sequential', which means that the
: u* M( ~5 `) i$ P' m7 {6 U* [ // order of iteration through the `heatbugList' will be0 @7 q; R# A1 E
// identical (assuming the list order is not changed
/ T1 n6 A# ]- d( h // indirectly by some other process).. ?0 c: U& x9 O: |+ c) ?% r9 @7 s
% R" ^& I; d( w/ p1 E$ u4 S modelActions = new ActionGroupImpl (getZone ());5 ]* Z! c0 a; U1 m2 j1 r. f% ~! ^
' Z1 P2 h% ^1 I* d; g$ L
try {
( W" i! [' }- u8 T8 c% X modelActions.createActionTo$message! _1 |/ R7 N w6 c/ y
(heat, new Selector (heat.getClass (), "stepRule", false));' S6 N# w. J; G2 G9 g* P- R
} catch (Exception e) {
8 {0 |. Z O/ H: S1 S% } System.err.println ("Exception stepRule: " + e.getMessage ());
! K; s7 }6 }0 ~ }
6 S+ S& I0 ?1 A1 d, _2 `' h9 G/ q- \7 ?. y, F6 {
try {
q: L; ~. P! I2 ~( L) X1 v) U: N Heatbug proto = (Heatbug) heatbugList.get (0);3 W/ |" d' \6 [ L) Q j
Selector sel =
, x8 s+ W! s- _5 y( ^ new Selector (proto.getClass (), "heatbugStep", false);2 m0 N5 W# Q0 n5 h4 A
actionForEach =
- C! n% ?6 B9 S# U modelActions.createFActionForEachHomogeneous$call2 {! e4 M% u0 J
(heatbugList,6 N8 E2 P& |2 j' |& k& m
new FCallImpl (this, proto, sel,- w: Q+ n* K% s3 w9 h- J
new FArgumentsImpl (this, sel)));+ ?9 H! D# {8 e0 v
} catch (Exception e) {& T6 @# f* o4 y. z
e.printStackTrace (System.err);
$ X* c( J* q( G }5 D$ R3 _; H# |( w: x! U1 n
% C3 D& h2 v' T) I5 Y syncUpdateOrder ();
3 c7 A1 Q0 M3 |. L& h$ |) k
. k( r" n# A N3 e! {& s6 z try {0 b! y* X$ k3 ?$ M' |
modelActions.createActionTo$message
: v( z; H+ e- u( S (heat, new Selector (heat.getClass (), "updateLattice", false));
4 p. V$ L6 w. J' C2 |% v } catch (Exception e) {
P' h1 }# t0 O4 ?. ~5 h System.err.println("Exception updateLattice: " + e.getMessage ());" d0 G1 s" @3 s* b1 G- F
}
. A* f7 x: j& \* {" e9 Q# P. y! I6 K % |; O- o8 q9 r# e
// Then we create a schedule that executes the0 S2 x \( e- ?0 m0 w- \, k
// modelActions. modelActions is an ActionGroup, by itself it
7 e) f2 S0 s B3 F9 b // has no notion of time. In order to have it executed in
7 ?/ T7 s }6 R) G+ j // time, we create a Schedule that says to use the) ^- _! W1 ^4 x: J
// modelActions ActionGroup at particular times. This" s: [9 D! u A9 b# K' S4 r4 h. w
// schedule has a repeat interval of 1, it will loop every
5 i0 h2 J9 w+ {" x. _8 @ // time step. The action is executed at time 0 relative to
/ h: ~3 s" ?7 U7 m# |: y% |7 C$ l // the beginning of the loop.% |* n s0 T. I) J N/ c6 w
% E8 u( j r# \- ] // This is a simple schedule, with only one action that is
2 U9 a. n7 g4 d ?5 @% K* ^" h2 N // just repeated every time. See jmousetrap for more
# @" Q, }& I# R$ H9 D // complicated schedules.
' L! B7 O6 V% A1 B' V4 v
; g6 X, _6 s3 y s modelSchedule = new ScheduleImpl (getZone (), 1);$ J4 W9 g. B7 ]0 w9 F( F
modelSchedule.at$createAction (0, modelActions);
, x- \% y: \3 l& m % W3 ]" @9 y) |/ h1 |" {1 H
return this;# V1 p6 v& F* A9 l2 Z
} |