HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:; l; t4 D, l) h {
7 B# d% a! W/ s+ s0 m: w3 Z+ J' ?
public Object buildActions () {
% o6 S) \! ]& m/ D0 k7 b super.buildActions();% y2 ]6 g$ L7 I1 g" I1 j' F0 D4 \
8 Y% O/ J$ p' a7 J3 x: k9 ^. w
// Create the list of simulation actions. We put these in; O" \- u+ [. p2 S$ U
// an action group, because we want these actions to be% R/ x5 Y1 G) i+ W8 O& f% F( L5 ^$ r
// executed in a specific order, but these steps should# b- T. V% |5 A$ c7 A
// take no (simulated) time. The M(foo) means "The message& [" j: f2 K* q0 f9 [
// called <foo>". You can send a message To a particular/ U& s# A" z- Q8 _5 N
// object, or ForEach object in a collection.
4 [' O1 C# @# j% m4 ?) q # V* `. i% c2 x0 ^
// Note we update the heatspace in two phases: first run4 _& }' f1 }9 K/ n1 C/ Y
// diffusion, then run "updateWorld" to actually enact the! t' c2 S! \: U/ Z/ o9 o m& O
// changes the heatbugs have made. The ordering here is
. o2 z" t, r% B // significant!
( c% Y( B: f( Z# b8 p& a
( q8 c4 N0 p$ o8 S- K( ]9 O) S // Note also, that with the additional! s; I. i! z+ m6 D7 a9 ~
// `randomizeHeatbugUpdateOrder' Boolean flag we can L- r# ]. [ L) ]: z8 q* z8 U0 J
// randomize the order in which the bugs actually run
' O% x# P# V9 d1 C2 u, U7 [' q+ X // their step rule. This has the effect of removing any
9 y A, S% E: f; z" j# b // systematic bias in the iteration throught the heatbug
! @2 [7 `& J* F9 \ // list from timestep to timestep+ h3 h% n2 @8 D* K0 q" s
0 M: m6 _! V8 j6 b* d // By default, all `createActionForEach' modelActions have. U" p2 p) R* M2 t5 }: |
// a default order of `Sequential', which means that the v+ G; F& a9 g! J0 f6 ` v& ~
// order of iteration through the `heatbugList' will be4 e6 t6 }. U5 O0 z6 x
// identical (assuming the list order is not changed0 I7 f" Z* a) s8 p& s: ?5 z
// indirectly by some other process). ^1 _7 m4 y/ [! u# P& m. U
+ p0 u5 n$ S. K* H: i modelActions = new ActionGroupImpl (getZone ());3 e) ]8 b1 c8 T2 }: A' q
; V: J2 E! _* S; m" A) ?- B/ Z# z try {& E1 U4 _3 b8 j/ `1 ]$ l2 g7 f: o
modelActions.createActionTo$message
' Q% {( g* E- l8 L/ [- i (heat, new Selector (heat.getClass (), "stepRule", false));
# F+ d ^! q! S w" b- j } catch (Exception e) {
2 e6 _) }+ P+ f, I4 k e; R+ p) p System.err.println ("Exception stepRule: " + e.getMessage ());. R7 U$ N8 [+ {, P
}
/ ~) z& [4 O% f8 E4 }
# L) _7 o; }- Z. W try {# C* ] T5 ^7 b. b% @4 f1 N9 [; |
Heatbug proto = (Heatbug) heatbugList.get (0);" ] {) o5 w2 v" @
Selector sel = 9 p- u5 e. k8 u6 }
new Selector (proto.getClass (), "heatbugStep", false);* `4 h3 F4 `1 Y* H
actionForEach =
, w9 r$ Z- I- ^% Y$ b; A modelActions.createFActionForEachHomogeneous$call
9 O* o9 d0 H3 |4 g% ~: N: z, g: k, ~ (heatbugList,; y$ e. ? n$ M- X8 t; _
new FCallImpl (this, proto, sel,
/ ~( U2 }5 C; b) J& j6 Z new FArgumentsImpl (this, sel)));
; J1 V5 x: B- U9 S. d } catch (Exception e) {' ]6 O4 g; ^3 _9 ~. \
e.printStackTrace (System.err);; w- M" ]" k# ^( H& V5 g9 q
}
4 e$ K% t6 M, O% f2 Q
1 |, \- I2 F o' V8 c/ ~ syncUpdateOrder ();
! c5 M7 r3 i6 E1 l1 {% q! A/ |$ e
try {
$ f" q0 q* q/ o3 { modelActions.createActionTo$message
; k8 p2 ^' G9 `9 p; q! m$ \; W (heat, new Selector (heat.getClass (), "updateLattice", false));
% b1 x% X2 P+ a3 o } catch (Exception e) {! @) F+ _- d& p+ A- b+ U: J0 e8 x9 V
System.err.println("Exception updateLattice: " + e.getMessage ());
4 X C- S( h. H* I) N- ? }" G" h8 e" T- l( U d
+ u7 m& Q. ?% I( r5 R4 X! J7 ] // Then we create a schedule that executes the# d) k* ~1 w4 p, d% W
// modelActions. modelActions is an ActionGroup, by itself it
/ L6 W. I. j/ R" q9 t5 g: g8 h" ] // has no notion of time. In order to have it executed in M+ ?" O. E- s
// time, we create a Schedule that says to use the- b7 i9 E" |; `" _
// modelActions ActionGroup at particular times. This4 l4 r- ^9 \9 j/ G w
// schedule has a repeat interval of 1, it will loop every4 z- | W% y& o. C( Q) ~9 ^
// time step. The action is executed at time 0 relative to# Y7 a6 j0 J5 j$ I: `/ p0 e' n
// the beginning of the loop.
$ J. S$ [, a+ t# u. V1 R. B
0 d! H$ c) F! f; x5 C! E' K // This is a simple schedule, with only one action that is0 E+ | g: G' e$ T+ {
// just repeated every time. See jmousetrap for more4 Z. p+ S7 V4 T; ^% B, J
// complicated schedules.: J7 i j3 w" u3 h
8 u h. C6 Q5 N( s2 s- u- S modelSchedule = new ScheduleImpl (getZone (), 1);3 C0 R* s. ] i
modelSchedule.at$createAction (0, modelActions); e! c2 b/ P0 m. L
0 i5 C8 ~! ^. T# H
return this;
! B$ ^2 g- |$ N8 \% Y } |