HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:" D7 V7 _! k2 K0 B& _; W: g- Y
& T, F; d. }- j0 g# c" j( t
public Object buildActions () {
% s& I4 \+ g6 S9 I% q; M super.buildActions();
2 L, W& O1 K: F' H, c* T9 P* D- t
. R; q7 z7 y8 ^' j# X3 x) \0 C // Create the list of simulation actions. We put these in
$ k; l9 \7 W& a2 W/ v // an action group, because we want these actions to be
1 K4 S. ]! X: S* a7 W1 x // executed in a specific order, but these steps should3 @$ v! |1 ?) x* z" X2 P% _7 P
// take no (simulated) time. The M(foo) means "The message: @& q; {5 P2 L( s; @5 }/ A8 }% W
// called <foo>". You can send a message To a particular/ j# R, I5 y. i$ `
// object, or ForEach object in a collection.
2 ~6 _. w. f; n# ~8 k
) V/ N# B2 V0 k0 Z% e // Note we update the heatspace in two phases: first run3 }+ g5 F5 ?4 {3 `3 `' E, V
// diffusion, then run "updateWorld" to actually enact the
( f6 [+ I* x; ]- _& q3 v // changes the heatbugs have made. The ordering here is/ f% @3 W3 Y" W4 \0 _
// significant!7 U/ `! \" {7 f2 v( g. M9 Y
* u1 E1 b- l8 v- X1 \* y8 L6 }1 A- ?! r // Note also, that with the additional, G) r. j# O! i0 V( }' s
// `randomizeHeatbugUpdateOrder' Boolean flag we can
" e! z& Q& F) F/ T- ?! ] // randomize the order in which the bugs actually run0 V$ @/ Z& D2 C8 J& V5 _# }% v
// their step rule. This has the effect of removing any+ k- h ] G' L: z+ `2 [5 W
// systematic bias in the iteration throught the heatbug8 c- Y8 a8 q {" {4 f. l4 [
// list from timestep to timestep F4 _" ^4 @ ]/ \7 L/ C: Z
" |9 R, N; e4 h5 Q/ b0 j! ]7 ?, x# A // By default, all `createActionForEach' modelActions have: p7 x0 O9 K( y$ ?% K8 N
// a default order of `Sequential', which means that the' f9 p# o% F8 L) u* O
// order of iteration through the `heatbugList' will be; W4 w9 o" }, y9 h1 E) l
// identical (assuming the list order is not changed
9 }) D% t/ f) M( u // indirectly by some other process).* W0 }7 ]& x( U! i& } \
- s/ v: ?* B: c F( s" h modelActions = new ActionGroupImpl (getZone ());, H5 y* I8 Y g+ o- l k8 a
7 q7 S1 I4 y n# E. t) @1 K
try {
" d" u& _5 e3 Q( a5 _5 ] modelActions.createActionTo$message. H; E+ Y7 K3 X) T
(heat, new Selector (heat.getClass (), "stepRule", false));
' T/ d# P! l& n/ F/ f0 N } catch (Exception e) {. M7 B6 ~6 D# {1 L0 G: d0 g+ }
System.err.println ("Exception stepRule: " + e.getMessage ());4 X: y. X4 e; v- x M& J
}1 o4 z& t3 ~+ V
/ l4 V3 t( C% F+ L5 S7 @
try {, ^7 |. [* ]5 X2 L
Heatbug proto = (Heatbug) heatbugList.get (0);
) N$ H+ v _% O/ @4 b+ H Selector sel =
9 R0 K i% u3 C0 r new Selector (proto.getClass (), "heatbugStep", false);3 P8 t1 i9 R9 z7 U& p5 H2 N
actionForEach =
: e y) f) W6 y( o$ v. X; g modelActions.createFActionForEachHomogeneous$call a8 G! b7 Y6 l7 D$ ^, `& G
(heatbugList, H m, V$ l, {3 o; o' k
new FCallImpl (this, proto, sel,* h" [, U2 F& E' q+ P
new FArgumentsImpl (this, sel)));
% G& z v$ X2 }/ s4 | } catch (Exception e) {
' G, x; L- B3 @$ t* k" t- m e.printStackTrace (System.err);
8 |+ K& A! O3 p6 N b4 S }
+ A& L( f: b1 V/ Q: {; A ! c: \: r0 u1 \4 `9 Q
syncUpdateOrder (); s g' `/ a- A5 `
' q6 V1 R& t* J( i( b4 t0 S: r, U- k2 } try {9 l( J+ J u+ z3 N
modelActions.createActionTo$message 6 D0 D0 d" X7 V8 k% @6 K
(heat, new Selector (heat.getClass (), "updateLattice", false));1 y8 E7 J" H" c! _- T3 h! n! e
} catch (Exception e) {
3 ^* D- O( A8 T: I4 a System.err.println("Exception updateLattice: " + e.getMessage ());+ b I7 {% u, P! n9 {5 E- R, |+ o
}
; B0 ?! n/ n* U: d# N8 w' f 9 a; T6 b/ |3 G: V' `2 ?. f- f5 u
// Then we create a schedule that executes the
( Y& Q" L" b# j3 F // modelActions. modelActions is an ActionGroup, by itself it
# [4 U0 D. D, W* R3 P$ i' y" i // has no notion of time. In order to have it executed in, i# F2 `% v2 z, T1 [
// time, we create a Schedule that says to use the" v; ^) v; H& e
// modelActions ActionGroup at particular times. This
4 Y2 T7 |0 a/ \0 \ \ ?$ o // schedule has a repeat interval of 1, it will loop every; P/ D' L; ~( q
// time step. The action is executed at time 0 relative to
0 q) E- \# O* z% {8 P8 ^! V3 M& | // the beginning of the loop.) H1 ~3 Q) y7 L
" A' b4 [. T x: N6 m- N1 C // This is a simple schedule, with only one action that is
( e. ?7 i9 G# \( F // just repeated every time. See jmousetrap for more
/ a7 M+ w) F. Z- C3 r // complicated schedules. I8 l2 A) t% E% p, B: [2 a8 ]
' H, R* b! q# N& X7 o2 O0 `4 F7 \
modelSchedule = new ScheduleImpl (getZone (), 1);0 S' |1 x" A+ p$ D! ~) n% C! b5 T0 F
modelSchedule.at$createAction (0, modelActions);: G% H5 s: k' ?! @( U
2 z! s' e0 w4 B3 i1 V return this;
9 g, U" K* ~2 n5 D } |