HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:2 }- I' q9 s/ n& r& B
" B1 ?6 u6 o+ W$ q
public Object buildActions () {- _! m$ k0 |( T5 K6 O% X; l( P
super.buildActions();8 h% d% c( D4 d9 x- x: H
4 j6 g4 m% ^% ^4 d8 V // Create the list of simulation actions. We put these in
% \- u5 S. {7 {% j, X/ p4 W+ M: b // an action group, because we want these actions to be5 E9 I7 {0 F% M0 V( E) W
// executed in a specific order, but these steps should
F9 z/ b! `+ y- T, @. K7 }; | // take no (simulated) time. The M(foo) means "The message0 W6 y$ i% u6 f( v1 G! p" c
// called <foo>". You can send a message To a particular# c D8 B, d l9 l
// object, or ForEach object in a collection.
1 F% T. y' `: @ " h9 U6 g- u8 i" C. t0 x
// Note we update the heatspace in two phases: first run+ d# c7 _1 W9 L1 Q& b( w- ]6 }+ P
// diffusion, then run "updateWorld" to actually enact the
% g5 y" E- K& f7 d5 j% @6 Z6 A // changes the heatbugs have made. The ordering here is; p# T9 J3 x( c# l# h4 Y* H, W7 I
// significant!
9 s0 U/ ^( D- z ^& N+ z* [0 u4 @7 H
// Note also, that with the additional: ]3 q9 L4 }$ |$ a
// `randomizeHeatbugUpdateOrder' Boolean flag we can& O/ W% \/ L0 r4 R3 l9 p
// randomize the order in which the bugs actually run& `8 C. x9 \0 _7 c" F: G
// their step rule. This has the effect of removing any" h- a2 {7 `3 R% E/ T% n+ g
// systematic bias in the iteration throught the heatbug% R6 O) e- u! l1 Q: h8 W. R; i' w
// list from timestep to timestep# L( y/ m6 w# I6 f
0 _5 k. A, l6 A$ N
// By default, all `createActionForEach' modelActions have3 b, D Q0 z1 u' X) A
// a default order of `Sequential', which means that the
( u4 P7 Q9 G0 y/ H2 J0 F9 t5 { // order of iteration through the `heatbugList' will be
3 m. X1 @! u4 B, g% e) |3 Z // identical (assuming the list order is not changed
; t \" v( o9 `' @3 R& x9 E/ ` // indirectly by some other process).
3 l# m5 N. s. U. w$ G
! u* _, r H. j) z0 J- d modelActions = new ActionGroupImpl (getZone ());7 k. {# M/ Q6 l8 B
% ?0 y! Y7 Q1 E
try {0 c0 K9 W: U! l% e: O' s9 v. U/ Q
modelActions.createActionTo$message/ q. g: O2 T; X# V9 Z# i
(heat, new Selector (heat.getClass (), "stepRule", false));
m: M7 x% }/ Q. \, ^2 c% B0 ]0 a8 h } catch (Exception e) {
0 k# @" k. t0 s" `/ H5 x System.err.println ("Exception stepRule: " + e.getMessage ());$ I6 o2 T3 {9 `
}: v7 I/ M3 b1 ~1 j. y7 }* B
. [0 J q5 s+ f
try {. ]3 Q' s) S+ [7 d+ \
Heatbug proto = (Heatbug) heatbugList.get (0);$ K" _1 n+ @; }! ~
Selector sel =
/ G/ E7 @- J( L" M new Selector (proto.getClass (), "heatbugStep", false);
* M9 E1 u+ H7 B' ?6 N; L actionForEach =
2 M7 T) P$ _; X0 c5 r. r! ^ modelActions.createFActionForEachHomogeneous$call4 z; t5 w7 b. m, e) f& V* l
(heatbugList,% f$ C, H( v/ M# S# g% p: T
new FCallImpl (this, proto, sel,
4 B6 _: d/ P/ t& B! @3 B new FArgumentsImpl (this, sel)));
" x3 i$ A+ y! _, S* s, E, | } catch (Exception e) {
3 }6 E. y9 n2 Z) { e.printStackTrace (System.err);9 o' t; I5 w1 A8 ]; n1 Q
}0 M. t! ?; U& r/ b- H
1 e. H3 I% q" _( x syncUpdateOrder ();
) G- W- N4 D7 ?9 V& `$ d
( r! [6 X ^+ N+ i try {9 {! r/ Y/ k9 r% I3 N! k) @
modelActions.createActionTo$message ' q0 ^1 N7 u" K! N
(heat, new Selector (heat.getClass (), "updateLattice", false));' f% ~3 j7 }) i: s* T: _- I7 r* I
} catch (Exception e) {
- v4 w/ K- A* J System.err.println("Exception updateLattice: " + e.getMessage ());
4 Y/ _$ r! B: ]+ L2 c* q9 D* f6 { }
3 n+ m8 S* r' a. [6 T5 M
! a8 U! d+ w9 W& v m* y // Then we create a schedule that executes the& D( H h9 i! A; `1 }9 e
// modelActions. modelActions is an ActionGroup, by itself it, @. z B: G$ | K# v( O0 `
// has no notion of time. In order to have it executed in: F: w3 [/ C- }0 [/ k9 _
// time, we create a Schedule that says to use the0 P" `2 k1 T1 `
// modelActions ActionGroup at particular times. This3 M9 g' J" Q2 }9 }0 @
// schedule has a repeat interval of 1, it will loop every. J# N8 z4 ~8 F7 E6 j% ^
// time step. The action is executed at time 0 relative to
& e; \$ t" m1 \* [6 P7 U$ c5 s // the beginning of the loop.3 Z) ^' e: }& {1 I: w5 j J
/ x. w5 N# {9 f1 u+ {! J; W/ M6 r
// This is a simple schedule, with only one action that is
$ B/ L! D. H2 a1 i // just repeated every time. See jmousetrap for more' v% t& }7 A2 s/ F- v
// complicated schedules.
1 \% D# i, b7 l4 O 2 u6 h+ c# Y# Y! d$ v
modelSchedule = new ScheduleImpl (getZone (), 1);
: j* z% O- A4 I2 t) F3 R' Y modelSchedule.at$createAction (0, modelActions);! w$ I+ s) a' A& `- r4 `% O& W! Q
5 d5 d8 j ]' R0 R. z- c
return this;9 |9 x+ N' D1 d* ?" t3 B
} |