HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' l) Z2 X( ?9 D/ n
$ x5 ?* p9 x7 H- u g+ g
public Object buildActions () {' ~5 Q$ U' L7 |3 }; I; x% Y) Y
super.buildActions();0 R, v. f8 S' x, x V7 @
: O9 I2 Z, @1 [8 J2 T // Create the list of simulation actions. We put these in
* Z0 P" l, [: F7 x" I // an action group, because we want these actions to be% Z9 @# F" z' I" A" M
// executed in a specific order, but these steps should
2 p& j6 u2 a; L; _$ C% w( E1 [1 r // take no (simulated) time. The M(foo) means "The message- ?' _1 Y4 E5 m; A! H6 b4 _" R
// called <foo>". You can send a message To a particular' O" l8 A$ o- m" I5 r
// object, or ForEach object in a collection.& ]; N) Y5 E: h% k4 J: u2 B7 \
9 j7 d- c- `* ]" ~
// Note we update the heatspace in two phases: first run
9 ~0 E2 ~4 o- f& Y p // diffusion, then run "updateWorld" to actually enact the
# {# \2 ]# q$ }* s4 E // changes the heatbugs have made. The ordering here is h* b! P ]/ u! L9 m& W
// significant!
+ u1 B$ x% X0 O* H
+ u* j! a; V! p. v8 Z7 f // Note also, that with the additional
1 P7 c |7 K% e+ K5 {, _' { // `randomizeHeatbugUpdateOrder' Boolean flag we can D5 M* w4 g& y2 t) s2 {% Z) f
// randomize the order in which the bugs actually run
7 X' F+ t+ v* |& J% a // their step rule. This has the effect of removing any
/ {9 x! Z- M6 F( L4 s // systematic bias in the iteration throught the heatbug
) K6 E% s: X1 a1 B: y // list from timestep to timestep
# W8 H% I1 m8 \7 ?: j2 R: g
& I( k) f) O7 ^" ] z // By default, all `createActionForEach' modelActions have
; {2 Q1 t1 ]" o) ? // a default order of `Sequential', which means that the3 ^6 W6 u- [, L" T- [4 P
// order of iteration through the `heatbugList' will be
( ]8 c% w/ @& B# ^* D( x8 _* W! r8 _ // identical (assuming the list order is not changed
& {& }0 W! X- k: W // indirectly by some other process).' B2 G W/ t: B7 E
6 t! U: i- c) I3 A2 A. K6 n! e
modelActions = new ActionGroupImpl (getZone ());7 j1 P* T6 ~; W2 p+ {; k5 q
2 |( o. A' s8 ~* T
try {
1 M) ~) y' g6 S' H8 S9 A, r$ L modelActions.createActionTo$message7 y2 W' }, I. b) X& P y4 ?5 {
(heat, new Selector (heat.getClass (), "stepRule", false));
) J9 k8 y; B; p8 q( X8 \6 r2 w } catch (Exception e) {/ n9 ^( A w) j0 ~# K
System.err.println ("Exception stepRule: " + e.getMessage ());6 `7 X* |9 \! ?. Y8 N, _
} ]- z$ s0 j7 n
, K. Q5 Z7 ^2 Y: y( K try {
- ^' f: n1 X% a/ q; E# ~; z Heatbug proto = (Heatbug) heatbugList.get (0);
+ a( U' B: G+ D8 @; A* H Selector sel =
9 R: L0 X6 j; B* c, K new Selector (proto.getClass (), "heatbugStep", false);( x9 M) p: |+ q! }6 s4 ^) ?0 R
actionForEach =
4 c; K+ }5 ^+ W modelActions.createFActionForEachHomogeneous$call( y( Z/ c- d, o0 N: v' n
(heatbugList,
, N1 b5 p4 s( Y( m$ S" m2 W new FCallImpl (this, proto, sel,
% N3 E9 m! O5 A/ N new FArgumentsImpl (this, sel)));
" T2 x7 L& v0 R) t( ]. |" o/ i8 X } catch (Exception e) {
3 k. h3 w) p9 R0 R# @ e.printStackTrace (System.err);4 `- `/ c' \7 F" p' w5 h& _
}2 I+ n) L$ V+ h$ Q
: @ P5 |* c ^8 l) i' I syncUpdateOrder ();+ B. Y. o* j6 l0 b. [$ G
" @- b! b5 U9 e5 v" A' M/ Z try {' p! Y& A4 W4 H
modelActions.createActionTo$message
+ w, }5 a6 C# J (heat, new Selector (heat.getClass (), "updateLattice", false));# \; @& M/ j1 R, @ r
} catch (Exception e) {% T( u1 \5 S3 ~2 Q
System.err.println("Exception updateLattice: " + e.getMessage ());/ b, w( ~+ B1 |. t6 ^) b
}
5 S% K2 U7 y$ w- y$ I' k/ q8 a
* M' U, c: n* c1 \ // Then we create a schedule that executes the5 F) t* S. F% `0 ?8 Y: l
// modelActions. modelActions is an ActionGroup, by itself it: n9 l3 b) q/ `/ w4 ~9 b7 {
// has no notion of time. In order to have it executed in- Y% D! o# I" w" Y
// time, we create a Schedule that says to use the
7 A$ _$ J- C$ [, b. P // modelActions ActionGroup at particular times. This1 D' M6 S1 B/ V8 r
// schedule has a repeat interval of 1, it will loop every
4 D! [: F: m. g& z3 L' U0 l // time step. The action is executed at time 0 relative to
+ l( H. |' a) D! k( X/ g& l // the beginning of the loop.
. B+ {/ E: B( J) t# z7 T# x. r% ^4 u6 `
// This is a simple schedule, with only one action that is+ {: A. l( \# r4 w0 S
// just repeated every time. See jmousetrap for more2 d1 w2 Y1 C7 g( R( y
// complicated schedules.9 W4 e1 Q) E7 D. x3 Q0 w8 r1 K3 @
& G. G* I. {2 ?( k" O
modelSchedule = new ScheduleImpl (getZone (), 1);# p4 ]. d5 D7 Q; C" s
modelSchedule.at$createAction (0, modelActions);
: u. j0 q8 x- P3 w B/ C3 k) L5 X
, T+ o9 Z ]% q6 A( f5 f7 z _ return this;. G8 h2 x0 u) t0 m, i a, D
} |