HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:) q( a" }+ i; `( L! B
# }6 Z' K$ g7 L3 f2 _, K
public Object buildActions () {2 w% ?' @% N; }' P; Y
super.buildActions();, F; A& }; t% q/ p* s& S
7 ^" `4 J; w, J // Create the list of simulation actions. We put these in) F w1 ]& l) D8 f% }
// an action group, because we want these actions to be
8 P x. o5 l: ]' [' V9 P8 q3 r# H // executed in a specific order, but these steps should
, l6 h3 S N& w9 }# w5 y // take no (simulated) time. The M(foo) means "The message
4 T: [; |( s) s& o. S; q: f1 I // called <foo>". You can send a message To a particular+ t2 s# s2 a2 V$ b2 d7 P& g- A
// object, or ForEach object in a collection.
: ?9 U0 u) A- R* r0 ^
& l S( M; M/ `* H& L4 q // Note we update the heatspace in two phases: first run3 U. Q' j0 Y# O
// diffusion, then run "updateWorld" to actually enact the
* v7 A+ v" [$ \ // changes the heatbugs have made. The ordering here is9 @1 x& u& }# z. y" ]) n2 j; V
// significant!
: |% _& p9 R2 M7 t * t6 M/ H8 v9 i4 r, }8 o
// Note also, that with the additional' J& ?% b% p/ I9 P& l; _9 P
// `randomizeHeatbugUpdateOrder' Boolean flag we can* d( V; D. a0 B9 ^3 H
// randomize the order in which the bugs actually run9 n% Q! L+ R7 H( g+ _7 T$ I
// their step rule. This has the effect of removing any0 _4 K! D) n- \
// systematic bias in the iteration throught the heatbug7 j" e9 j( I! o9 g1 a8 v
// list from timestep to timestep
; {# J6 n# n9 U |7 f
6 q. C+ P* z/ x, J% F5 t. v // By default, all `createActionForEach' modelActions have
6 b0 v( a+ ~/ z // a default order of `Sequential', which means that the
9 O* e4 B4 E) }7 ? // order of iteration through the `heatbugList' will be
9 d* U8 Z2 o1 k# k% p // identical (assuming the list order is not changed
/ r4 U9 a5 i% z5 c2 U% q1 T7 p3 m7 j // indirectly by some other process)." d6 u& R+ ` [" Z/ N
0 g% `8 Q/ s! W$ t* p- T2 A modelActions = new ActionGroupImpl (getZone ());: ^0 b# ~$ e1 j
+ y; C% a5 Q+ t9 Z2 J4 K
try {, {9 t4 ^+ Y( T. m4 g
modelActions.createActionTo$message; n0 M4 o% W* s. G& U
(heat, new Selector (heat.getClass (), "stepRule", false));
. ]/ M# ]' B% O/ D0 ~3 o } catch (Exception e) {/ a. A! w. R" p7 R
System.err.println ("Exception stepRule: " + e.getMessage ());! d; Y' M9 i- R6 y) Y/ G- V* D
}! {; d5 t! o! Y7 C
0 `8 p0 i5 V# H; ~3 V try {- b' n0 Q+ A) v
Heatbug proto = (Heatbug) heatbugList.get (0);
0 t' B$ p6 }) s Selector sel = & I5 g: U% F6 a/ w
new Selector (proto.getClass (), "heatbugStep", false);
6 ?5 b3 T4 r. j actionForEach =1 f6 g( M- D: {/ M
modelActions.createFActionForEachHomogeneous$call
& P. R8 F0 C) L: k& C! @* Z/ q (heatbugList,
( s9 Z0 [5 j# H3 i5 V new FCallImpl (this, proto, sel,
0 N$ N+ P$ r8 o+ e new FArgumentsImpl (this, sel)));9 `9 P% a/ f. l' f5 i7 ]& @/ x
} catch (Exception e) {
. E/ u9 F& }7 \# E8 H4 n! u e.printStackTrace (System.err);
9 K' M; w* R" z. Q }
' {. ~, q ?' Q3 f% u/ ~ 6 x; B& e L6 t0 Y
syncUpdateOrder ();# k' U* s: x! a! _" t0 `/ y2 r u
- ?; L9 J" E2 {& e* E7 @) W try {! o- g$ f' B. q0 h3 J9 L: y8 K
modelActions.createActionTo$message
' K8 j4 w7 J4 t; |; D8 _/ A (heat, new Selector (heat.getClass (), "updateLattice", false));
' V& V V% m# O6 ~6 k& q } catch (Exception e) {2 p9 {' _, `# d& D1 p0 s7 S
System.err.println("Exception updateLattice: " + e.getMessage ());' c7 i* r# F1 I+ C9 ?! }
}# Y# ^! b1 {& q( t9 T
$ e" [; j; @ ^6 e( p m
// Then we create a schedule that executes the
4 h V9 ?4 _: e& }9 l // modelActions. modelActions is an ActionGroup, by itself it: m# G- q9 N/ C
// has no notion of time. In order to have it executed in
9 t: e3 e+ _ x5 |" `" N8 P/ p% ^ // time, we create a Schedule that says to use the4 \' b* E# @4 O( J( Q0 w! w, F3 Q
// modelActions ActionGroup at particular times. This) u5 C8 T# i. Y' \! l" y
// schedule has a repeat interval of 1, it will loop every
+ u7 [/ V" n% e' H // time step. The action is executed at time 0 relative to9 u2 |+ C6 K! g, S
// the beginning of the loop.
; x0 u9 `+ c1 _) Y$ ~ W) {" u" k# q: x5 m
// This is a simple schedule, with only one action that is
4 ^( n0 E/ n1 Y // just repeated every time. See jmousetrap for more
7 _, @0 V4 E' b s- X // complicated schedules.
6 p+ r$ ~* `: ~3 \. V( S8 C! H8 V$ x ' m7 s6 u X" ?6 N2 p; a3 V; n" G0 z
modelSchedule = new ScheduleImpl (getZone (), 1);
* \* ~% v& g8 v modelSchedule.at$createAction (0, modelActions);
& e# v4 S; |: {) z- N6 o- f
4 W+ y9 ]1 g8 J, A3 N3 t7 L return this;/ b2 }- F# l! F: W
} |