HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:" I; p" Z0 g! N5 n
* A; g/ E& y* e public Object buildActions () {
7 D a v' D2 @/ D1 T super.buildActions();3 n% H |: D4 L% w8 a
0 l/ ]- Z, E. h // Create the list of simulation actions. We put these in
& l! I4 y7 o7 c; x2 H // an action group, because we want these actions to be
# f" J5 g1 l }+ h4 t# f // executed in a specific order, but these steps should, b; S& z; I/ E5 `
// take no (simulated) time. The M(foo) means "The message
: U: Q" r- p6 x2 [7 X# L0 ?% B // called <foo>". You can send a message To a particular
: v: ^7 z* L' b w% R2 I // object, or ForEach object in a collection.
. M! g5 e7 b2 W4 h% u
) N$ k, S1 ~- T( d // Note we update the heatspace in two phases: first run# U2 Y4 s( v! j( i
// diffusion, then run "updateWorld" to actually enact the
5 l( @' `2 ^/ A" K$ | N // changes the heatbugs have made. The ordering here is) I. o, g4 E0 U8 _' N
// significant!( F; l. m+ n5 T% ^3 T7 O3 R
' ^8 l( }& @4 S // Note also, that with the additional
F( o5 ^+ B7 l7 P // `randomizeHeatbugUpdateOrder' Boolean flag we can, `* O g3 B! q# B. n
// randomize the order in which the bugs actually run
: j. x" D5 Z& U6 F // their step rule. This has the effect of removing any9 U2 I. U2 y1 e9 ^% l, O
// systematic bias in the iteration throught the heatbug
% Q Z* P4 @# a+ e4 W' B$ i // list from timestep to timestep
% d. c& X, `3 A& w* @
7 n7 Q1 H) D) k // By default, all `createActionForEach' modelActions have3 @ Y4 o4 z( b5 V y( d! y
// a default order of `Sequential', which means that the1 k# b7 C4 }' f- i; y
// order of iteration through the `heatbugList' will be
$ y1 Q$ P# k* g, N- _: r // identical (assuming the list order is not changed
; _ x" {1 m6 e% o) m* U% l // indirectly by some other process).3 M% a7 ]$ {- e; M/ Q
/ I8 v( C, |# f0 A modelActions = new ActionGroupImpl (getZone ());
7 S4 j- W; ^" Y
H7 [! w& G6 ?$ G1 _, ^ try {
7 ]( N& F% o; [2 x4 { modelActions.createActionTo$message1 X7 c) l2 m% R& V1 C' l
(heat, new Selector (heat.getClass (), "stepRule", false));! K* m( n, R" n
} catch (Exception e) {: v. o) I1 ? m1 G) a
System.err.println ("Exception stepRule: " + e.getMessage ());
4 ?+ E2 O1 j2 e" P( k" p }3 |/ q: x9 K# K; f8 Y: J" k; k
3 f; T2 O2 o9 r! C$ ~# m( u7 k try {
+ r0 m+ E9 p& W4 m! B* Y Heatbug proto = (Heatbug) heatbugList.get (0);' z3 k3 f' T* l& ]) F9 ~
Selector sel =
6 t6 C: K9 ]0 j6 a new Selector (proto.getClass (), "heatbugStep", false);& y) B9 Q" d# L# a; h* a% L0 k
actionForEach =$ [! A3 E0 p' L$ s
modelActions.createFActionForEachHomogeneous$call
, [# C* ^ J% B (heatbugList,
' H; c7 h7 w7 A6 a$ z new FCallImpl (this, proto, sel,
$ ^/ x' @3 U" y0 u3 I# F new FArgumentsImpl (this, sel)));
! |* L6 a. b8 C0 ^6 J4 [6 W+ ~ } catch (Exception e) {; S: h$ L+ @% \1 M2 ?4 q
e.printStackTrace (System.err);
0 U' g7 A" q/ ?4 W9 |- i }- Q' B: s( }5 N# ?# j. o; z4 A
( {) M! n1 Z5 W1 }
syncUpdateOrder ();
- K) a E# Z1 X3 `* ], l, Z4 |% I% r \7 \) f
try {% b3 f, P% i. ]2 B O
modelActions.createActionTo$message 1 P2 o8 O1 b" U% C! ^
(heat, new Selector (heat.getClass (), "updateLattice", false)); j) g9 D# j5 k4 ~& R4 X$ _, m
} catch (Exception e) {
9 n* @* S& b4 |* B% B System.err.println("Exception updateLattice: " + e.getMessage ());
2 v6 f# g: A* e! l5 z9 f! p }7 {2 z T7 h- l* j
0 L; {/ b6 @6 h$ h // Then we create a schedule that executes the
! }% t9 K; Q. s5 e/ E // modelActions. modelActions is an ActionGroup, by itself it
$ @0 ]7 M' l. z1 m. L, a1 f // has no notion of time. In order to have it executed in
; M3 t1 |9 ~( E // time, we create a Schedule that says to use the
+ f6 T2 m0 j7 z% M$ H* i // modelActions ActionGroup at particular times. This& t, O: R$ _+ m7 k
// schedule has a repeat interval of 1, it will loop every
8 D: z4 Y' X4 l R& L" e1 d" J // time step. The action is executed at time 0 relative to
~# ~6 T% H: X! r | // the beginning of the loop.
. s5 O* B- b8 `2 u( M, d' \7 E, W' j+ S
// This is a simple schedule, with only one action that is
/ q' i) [% f. Z$ ?$ |" X$ k // just repeated every time. See jmousetrap for more
e; _; S" }: t, i0 @" b // complicated schedules.
4 J' `# }# p: H$ V U3 t 0 D) P6 e8 i2 }* q( `
modelSchedule = new ScheduleImpl (getZone (), 1);; @! N3 ?7 @: k: @
modelSchedule.at$createAction (0, modelActions);
* H3 }! S# \2 N3 r- P) c+ ~+ \ ' L2 k6 _, s+ I8 K- C
return this;4 b8 z. {- ]* f- z
} |