HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:, C" O- c* y4 `; u
3 o7 }- m$ _: S& _" \ public Object buildActions () {
) B& M& G9 d+ u4 b& L. z# Y- G super.buildActions();
$ |+ e4 H# o5 k 3 O2 ?# R1 ~9 p9 R
// Create the list of simulation actions. We put these in
8 O5 b3 O% p) y9 i% a! T1 p* t // an action group, because we want these actions to be& g8 c$ p: I( S* }
// executed in a specific order, but these steps should
7 n4 w/ O, m4 i8 b/ O" V // take no (simulated) time. The M(foo) means "The message4 A/ ~) x2 w- C! n$ n3 W
// called <foo>". You can send a message To a particular1 f) T! L; `2 |* L' n) Q/ n
// object, or ForEach object in a collection.
v1 e# y# P- F$ ]0 ?9 m 7 R9 j! r9 q J
// Note we update the heatspace in two phases: first run2 D9 S, W5 [3 w2 j- ^7 K
// diffusion, then run "updateWorld" to actually enact the+ I8 D3 L! W: @4 s' V
// changes the heatbugs have made. The ordering here is9 ~7 M) v0 p$ b
// significant!% s& F M8 s* g; \. S
* V9 H4 X6 Q; V6 F2 A // Note also, that with the additional7 P/ }( j+ P# b% D9 V |6 F
// `randomizeHeatbugUpdateOrder' Boolean flag we can! C* K/ u; q- d6 j7 O
// randomize the order in which the bugs actually run
3 J2 g" s# C6 Y% v0 }, H; _- T // their step rule. This has the effect of removing any3 m+ {. X# Q( ~/ V: @
// systematic bias in the iteration throught the heatbug
1 L# n8 a9 D: v: B // list from timestep to timestep
Q* N3 c* p% L, [7 Z7 T 6 M# n- n1 B) Q
// By default, all `createActionForEach' modelActions have) @9 ^# ?3 t, ]$ I
// a default order of `Sequential', which means that the0 f7 i& |6 n) i$ x/ P
// order of iteration through the `heatbugList' will be. Q' V' ^, v, W5 Q) R9 \ F& q5 B
// identical (assuming the list order is not changed
' @+ D9 f' Y0 Y+ ~6 V E3 t // indirectly by some other process).% |9 z4 ?& W# l# j t( j8 ]2 X/ B
6 @8 z' x7 m9 L ~% }! P# D- ?% D
modelActions = new ActionGroupImpl (getZone ());$ ~+ y. o# m6 p& F" |
: `2 `7 Z+ i" k1 W1 _; l
try {
0 R) c" m/ i6 H( [( W" k& X, {( D- R: P modelActions.createActionTo$message4 \4 k0 l% l2 R5 n8 v
(heat, new Selector (heat.getClass (), "stepRule", false));* L# g# H8 L5 i( s9 C: U2 j
} catch (Exception e) {
9 ]3 u) w0 M$ D+ B. T! T9 _6 B System.err.println ("Exception stepRule: " + e.getMessage ());
/ G% ^- Z+ Z6 s }' |- j$ J/ G0 W* v% k9 k, `8 Q% G
2 g' a6 z' Z6 N# B6 o! B try {
1 W; C& E( |. |4 r Heatbug proto = (Heatbug) heatbugList.get (0);
6 E# i; t, I6 f+ Q4 ~0 x3 l) f Selector sel = 6 `0 w! O: H- E( g& r# @& [' \
new Selector (proto.getClass (), "heatbugStep", false);
/ _ v" G* I: W/ D" i! q actionForEach =" ~' U+ C1 J/ Z K8 V6 Q! t
modelActions.createFActionForEachHomogeneous$call5 ~5 L5 \7 b2 E9 U: r) Q% P1 U8 ^
(heatbugList,& o! p1 w2 E x" Q5 g
new FCallImpl (this, proto, sel,7 S: G+ q, s7 r& h
new FArgumentsImpl (this, sel)));
0 P+ n, i3 p! y* O4 @7 W } catch (Exception e) {
, b4 _3 d8 S0 v0 k6 t1 M: D e.printStackTrace (System.err);6 q! Q4 x( s, E: y$ ~% Y, ]/ I
}
. {2 i6 M' Q% D
& r' k. l( }+ O7 W syncUpdateOrder ();- M! X, w9 W# @3 x$ s
5 [# `/ S4 o4 {2 T9 n3 r* c: | try {- Z( m& l9 f( o# C. m# a
modelActions.createActionTo$message 0 A* s8 ~+ g% g5 Z) S& G4 k2 c
(heat, new Selector (heat.getClass (), "updateLattice", false));
% y e. X/ \1 I4 w* j$ h% g8 q } catch (Exception e) {
1 _; @& f1 A: K9 U, @/ u System.err.println("Exception updateLattice: " + e.getMessage ());( _$ _9 ]0 D& p- @1 i0 G
}
1 x, ?. q8 j9 ?4 S; n ! t/ D1 f& [, M
// Then we create a schedule that executes the$ Q! a7 H) `0 Q$ j/ x
// modelActions. modelActions is an ActionGroup, by itself it
) b. X P2 I' j2 Y8 T0 L- O: w: H // has no notion of time. In order to have it executed in) A( y0 V- \' V: X9 G- H
// time, we create a Schedule that says to use the
5 T6 r" _ M) k5 Q' W+ e // modelActions ActionGroup at particular times. This
3 x4 K7 p/ |5 o. _5 @4 D7 w- P // schedule has a repeat interval of 1, it will loop every/ o3 v! t1 s7 J1 t2 {
// time step. The action is executed at time 0 relative to* @! E9 c0 ~4 L* d" N
// the beginning of the loop." J" X2 G. T& v. Q% w
. f. w2 k, \4 R* S U // This is a simple schedule, with only one action that is
3 j9 M% ~% F, M& l0 \7 q& a // just repeated every time. See jmousetrap for more/ b8 J" z4 A$ B. ~
// complicated schedules.
: u) ^% Q1 _; }5 K : i) m5 }: b' ^- o
modelSchedule = new ScheduleImpl (getZone (), 1);" L$ l. L# G; D ^( K
modelSchedule.at$createAction (0, modelActions);9 D; y$ k" y5 \
" j+ P& J0 |1 l e
return this;6 Y4 L2 T* P* e% ]" q
} |