HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:0 P3 g2 ^6 Y$ L I
' j" ~8 r2 O9 S2 c+ A public Object buildActions () {
9 Y# |; O3 c1 \: T5 x4 J super.buildActions();/ w# U4 V$ T& N# b _, G
1 s# x9 H% H8 U8 H: p: ~3 }6 U
// Create the list of simulation actions. We put these in
) {0 C' y8 s0 H* D1 ? // an action group, because we want these actions to be* H, U" h" b1 f: A( X
// executed in a specific order, but these steps should
, L' V! A' m3 s# j8 L5 t // take no (simulated) time. The M(foo) means "The message
C3 G$ `( C) S, T& M5 s) G // called <foo>". You can send a message To a particular* R' |$ s$ i2 `( e( B9 w
// object, or ForEach object in a collection.
+ Z7 Q5 n* ]% U# |8 |
I& U7 G) ^6 f( ^' W8 D1 j // Note we update the heatspace in two phases: first run
7 V6 F1 F2 i5 A; E3 {# L9 L // diffusion, then run "updateWorld" to actually enact the
( |# P2 Z8 l6 [, z% V // changes the heatbugs have made. The ordering here is
- d* b5 I# H; h3 c // significant!
/ n: h0 h( Q/ v
3 o, f5 W9 @+ X- p2 x5 A // Note also, that with the additional2 D Q' `1 ]5 q$ z4 @
// `randomizeHeatbugUpdateOrder' Boolean flag we can
- T' Z* M3 ^! `; ` // randomize the order in which the bugs actually run
8 Z$ a7 \% {1 p4 `1 C6 |5 W // their step rule. This has the effect of removing any
$ H) M" h! b$ J9 S0 j1 r // systematic bias in the iteration throught the heatbug. p; W! D& ^" I8 ^: t% `/ W* b
// list from timestep to timestep. n& a0 t, ]) t: ]5 C
R/ |; X. ^# ~; _4 L; e4 { // By default, all `createActionForEach' modelActions have
/ u+ k* I# h1 n# h // a default order of `Sequential', which means that the l; y* |- |5 o6 j' a$ q) b" V
// order of iteration through the `heatbugList' will be
9 K2 C f, p$ n- O$ n) {; H // identical (assuming the list order is not changed
2 K9 D! h, ?+ H // indirectly by some other process).
% K! t' r- m' ]
) ~1 F+ |7 F2 Q, }, J( i8 _( E modelActions = new ActionGroupImpl (getZone ());
) j( J8 F& O8 y0 T) d9 {0 H$ @ J4 \- f
try {9 E# ?# `& o) p( S: ~' W5 O! v6 s9 K) Y
modelActions.createActionTo$message8 m6 ], ?; I4 S
(heat, new Selector (heat.getClass (), "stepRule", false));& `: ]: P% O( L! R
} catch (Exception e) {
3 d3 G4 P5 {# c/ p System.err.println ("Exception stepRule: " + e.getMessage ());/ Y, l4 B h' n" m) X
}6 n' e, u! Y7 l7 }3 Q
* O9 g, K, |4 Q4 N, v0 c4 N try {
) _1 F, U1 m% P2 ~: T Heatbug proto = (Heatbug) heatbugList.get (0);& e* J* n; i7 c" x* } |
Selector sel =
1 y5 `, K9 w I0 c3 k5 j% n Y new Selector (proto.getClass (), "heatbugStep", false);
, k) }# i: y5 G4 D \ actionForEach =
, X1 e7 d( _, K$ U modelActions.createFActionForEachHomogeneous$call: R9 ~/ Q4 @8 R6 ]9 Q4 J
(heatbugList,
* {! \9 p, p# e! B8 u new FCallImpl (this, proto, sel,# y9 w1 ]% m. [! p# |& _- g6 q
new FArgumentsImpl (this, sel)));: B0 }- j$ U# Y+ N; s' l
} catch (Exception e) {% i/ {! ]0 n0 w
e.printStackTrace (System.err);- Q% A. R8 r& @/ s1 \) m
}
5 s' [; a" M( ?# R% g# \: y
) f5 W5 ] R) n1 G0 S syncUpdateOrder ();
3 M% B$ C/ ~9 I" i% J( b, _, D2 n& L' C( c# u( q& B. b- |
try {( N3 k- ?. j5 e1 ] `: G$ P& R
modelActions.createActionTo$message 6 s n, ?$ y! {' E
(heat, new Selector (heat.getClass (), "updateLattice", false));8 K% w4 I; }( [3 t
} catch (Exception e) {$ e1 N7 _+ C* N9 e# k
System.err.println("Exception updateLattice: " + e.getMessage ());- l! }+ i9 o3 f1 o/ x
}9 s# @' Z3 x+ J0 w: K4 o
( T- h; e3 \0 W3 j
// Then we create a schedule that executes the
$ t( e& M- S" n // modelActions. modelActions is an ActionGroup, by itself it+ Z2 c- D* y5 C, l
// has no notion of time. In order to have it executed in& \ e! `' K5 b8 R
// time, we create a Schedule that says to use the( {9 U0 c. s- f" d
// modelActions ActionGroup at particular times. This4 `8 s0 d9 U2 z3 I8 _5 R
// schedule has a repeat interval of 1, it will loop every
' J! L! k7 d+ `, n2 x$ N // time step. The action is executed at time 0 relative to
6 Z. q% E$ J& d& f/ l- L; u' v // the beginning of the loop.+ U9 ]- M: @; E% @
4 N& {5 H$ @; `' Y; i+ T2 J/ e8 z
// This is a simple schedule, with only one action that is
# j; |/ c/ {' D; K8 f! l* a3 z: q3 F) v' t // just repeated every time. See jmousetrap for more( V3 R: D8 S% T0 L* C
// complicated schedules.
' j$ { L3 Y6 a6 q' W& r
. A+ K3 F. p. x modelSchedule = new ScheduleImpl (getZone (), 1);2 @" \4 h+ R# R4 f. F% e' D
modelSchedule.at$createAction (0, modelActions);1 @; f+ }0 ^4 s2 d
1 l+ S7 U) X6 V) b
return this;# S' [/ j2 g/ V7 a/ I3 I. @! Q
} |