HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
' o1 o/ Z, Q! ~- f9 i8 K6 B0 h$ O9 F% d
) T6 r1 l7 ~. v, L/ \ public Object buildActions () {. [- ^" m6 Y% c M" L( z2 h
super.buildActions();
4 t6 s0 p% ]4 m% q- }
. f L a7 ~ S // Create the list of simulation actions. We put these in
$ D- q u2 U, o {; x1 \$ @ // an action group, because we want these actions to be. M- X% {8 C& Q0 b- |& N
// executed in a specific order, but these steps should( j$ q9 j8 H3 H5 o- t
// take no (simulated) time. The M(foo) means "The message( N9 n. F& _, e% b
// called <foo>". You can send a message To a particular8 H$ i1 j6 W" T( d! n
// object, or ForEach object in a collection.
% y s/ d: \, b9 x: f" Z , C2 b% y/ v6 N5 I2 s
// Note we update the heatspace in two phases: first run+ }/ O( O" l: o5 Z
// diffusion, then run "updateWorld" to actually enact the8 w: E6 z- G7 w# \. {
// changes the heatbugs have made. The ordering here is; |' Q& H0 t; y
// significant!
# O8 `5 y# [8 T2 H* u! S n+ g( w
0 X7 i% Y" F( l$ o! F8 t' }1 x1 t // Note also, that with the additional1 B9 i* Y2 n) L, F- u
// `randomizeHeatbugUpdateOrder' Boolean flag we can1 Q. ]- d3 U, e1 v: g
// randomize the order in which the bugs actually run
8 _2 [; A- V; g6 @ // their step rule. This has the effect of removing any8 Q8 I* k$ ~8 D
// systematic bias in the iteration throught the heatbug% q) Y9 V; ?# d6 U9 K ~
// list from timestep to timestep; F4 ?0 \ ~2 l7 ]3 Z$ A
: l1 p0 n0 A+ d: P2 y" ~' V+ @" r
// By default, all `createActionForEach' modelActions have
* g' v/ G" o, q) |3 i2 ~ // a default order of `Sequential', which means that the
* E: j* c2 n: {+ u // order of iteration through the `heatbugList' will be
/ W7 z7 H4 O) D7 @8 ]* F+ g* X // identical (assuming the list order is not changed0 M4 A. C2 D7 a$ t* b8 T
// indirectly by some other process).
% p- M% a7 y8 y" a: ~
: F4 A6 i8 A. _9 M modelActions = new ActionGroupImpl (getZone ());- C7 ]/ G$ M" p: J0 v& x, }
' d6 `0 p+ H$ ?3 l$ V# i) _' F9 W
try {9 q" q; y i I' C( G/ J& [6 I
modelActions.createActionTo$message
) x# T5 J) C$ L! i+ r, [0 ^ (heat, new Selector (heat.getClass (), "stepRule", false));2 R) L1 _7 |/ Y! f+ G* j
} catch (Exception e) {1 v% I" w$ b$ ?8 w: K0 P$ c
System.err.println ("Exception stepRule: " + e.getMessage ());
3 o0 w7 B9 G6 P$ d; P6 Y }
: K+ m' k. b9 U( A2 r( I* N: i# Z0 t/ v
try {
# ? _! o/ ~- ]+ t5 @/ Q Heatbug proto = (Heatbug) heatbugList.get (0);7 a" |: F4 E( ?3 Q0 L, x) Y& R
Selector sel = 6 \* }) `6 J5 K7 i9 Z; d8 Y2 G
new Selector (proto.getClass (), "heatbugStep", false);2 w( r2 Y- |# J" T& v+ D+ K$ }
actionForEach =
& _3 e7 a7 I: y' A! @6 b6 L5 ? modelActions.createFActionForEachHomogeneous$call
; o7 d$ }' Q3 f9 g) A c3 ]5 X (heatbugList,; a, L9 z8 m8 o3 _6 |
new FCallImpl (this, proto, sel,/ ~! f/ K3 m4 W/ O8 n
new FArgumentsImpl (this, sel)));4 c, h$ y6 [" |2 e8 ^) B
} catch (Exception e) {$ D1 G" }7 P; U/ I1 Q7 E, u! G. E
e.printStackTrace (System.err);
% f5 V" E; T: v. i8 ^: A( F, d }
, ] a) K, v8 o# L 1 _8 t) S4 u3 C7 J
syncUpdateOrder ();! d7 _& |% o" k& T- k! c
' v' d7 G+ R$ z1 u& v try {
* [6 L1 C1 x; f) G2 i' @+ G modelActions.createActionTo$message ! j3 ^/ i) W$ P) ~3 I
(heat, new Selector (heat.getClass (), "updateLattice", false));7 [4 @# K% s8 L3 P; S& l8 ~; m
} catch (Exception e) {; l) L) w# N( w! k6 A* Z
System.err.println("Exception updateLattice: " + e.getMessage ());8 [+ A z N& U% n7 _; `
}, Q$ r* h$ f$ B- u& Q
2 E. L( B r+ n) W2 G
// Then we create a schedule that executes the
# \5 [. |% ]' e" e# Q. @ // modelActions. modelActions is an ActionGroup, by itself it3 a9 |2 w' {( B+ Z, |6 b6 y9 G- t
// has no notion of time. In order to have it executed in" y' b( l' U4 x/ f! R. b! B
// time, we create a Schedule that says to use the% |; I# L5 ?- I0 a* y k% ^
// modelActions ActionGroup at particular times. This* \! ~8 ^* t9 \2 ?0 y
// schedule has a repeat interval of 1, it will loop every0 Y" H# Y3 Q6 v) D9 t
// time step. The action is executed at time 0 relative to, Q6 k8 l/ W% T* P. s
// the beginning of the loop.
+ h% T3 g# W+ _! i3 x% F& o; C* m, D) G# ?
// This is a simple schedule, with only one action that is
3 `0 V2 @ U- i5 R* j8 Q" v$ o' X( }3 ` // just repeated every time. See jmousetrap for more
2 T, Q* m$ R) F8 `/ l0 i5 | // complicated schedules.
+ r n5 ?3 K" E ( z; F4 C }, }3 z9 E2 ?
modelSchedule = new ScheduleImpl (getZone (), 1);
; r+ |% `& c) b0 n7 X! W1 o modelSchedule.at$createAction (0, modelActions);
( _2 A* b4 H2 A( w" `2 w
7 z& |1 t& S# z9 _ a9 F" F return this;
" W$ \& j o0 j8 f' \, e" [/ c' J } |