HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:/ R/ ` A( q4 @6 `3 ?3 P+ g
* n& B0 F) ?& k2 e* u1 N
public Object buildActions () {
9 E A' S1 m& @2 d3 c- h9 }* _+ V super.buildActions();* I) J5 `' w$ U. d
# t$ z2 w7 b! {, P' P0 @ // Create the list of simulation actions. We put these in. Z; s; }4 B6 C; H6 R
// an action group, because we want these actions to be
' a) A7 U& l8 \ // executed in a specific order, but these steps should
9 Q0 L( r8 h9 B3 b. Z7 W // take no (simulated) time. The M(foo) means "The message
; k( b9 ^; r/ C. g3 e) j // called <foo>". You can send a message To a particular- r K1 v& i! I2 J$ [
// object, or ForEach object in a collection.6 [* ~, @1 o* f2 E( `
- D( u6 J7 c, E/ B2 ^- l, ^ // Note we update the heatspace in two phases: first run1 X' O) J; ^8 J: Y8 x
// diffusion, then run "updateWorld" to actually enact the% G n/ v- k+ n8 P% {
// changes the heatbugs have made. The ordering here is
p3 Y, R! y R1 b // significant!; G3 a+ R* C2 `* l! H. f- V
1 ~2 I7 T+ A% f3 E
// Note also, that with the additional
9 m9 X5 Y6 T, S# s! @' y9 q2 Z- J // `randomizeHeatbugUpdateOrder' Boolean flag we can4 p g. q' l* G' c d0 }
// randomize the order in which the bugs actually run
: z7 u' e0 z( B3 X% o0 r0 G // their step rule. This has the effect of removing any
+ ^& s W$ m% g9 ~ // systematic bias in the iteration throught the heatbug
5 Z8 d* Z+ I7 j // list from timestep to timestep* b& Q# ~7 |% Q. n2 g
% d$ S. M6 f: U0 d2 k# f: W
// By default, all `createActionForEach' modelActions have
r/ Z' J: f+ z // a default order of `Sequential', which means that the* U5 w. v7 Y( j3 E. H
// order of iteration through the `heatbugList' will be
. v5 w5 u! T3 q* }1 Z9 L0 t/ @ // identical (assuming the list order is not changed: m# b4 p' I g- t. c( c9 p1 W
// indirectly by some other process).
/ ^9 d" _" e* ^9 j: R5 k+ L- k! r / B' {' O H2 ~+ E$ E- A- y4 G/ V1 s) {
modelActions = new ActionGroupImpl (getZone ());
, R- h( B- d; X* V# B
8 B, ~2 Q% o& ?1 y2 T% z try {
- S9 j& z6 K& X0 w' B2 K. ] modelActions.createActionTo$message
0 r( f! @- W$ \2 K (heat, new Selector (heat.getClass (), "stepRule", false));
# |1 y0 |" r& y } catch (Exception e) {
: }6 J; o* k8 n/ ?* W System.err.println ("Exception stepRule: " + e.getMessage ());
0 q6 z! S7 I& E }; ^: T3 Q( ?: C6 v; P. x$ j! o- B" q
0 ?3 r3 h6 A3 `3 O5 p5 [
try {
* S$ @6 H6 d0 \ Heatbug proto = (Heatbug) heatbugList.get (0);
9 e% ~5 o! k/ `, V0 L Selector sel =
- ^7 ^9 X& J4 Z' l+ T* F new Selector (proto.getClass (), "heatbugStep", false);
Q) H% B4 e8 l# j5 v% x) e actionForEach =. b+ O$ Z! k% M: t: c8 H1 I0 N+ g7 b# u
modelActions.createFActionForEachHomogeneous$call9 ~3 u5 D& _, q' z" Z. T4 J% B
(heatbugList,+ [- l6 x9 \5 A; J t, o; o! c
new FCallImpl (this, proto, sel,7 U+ k6 s- _. \' d+ M6 N
new FArgumentsImpl (this, sel)));- n1 s4 B t5 F( Q5 ~' s& o+ v
} catch (Exception e) {
+ j( \& H0 O' D/ O2 I5 c' O: ? e.printStackTrace (System.err);
( c! N G9 M+ v }2 T3 L& n5 Q+ L( }5 D/ B! j! a; j0 Z. R
6 l8 J6 G9 k* n+ ? syncUpdateOrder ();
. ], R, @9 }0 ?+ A* [, d
. N4 [* e& y0 J try {
8 d+ c9 y# b8 N1 [) A. e1 M% t& B modelActions.createActionTo$message
. |1 M" V n0 Z- E7 i (heat, new Selector (heat.getClass (), "updateLattice", false));- u; H5 ?- I8 L( J/ G1 A
} catch (Exception e) {9 k3 J9 i3 U9 j) z% c( ?: E
System.err.println("Exception updateLattice: " + e.getMessage ());8 C4 i0 C6 N/ d7 N& @
}6 z- Y4 M1 N8 E# V8 @1 o8 ^
6 h8 I3 p" |# N5 J' r, @' \+ ], `, F // Then we create a schedule that executes the7 m3 E7 o3 q, p' D3 O- y
// modelActions. modelActions is an ActionGroup, by itself it
- J# {" J! E2 S7 {$ t' f // has no notion of time. In order to have it executed in
! ^: y' |& N; v4 U! b7 q0 x // time, we create a Schedule that says to use the3 t! a) o9 [. r6 q
// modelActions ActionGroup at particular times. This
W6 i' S5 _/ g) H: B // schedule has a repeat interval of 1, it will loop every/ R( E; W/ z" [+ ]
// time step. The action is executed at time 0 relative to% P& m: I/ C- A) ~8 y0 o- Z; K' e
// the beginning of the loop." f; [2 z) _" E
' \8 Y. m0 H. }0 p
// This is a simple schedule, with only one action that is
2 {$ h4 @) Y, }4 K+ | O, P // just repeated every time. See jmousetrap for more
/ W p6 V$ A" C, m D1 @ // complicated schedules./ G' Q9 v5 H2 B. ^
: [0 P1 M5 w$ [0 j1 k
modelSchedule = new ScheduleImpl (getZone (), 1);
& ?6 ?5 f% }1 k modelSchedule.at$createAction (0, modelActions);
! h6 Y0 ^* @+ p1 `: V
" U9 ?3 L5 }: @2 F return this;
+ ~% P7 q9 H0 m+ d0 \. m } |