HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
( s3 [& |+ X- r8 G% I+ \7 y: i, Q) J! b% p( \5 a% g. p
public Object buildActions () {6 U6 y+ D/ S7 g
super.buildActions();
4 Q0 `" g0 S& p& V
; V$ H w# e- q# p: a: A // Create the list of simulation actions. We put these in
8 v8 m0 a, r2 ?7 W& } // an action group, because we want these actions to be, M( v0 R- [6 G, a" W
// executed in a specific order, but these steps should
0 r8 r+ u' L* Q // take no (simulated) time. The M(foo) means "The message
M8 V+ n# K- \4 _ // called <foo>". You can send a message To a particular
. j/ U$ s( |+ H // object, or ForEach object in a collection.- b& M2 F4 M# e# h
4 y1 s0 k5 h( }
// Note we update the heatspace in two phases: first run
6 l+ t, h( q/ \ // diffusion, then run "updateWorld" to actually enact the ?9 s% r' a/ U$ c+ x# s* G" `
// changes the heatbugs have made. The ordering here is7 f- Z1 u# @- O: r$ I, j
// significant!, ]8 z7 W& {1 I, Y# I1 G5 s
$ x9 j9 _& G( }$ P
// Note also, that with the additional/ k. w9 F+ Z. P+ U& ?3 ?5 `. p
// `randomizeHeatbugUpdateOrder' Boolean flag we can
( X# ~% [2 |# ?- Q" a // randomize the order in which the bugs actually run. _- p( N! [& I% E; r
// their step rule. This has the effect of removing any
+ p+ O( z" V3 H( {6 G- I o+ Z // systematic bias in the iteration throught the heatbug9 l8 v& e* j* s5 G# c8 U) _3 H4 D
// list from timestep to timestep9 b8 s' G0 _, H% [/ B% ^$ M7 I
- Y" u8 z9 u0 W( d) |/ j
// By default, all `createActionForEach' modelActions have9 \1 E0 \+ x4 s0 O& X# n* d! M5 w
// a default order of `Sequential', which means that the
( N- ?* D* b5 l1 C" B) [( I, b // order of iteration through the `heatbugList' will be/ V% p/ n/ N& z. D
// identical (assuming the list order is not changed7 o E5 B! j# \ M
// indirectly by some other process).
1 s( k G# _1 i) D2 c0 c: P7 k
8 [- p$ B ^" C( D- a modelActions = new ActionGroupImpl (getZone ());7 O0 h- d) f; [* @% J
$ c7 z; V' \" G* k. c. V
try {, A }( ^0 l, b" i
modelActions.createActionTo$message
0 D6 m* u6 P! v0 C3 t4 ] (heat, new Selector (heat.getClass (), "stepRule", false));* L; P) i' j! k- X+ z8 X! N
} catch (Exception e) {
7 Y$ L1 e% A$ z4 D$ }9 Q System.err.println ("Exception stepRule: " + e.getMessage ());
" ~9 Q- C" q/ g) i }7 E7 ~4 E2 Q" E8 ?* I
6 |7 |9 C" d u6 [; J* S! r# R8 B try {& f, D0 P$ ~+ H8 D
Heatbug proto = (Heatbug) heatbugList.get (0);7 z& C! x7 P) E* N) c4 ?
Selector sel =
, U+ @7 e/ @" w" U [$ E new Selector (proto.getClass (), "heatbugStep", false);8 \& v. P" P! H. [/ p
actionForEach =* C& }& Q5 S8 Z+ c$ d8 I2 P
modelActions.createFActionForEachHomogeneous$call
: j3 H. G- B0 f (heatbugList,
/ x) F. @ K" }. o3 t new FCallImpl (this, proto, sel,7 ]9 l; x7 w/ |" }6 V
new FArgumentsImpl (this, sel)));* p, o- v) Q6 I" n) l4 n; G
} catch (Exception e) {- B5 T* N1 H: B
e.printStackTrace (System.err);3 c' C; n; N. J2 Z9 Z
}
4 i, O+ j: \, Q: Y
5 T( Z% ?% g4 L7 k) r. |9 | syncUpdateOrder ();9 t$ f; M" m+ n) [ k1 O3 z: H' F
- i& Q5 x8 e; ~' n% {; y$ R
try {
0 h5 R: k' `; `; n- ~$ ? modelActions.createActionTo$message 5 E2 r1 x8 Q) k8 Q9 z' ]4 m
(heat, new Selector (heat.getClass (), "updateLattice", false));$ o+ r# ?) G) R/ `
} catch (Exception e) {
0 `2 b+ X* l; C5 j# m; M! N System.err.println("Exception updateLattice: " + e.getMessage ());& f1 I' m5 J3 N8 ?0 h& |
}9 T2 ~% `1 j+ V& j
! G4 I+ L" @- {& \$ I+ s // Then we create a schedule that executes the
7 C' Z. s+ ~! `1 o5 g& s$ i // modelActions. modelActions is an ActionGroup, by itself it
+ n* v+ R) l" ?7 A [+ b // has no notion of time. In order to have it executed in% X( f+ A8 Q+ @: t- `
// time, we create a Schedule that says to use the
- I: t u4 H0 ~ // modelActions ActionGroup at particular times. This5 D& \) S& ]- v7 {" I
// schedule has a repeat interval of 1, it will loop every
1 ?! \) o5 [4 h' |) H9 A // time step. The action is executed at time 0 relative to% _. X- B S5 F# J' A0 V1 E4 ^ X
// the beginning of the loop., u) {9 Q, Y3 U o
i8 Z n1 w5 B) }. K; x/ ?2 u. p: c2 w
// This is a simple schedule, with only one action that is
$ J4 v: N0 M$ f! b- ^" b // just repeated every time. See jmousetrap for more P0 ^' t) s( y* n; ~, g: D- k
// complicated schedules.
5 P5 B) V8 [" ]# {6 I+ F 8 n- N& w* U# W7 ~7 J W( h
modelSchedule = new ScheduleImpl (getZone (), 1);+ R( X% E3 V3 C/ f4 p) U8 |
modelSchedule.at$createAction (0, modelActions);% {) a& Y+ }4 P( a
: G2 E4 v/ g6 ] n
return this;
0 Z- J7 r. n0 C- ?, W/ y } |