HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
- }8 X$ U6 [" s- n* h1 u
' e6 V3 @+ a) M/ }$ y% \- u public Object buildActions () {
; B2 N, ^+ `2 N7 J8 M l super.buildActions();
2 k- a! c- u8 { / D/ `6 w" _2 t. n
// Create the list of simulation actions. We put these in
0 e) g: C q4 ~+ _% E$ S // an action group, because we want these actions to be
! o4 `3 ^. T! N // executed in a specific order, but these steps should1 a! w1 E- j; j( g
// take no (simulated) time. The M(foo) means "The message
3 }6 w6 d, e+ I0 \0 N; B // called <foo>". You can send a message To a particular
0 c( ~9 v- {- u% x% `+ q // object, or ForEach object in a collection.
+ b" Q* u# p6 u% f: D4 h2 `& i
) J# m0 J& f) ^3 X, _ // Note we update the heatspace in two phases: first run+ z( j& E% R4 S& h+ O
// diffusion, then run "updateWorld" to actually enact the
2 @- O' L' T. o. O G // changes the heatbugs have made. The ordering here is
9 b6 p; n9 j0 \ // significant!9 C# r! [- H S; ^
2 l: f9 b* X. }
// Note also, that with the additional
& V: A) w" j) C8 { // `randomizeHeatbugUpdateOrder' Boolean flag we can
! v$ X& X0 `8 N# w // randomize the order in which the bugs actually run! i! c9 k& x3 V, c3 k2 o( g
// their step rule. This has the effect of removing any8 ^- |" g: H4 ]( f0 u0 ]
// systematic bias in the iteration throught the heatbug
. [1 j" W4 u+ G) O7 g1 q // list from timestep to timestep2 j% X% s1 r' Z1 }
1 j. D+ k$ X0 B2 b$ D
// By default, all `createActionForEach' modelActions have
$ F4 \9 x, @( X // a default order of `Sequential', which means that the
7 Q4 Q u+ O0 P: [/ y9 \& K0 z // order of iteration through the `heatbugList' will be
" @6 \! M! s! [$ U6 ] h: w% j // identical (assuming the list order is not changed
) n* E5 t( L3 B& j2 w! y3 @6 ~ // indirectly by some other process). L3 M/ u& h+ i2 Z
) }! V- Z& R. U+ z1 O; b1 j* z8 h$ Y0 l modelActions = new ActionGroupImpl (getZone ());
\, [4 u0 d+ j. q
" @7 F$ i5 w y1 Z0 F try {6 ]3 T- N3 w6 s% a
modelActions.createActionTo$message
1 w/ P) K7 ~' H (heat, new Selector (heat.getClass (), "stepRule", false));
+ l q1 _9 ]- d2 B1 k/ Q2 z) K* z' x } catch (Exception e) {4 r5 N/ P4 X7 I
System.err.println ("Exception stepRule: " + e.getMessage ());
1 f' V% o( G0 P0 c7 c/ k }
7 J7 `, S" [ o9 l" f5 i& D9 X; r1 w# S6 Z1 o8 x( h
try {
! g/ e4 l3 }" E( w8 W1 X2 e p# b Heatbug proto = (Heatbug) heatbugList.get (0);
W/ i$ O) ` w/ `# f Selector sel =
8 k, {3 v5 z& w new Selector (proto.getClass (), "heatbugStep", false);: L5 U# C- C( z6 x- A- @& Y4 j) |9 s
actionForEach =$ a2 Y1 [7 {. b; k6 R/ u
modelActions.createFActionForEachHomogeneous$call
3 C" `) q, Z9 g7 t' ^& B# s/ X (heatbugList, u- A0 b, S( J( c
new FCallImpl (this, proto, sel,
' S# F3 q$ `4 v. x) I- N$ w new FArgumentsImpl (this, sel)));1 P/ t; Q$ v$ p! v* A0 z
} catch (Exception e) {- _+ S5 Y1 y. _8 F. i( `. ~ e2 e+ y( D
e.printStackTrace (System.err);
+ D$ j. u) F! a% ^3 @$ w }8 d3 r- a$ ?' M. m2 b6 }* A
7 M$ [) J, R d" {6 e) r$ ?, N syncUpdateOrder ();
5 d+ O, I6 k0 U7 E
. O% a) U$ |8 r8 R5 I try {+ g! K# t5 \) X. X+ W1 X1 a. |4 ~
modelActions.createActionTo$message
' M. f" b; l8 j7 J3 p/ q4 z& P4 X (heat, new Selector (heat.getClass (), "updateLattice", false));
4 l1 w2 J+ j6 B3 `; ~- \ ~ } catch (Exception e) {3 T, U; h; g2 W; M0 \3 F
System.err.println("Exception updateLattice: " + e.getMessage ());
/ r' j, k$ V6 ?1 I }
; V0 X( v% P+ }" N' z0 q# Y * S- g7 P1 B# @6 y, L
// Then we create a schedule that executes the/ l2 U1 Z8 y' Y$ k% `6 v/ I9 }
// modelActions. modelActions is an ActionGroup, by itself it$ r* h: }* v8 A9 V* Z3 h
// has no notion of time. In order to have it executed in6 e5 M: I5 L J
// time, we create a Schedule that says to use the! c8 Z- e* A6 S0 a
// modelActions ActionGroup at particular times. This" w. x! ^# d) r: z0 W8 X% m# G
// schedule has a repeat interval of 1, it will loop every
?- h: i1 B# g. j // time step. The action is executed at time 0 relative to9 d W# R: O4 l5 h* M7 h3 e- P
// the beginning of the loop.% |7 R, \& d& q" K% W7 F9 l9 ?
/ b) [' W2 s9 O3 g! g) M; t8 d // This is a simple schedule, with only one action that is
% |5 C3 e/ ?! _8 |6 k5 O // just repeated every time. See jmousetrap for more
0 i% E! p% U9 k$ \ // complicated schedules.
2 P; y" R4 I( W( z! d$ |
- e Q$ ^5 x+ y7 m( d7 z0 Z9 W modelSchedule = new ScheduleImpl (getZone (), 1);5 x2 C3 p2 V% y8 M$ b( x/ G# H
modelSchedule.at$createAction (0, modelActions);
5 g3 \* z3 t) B+ C" K
4 Q. G! [$ B2 u y S return this;7 R% d ?6 K `5 `' c. S7 H
} |