HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:+ `1 K1 B4 d( ?8 c! t
x: g0 t% H+ V( A, J
public Object buildActions () {
; i$ U7 @' L& k, y; d3 H super.buildActions();+ ?" m0 g' |( W/ [8 E
& m: [/ F1 h7 c. H% y8 r // Create the list of simulation actions. We put these in8 {- K; u+ X3 T7 n' ]) B
// an action group, because we want these actions to be- {- A! x V5 z
// executed in a specific order, but these steps should
3 e; o4 Q6 B" O, _ // take no (simulated) time. The M(foo) means "The message" B( u& _0 i) t3 i
// called <foo>". You can send a message To a particular
& \0 d9 F4 m! \# n! h // object, or ForEach object in a collection.3 u& h- j# G: H5 q; G$ v
8 x {6 j) X1 p // Note we update the heatspace in two phases: first run
# e3 V8 q# Q) A9 o" O/ _6 P2 T // diffusion, then run "updateWorld" to actually enact the, h- Q2 w, X- `& f. q
// changes the heatbugs have made. The ordering here is
- O5 c4 U1 E! m T& Q+ Q+ w& R w // significant!% s9 I- R- l7 f3 v4 F2 @7 [
1 u- g( z; L! a$ L! @ // Note also, that with the additional) z, [. N7 s2 j! U8 J
// `randomizeHeatbugUpdateOrder' Boolean flag we can
# H" f1 m# U0 c8 Z // randomize the order in which the bugs actually run
; V' i% n7 t! f$ D! Y2 g // their step rule. This has the effect of removing any
6 F4 Q7 Q1 c8 [/ i+ p3 c& A // systematic bias in the iteration throught the heatbug
p9 h8 n4 |2 ~& h' }" ?! w- ~* d // list from timestep to timestep) q3 I% t$ v6 X& @( A2 T
- _( ~( ]' S# Q- J( Q {9 k, x // By default, all `createActionForEach' modelActions have
3 n/ f- p: d) Z // a default order of `Sequential', which means that the3 P9 s8 v9 ?; f' s- z
// order of iteration through the `heatbugList' will be
/ J* p/ N z `3 k4 x' p // identical (assuming the list order is not changed. L& l. c( ], w' L" b
// indirectly by some other process).3 B* @; K6 D% [( _! |
4 r# i" |4 y: Z9 S7 N0 K modelActions = new ActionGroupImpl (getZone ());: ~8 V8 _* c/ I; Z$ L' H' K! U
0 B8 H6 B& A1 s' `1 n. }, Z/ F: n try {
: |' Z) ^8 h/ s" Y. I u modelActions.createActionTo$message
4 D7 a9 [: J* @& U A1 s (heat, new Selector (heat.getClass (), "stepRule", false));
1 S; k8 Y( L& B2 q( G1 L } catch (Exception e) {
" x4 X" u, Q: B. V" A* n System.err.println ("Exception stepRule: " + e.getMessage ());
I$ @( ?: i6 Q( R }6 I1 @, E( N& Z5 W7 l5 |
7 Q; K) o' R. h. a" B
try {& }4 l. }3 |6 ^- N- @
Heatbug proto = (Heatbug) heatbugList.get (0);' w# a" h1 a {5 ]6 T, |
Selector sel =
. ]+ B1 h( f" J0 T new Selector (proto.getClass (), "heatbugStep", false);8 c( m7 Q# M# a% Y* u) Q8 E" K2 g
actionForEach =
8 _8 l6 r8 d" @" ]6 S( Q, o+ k" N modelActions.createFActionForEachHomogeneous$call
( N$ `/ P5 B" p0 ^7 Q& t, U1 f (heatbugList,
2 `. H D+ L3 ?7 t3 c5 s/ y6 p new FCallImpl (this, proto, sel,, |& w( E' w8 r/ G" R
new FArgumentsImpl (this, sel)));
) Y7 i6 G% M/ D, R' L. m4 j# H9 b- m+ A } catch (Exception e) {2 \$ o0 P& g- `3 k7 V
e.printStackTrace (System.err);
9 L; j3 M5 P0 Q2 A D }
' b% x5 ]7 N4 X" H: k" O
: M s! V- X4 e4 p5 E0 t syncUpdateOrder ();$ ]) O% |6 K4 d# a
. w5 k6 }& x. {/ _
try {3 H# z( k, s& L6 v& c9 M
modelActions.createActionTo$message 0 }. P0 g" K2 p
(heat, new Selector (heat.getClass (), "updateLattice", false));
( N h8 }$ I a, t } catch (Exception e) {8 | X" j% q) S7 p+ y; Z1 b/ I2 g
System.err.println("Exception updateLattice: " + e.getMessage ());, g; c" l: G q6 L" r ~
}
" ]0 w: R! s3 Z; ~. S% b0 o; |
, m. G3 Q8 `9 ]( E! D // Then we create a schedule that executes the
4 ]+ \# n7 Q- q/ u3 I# _ // modelActions. modelActions is an ActionGroup, by itself it" M; }* c" j9 P M7 W+ ~7 _
// has no notion of time. In order to have it executed in& f4 p! J. t! d) S/ n: ?
// time, we create a Schedule that says to use the
/ z# C' N @/ ~3 m2 t6 `! w' \) P // modelActions ActionGroup at particular times. This
# p3 ^, j3 u% p, ]+ K& G. N // schedule has a repeat interval of 1, it will loop every* J8 N+ x7 O# f/ G
// time step. The action is executed at time 0 relative to) G+ K5 B8 R% S+ X$ V$ U- o9 f
// the beginning of the loop.! W8 m: S8 v, l5 R( F
% T# t3 B# s' p- G, \
// This is a simple schedule, with only one action that is' ?6 S. V0 i4 r9 T+ m
// just repeated every time. See jmousetrap for more! Y/ J$ K+ [' y4 U" Y
// complicated schedules.% E4 V5 v0 Z" C5 s& y# H* Q S
+ f, `9 P, K& G* c/ c
modelSchedule = new ScheduleImpl (getZone (), 1);/ T# \6 l2 f9 s m
modelSchedule.at$createAction (0, modelActions);% {8 U* }" y4 \0 ]* Y
" G+ G" f3 f% \ return this;
9 e$ M* [$ ]/ L* {2 O; e: {6 X } |