HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
) {# f" ?! ^; p/ c2 h0 P
6 v/ m2 a6 h% k2 M1 v: N% g' Z1 y public Object buildActions () { y6 o2 K6 S6 e, V9 K, j
super.buildActions();0 F* X4 L" t. s: O5 n* r4 ?
5 t, A) M, ?& L1 s+ S0 D // Create the list of simulation actions. We put these in
9 U: w5 o$ D, N // an action group, because we want these actions to be
3 L, H) m6 u/ `) r" B: T( p // executed in a specific order, but these steps should
, p5 S% w1 f$ v" }& G // take no (simulated) time. The M(foo) means "The message
8 L5 ^/ U; H/ Q+ l" o4 A9 Y5 D // called <foo>". You can send a message To a particular4 |$ M! [1 p' W i+ r6 X+ o
// object, or ForEach object in a collection.
; q ~5 R0 X6 B- `! s# l3 j- Z) o
}3 t( Q: H* a6 P // Note we update the heatspace in two phases: first run; z/ H* D0 k, z
// diffusion, then run "updateWorld" to actually enact the
9 L+ X. V* b$ G" ^+ u Y // changes the heatbugs have made. The ordering here is& M! }4 }4 C# p
// significant!
( l* u* U9 p3 n4 y/ A/ d9 Y* J ! U$ t) w$ g% H8 o& C
// Note also, that with the additional' F5 W; M; c% ^2 m. k3 F2 K' a
// `randomizeHeatbugUpdateOrder' Boolean flag we can
f5 |6 L! o+ O; C, o // randomize the order in which the bugs actually run
4 b" J4 s3 W4 F/ U // their step rule. This has the effect of removing any, S e6 M; ~0 o
// systematic bias in the iteration throught the heatbug
* V" O& k# B* r- ?* Y* K // list from timestep to timestep+ o C1 O2 k# b$ g- o5 h' J
4 ^( `4 C( H9 R5 y" P' f
// By default, all `createActionForEach' modelActions have" @8 n, k! R H2 z/ \3 L
// a default order of `Sequential', which means that the
D2 P$ L* L2 h- Z- x* h // order of iteration through the `heatbugList' will be6 }7 v8 `0 H0 s) Y+ T( V2 i
// identical (assuming the list order is not changed
8 w+ v5 Q# Q: f) x. N* J* c& M5 \ // indirectly by some other process).! A; W& P+ t4 j/ g4 @( G: F
3 C7 y1 Y: | B
modelActions = new ActionGroupImpl (getZone ());2 m7 W6 h& J$ E) z1 S4 P, X7 \
) ]3 p2 |2 B" |) a7 S; t7 U' ]7 f try {
# H" [/ _5 o! y. C" T! G modelActions.createActionTo$message; A$ C. J! ?8 P" F" i9 [8 _
(heat, new Selector (heat.getClass (), "stepRule", false));
3 A" L% h0 j \4 ]% q# H0 U } catch (Exception e) {
! O; M: e ^7 @ System.err.println ("Exception stepRule: " + e.getMessage ());" T) w3 ]" `; F3 y
}! J. P/ R2 w$ n2 T ]2 d m! F
+ H Z$ I9 D/ X
try {
8 l0 @1 z& L6 G Heatbug proto = (Heatbug) heatbugList.get (0);
; E/ c C0 P i+ R1 j Selector sel =
* ^1 R* E5 Y$ P" Q6 d( W( j new Selector (proto.getClass (), "heatbugStep", false);
* {7 q. X0 Q% {2 K2 j& q actionForEach =. I( K0 q5 q% J- Y5 ], D. _* W
modelActions.createFActionForEachHomogeneous$call7 W1 b9 A( X+ |$ y. z% ]2 ?0 w' J
(heatbugList,% G* Z) D5 N! s& ?/ @# @" v; J/ v- ~
new FCallImpl (this, proto, sel,
# R, a& A9 f+ z4 ^ new FArgumentsImpl (this, sel)));$ w& k+ O8 j) I! b0 V+ ? T- i
} catch (Exception e) {
: d& M$ h1 e% u+ {3 ~; R e.printStackTrace (System.err);
" X( p0 R. d7 E# S" e% Q }
; r' e& c4 g' X2 N
1 _9 S# N, h& x, [( n9 o syncUpdateOrder ();
0 d2 _& F! i( z1 `- z' W: G- t/ z+ i2 u. N- }" l1 E6 x
try {
H/ V9 y- S1 d: l& I' x modelActions.createActionTo$message * [- g: c, L/ b& [; A* E; ~
(heat, new Selector (heat.getClass (), "updateLattice", false));
/ b& ?3 w7 R; G2 G: S9 L( L } catch (Exception e) {
2 y" j/ N) l8 r, |1 T2 d3 C System.err.println("Exception updateLattice: " + e.getMessage ());
8 Q; h2 w1 g2 ~! q# ] }( s$ F/ P+ R/ A" k, Q
4 a5 J9 ~! v3 v$ I$ U // Then we create a schedule that executes the
# `4 D5 }8 d* i# [: ^. @ // modelActions. modelActions is an ActionGroup, by itself it
$ x" Y- I% c, I1 n9 m# t& u: [ // has no notion of time. In order to have it executed in$ @7 h- v) G, w0 W2 L
// time, we create a Schedule that says to use the
& S# [" q3 g5 Q, W ~ // modelActions ActionGroup at particular times. This
5 U9 x0 C* ` R6 {" h: \1 j // schedule has a repeat interval of 1, it will loop every p) c M8 @4 ?3 k7 G: U2 |
// time step. The action is executed at time 0 relative to- R' A; B3 q' D8 r2 v9 j. n/ ]
// the beginning of the loop.
, y, V' b+ y& ]4 k @! w9 Y8 ?- d: R5 t3 z9 @$ h5 R
// This is a simple schedule, with only one action that is, p S. n C) F) i4 M) z
// just repeated every time. See jmousetrap for more
& x! \6 A# a8 |9 r4 w% e5 R4 { // complicated schedules.( l" q7 Q; m% N* J) t- q4 c( h6 `
+ k. c+ B8 r8 ]
modelSchedule = new ScheduleImpl (getZone (), 1);
/ D5 p2 D% c6 X4 f/ u8 T& \ modelSchedule.at$createAction (0, modelActions);
" s, l' G* `0 ?4 ~0 L( Y
' M2 {) E! `) z7 @ return this;' Q6 V- m$ [5 F( J% k' ^
} |