HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下: X3 Q& p% ?6 Y8 k' |' ]& K
( |: _8 r# C2 E, q; ? public Object buildActions () {
5 Z8 f5 N: s( \& Q& Y! ^, |( B super.buildActions();) m E+ E* q6 V% E$ ~7 Q
9 m- }6 R" E) s8 o ^' v& j
// Create the list of simulation actions. We put these in4 r8 @8 L( {8 T+ I- q8 U$ J7 v2 X1 O
// an action group, because we want these actions to be
/ M# n9 k4 r9 b // executed in a specific order, but these steps should- o" e' M" v2 e/ [ P/ h7 i7 d
// take no (simulated) time. The M(foo) means "The message' F; w' f0 B8 @0 A6 {9 V" u, y
// called <foo>". You can send a message To a particular
3 H% b- Z7 A( {# m8 ^& Y: g // object, or ForEach object in a collection.
. C2 Z+ U# M& K3 [, B ! O: P u5 a6 w' q
// Note we update the heatspace in two phases: first run# ?/ A/ X/ E& |: e: m9 G
// diffusion, then run "updateWorld" to actually enact the
4 }- w" @& q6 o6 w* V, i! O // changes the heatbugs have made. The ordering here is! |% Y' q; N' v7 f2 V6 A4 j
// significant!) W, a [8 s+ {
% ]4 p! H, P* R0 y8 m: j; ?. E // Note also, that with the additional$ d7 P0 h' L4 j7 C& P- Y
// `randomizeHeatbugUpdateOrder' Boolean flag we can' n% C2 F9 v, y8 O* U
// randomize the order in which the bugs actually run
3 W7 p4 b' d* h9 K1 n. _7 ~ d) J6 `) r // their step rule. This has the effect of removing any
& s$ y& S# Z/ f/ Z // systematic bias in the iteration throught the heatbug0 j- S1 B0 }6 J: O# X0 t- {
// list from timestep to timestep
# ~2 y' e- ~7 M4 s
; Q6 M; h+ ^$ K2 E // By default, all `createActionForEach' modelActions have) |4 D* X) @' i& p: L$ `
// a default order of `Sequential', which means that the' a9 {1 _' a3 O2 p3 o: R, t* I
// order of iteration through the `heatbugList' will be7 s- g0 z8 s( i4 [
// identical (assuming the list order is not changed
) `# B) b: K# S- E // indirectly by some other process).3 j8 O. w1 s' D7 z3 r
" s" p% l- y1 X
modelActions = new ActionGroupImpl (getZone ());
, k% n! O5 a# C. P" H8 B4 H2 x; @. h6 s: ^6 ~
try {
7 W9 c& Q* {% g# H. j. ^3 m modelActions.createActionTo$message7 w6 |2 U) M( l
(heat, new Selector (heat.getClass (), "stepRule", false));
/ S, e) F( ]$ L* M6 M5 c" e } catch (Exception e) {
3 K9 v/ N3 R( C* A9 I) h. p System.err.println ("Exception stepRule: " + e.getMessage ());- i7 M. j" Z! W
}
3 R% O, i7 N5 X9 e s1 u2 s5 X
, A; r R2 n6 m- s( x try {# j- {6 c' J# z7 j' p9 d1 I8 i+ k
Heatbug proto = (Heatbug) heatbugList.get (0);8 p* z; E+ R- h9 c7 Z
Selector sel = - \7 b# D0 l8 t( M6 `5 Q
new Selector (proto.getClass (), "heatbugStep", false);; R. m4 V" ~7 P, Q
actionForEach =, a$ x6 C0 z4 x A3 P- E
modelActions.createFActionForEachHomogeneous$call
: D& b, M6 m, b* m% D7 A. Y (heatbugList, e- J0 V5 G8 p; ]
new FCallImpl (this, proto, sel,
; B! E4 T7 ~4 a( q" @ new FArgumentsImpl (this, sel)));
- W) I4 K+ {4 L7 E+ }7 Y/ A) P! Y } catch (Exception e) {0 Z8 ]% z7 a# M) h& n, v
e.printStackTrace (System.err);+ e8 t# c. M8 [
}" A1 D+ K2 ?$ Z1 C. \
. t0 G' z, ]% \, n- j syncUpdateOrder ();
$ c/ |! N) u( {+ ~& x( ^; U2 b5 d J" n
try { _& W* W; b& |! V B' N
modelActions.createActionTo$message
2 j" c' T3 v: [3 p) a (heat, new Selector (heat.getClass (), "updateLattice", false));& o5 c) U1 y" R( W$ ? p, L
} catch (Exception e) { L- U% C9 K. f
System.err.println("Exception updateLattice: " + e.getMessage ());1 g" \/ Y$ f6 [4 }6 `) a
}8 Y3 v4 @3 ?. }7 [3 I4 z
' m& e. l9 p+ [' k
// Then we create a schedule that executes the& I" y2 R2 @7 S. l( M9 z& z
// modelActions. modelActions is an ActionGroup, by itself it, k7 |9 i4 I: F/ |
// has no notion of time. In order to have it executed in% Y& Q5 r: w x9 x2 [
// time, we create a Schedule that says to use the7 I( U& k8 B! D: F0 S/ g
// modelActions ActionGroup at particular times. This: H6 J3 |: u+ K& D/ [* K [1 {, X
// schedule has a repeat interval of 1, it will loop every
4 q: U! }# ?5 V+ g // time step. The action is executed at time 0 relative to& Q( \& a8 x2 T0 G5 e4 T/ I/ S
// the beginning of the loop.
& t4 K" y! K0 h' V
7 y' z% }2 B, z6 o // This is a simple schedule, with only one action that is; _! G; k7 J* Z1 V" K ]" p
// just repeated every time. See jmousetrap for more0 H0 V0 t, ~2 V; Z o0 x6 ]" Y' q
// complicated schedules.
6 ^/ Z. {. C, @1 Q: y
T! Z' m5 @- y) T4 S+ B modelSchedule = new ScheduleImpl (getZone (), 1);" l/ N8 H/ E8 Z, a. U9 a" @" i
modelSchedule.at$createAction (0, modelActions);4 c1 |' A' w* Z
& Z" S4 U# l3 Z* L/ X8 v return this;" g: R/ e! \& J
} |