HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:! Z7 Z R: q2 n
/ ` E/ }' }% C2 j% _2 v public Object buildActions () {
$ L% s! g3 K3 |, _, _8 l7 l super.buildActions();
9 w1 t+ C4 t) c, m ! c" ?4 c, R7 ]& k
// Create the list of simulation actions. We put these in
2 g' ?7 P3 v9 {' \/ q // an action group, because we want these actions to be4 C) y* y* I6 t# l0 r
// executed in a specific order, but these steps should6 c2 w- B1 w# d; Y7 O& r
// take no (simulated) time. The M(foo) means "The message
, z" a9 ^: D/ A c- N6 ]' a // called <foo>". You can send a message To a particular
5 C4 ?$ P* X1 v" L( F // object, or ForEach object in a collection.& d3 ]% V8 B% {2 _9 Q; d8 p
, n' p+ B" I1 E. X' E$ _5 V // Note we update the heatspace in two phases: first run8 i! v: c5 ]4 G
// diffusion, then run "updateWorld" to actually enact the ?+ V8 B* r9 x) M1 c; |: I$ j
// changes the heatbugs have made. The ordering here is4 u* e* b* T( v) w
// significant! K: e( I m4 y1 b$ U
9 i- t' V- k8 ]6 l
// Note also, that with the additional; S" E' }1 u! X' E: y, i0 |
// `randomizeHeatbugUpdateOrder' Boolean flag we can1 Y* I3 B X, C) e$ g* D5 m0 a
// randomize the order in which the bugs actually run
. z+ [2 [! w! Y, [$ T // their step rule. This has the effect of removing any
- P0 r: H9 K5 m" u // systematic bias in the iteration throught the heatbug% Y9 j; O& a+ n5 {
// list from timestep to timestep
1 Z* Q& a8 Q( ]/ u * U3 y* ]0 H8 d* j
// By default, all `createActionForEach' modelActions have3 Y$ |( h3 F( u7 W. J& p8 `1 u3 I
// a default order of `Sequential', which means that the4 @9 u2 j9 w6 n" x* A
// order of iteration through the `heatbugList' will be0 v8 j9 n$ j' X& Z: y$ @. [& {
// identical (assuming the list order is not changed
, c" D1 l' j" }( v% ^4 T // indirectly by some other process). L3 W' b& P" l. [" t
4 B' c' W+ q4 h' h. f+ x! n& {: m modelActions = new ActionGroupImpl (getZone ());( b z' t5 h& `& ?# B, j& y2 ]
3 s7 z# \' Q& ?# t
try {
, }" }, m3 J' Z1 v& ^2 h$ x5 W D modelActions.createActionTo$message% P* M$ c8 L) a& K
(heat, new Selector (heat.getClass (), "stepRule", false));
( p6 N" ?5 n# G; c* h. K3 ] } catch (Exception e) {4 x# x! q7 a: A7 R
System.err.println ("Exception stepRule: " + e.getMessage ());3 o1 d$ a; D2 g- g
}
0 r9 E: t3 U* O8 D% U6 F! N' r2 H! D
try {3 E0 d* ]8 L) A5 G- x
Heatbug proto = (Heatbug) heatbugList.get (0);% }" c- R, H; p2 @4 V
Selector sel = - s3 W2 S+ s. [0 ]2 l- ^
new Selector (proto.getClass (), "heatbugStep", false);
v) U. w. u: N. I) H actionForEach =6 u1 y1 M9 q6 B
modelActions.createFActionForEachHomogeneous$call
2 K0 Z/ z+ E2 h1 E$ r! ?5 w (heatbugList,# l: ?1 a" P5 S5 b4 N
new FCallImpl (this, proto, sel,- [0 O9 m* `4 O% w4 z* e
new FArgumentsImpl (this, sel)));4 [) S$ p9 E1 x! l% Y/ v
} catch (Exception e) {
6 [5 i( O& v( g% I e.printStackTrace (System.err);
( B4 I7 L$ y3 p } W# u$ Z( Z! v5 [
+ X! c" l/ @4 k5 d. i6 z syncUpdateOrder ();
3 V* Z+ q+ f, X& L% e H% i0 ^( n6 G: c) a' k
try {/ C# A/ p; I6 f
modelActions.createActionTo$message 2 J' C7 r2 g ^7 ?
(heat, new Selector (heat.getClass (), "updateLattice", false));
. @4 ` |; l7 H1 | } catch (Exception e) {
/ u- m1 j7 e- x0 ~7 I5 R. E) y System.err.println("Exception updateLattice: " + e.getMessage ());3 _' s9 Y$ @& G1 M M M
}
+ R% m8 _0 V8 h. ? ( G( ~3 c: a% v* l/ b
// Then we create a schedule that executes the
. ~4 ]. {! I. m8 j( r: N // modelActions. modelActions is an ActionGroup, by itself it+ |2 q+ N) ?/ z" `# d; H/ {
// has no notion of time. In order to have it executed in
# f: _. m: |6 W G3 H" ` // time, we create a Schedule that says to use the
8 W/ w* t2 e, d* G( v e // modelActions ActionGroup at particular times. This% C6 P7 U+ U5 g" ]' Y
// schedule has a repeat interval of 1, it will loop every/ M7 T* ^% Z" r, i+ |1 N( f8 [
// time step. The action is executed at time 0 relative to0 Q5 P& L0 O; X( X, }
// the beginning of the loop.
& h6 j7 o( f4 e) A, T# S0 j x: B0 z, G
! @% M% h: D7 R* T% z/ [7 k // This is a simple schedule, with only one action that is
- P, E6 \& v d, p5 K // just repeated every time. See jmousetrap for more& J( {* M2 N1 J# L! K9 \
// complicated schedules.4 f' z2 J% @- f' f
4 X5 S) {8 N6 }' t4 ~3 H6 a8 t- U
modelSchedule = new ScheduleImpl (getZone (), 1);
% |! F. D& `% J- @- G) P1 a modelSchedule.at$createAction (0, modelActions);
& ]) ?5 B; {$ ]. n
; q& A- T6 U L9 H9 M return this;9 ]; o5 [' L1 o9 R3 \
} |