HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
* ?/ X0 P, c2 A5 {( g$ x: [2 `9 ?8 ^8 P0 m8 [% C
public Object buildActions () {
: z$ C: }* P$ z* ~0 D( P) u super.buildActions(); |1 P2 K) z/ ^! m
2 W J, w5 G& i8 g // Create the list of simulation actions. We put these in
+ g; H2 o( G# s" G- n // an action group, because we want these actions to be2 j1 O8 c7 ]: g
// executed in a specific order, but these steps should) D2 ~* u ?" b8 r- J$ F- Z2 | t
// take no (simulated) time. The M(foo) means "The message& u" }( }+ y# s/ b
// called <foo>". You can send a message To a particular, V# c4 I% F4 u, ]9 m% @0 ]9 [
// object, or ForEach object in a collection.( J1 K. v6 \) L2 [# @0 e
0 g* E/ q2 C7 w N3 [ // Note we update the heatspace in two phases: first run% a9 E6 b7 u$ Z& e, g0 g% y/ u
// diffusion, then run "updateWorld" to actually enact the. I. a2 D) A9 O/ k1 z7 e) L7 ]! E. l( K
// changes the heatbugs have made. The ordering here is, K4 I. Z8 d- B) o2 }, n W: H$ C
// significant! |2 @3 o# b0 B( l/ [
+ H! M/ Z$ w6 M8 a* m( `' @8 j; C // Note also, that with the additional) @0 ]0 d5 t, [- k9 F, L" b% ~! e
// `randomizeHeatbugUpdateOrder' Boolean flag we can
- p8 \) D. z3 V( { // randomize the order in which the bugs actually run
* m; p/ h N0 W- H+ _/ U // their step rule. This has the effect of removing any! D9 t/ o& C5 z6 _; v# f- d5 I
// systematic bias in the iteration throught the heatbug. U- \( j7 n2 |' t$ E K1 `
// list from timestep to timestep3 p8 N7 ? Y9 U5 [
$ B7 {+ g$ R% j, r: G
// By default, all `createActionForEach' modelActions have
; V: d& R% T4 r# Y! ~ // a default order of `Sequential', which means that the8 \, g$ ^$ Z/ h; M
// order of iteration through the `heatbugList' will be
) y- X$ v$ F$ [& _# N9 T, j: O- x // identical (assuming the list order is not changed8 P# Z- C+ ?9 L$ U
// indirectly by some other process).
/ e! O0 B7 B$ i N: k& F/ w, _6 g
! e# B+ v; y; ~0 p modelActions = new ActionGroupImpl (getZone ());
: _6 Y7 e5 S5 H* p; ]/ [7 L7 x9 {! V7 W
' p+ o( [( A' t# X try {
$ C Q( Y; O( o modelActions.createActionTo$message
8 n# s( L. Y( |+ H. v) R: G (heat, new Selector (heat.getClass (), "stepRule", false));! ?$ ]+ H. { K* H+ m5 Z0 j, u
} catch (Exception e) {# Y& ^' w8 X: o7 f& w# {1 d5 V6 L
System.err.println ("Exception stepRule: " + e.getMessage ()); U8 X9 s0 w% K; V# N* [
}
+ M. V) B; ]8 R9 ?! @1 `
! R4 {2 u2 C* _5 m& e! r ]' Z ~ try {
' |1 b2 x; V& ~$ O9 L% ]: m) o Heatbug proto = (Heatbug) heatbugList.get (0);
2 Y1 `6 b) s! V H! w8 h Selector sel =
p5 X/ J/ w7 E- _! J new Selector (proto.getClass (), "heatbugStep", false);% O% P2 \2 x! d$ _) ]4 U0 i
actionForEach =9 n; q% ?7 H- X. X9 S
modelActions.createFActionForEachHomogeneous$call! \( F9 d- q {1 `5 i+ z
(heatbugList,
& O: @3 y2 q' ]- G. G/ S new FCallImpl (this, proto, sel,
/ k2 I7 P- V# b( p q8 _8 S4 E: a1 t new FArgumentsImpl (this, sel)));, D( r3 v3 B+ G% f' U7 X! r
} catch (Exception e) {6 Z9 w* v+ V0 z2 ]- c/ H
e.printStackTrace (System.err);$ s M; E1 `5 b$ L; i; V
}
* v( E* @7 _; Z* v l6 V/ @* G ; }: x! n2 H A, v8 E" C6 d. A
syncUpdateOrder ();6 A" C1 b. n& }
% k( h& g! k( G2 @% L' h try {
1 C5 w. x, l& w' Z' u modelActions.createActionTo$message " y% l4 |4 w Q) g& J
(heat, new Selector (heat.getClass (), "updateLattice", false));: j/ D# ?( ^- H' y9 i S z
} catch (Exception e) {
. l+ `. M& i: z5 r1 d: } System.err.println("Exception updateLattice: " + e.getMessage ());
& y+ ^- \% Z+ q1 A3 p. w }
\; B" ^3 O) y ~) N; r$ y / A @* ?3 P" ^% l2 l4 L4 V; g, k( Q
// Then we create a schedule that executes the4 s7 s/ l- U4 d7 j& l! W
// modelActions. modelActions is an ActionGroup, by itself it+ o0 H" {8 t, W* E
// has no notion of time. In order to have it executed in
?9 g. u$ D* i' J. y // time, we create a Schedule that says to use the
7 d: J! r) x( J0 R/ i! ~; r* J // modelActions ActionGroup at particular times. This
0 t4 Q, O" k8 U1 k& \9 o M1 C9 H5 x // schedule has a repeat interval of 1, it will loop every
+ m# |! J# k! P0 Y // time step. The action is executed at time 0 relative to
$ |, J% M) ?+ @. U // the beginning of the loop.0 p, J3 V8 N- Z' o1 S6 s
7 ]; c/ T7 Q3 ?4 T+ `( K // This is a simple schedule, with only one action that is8 @3 y* ~, S2 v2 P) M
// just repeated every time. See jmousetrap for more
3 P" d) |+ k/ k // complicated schedules.2 b( b! H! U0 ~! \
3 f7 y2 f# d" K0 o, {3 I modelSchedule = new ScheduleImpl (getZone (), 1);
: F/ u1 T8 C, R; _ modelSchedule.at$createAction (0, modelActions);7 v6 p% {9 v- P
: T) @ p9 c' ]. F, D$ k, t6 \
return this;/ V" O2 z# X1 n
} |