HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:# j! H& W+ _7 v; i7 M) T- n$ p
0 z; `4 B$ g* D- C/ A8 ~8 c
public Object buildActions () {
) Q& L! I0 G9 c) g2 n super.buildActions();
! V0 g) A+ V% v 1 l% q) f; l$ x
// Create the list of simulation actions. We put these in8 ]" h7 S+ r9 S9 Z
// an action group, because we want these actions to be
+ q k G/ q: _. S, b( E* \( [ // executed in a specific order, but these steps should$ J! o6 L) x% w# a- c: j5 ]
// take no (simulated) time. The M(foo) means "The message
% ]- Q, ? [( A1 W // called <foo>". You can send a message To a particular# g8 X! j' q5 w, |( w! Y
// object, or ForEach object in a collection." J ~7 p+ ]2 F) K% n" h' L
/ @# p) d2 S: t) g: N% L
// Note we update the heatspace in two phases: first run
! a8 K3 K3 ] z' e+ x // diffusion, then run "updateWorld" to actually enact the
" m6 }6 a9 Q3 V# d) A0 @* l1 w // changes the heatbugs have made. The ordering here is7 c( M# t% \3 d7 k5 O& _+ E4 u+ l
// significant!% q( K! X! J9 b: [
5 a9 w- A6 M! B6 Y1 F
// Note also, that with the additional- H' a3 {. ^% w5 M u% h
// `randomizeHeatbugUpdateOrder' Boolean flag we can
9 a& i- u( z0 u+ ^- K& u6 b9 J // randomize the order in which the bugs actually run
- c Q9 j; P6 ~" ^ // their step rule. This has the effect of removing any6 F" b+ _$ d% C! t, A
// systematic bias in the iteration throught the heatbug
9 i- {6 k* R; ?$ D$ |+ U. ] // list from timestep to timestep
O+ X/ o7 G% H+ I2 c6 s9 A : {* ?5 P# j$ @* V! N
// By default, all `createActionForEach' modelActions have" D. }$ k) J. h
// a default order of `Sequential', which means that the
% n! P3 l0 [% C // order of iteration through the `heatbugList' will be" w* ]4 K" q4 D* c7 p
// identical (assuming the list order is not changed- l4 L( K) D: Y- _6 v
// indirectly by some other process).9 G7 G' b1 h" v& z1 s' @/ L
; X5 B6 ^$ C* J& _ modelActions = new ActionGroupImpl (getZone ());
1 \9 M1 U5 T+ _! v& `" |$ r- }: p6 R) G4 b
try {
, N* x) f* O) u4 F8 {8 B modelActions.createActionTo$message& g1 o8 s$ t3 Z; r f0 o
(heat, new Selector (heat.getClass (), "stepRule", false));4 r5 V3 g- Z0 H: W) X
} catch (Exception e) {+ \: o [7 I8 F( Y5 B2 L1 ]9 P
System.err.println ("Exception stepRule: " + e.getMessage ());
! ^% u) w- _1 J7 {; v4 o8 t }8 g6 \' H* R W
, T3 w# c d- m. I! t2 h0 U3 [2 P try {$ c. Z0 P g7 j0 E3 X
Heatbug proto = (Heatbug) heatbugList.get (0);
- U" K3 a8 e; i Selector sel = 7 q! g& ^* G/ g/ i
new Selector (proto.getClass (), "heatbugStep", false);4 Q# A9 Y5 z! \" f# b2 U
actionForEach = m, }7 S( z6 w/ x
modelActions.createFActionForEachHomogeneous$call- Z6 z4 C" q% [; @" ^, N
(heatbugList,# V6 R9 u* r. N2 _- X4 e9 a- u- @
new FCallImpl (this, proto, sel,- D1 c7 i1 U+ U3 w4 _# Z
new FArgumentsImpl (this, sel)));: \6 U5 n: B ~/ \8 N0 ~3 O
} catch (Exception e) {, u, w5 r" h, V" F# b3 H$ S3 i
e.printStackTrace (System.err);5 |, L/ i E/ i
}
, N: \% T2 \2 F3 R9 S
0 Y6 ^( B4 l) B s1 k6 K syncUpdateOrder ();
: U$ _, d! L5 p' r6 ]0 G' u" m+ N P5 T
try {) H/ K. A9 u0 F. \7 P
modelActions.createActionTo$message
8 J; x0 b& v4 A5 z- C1 { (heat, new Selector (heat.getClass (), "updateLattice", false));1 c- a. c) |8 {$ y: Q; {9 y7 B2 k
} catch (Exception e) {
a" t1 `) b, @: C System.err.println("Exception updateLattice: " + e.getMessage ());
; V3 X8 s- h7 W3 ] } n# `# Y6 W! V$ ~ S
}- ?+ n8 C2 V5 z9 @, R
// Then we create a schedule that executes the
4 b2 X R$ M+ z0 |) g, ?; N& A; \ // modelActions. modelActions is an ActionGroup, by itself it+ j3 s: u/ X/ s/ R0 h1 b# e
// has no notion of time. In order to have it executed in' ~) t& I' L* w0 C$ t& U
// time, we create a Schedule that says to use the
+ k+ n5 f. T& h' z) A // modelActions ActionGroup at particular times. This
% K: F9 q( F9 ^) U( j // schedule has a repeat interval of 1, it will loop every
# G5 _; x- K$ ~ F! l // time step. The action is executed at time 0 relative to/ O6 w+ g& j, _. t9 C" D) @
// the beginning of the loop., B( s3 E+ z4 a2 M
2 N% B5 G/ ?( l* K; Z' u* d // This is a simple schedule, with only one action that is1 o0 o9 Y' Q( G+ I
// just repeated every time. See jmousetrap for more
( [) S0 X+ H$ _' R5 U) ]& A // complicated schedules./ T* ^5 M0 e8 _8 x2 O+ J
" S/ r0 j6 k. t( ~. t: T modelSchedule = new ScheduleImpl (getZone (), 1);, s" ~. f; q! U$ b
modelSchedule.at$createAction (0, modelActions);
3 ^& U# i1 l0 W9 R# l: w k& V! y
! u" u5 @- }; A return this;5 I9 w0 k& s7 c: d9 G
} |