HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
, j% c9 P) I4 X$ ~
6 n1 X, {, }+ ]( R public Object buildActions () {: [" w" d7 B7 p/ B
super.buildActions();
, ~+ i' m5 l5 N. U* e# [ 5 Y4 S/ {* i- c( l% n, @
// Create the list of simulation actions. We put these in
0 r: A- N$ W1 o3 s; @ // an action group, because we want these actions to be
8 S J' s! _2 w+ c: a // executed in a specific order, but these steps should
1 B. y. _+ O; y v) T# Z5 | // take no (simulated) time. The M(foo) means "The message, a6 b2 l. \$ E4 ^; N7 J
// called <foo>". You can send a message To a particular" P/ I. K% R$ k h8 N5 }. r+ V
// object, or ForEach object in a collection.$ H3 e+ C. Z1 Z. o5 X
$ A9 @# f* v% k9 D // Note we update the heatspace in two phases: first run
* ], A& D' h% O# d# ?& J# f // diffusion, then run "updateWorld" to actually enact the- m% W* R% i' S8 q0 |, i
// changes the heatbugs have made. The ordering here is
$ a$ U5 T- q, h2 b! L$ T // significant!
+ m9 _# N9 D* v$ e* K1 p ) e+ m" ?5 h% e# J
// Note also, that with the additional
( \) {) K3 k, ^0 M& X // `randomizeHeatbugUpdateOrder' Boolean flag we can
3 ~4 B3 \ Q2 q6 I9 z f3 Y2 k( D // randomize the order in which the bugs actually run; \- `% s5 c3 z$ B
// their step rule. This has the effect of removing any0 }8 @5 k9 L; Z
// systematic bias in the iteration throught the heatbug
* G2 z+ B( z0 J( s5 G6 [ // list from timestep to timestep: z% c* |7 o2 J0 }! s! n" y7 G
* V) k' F, b8 Z5 S
// By default, all `createActionForEach' modelActions have+ q# ?, k: g( v' r- B7 C$ U
// a default order of `Sequential', which means that the& x. p5 h3 d9 Y" b) j6 r6 L% H7 C4 t
// order of iteration through the `heatbugList' will be/ G: o+ {4 H7 @2 g3 H' j
// identical (assuming the list order is not changed! U# P2 n: V2 @) G
// indirectly by some other process).! v1 n: G1 i4 a# F1 h5 N: }
9 ^7 v$ k1 ^% j, A$ M6 A( D A
modelActions = new ActionGroupImpl (getZone ());, _7 S, }; X6 |9 Y
( n# |% s7 h( C
try {
, ~. j; t' T. I/ H ~% |! b modelActions.createActionTo$message6 _0 B7 W/ U0 r" F, f
(heat, new Selector (heat.getClass (), "stepRule", false));; |! V0 m [# k; R
} catch (Exception e) {
5 s+ |& k4 S3 B6 A" m0 i% ^2 D- r System.err.println ("Exception stepRule: " + e.getMessage ());" @. i( F4 H% T4 l
}
6 ]# @/ I# ] _; }* u U, h; Y) f: y: H( }# g, m6 d$ u. u# S
try {' H. B2 K8 d; o' H( M1 S; e
Heatbug proto = (Heatbug) heatbugList.get (0);
0 T) S8 g& D9 N! z) O, J Selector sel =
6 f0 u- }3 S$ ]" G9 J. ] new Selector (proto.getClass (), "heatbugStep", false);
7 r1 p h7 k7 ~ actionForEach =2 D5 ^; c/ [( Z% ^6 D
modelActions.createFActionForEachHomogeneous$call
$ x- ^& d) u0 {, C( b (heatbugList,
' N* q3 D' h2 u/ W new FCallImpl (this, proto, sel,
- |) t( x5 q! A! U1 i. l/ U new FArgumentsImpl (this, sel)));* [8 Q+ I/ B9 ^' q+ @+ s' ^9 C
} catch (Exception e) {8 p( O# i$ ]- q9 N* c* [
e.printStackTrace (System.err);4 w! a% A$ o9 Y; r8 o5 ~0 n
}, o$ S. u# S. ?( T( D- V- S
) ?. \* Y7 H5 N t: h9 t syncUpdateOrder ();
) N% G3 ?3 \* }
[% W. L" b1 Y9 z2 I try {; I% K7 _) r& s% ~- g. x
modelActions.createActionTo$message ) ]' \$ P! D# Y! W4 U
(heat, new Selector (heat.getClass (), "updateLattice", false));9 }) y4 ]0 n" a- w) E5 ^$ U9 t
} catch (Exception e) {# ^% A3 o7 D, O$ c( q+ F) O
System.err.println("Exception updateLattice: " + e.getMessage ());; Q" a( Z0 [( ]+ `" n* u% P
}
: m( d p5 D' X h; n% S& [( M ; r8 {- y$ D* P9 L
// Then we create a schedule that executes the& z/ \4 j, p. `/ w* E" s
// modelActions. modelActions is an ActionGroup, by itself it& S# p) K# |' F Y" _
// has no notion of time. In order to have it executed in0 p, Y* S( k% _9 _! r$ {
// time, we create a Schedule that says to use the' E6 h; |/ G0 u5 I7 U5 a
// modelActions ActionGroup at particular times. This
1 s5 \! E2 S- O4 j3 J9 p* y // schedule has a repeat interval of 1, it will loop every
M; { z, o* S // time step. The action is executed at time 0 relative to( ?, M0 V. _3 _( j$ {9 K- X2 z
// the beginning of the loop.
6 B4 F5 y! C( e$ T7 _0 e# ?; j2 R
// This is a simple schedule, with only one action that is2 Y2 a3 [( t1 J8 X n D
// just repeated every time. See jmousetrap for more
, L, t: T4 S( s" I5 ~- z5 l& q // complicated schedules.( {4 w% A$ B' i& f2 z4 q
& i/ U) _$ U8 I) d% i
modelSchedule = new ScheduleImpl (getZone (), 1);" o$ `- s9 g# W/ ?0 c2 K
modelSchedule.at$createAction (0, modelActions);* ~& ~7 m$ ]' S) R( o) l' q+ L) L
: f6 J# Y# y- l a return this;
# l8 i( n/ _: @/ Q6 a' o% y } |