HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
, e7 D$ g$ P }( x c- `' B
) v' K& e" N: F public Object buildActions () {
* O9 j O A% U* P1 B' N super.buildActions();
) i6 `% R3 v9 ~0 ]$ V
* U* X6 E; [3 } // Create the list of simulation actions. We put these in, ^& z+ i3 Z9 q# Q. v
// an action group, because we want these actions to be
5 v A- p, x# t1 g // executed in a specific order, but these steps should
7 Z x2 ?0 j r# T: g; i* h // take no (simulated) time. The M(foo) means "The message; x5 ^9 |9 B4 h( k
// called <foo>". You can send a message To a particular, |; E9 M8 }4 ^
// object, or ForEach object in a collection.
8 x/ a5 a! G2 R! V9 q N
- H6 {# b* @3 C% L* n, e // Note we update the heatspace in two phases: first run4 j, r L& m( t* a
// diffusion, then run "updateWorld" to actually enact the7 t, G" ^. o1 k u& i, l6 Y
// changes the heatbugs have made. The ordering here is: {5 S0 q2 R2 H; ^0 w
// significant!$ d. _$ D% W1 b* @# _
0 M% ^3 R5 H! _" @ // Note also, that with the additional, \; w% m, \ }# n" f5 i
// `randomizeHeatbugUpdateOrder' Boolean flag we can
5 @3 {$ o9 H. K/ s J // randomize the order in which the bugs actually run
) Q* a* L4 ]9 W9 i6 X // their step rule. This has the effect of removing any' Z: p: }2 ^* p* P; S/ t
// systematic bias in the iteration throught the heatbug& }# K8 M2 m5 i M' C/ q) T
// list from timestep to timestep
( W( q/ \/ \; V3 ~& w5 |* X9 W
2 @! A0 l6 }+ n* @ // By default, all `createActionForEach' modelActions have: I( u+ S7 G1 f0 g3 G! E0 B
// a default order of `Sequential', which means that the9 l7 O" O6 T1 k( L" O9 n9 R. G$ V
// order of iteration through the `heatbugList' will be
# `7 L$ F! C/ ]( w& ]" j // identical (assuming the list order is not changed; Q5 x$ i r3 ^3 B+ A, S
// indirectly by some other process).0 z! B8 V$ ^. l8 N* J! z
# X7 z* ?- }) F2 z9 Z8 k: N
modelActions = new ActionGroupImpl (getZone ());
( k4 u3 i" M! }+ o* v$ X8 I8 I8 W0 A! ^7 I0 c
try {( j# L6 y) U* [! g
modelActions.createActionTo$message: r6 V: o) m+ R/ P* s
(heat, new Selector (heat.getClass (), "stepRule", false));# M3 A F* N0 Q- K8 N: F
} catch (Exception e) {% F$ Z; K9 o& e
System.err.println ("Exception stepRule: " + e.getMessage ());
2 ~, a( J- l+ p! b; F4 S0 j" O }. ^# t$ e1 t$ d5 I" u/ H
: X' P |! ~6 t* u: Z& D, q. Z
try {
2 E* d3 P) r: s/ j @. c7 Q Heatbug proto = (Heatbug) heatbugList.get (0);: C$ u0 o( |" d8 z
Selector sel = * l7 r6 B; F' h* l& x
new Selector (proto.getClass (), "heatbugStep", false);
) |% I: J4 z6 ]3 l actionForEach =( t) ^4 R8 `, C
modelActions.createFActionForEachHomogeneous$call; }6 k6 Z: ~. L% y3 }6 q
(heatbugList,% K. @: c9 l8 `2 D' v
new FCallImpl (this, proto, sel,
& P+ @* T9 y$ T$ ?& R/ x new FArgumentsImpl (this, sel)));, @+ D' X% w1 }! B8 G/ X& ~# y' {* J
} catch (Exception e) {
T3 }; Z- i- R) g e.printStackTrace (System.err);( V' g% u0 I- {+ H- f9 h9 R9 E
}$ q! d- x4 ]4 S
7 z( j7 B% v3 ^: f syncUpdateOrder ();2 s2 B- ~3 _+ D$ K( N# [
' f' a' r( o& f$ @& x) F$ j5 X
try {
; h# @% E& V7 \* ?3 K modelActions.createActionTo$message ~5 O1 e% n4 \
(heat, new Selector (heat.getClass (), "updateLattice", false));
. {- m; e4 T2 S6 l9 N$ k } catch (Exception e) {' S2 {' r$ _2 o( A. u8 A; g
System.err.println("Exception updateLattice: " + e.getMessage ());
0 j# N% r% P. w! h }
1 U- o2 ~! G0 J) ^9 o
' {3 e7 P3 D1 {5 n0 C // Then we create a schedule that executes the
. p( Z6 l) o8 v& E9 J // modelActions. modelActions is an ActionGroup, by itself it
) s$ L2 p0 D/ c // has no notion of time. In order to have it executed in
! k) e; r r5 Y& T5 e& |4 Z& @ // time, we create a Schedule that says to use the
5 x/ D( z, T9 v // modelActions ActionGroup at particular times. This# T; j' B: v- p2 k* I
// schedule has a repeat interval of 1, it will loop every$ j4 A4 g7 a% o3 J
// time step. The action is executed at time 0 relative to$ V" D4 I# }( K% b
// the beginning of the loop.
3 R' r" b7 l* H, z, H8 S+ X- f3 K5 t
// This is a simple schedule, with only one action that is
6 w% B" k& C( X; Y5 t // just repeated every time. See jmousetrap for more
$ k2 \9 L' y' U // complicated schedules.; o5 p& D2 P4 K2 W, ]5 c
6 c* K3 K8 y7 Y9 x/ a& S2 x7 O$ D modelSchedule = new ScheduleImpl (getZone (), 1);' Y- U5 O, u5 |5 O9 d( S
modelSchedule.at$createAction (0, modelActions);
: V* `& X* E7 {5 Z ; a$ `9 W" r2 M7 L" _; L
return this;% I1 `0 X) y+ p6 K5 M* W
} |