HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
/ s0 `$ K) N4 ]! G \$ p! f1 j B# k
public Object buildActions () {
- w, j0 S1 r& f4 D: [4 j3 \4 \ super.buildActions();
; H- o: d6 y; y& O/ Q 2 x4 h/ {% E$ C: C! C( {" m6 r4 y
// Create the list of simulation actions. We put these in- I& N8 e& I4 D7 j4 c
// an action group, because we want these actions to be
! L6 E" T/ ?5 O) z b/ L, q2 q // executed in a specific order, but these steps should0 P0 {4 @( b* ]1 w7 ?
// take no (simulated) time. The M(foo) means "The message, L3 L; I8 w- A, ^/ ^) `/ ?
// called <foo>". You can send a message To a particular6 r; I, t) R6 I* R# [- Z
// object, or ForEach object in a collection.
Y7 Y9 }9 r& H. w: V- x& ]; C0 x 2 a. a9 m4 U; c/ i' L2 Q. J) K
// Note we update the heatspace in two phases: first run
: y; \) |* @1 {8 V/ I9 o, N // diffusion, then run "updateWorld" to actually enact the
Q4 {) i1 G, B/ h1 D4 x6 B // changes the heatbugs have made. The ordering here is6 ?; K0 M# x4 N% J/ w# _
// significant!2 g I) o: r5 G J3 |8 l
* }: w" T. C% j) K // Note also, that with the additional
/ M5 q; M* L( w- m // `randomizeHeatbugUpdateOrder' Boolean flag we can
& a1 m. I2 Y. l+ U // randomize the order in which the bugs actually run/ F- }. y/ ?( L" e
// their step rule. This has the effect of removing any
, t. l3 d7 I" ?9 U9 m6 }9 |0 \ // systematic bias in the iteration throught the heatbug% Z/ V1 h6 {/ f4 O( z1 l
// list from timestep to timestep
3 H0 ~- C1 g4 Y# K! F 9 J! x% \2 m h
// By default, all `createActionForEach' modelActions have2 s: @0 e8 K3 |5 Y
// a default order of `Sequential', which means that the
& Q/ {8 l6 B: ^/ g // order of iteration through the `heatbugList' will be
( G" M$ _5 h$ O // identical (assuming the list order is not changed5 K! o, F0 j+ s: n2 }' z+ h6 l! e
// indirectly by some other process)./ ?3 r' g2 \3 T! \( u
; @' e( J; U$ Z9 M0 I1 p0 n9 J+ V modelActions = new ActionGroupImpl (getZone ());
- u" h. _" d) t% X! i+ J5 ^
/ j1 X. z1 p; Z, P R try {
9 f# t. C3 S" @ modelActions.createActionTo$message" K2 m" N5 k/ a+ _
(heat, new Selector (heat.getClass (), "stepRule", false));
0 N1 j/ Z1 `0 l* ? } catch (Exception e) {% h) \$ o, B& C3 |7 f _+ S, Z0 m
System.err.println ("Exception stepRule: " + e.getMessage ());; F; x. r& A/ @. u0 Q1 O
}% F2 d& J+ g8 ?4 J# ]6 s; c
9 Y5 b) `. e) K1 [ try {
' K8 _ J- n) W. h Heatbug proto = (Heatbug) heatbugList.get (0);
9 G. Y. u! d8 u4 k( j& e7 h8 d: F Selector sel = 0 W0 W+ K9 H' C6 D! X) Q. r
new Selector (proto.getClass (), "heatbugStep", false);; k6 E2 n3 r5 q! E% c
actionForEach =; G& L8 d% p/ j" B. D: }
modelActions.createFActionForEachHomogeneous$call- e+ u( @- N7 j0 k: g
(heatbugList,
1 ]. N/ @, S( W) x/ ~: W' r1 ` new FCallImpl (this, proto, sel,
9 E- [ q) }' n: ?8 `# R new FArgumentsImpl (this, sel)));
) x( d7 r& M ~8 r* t: ~+ ^ } catch (Exception e) {6 E) {& y/ c" D" J1 |- R& f2 s
e.printStackTrace (System.err);4 ?% e# e, s% O! j |7 L! ]8 s
}# I) {, a1 a2 t7 `) c* h0 r
$ R8 P* u( u1 @. `4 M S1 p4 F syncUpdateOrder ();9 i4 i$ H" L5 N/ _
1 Z- M% p9 \+ c- `
try {
: o0 L9 K9 c: R, V) E5 ^ modelActions.createActionTo$message
* q" d7 ^! i4 L: ?2 ~ (heat, new Selector (heat.getClass (), "updateLattice", false));
' c9 x$ U: ]7 S } catch (Exception e) {7 P9 c; c+ ^- J9 h; G: n
System.err.println("Exception updateLattice: " + e.getMessage ());" j$ \6 Z. y& A$ [8 S" f% d
}9 M7 m+ J9 A" L
9 e- w* N7 i8 z& \5 A* E5 i
// Then we create a schedule that executes the6 N% U- W' L2 P6 Y$ [/ U
// modelActions. modelActions is an ActionGroup, by itself it0 i+ G+ z# U. {: g$ i
// has no notion of time. In order to have it executed in. {2 f: S; Z) N- S
// time, we create a Schedule that says to use the+ q, B- m0 n0 K1 ~9 m
// modelActions ActionGroup at particular times. This4 q% k7 `' t" H4 _( I5 A) Z& O
// schedule has a repeat interval of 1, it will loop every q0 S9 Y( p3 W$ ], j: @ d
// time step. The action is executed at time 0 relative to/ t) d/ G! Y" l U0 u% ]
// the beginning of the loop./ s+ w% D4 z1 O+ V
1 \+ k. b5 S! o0 _, C% v // This is a simple schedule, with only one action that is
% ^# `1 H3 Z- V' G* Z // just repeated every time. See jmousetrap for more
! H" J) G! F3 `8 m4 u, U% C // complicated schedules.
! D1 C1 e6 e& |* W: D- y 7 M* Y3 T# v! G( M5 x$ g4 v$ {6 f6 S6 \
modelSchedule = new ScheduleImpl (getZone (), 1);
! a: b5 a/ E% ]/ C( |. n2 r! K* r modelSchedule.at$createAction (0, modelActions);
- }8 i) t, s1 V0 g 5 M% u0 {, W7 x' V
return this;
& u9 L/ C9 R& h7 a } |