HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:; p# M, K8 w3 e- q; o6 z6 C% m
' J& x* n% C( g I( d# i5 D public Object buildActions () {
8 X# E* G5 G8 o+ S% }" g& R super.buildActions();
- b- }7 q4 n( P# C/ z ) f t: u: ]( _6 X
// Create the list of simulation actions. We put these in6 Z! t6 y7 g0 h" B5 W
// an action group, because we want these actions to be: e# P) B. a4 [( H
// executed in a specific order, but these steps should
) K9 }- e+ I0 q* D* u // take no (simulated) time. The M(foo) means "The message6 o/ a6 g& H5 @' @1 }& ]+ `
// called <foo>". You can send a message To a particular
) W: \$ h- ~" h3 u% d/ v // object, or ForEach object in a collection.
- K4 ~/ `7 [* n- r8 o x
) O2 V. _: E' j" { // Note we update the heatspace in two phases: first run4 Y7 M+ i( ]/ W6 L3 P
// diffusion, then run "updateWorld" to actually enact the
7 H1 m+ n0 |2 [ // changes the heatbugs have made. The ordering here is r/ j" S/ j5 Q6 k# C* ^
// significant!
: C7 r. x4 r; B* q
+ f+ E0 r+ c- @+ Z: E' F1 T3 w // Note also, that with the additional, Q7 d1 O9 I* F+ ^3 ~' G
// `randomizeHeatbugUpdateOrder' Boolean flag we can A8 A9 C. I J" V, _3 z
// randomize the order in which the bugs actually run6 [( j% M- \: F) K
// their step rule. This has the effect of removing any$ s& a; a+ m( V4 \( s" e3 [: |* u
// systematic bias in the iteration throught the heatbug
3 V* j$ F2 f+ S% q I4 B& n5 x7 \ // list from timestep to timestep
0 c$ B. F- k- ^5 g % I. S; v) I6 N8 M: e8 Z
// By default, all `createActionForEach' modelActions have. T$ U3 ?: l( Z7 N' k) E7 ]
// a default order of `Sequential', which means that the
5 j: k( p! Y, Z // order of iteration through the `heatbugList' will be
: d! R: N/ m* J1 ^- B3 P2 e% M // identical (assuming the list order is not changed2 \0 u; q9 q- @. z+ Z/ S, w" C2 [
// indirectly by some other process).
3 Z" N- [6 [# A" B 2 H. F# F5 d2 E. T- V3 K
modelActions = new ActionGroupImpl (getZone ());3 I3 F9 Q& Y3 s1 Z
6 R9 A( C6 ?" l1 a# J2 S, s& c
try {
- |1 R) q7 N r modelActions.createActionTo$message) M* ]& n" B, ?' R
(heat, new Selector (heat.getClass (), "stepRule", false));, R+ f6 I: L/ b8 C3 c' ]# l
} catch (Exception e) {1 h% C* V) ]2 l- u% k
System.err.println ("Exception stepRule: " + e.getMessage ());2 n; [$ @3 J( I! U C% ^. n0 @
}
# D" A/ x! u0 n+ I5 B# f
. f( u7 F4 C: y2 m8 }9 A try {
6 J* g# p3 j& q- @/ r* i. M Heatbug proto = (Heatbug) heatbugList.get (0);
9 N3 \# r+ U; D2 u Selector sel =
/ g( c3 G( }5 B new Selector (proto.getClass (), "heatbugStep", false);
- _6 e/ s" S! m( m# n actionForEach =# i# L, }4 Y' V* s7 @* F6 T
modelActions.createFActionForEachHomogeneous$call( \, N. g l- p' u. V3 c6 g
(heatbugList,
. b' P# a3 |4 e/ Z0 m# T* Y2 a new FCallImpl (this, proto, sel,' f w+ W6 H/ f" E' c$ C7 t1 Y6 g
new FArgumentsImpl (this, sel)));, X5 m6 l1 ?- ~* W3 V: K, N( N, J
} catch (Exception e) {% h& S) {* D" L7 G
e.printStackTrace (System.err);7 B( |& l2 ?' B7 Q& e$ E& C; z) V- m
}
& d, C4 H! q9 s' N' H* p
6 `& K- d9 l. u syncUpdateOrder ();
6 }. C5 s E: R5 P
, A' t: J7 x! ]" T' D- ?6 L+ L try {
" Y+ k2 Q% E- F+ A modelActions.createActionTo$message ! l% T( d0 ]7 M% b
(heat, new Selector (heat.getClass (), "updateLattice", false));$ g! v. }8 B! i$ t$ E, B
} catch (Exception e) {
* Q/ ^5 `0 B* W! Z- E4 O System.err.println("Exception updateLattice: " + e.getMessage ());$ O) m8 a7 d# x9 Z3 T+ v V
}) N4 C9 _2 x2 _. ^
! T; w8 ]0 j# j- D // Then we create a schedule that executes the
+ d4 H% G: L$ F; x // modelActions. modelActions is an ActionGroup, by itself it
! _ a9 \- K# J9 b: D; x // has no notion of time. In order to have it executed in% s5 Z! q% w: E/ j- X
// time, we create a Schedule that says to use the. f9 P! [; X( w2 C& ^3 s3 N
// modelActions ActionGroup at particular times. This" {8 E, ]4 [- Y+ \8 t
// schedule has a repeat interval of 1, it will loop every
$ ]. _0 u+ [) H) B! T) ]4 e* K1 R: g // time step. The action is executed at time 0 relative to$ v+ T, ]( d5 i; O
// the beginning of the loop.
; J/ u/ v. C" M( P" @% ]& n6 x, `$ E' J, }
// This is a simple schedule, with only one action that is7 A9 y f) H5 h6 B: q5 T( Z
// just repeated every time. See jmousetrap for more, p0 ^+ a2 x- Q8 |- X4 M6 b! h
// complicated schedules. e$ V! P7 \5 U
: e. Z) v0 A! Y5 v) t
modelSchedule = new ScheduleImpl (getZone (), 1);! p& B" c& d( F) c+ A b) {
modelSchedule.at$createAction (0, modelActions);
$ x0 g% d$ N6 ?, n0 I6 \ 0 o8 ?. z' X9 { x7 w) K- H
return this;. y4 a. y6 n5 Z" ~! ~
} |