HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' ^7 G. J+ F. u" X8 H
9 B F' S& O( D# s# ]' C/ ?9 ?# g% \
public Object buildActions () {
5 H' E4 h- U9 O4 ] super.buildActions();
$ y \$ S5 H' j D B, s" r9 `8 z5 ^3 G" \
// Create the list of simulation actions. We put these in
( E9 q" \: l9 _0 a // an action group, because we want these actions to be! {/ M( k# X, Z8 S/ U
// executed in a specific order, but these steps should
r% d# h$ P1 \( A% I // take no (simulated) time. The M(foo) means "The message
" ^. k, n$ I0 H$ W: h! l // called <foo>". You can send a message To a particular) c# q/ t- a3 s6 ?: c4 V' ~; U
// object, or ForEach object in a collection.* q! x. z( A+ s) Y! X/ H. t9 o1 C
c }+ B E3 J2 H$ k: {" w // Note we update the heatspace in two phases: first run8 W0 W6 a9 o% u# v, }! U
// diffusion, then run "updateWorld" to actually enact the' P/ L, r- M! H. r+ D1 U6 q) W
// changes the heatbugs have made. The ordering here is6 s$ S9 T! ~% x& W; _4 H# J
// significant!" O# j' [- C c9 U4 o: [& ]9 U
5 Y- k5 F6 l7 q& Z8 z# ^
// Note also, that with the additional' j: G8 ^, h8 X: j
// `randomizeHeatbugUpdateOrder' Boolean flag we can6 ?6 R7 ?( k: Q% |% s% R. M P2 [8 B
// randomize the order in which the bugs actually run! I4 C9 z) s$ w, [ s" @0 x
// their step rule. This has the effect of removing any' V U9 u4 N( u5 K5 t2 V
// systematic bias in the iteration throught the heatbug
: H. U( s1 K* k7 w8 [! Z. \( X // list from timestep to timestep
! h2 G$ k9 i/ C. K! l& E
4 u; D1 f( f# ?3 [& r // By default, all `createActionForEach' modelActions have1 O- `; w2 E5 r2 P# u" j
// a default order of `Sequential', which means that the, f/ B' s2 x7 Y; y1 {1 d
// order of iteration through the `heatbugList' will be
% u+ m0 M1 `' A5 I: U // identical (assuming the list order is not changed& B! N) A& \3 P$ b
// indirectly by some other process).% P% Q- t- T6 ~/ }0 ^9 p
: o6 t* S6 [) c7 | modelActions = new ActionGroupImpl (getZone ());
4 T- `! I# ~% I+ g, I- {' P, K& @7 I, j) D5 I, r$ Q4 ~" x/ [5 Q
try {
; _# R+ L$ R6 r, S9 h modelActions.createActionTo$message
2 c4 T1 [6 y. H8 a (heat, new Selector (heat.getClass (), "stepRule", false));5 m5 B6 t" U t1 e$ d
} catch (Exception e) {
9 _ m& G6 x/ ^6 l6 `" M* A System.err.println ("Exception stepRule: " + e.getMessage ());6 X+ C* O! P0 }: P
}& E( Z' s. q% i& `. N( p# m( c
2 e4 f8 P$ s6 ~$ q, {; N- Z. V" g( [3 ] try {
. Z$ w1 l" R* |# W! s' N/ r Heatbug proto = (Heatbug) heatbugList.get (0);" z2 C8 S, d9 {. T
Selector sel = . H2 J# D. ?9 ~- p% h: n6 V
new Selector (proto.getClass (), "heatbugStep", false);& @* _6 _) j$ j- r# v. e: R
actionForEach =% Z8 ~) E4 s, }" P, {# j$ ~
modelActions.createFActionForEachHomogeneous$call
* m: k5 L! V( |& C# w$ q (heatbugList,
2 j( T! j9 c6 w8 W, [; J8 n new FCallImpl (this, proto, sel,9 O6 |# F2 e/ C
new FArgumentsImpl (this, sel)));
" j( S3 s, S L: ~- Z } catch (Exception e) {0 ~8 l- x- a3 t" z5 k2 D# H9 E0 k
e.printStackTrace (System.err);
6 ~2 A- _3 Q" |' E }8 J) D$ M2 ?- @1 Q7 n) Q
1 a# I: P4 y' Y/ d" ?
syncUpdateOrder ();
/ N. c$ V: Z3 q, O
0 B7 ^' v/ [% e" I$ g5 s try {' k& M8 v5 S% W' o+ U
modelActions.createActionTo$message
+ P$ Z; d8 h" n9 ~, O" c (heat, new Selector (heat.getClass (), "updateLattice", false));. x) Y& O& N3 `4 B
} catch (Exception e) {
, |4 r0 U- U, S* Y5 E, Y System.err.println("Exception updateLattice: " + e.getMessage ());
, p, \1 c) a2 X }
, t- S6 I; t* z! J8 T5 ^* r# Y0 W 5 G; m5 I7 X p" \4 o9 a
// Then we create a schedule that executes the+ d% p: R" ~( W" d* G% N
// modelActions. modelActions is an ActionGroup, by itself it
% C( C5 p# h q5 P- b. S) K // has no notion of time. In order to have it executed in* N) M* N* M. w, D% q
// time, we create a Schedule that says to use the; g' v) f! t! i8 y/ K% u" x4 L
// modelActions ActionGroup at particular times. This
$ | }8 d$ ?' O8 [. h' _ // schedule has a repeat interval of 1, it will loop every
9 b2 d/ A! j) M7 A/ ~ // time step. The action is executed at time 0 relative to: S. h0 H) v# R X
// the beginning of the loop.
- V9 A1 U, b: S2 p# p" l
* g: ?' F9 E6 W, j( ?. P% R5 S // This is a simple schedule, with only one action that is' w! l4 T# u- W/ V. b
// just repeated every time. See jmousetrap for more
K1 p0 V0 Z6 v; I! i# \: @! R // complicated schedules.
# W+ t" n" ^8 h. c0 M1 B9 W; R
0 T6 N) n Y( K W% O- a modelSchedule = new ScheduleImpl (getZone (), 1);
; O8 P& `: P2 F/ V$ T modelSchedule.at$createAction (0, modelActions);
~6 I+ V* c/ i1 {' l& |
8 G8 Y0 ?# V7 A# R7 C$ i3 p return this;
7 g1 M! t$ ]1 N- w" R: h } |