HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:* a' ~4 F1 k5 M2 l0 y+ e
$ |# t) v1 F5 J public Object buildActions () {
6 W- W9 X: Y; @* e7 u super.buildActions();
" x% C4 k7 v. @" O
( t# T, `- s$ S# Y, h2 |' z% H // Create the list of simulation actions. We put these in
2 A7 }# w/ j4 V6 b( Q k, t5 a$ A // an action group, because we want these actions to be- ^7 X4 |+ B' e' J
// executed in a specific order, but these steps should- T, J' q0 u" U( b, L7 Z: r; M( M
// take no (simulated) time. The M(foo) means "The message
/ w8 B+ W6 b/ Y1 Z // called <foo>". You can send a message To a particular
! P9 G7 D/ L& ^1 F // object, or ForEach object in a collection.8 [, K5 O( C8 y& I6 \) }) r
8 L9 m& e0 w; c7 e' W
// Note we update the heatspace in two phases: first run
W9 x$ c1 ^' ^5 u A // diffusion, then run "updateWorld" to actually enact the
7 P, Z1 T, C! j2 e3 Y+ M // changes the heatbugs have made. The ordering here is! f7 w# y; q: ~" q+ W; u2 s: e7 E& \
// significant!
; Y: Z6 |7 ]* s' a( U5 j G0 O7 _. H
6 H: i* O/ z4 X0 w; b* W. L K // Note also, that with the additional
. A# F; h( U2 f+ ]+ V* r // `randomizeHeatbugUpdateOrder' Boolean flag we can8 f8 k2 O8 Q+ B L7 l. A( S
// randomize the order in which the bugs actually run
% a! e0 V2 U1 Q2 \* D N @ // their step rule. This has the effect of removing any
$ H5 O; n# w t // systematic bias in the iteration throught the heatbug, G# d# u- B6 S+ B
// list from timestep to timestep
9 G2 U2 E: K% C* B$ f, V9 z( d+ X, n1 W
6 g8 v/ ^2 J M. w+ [8 q' w' H // By default, all `createActionForEach' modelActions have
5 O b/ e, U; L+ R // a default order of `Sequential', which means that the& ^1 l+ K& d2 T; B% t
// order of iteration through the `heatbugList' will be, c% p+ m% e& r- ]3 D
// identical (assuming the list order is not changed9 _7 P* n3 A' i; u% {
// indirectly by some other process)." M' z# d7 N. P
. M& w8 X3 p' T1 Z8 Q
modelActions = new ActionGroupImpl (getZone ());
5 L- z. [) b9 Y- n) d! v: }0 |! }& c
try {/ Z- {' K) f- |9 K7 ]
modelActions.createActionTo$message
! `; p: q, x! {% T. l# M. N. q% N! X (heat, new Selector (heat.getClass (), "stepRule", false));/ e8 M3 m r G2 O
} catch (Exception e) {. T1 D8 I6 J. k2 ]! R
System.err.println ("Exception stepRule: " + e.getMessage ());
/ C: D# i% t9 K8 m# Y4 G0 y: g }) |) H7 g" W5 }6 w
4 |" R; t1 O+ `* q try {. k% h3 _: |2 W8 H
Heatbug proto = (Heatbug) heatbugList.get (0);3 C8 `# ~4 S8 K
Selector sel = ; y0 g/ n, F6 q& r4 t: t
new Selector (proto.getClass (), "heatbugStep", false); N% j7 T. V" s) K( c
actionForEach =
6 I3 m# j5 c( {, M0 a4 B! w modelActions.createFActionForEachHomogeneous$call
L) {9 i9 o" n. f/ n8 _ (heatbugList,- p1 R# v6 E1 E. n. r
new FCallImpl (this, proto, sel,8 Y* M+ N' _) C w5 ~5 }0 O4 M, r g/ ?
new FArgumentsImpl (this, sel)));$ i5 _+ R, b( r) W
} catch (Exception e) {9 Z/ R' Q* R4 A3 S7 [
e.printStackTrace (System.err);
7 n/ R( d9 t" S) h: t }7 n- u( x; | K
% T0 E7 K/ S0 l syncUpdateOrder ();
5 [5 W$ \5 q( ~8 Q( [" ~) X: U% P. {8 j, j$ z5 V* j; q" @8 b
try {
% ^6 r2 g4 v! L+ R ] modelActions.createActionTo$message
2 F' y! [( Z g0 ~' g (heat, new Selector (heat.getClass (), "updateLattice", false));( H; B2 K( k/ k. O0 G0 H- q4 U) C
} catch (Exception e) {
0 m+ w! l" r4 p `9 L System.err.println("Exception updateLattice: " + e.getMessage ());! { Q3 l8 y6 b: N
}6 T/ v# e/ c) k! q' a5 Q3 ^
\" v, J: B# d
// Then we create a schedule that executes the
( C: q- F+ d* p# B* V( n0 A // modelActions. modelActions is an ActionGroup, by itself it' c* q3 Q3 ^+ B+ @* j# ~$ b A
// has no notion of time. In order to have it executed in, G6 }: p% [, e- ^
// time, we create a Schedule that says to use the
2 d4 g- R0 k% ? // modelActions ActionGroup at particular times. This5 H6 o/ T: W! c0 z
// schedule has a repeat interval of 1, it will loop every, }" ~1 G/ o4 W8 M
// time step. The action is executed at time 0 relative to" ?+ G0 m) a/ `! r* R
// the beginning of the loop.
$ f, `. h- s$ O, G7 B3 Q) G
( h+ o- V8 D1 w // This is a simple schedule, with only one action that is# S5 q9 f; `/ B$ z5 B' F
// just repeated every time. See jmousetrap for more
0 r5 ?1 W; r2 K4 v6 @$ g // complicated schedules.) I" n9 }4 x0 T- Y' C
6 w. C5 D: R& ?" ~0 @ modelSchedule = new ScheduleImpl (getZone (), 1);
* L2 G. ~( U. d) S$ t+ ~. f) v: j modelSchedule.at$createAction (0, modelActions);
- q1 l3 M) T# \& D# w' \; f1 `
4 y$ s/ s7 }! f- o; b9 ~& C return this;3 v- W. [; r* d0 h A( K
} |