HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:- l8 }/ L7 e) k
% G; i' j$ d) l' Z5 I' ] public Object buildActions () {% w+ g) Q& P9 l9 _
super.buildActions();' ?) I$ W, b" ]4 w
" n* j2 ]! G" l; u- r // Create the list of simulation actions. We put these in* Z- r3 j# O/ o! [: W% m6 v+ b8 U. ^
// an action group, because we want these actions to be) Z/ [2 g8 j( T- ~/ E
// executed in a specific order, but these steps should
* W% F& d& F( g9 ^- e, u! s // take no (simulated) time. The M(foo) means "The message7 Z5 g8 w$ ]: G2 y7 l/ h- l
// called <foo>". You can send a message To a particular
3 O% P$ A L2 C1 [) w& [ // object, or ForEach object in a collection., j9 b: }1 m/ i# h8 r
7 B! ?# o- i" M" `& q // Note we update the heatspace in two phases: first run
$ V* u+ L, j0 S4 y- [$ v% ~ // diffusion, then run "updateWorld" to actually enact the) l1 Z3 v c; ^! u; [
// changes the heatbugs have made. The ordering here is4 _6 Z! D1 _$ m" G' Y
// significant!- \6 S* T# S1 Z% ]- u' n* q; r* E5 x
+ m" \. `* L, J0 O9 `
// Note also, that with the additional
. O! W, P8 U6 \ // `randomizeHeatbugUpdateOrder' Boolean flag we can. p$ j5 k- Y& Q( \
// randomize the order in which the bugs actually run
% `' i! c# K$ S6 l/ `# F- E // their step rule. This has the effect of removing any! |- r# w. ^; c& k# i
// systematic bias in the iteration throught the heatbug* j( G5 v* `; X8 v
// list from timestep to timestep
0 Y v" `& k8 V. D; I 3 q; }' T. n3 a" q( C- \
// By default, all `createActionForEach' modelActions have
: E/ b. ~! w) G* U8 y; f/ s // a default order of `Sequential', which means that the4 Z9 U; Z% Y+ F: Y& |2 [
// order of iteration through the `heatbugList' will be
- W' F4 E0 N8 _ C7 [ // identical (assuming the list order is not changed8 A8 T- Q( h T
// indirectly by some other process).
1 Q6 \# H" b) r! X3 I5 L4 h m3 V 2 ~* J0 m& r+ S4 o8 G
modelActions = new ActionGroupImpl (getZone ());
1 x$ l' y& h! T1 {* J9 f! I3 ^
& }6 T& \0 l- \! Y5 ]% d try {
3 Q' J$ E5 b/ w% I* [ modelActions.createActionTo$message. W4 I3 Z4 W+ v; m- P# U. r* ~
(heat, new Selector (heat.getClass (), "stepRule", false));( p: z2 a+ \: N& S4 S6 V! |( W
} catch (Exception e) {
% a/ p6 W! _' S1 Z System.err.println ("Exception stepRule: " + e.getMessage ());
% V1 C, q* x$ \, H }
, @' t Y5 C; U$ k/ h* S' n
* _/ ]+ |3 p7 p/ A8 a try {* Q4 k6 s, m/ p$ z0 p* X: h* ~
Heatbug proto = (Heatbug) heatbugList.get (0);
! g6 e# Y( u4 e" x) y* o9 } Selector sel =
0 b, j/ T! x" Y( ~' _ new Selector (proto.getClass (), "heatbugStep", false);
7 q! j& E4 |1 u; H# h3 |% U actionForEach = |. h' N% i9 y
modelActions.createFActionForEachHomogeneous$call# _( X, k& A4 w% R$ }. E+ \0 V
(heatbugList,
0 {4 x$ {# s h# L new FCallImpl (this, proto, sel,( n# [: E s" M$ P! \, \$ z. w
new FArgumentsImpl (this, sel)));- k' ^; D- X5 \' c* N& N
} catch (Exception e) {
0 B7 {) [! o8 b1 H- F9 J e.printStackTrace (System.err);& V) h2 q( d( H8 c7 d# z
}
6 r z& c; y, @% C, g ) Z, |- ?0 ]. M6 d$ v- C- v/ R3 U
syncUpdateOrder ();: p5 O. {" ^, T, C
; [1 N5 O( A6 V& c: n; |9 j" e
try {" i/ {% ]! H+ d( f0 D
modelActions.createActionTo$message - Z4 \/ g1 V' k: c0 a
(heat, new Selector (heat.getClass (), "updateLattice", false));
! e' P7 \ C1 b, J" k. z9 X } catch (Exception e) {
2 T7 d3 F a. l! ~7 K5 z/ k System.err.println("Exception updateLattice: " + e.getMessage ());
; T- c- E5 v) [+ w+ z5 D V7 u, m1 g }! _! Y0 H" N# q& d" W. z4 r k
6 e6 c" i8 h. J7 {$ }& n( J // Then we create a schedule that executes the
1 M0 g6 u3 ]+ T // modelActions. modelActions is an ActionGroup, by itself it
: L, Z/ m" \4 L // has no notion of time. In order to have it executed in
5 @( S! k: y! g0 k // time, we create a Schedule that says to use the- L- I- Q7 W- ^ J% o0 E5 T! h
// modelActions ActionGroup at particular times. This V. D/ _* N& t
// schedule has a repeat interval of 1, it will loop every
8 H4 x1 ]3 o( } // time step. The action is executed at time 0 relative to
3 e0 l0 L c# |4 } // the beginning of the loop.4 V1 a- ^$ D1 k* ~6 Q: m
2 J& d! y7 w" V: S, M( j // This is a simple schedule, with only one action that is
0 J- i/ x( K7 O: z0 ` // just repeated every time. See jmousetrap for more( m! N2 H7 Q8 @2 {. q$ A
// complicated schedules.+ _. m" H: x6 [) ?( b/ n
+ D0 g4 [7 c3 ?/ x" T. t# e modelSchedule = new ScheduleImpl (getZone (), 1);# Y2 Z8 _' |, v+ T
modelSchedule.at$createAction (0, modelActions);3 ~8 t4 [+ X/ W/ Q; k- N
5 o' h0 e1 [5 x6 J" [- M, n return this;9 v4 |9 _% e5 ^( A8 ]1 j
} |