HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
_# o4 o- {2 ^% S4 t B0 ^7 i
4 n$ c% f" p/ ?. I( X public Object buildActions () {
& O3 E4 s; U9 L, {- _ super.buildActions();5 c$ p$ @6 C E% L- L
3 {" _0 _! Z! O( ~7 N$ T
// Create the list of simulation actions. We put these in7 n, n6 p2 l) F7 j1 k
// an action group, because we want these actions to be# S+ @+ V- M7 n k7 D: m& Y9 G
// executed in a specific order, but these steps should
" d! Y3 ]6 H; c4 n# L; u, g // take no (simulated) time. The M(foo) means "The message
! g' T- W. E5 I- `* |' r% S' Q // called <foo>". You can send a message To a particular; C0 y2 P" d F- m. I6 M, I
// object, or ForEach object in a collection.. x$ _) R* D8 u' {4 G7 b
7 N& y4 D$ q a4 ?2 M0 A7 W* \ // Note we update the heatspace in two phases: first run
, c; |# y+ ~$ y1 W: J // diffusion, then run "updateWorld" to actually enact the; T$ m, C4 o( E; Q" L
// changes the heatbugs have made. The ordering here is
5 F2 d5 |$ T# ~0 x+ F* X // significant!
% {' W6 F3 ]" m! S+ ] / F9 H8 B# Y0 `& Z
// Note also, that with the additional
* h: O* E" |) i! w( B // `randomizeHeatbugUpdateOrder' Boolean flag we can
+ S# @$ b1 u& _& @" M m // randomize the order in which the bugs actually run
5 E8 n6 A& i% u // their step rule. This has the effect of removing any3 u% g1 ~# E+ ?1 s# [) N: ?2 E, D
// systematic bias in the iteration throught the heatbug
6 b' E$ Q% H1 e, ` // list from timestep to timestep/ S: F3 K( p" e9 V
" `0 P, A% t2 n9 B9 ^$ k6 N
// By default, all `createActionForEach' modelActions have
0 {$ Z. s+ ^1 r0 A8 }3 U- _ W7 w // a default order of `Sequential', which means that the. I7 C @ o% A# e% Z' q
// order of iteration through the `heatbugList' will be1 U4 B- }8 T& {
// identical (assuming the list order is not changed- V ]( D% j, F* v; H+ g6 j( Q
// indirectly by some other process).0 w3 Q6 I8 l1 e6 [
! h9 n2 y/ t0 O. z+ V- s1 N1 s modelActions = new ActionGroupImpl (getZone ());
& \4 I {7 f5 S W, M' |
1 i/ Y' Q: {2 [; ]" [2 E try {
7 t, C- Y. Q6 f- M modelActions.createActionTo$message2 U! U% G. l% f3 Q8 C
(heat, new Selector (heat.getClass (), "stepRule", false));+ N# Q9 m% |! b( I T- n2 Z/ o- r
} catch (Exception e) {
" F% y! ?/ {9 T5 p) j4 O9 ~ System.err.println ("Exception stepRule: " + e.getMessage ());
% N: x1 F6 U" A& Z2 `8 K* |& \ }% `! G! v( t J: k3 `5 n
% w6 `1 C; e& q& u try {# N# t+ \0 |8 q- o: u
Heatbug proto = (Heatbug) heatbugList.get (0);! N& o* o# a) X0 T! W; F
Selector sel = " ?( @7 r" d5 B" |7 F9 @7 R
new Selector (proto.getClass (), "heatbugStep", false);2 G0 T6 O2 m0 G9 K' J7 T8 ^
actionForEach =$ y- t+ p% l3 a
modelActions.createFActionForEachHomogeneous$call
5 K \7 I! F0 _8 j/ ~1 F( I (heatbugList,# V) i _# {& S+ [- M8 e/ X
new FCallImpl (this, proto, sel,: c ?9 \9 q5 [" }7 v0 J9 Z, L6 z
new FArgumentsImpl (this, sel)));4 K7 Y9 { e7 m
} catch (Exception e) {
- \5 a! A* q6 b' |/ a: c e.printStackTrace (System.err);# `9 q2 U4 ^% I- A6 c, H
}
, J6 _* X ?- ~8 b) O) I! X9 ` 6 k" L7 I& d* J
syncUpdateOrder ();
1 P0 v6 ~8 G$ L2 b; |! x( d' O& |" S' n& m5 P
try {
; k& m! N9 C7 [' b modelActions.createActionTo$message
, I. y4 p& t; k3 |: {: F- r4 w (heat, new Selector (heat.getClass (), "updateLattice", false));( k$ Q! ~5 G6 w% t3 x( Y2 Z" p
} catch (Exception e) {8 S k; t U6 K* K t- G5 q6 \
System.err.println("Exception updateLattice: " + e.getMessage ());
5 ]5 ~. V. |0 T# K4 P; c }
3 P d4 G0 W' {) I" p. D- T
5 q c! } Q X* I# I- D; }/ m // Then we create a schedule that executes the
/ S# R$ F6 C5 i2 Z4 W4 r0 [ // modelActions. modelActions is an ActionGroup, by itself it
. H2 @: D$ e& z) \( R. Y+ M" ? // has no notion of time. In order to have it executed in
# L2 |. N# b2 @+ ~% n4 J/ b // time, we create a Schedule that says to use the; |) o, L4 o" L
// modelActions ActionGroup at particular times. This1 _; {. l' U! i
// schedule has a repeat interval of 1, it will loop every
2 C% r* O. {& l3 h3 x // time step. The action is executed at time 0 relative to
( l. X$ L! g2 c- Y7 c2 g) a // the beginning of the loop.6 j7 U/ `4 r/ L
' U1 w. {9 K, @6 J, Y8 z9 Y6 P
// This is a simple schedule, with only one action that is
: o4 B9 f8 O. _: N, h( n1 V // just repeated every time. See jmousetrap for more
4 @* P/ h# }0 j4 E7 O, q // complicated schedules.( A- g2 L+ n( A& x
0 N8 O) S5 p& j. G4 Y; a4 v7 ^2 J
modelSchedule = new ScheduleImpl (getZone (), 1);
& {) a/ j" R) }# V ?0 D modelSchedule.at$createAction (0, modelActions);# |' U- j/ C2 J2 a' g6 Q8 f9 J
( C: n7 r* C% z, h, b6 l( U- j* K
return this;( r) h4 W2 T5 ?" r; t- u% t
} |