HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:" n, Y2 b8 v) L, [+ g$ ?* Z! @: S) O
% i1 D z) r# V% M public Object buildActions () {3 W5 l1 T1 {: d: \ t
super.buildActions(); s, ?2 _3 l5 r: t
" i V% P6 w! U, i. H; w // Create the list of simulation actions. We put these in5 H: e$ C* X) u6 E6 m! h
// an action group, because we want these actions to be
; p. @% ~, B, J6 u1 q' e // executed in a specific order, but these steps should+ G& ]8 n# a5 ?8 P! O- ?
// take no (simulated) time. The M(foo) means "The message
" P/ ^5 {9 J) t( ]+ [ // called <foo>". You can send a message To a particular) i9 D+ \# P; L: y7 H) s, F
// object, or ForEach object in a collection.
$ g" \2 {+ t7 t: U* Q $ Q, U/ V8 r. f( ~ V
// Note we update the heatspace in two phases: first run( W/ c1 d) I, |/ Y5 u9 a
// diffusion, then run "updateWorld" to actually enact the6 F2 B( g4 l; f! }' V1 i+ P( ^! a
// changes the heatbugs have made. The ordering here is6 e5 S0 \6 u+ {% ^8 [
// significant!
1 ^: l- e' ^: l# z; [
# B# K! Y' f/ ^9 d G; p // Note also, that with the additional
; {9 e6 E8 f# u) ?8 v( G6 f+ V // `randomizeHeatbugUpdateOrder' Boolean flag we can
1 R' ^! P6 ]3 c E* q0 j8 N$ M2 E7 l // randomize the order in which the bugs actually run
7 v5 J" m# a- Q+ M. H! Y: M2 P+ J. e // their step rule. This has the effect of removing any
2 v1 T% X( V/ I# K: V* [ // systematic bias in the iteration throught the heatbug5 r6 m& ?/ z' E2 b3 @& ~
// list from timestep to timestep4 p1 V4 k q" R) z8 `* p
& e0 I, Q. f3 ^8 p: ^: k
// By default, all `createActionForEach' modelActions have
. \/ r5 S: o# r) Z- H- E# n5 ~! q // a default order of `Sequential', which means that the
1 b K1 c+ i/ W4 ~ // order of iteration through the `heatbugList' will be
; B/ D) C8 h$ k3 u1 B8 w$ a // identical (assuming the list order is not changed7 i+ Y+ @2 v7 z, T5 V) u$ L
// indirectly by some other process).: A, b0 k9 R5 M7 G- n3 k7 Q0 K
! k& [& b7 }6 F; o: ~8 H modelActions = new ActionGroupImpl (getZone ());& d2 q8 I, C2 x
# y- O8 H! y2 {5 e try {3 n. W8 k9 l% `$ U
modelActions.createActionTo$message+ ]/ U8 B, `) H% B) P" ~, x& M
(heat, new Selector (heat.getClass (), "stepRule", false));
9 S, a4 j3 s0 V q2 U z# p. E } catch (Exception e) {$ z: p. Q" a' { k& v8 v' J
System.err.println ("Exception stepRule: " + e.getMessage ());; \3 O" H% _/ r
}7 ~! W9 Z/ H6 B. r# o& J0 M/ \
* F2 h* f( n$ g
try {5 Z4 t) S. R% X# w* K
Heatbug proto = (Heatbug) heatbugList.get (0);
! K6 s Z `5 v* f; A0 K4 ` Selector sel =
, }- I, y) o" A& V% j/ w# Q. g) M new Selector (proto.getClass (), "heatbugStep", false);1 H; \% X1 W. [: {1 N
actionForEach =
# o* F! l6 S2 Y" B5 ~0 E* `% I modelActions.createFActionForEachHomogeneous$call
" d8 K% ?. Y! U- Y (heatbugList,
9 z) e# m9 D' O* h new FCallImpl (this, proto, sel,
2 P: W( j( j" A* X0 O1 }% c q- [- C new FArgumentsImpl (this, sel)));
# ?1 y' S' L3 c: t1 O } catch (Exception e) {) M |3 U( N( ^
e.printStackTrace (System.err);; j K; o" ~) \7 x$ y
}$ i+ a* ~& s% D+ s5 Z" [
* K% H# S% _ W- r syncUpdateOrder ();. q5 }' q4 ]1 T7 L4 e% n& ~! _
$ \0 o$ ?( j1 J! [! m try {
7 i: m; p: W! c4 F& |* k3 Q6 k; F$ W modelActions.createActionTo$message ' m" u9 x: p% u4 j1 V Y
(heat, new Selector (heat.getClass (), "updateLattice", false));$ F# [) L( _! I+ D: z
} catch (Exception e) {
' i( j9 W+ d: F! M6 J1 P; [3 \6 m System.err.println("Exception updateLattice: " + e.getMessage ());/ p; q6 @+ m/ N5 K9 J0 P- J! H
}
; U1 G" M& i$ s7 o) Y1 f3 ^ 5 ?+ x5 `( b3 F E- Y
// Then we create a schedule that executes the- z4 B8 Y& S; |$ f7 }) g4 c( _
// modelActions. modelActions is an ActionGroup, by itself it
' U }' J7 c' ^- X: f j" ^5 V$ { // has no notion of time. In order to have it executed in- X! X/ u; j9 Q5 j" q$ b, N5 G5 ~
// time, we create a Schedule that says to use the2 H% i, H4 k+ C @( y
// modelActions ActionGroup at particular times. This
# b& E- Q$ k; |% P, r" S4 E2 V // schedule has a repeat interval of 1, it will loop every! Z3 P* E( q$ r5 ~9 d$ c; Z
// time step. The action is executed at time 0 relative to
8 j2 `0 ^$ q2 J' w8 g$ [* C // the beginning of the loop.; l. s- `/ _8 l; s2 v* E* U* q
( `5 s3 |1 z$ \- @ // This is a simple schedule, with only one action that is
% {4 q0 `5 \+ {' ] // just repeated every time. See jmousetrap for more
. Z" R" N7 X6 z( ~% J5 U5 m9 j8 q // complicated schedules.3 Q& C# w% E* g- b, ?+ q1 b8 b! X5 y# E
# l) s/ c' R! ^) j& H. K! [- k modelSchedule = new ScheduleImpl (getZone (), 1);
- @4 }. o# U6 z0 \: L modelSchedule.at$createAction (0, modelActions);# A1 }' ^; j$ b& |7 @
8 e$ g% T8 s" X
return this;
4 u- K( e, ?. i6 K, P6 V } |