HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
6 _" n+ y) r7 j8 Y4 n3 n/ q, x+ Q; y' h$ T4 z5 t7 }
public Object buildActions () {* H0 _! d$ E X3 h$ O; [+ n6 Y
super.buildActions();* |% S- d; h& e0 X2 q$ J; ] b: I
/ [' D! W5 [$ i! y
// Create the list of simulation actions. We put these in) h, z* s- f; W% Q% d6 n2 m
// an action group, because we want these actions to be. i- q7 |7 G5 w* M7 V% Z: K
// executed in a specific order, but these steps should
& s6 ^) ~; ~. m- V; d* \ // take no (simulated) time. The M(foo) means "The message. e. K* E! Q: e. r
// called <foo>". You can send a message To a particular
; B- {# _8 A2 D- c: E3 c // object, or ForEach object in a collection.
, v5 R! I7 \2 i1 y& {3 C: g
. x' a$ E h& o3 y: U // Note we update the heatspace in two phases: first run
8 s/ x8 w- b- i- a- h3 W7 c$ R& l // diffusion, then run "updateWorld" to actually enact the, q9 F4 J( p/ e+ L
// changes the heatbugs have made. The ordering here is
; t: I+ r8 X9 n- v7 Q // significant!
& f! n% o r: W0 k& I
4 `' H- f, e# X/ q. W; \ // Note also, that with the additional7 }1 o* }" ]! B4 l
// `randomizeHeatbugUpdateOrder' Boolean flag we can; m6 H% o7 H8 ~1 ?3 i# ~
// randomize the order in which the bugs actually run" S0 w: h! |) {+ f
// their step rule. This has the effect of removing any N. T8 b3 c* [& F
// systematic bias in the iteration throught the heatbug
m8 v6 m$ T5 i3 C. T' m // list from timestep to timestep
! Z x& k+ R: V7 d: r h* o
* v5 z) Y v( J" q$ i2 k# ?. I // By default, all `createActionForEach' modelActions have
! V$ d$ {; Y% `+ F- O- s$ P // a default order of `Sequential', which means that the
$ n4 C" A, ~' H! P# U- C+ A1 D! s // order of iteration through the `heatbugList' will be
# B: j1 t- | I // identical (assuming the list order is not changed, {6 K' X8 ^! Y& _4 v0 I/ l
// indirectly by some other process).
2 m0 O9 D9 w, ^1 E/ M" D- L% J: T m# p0 {( r. \/ H2 a/ F
modelActions = new ActionGroupImpl (getZone ());1 F: d$ k; x" w7 m E5 b
' ]( b7 P& y; k0 |% a
try {
- B/ u, o) Q5 y) z1 V v modelActions.createActionTo$message& o, z5 k x1 i
(heat, new Selector (heat.getClass (), "stepRule", false));
$ A; L( t" M3 N! | } catch (Exception e) {7 k# i/ F' Q$ m, X$ S7 @
System.err.println ("Exception stepRule: " + e.getMessage ());- A) `1 E4 J7 U
}
! p4 B8 \$ p" K: U2 @* z* M$ ]2 v0 r* w# C1 p* m7 C/ `
try {3 e: ~2 c0 u: D; f
Heatbug proto = (Heatbug) heatbugList.get (0); d+ Z( s* n9 U& f5 F4 L0 \! e2 B' y# F( ?
Selector sel =
! o% Y+ y8 n/ ?4 H' o' j new Selector (proto.getClass (), "heatbugStep", false);
4 u7 B: b1 k5 T6 p% c! A actionForEach =
+ F. E; ?5 e* k modelActions.createFActionForEachHomogeneous$call7 D. l `4 J ^; s# T4 Z3 G: N! S, F
(heatbugList,
D2 G A, o8 {2 I' D new FCallImpl (this, proto, sel,( Y! @) {8 H* b l% M9 I% p6 J* r$ V
new FArgumentsImpl (this, sel)));5 [' ?9 O9 V# K2 Z
} catch (Exception e) {* v" V& }1 O& |$ m
e.printStackTrace (System.err);8 v |/ H8 E, Q7 |. z: c( C% D# L( i
}8 O' ~8 D! d' K4 _8 |
1 v' z% G3 j2 Y) N6 [
syncUpdateOrder ();7 U; }8 Y; D! G. G/ M
8 H; r" J3 x9 ]4 b try {
& Y6 s, E: a" b% _$ J& i modelActions.createActionTo$message
+ z, H* Y( m: w8 F6 J$ R& L (heat, new Selector (heat.getClass (), "updateLattice", false));
3 T6 |# z0 {# G% n } catch (Exception e) {) e9 I1 x+ l0 D
System.err.println("Exception updateLattice: " + e.getMessage ());
3 v. y B; \3 p+ z }7 ~7 x. E. a1 O+ {, `
, ?# W3 C+ { L7 N5 M: f
// Then we create a schedule that executes the
9 d' E' H6 U3 M // modelActions. modelActions is an ActionGroup, by itself it2 q1 ~4 u8 K5 L: O R
// has no notion of time. In order to have it executed in
- W- m5 h, s* N, C // time, we create a Schedule that says to use the8 |0 [9 o6 F! q" V( w- l! x5 J
// modelActions ActionGroup at particular times. This A& G- d4 Q- h1 O, n9 P2 A
// schedule has a repeat interval of 1, it will loop every1 k+ c9 `# ^0 H$ h% c0 s# N9 r
// time step. The action is executed at time 0 relative to
- R- G$ H6 R' E // the beginning of the loop.6 x, I0 g; B G7 |, B& I* [
- z2 R3 w; o9 U- c$ B // This is a simple schedule, with only one action that is
2 X6 C2 M4 I+ ]9 G // just repeated every time. See jmousetrap for more
& `5 ^# O7 }8 l# } // complicated schedules.
j$ g" B% W/ ~/ G9 R
8 @& e" y6 ? D& ?, g9 G Y modelSchedule = new ScheduleImpl (getZone (), 1);
. N x4 e- X, w' \ modelSchedule.at$createAction (0, modelActions);2 c' P4 r q5 c' z, B
W* h6 b8 i' A* ^$ L9 X
return this;
' s/ h) d, v& ?; J } |