HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:0 r; E% F y4 a. O
( Q6 f& k6 W/ U
public Object buildActions () {
* E0 Y0 Z/ P9 X" @ super.buildActions(); f7 }8 K7 n" X: V$ G k% |* ^
6 V7 h) U: ~0 g // Create the list of simulation actions. We put these in
" [/ c. M5 Y4 d( J/ P3 H6 Z // an action group, because we want these actions to be
& r: B/ T9 L6 X' q // executed in a specific order, but these steps should
) J9 | `/ g$ A // take no (simulated) time. The M(foo) means "The message
( @' N& H c, X K( F // called <foo>". You can send a message To a particular
0 F! P1 \, i1 V) r% R8 z/ Y3 O- | // object, or ForEach object in a collection.9 p2 w( f# `: G0 ^& @: t
- m6 c% s4 F" Z9 v/ Q3 J
// Note we update the heatspace in two phases: first run- y E7 u( Z5 e
// diffusion, then run "updateWorld" to actually enact the
: O, V/ D2 Q" q* `2 l // changes the heatbugs have made. The ordering here is
" h! _/ c/ J% M) t* k // significant!
/ I7 I3 a: x5 }4 h$ ^7 u3 v : o) w; `5 q. j- a
// Note also, that with the additional
/ d% c( E% |( d2 a7 t // `randomizeHeatbugUpdateOrder' Boolean flag we can* L! z" G: V+ @
// randomize the order in which the bugs actually run+ ~' H7 J' v3 B) s! Q
// their step rule. This has the effect of removing any
: t% W" n' _9 l( W) K6 q9 {0 @' l // systematic bias in the iteration throught the heatbug
3 q; X. H) \6 }- V) _# N // list from timestep to timestep$ X! C+ C9 b; U( H. B4 M' q! |
% ^) q$ O- l) D, J8 C$ s( l" R, R/ e // By default, all `createActionForEach' modelActions have9 g1 v- g5 [' {% z4 d) k J- [
// a default order of `Sequential', which means that the- s$ G8 l) f; S$ j" C
// order of iteration through the `heatbugList' will be
. d+ x3 ]! Y! k5 `0 V // identical (assuming the list order is not changed7 K" C R8 W I. u$ T8 R
// indirectly by some other process).
6 W$ ~' B7 Y( p5 m5 q & ~4 f5 v* t0 T. ]7 W- R1 C
modelActions = new ActionGroupImpl (getZone ());; E, b0 n. c R: H
( V$ g9 z |8 C1 l
try {4 t9 a f% ]6 O9 S% l
modelActions.createActionTo$message
: |8 Q: H/ P7 f. S- c/ R+ R (heat, new Selector (heat.getClass (), "stepRule", false));
' c, t o* P$ k- f' o N } catch (Exception e) {. ]; c$ C8 ?; s v' X f n* B* u
System.err.println ("Exception stepRule: " + e.getMessage ());
5 w0 A0 I5 e- e5 u7 D* b }
* d; n/ s- L6 Z, z. _6 A5 b7 b1 [1 b( H% a* J5 ?$ K7 Z9 s
try { z3 S, }! x/ R
Heatbug proto = (Heatbug) heatbugList.get (0);
3 s- C% r- }8 b# @# c+ N9 E Selector sel =
+ X9 w8 r' }3 L- i new Selector (proto.getClass (), "heatbugStep", false);
* ^* A9 u8 F+ H' x4 k& o+ `3 f actionForEach =" ?9 L$ l- _$ o5 |2 i- K5 U, E
modelActions.createFActionForEachHomogeneous$call
4 z6 O" G" j3 ~& c (heatbugList,
" {. O+ O- L; Q0 I( g new FCallImpl (this, proto, sel,
9 }4 t8 R" } A0 [0 B: v P5 v2 M& V new FArgumentsImpl (this, sel)));
, J. j5 s( M; E; q9 T } catch (Exception e) {
% C/ A7 f( B4 ]2 h9 m e.printStackTrace (System.err);( F9 S H7 C0 A3 H, S; j. z
}- J; ]6 D/ F8 ]$ t4 X5 a6 U$ t8 l, {, h2 |
& p0 t: O: b& _) C
syncUpdateOrder ();; E. w8 x; |9 j C7 | E1 W" t
6 _/ G) A! ~9 U9 `' U. N+ e try {
/ k! m) h, p& U! y modelActions.createActionTo$message
1 T# E1 {% Q& M7 E& O (heat, new Selector (heat.getClass (), "updateLattice", false));
. E& J4 ^9 M3 L7 p1 q9 @& ~ } catch (Exception e) {
4 W% _2 n. g4 s6 k System.err.println("Exception updateLattice: " + e.getMessage ());5 h5 D" E* G! t8 L# \
}6 T7 E$ [, t( t8 P: m
6 @5 P2 C6 @$ T
// Then we create a schedule that executes the0 Z5 n! k! b5 _5 U
// modelActions. modelActions is an ActionGroup, by itself it
# X- G- A* c, S // has no notion of time. In order to have it executed in& C6 g/ i Z0 z5 x+ O
// time, we create a Schedule that says to use the
( Y$ l+ H) K4 Y" e/ j1 d+ O9 o // modelActions ActionGroup at particular times. This( N0 W: j* o, ^8 j: \/ j" D
// schedule has a repeat interval of 1, it will loop every
& ^" ]& x& v, o$ b6 Y* ~3 p+ v6 ~% v // time step. The action is executed at time 0 relative to
2 w9 f2 h3 e, j" } // the beginning of the loop.9 V/ A; H4 j1 L" e" \5 M0 |# \
( C- Q, I( Q7 f6 m1 I5 z
// This is a simple schedule, with only one action that is$ c% ^- `; p& N& m1 d: Y5 S$ K2 t
// just repeated every time. See jmousetrap for more
3 i; N x L* k! _5 K: P8 | // complicated schedules.
& G& p0 P# B+ w- P$ v+ W) x" p$ c % r$ M7 {5 E! f" U. c- ^
modelSchedule = new ScheduleImpl (getZone (), 1);
! I1 l+ ?7 Y: v3 h4 Y$ D modelSchedule.at$createAction (0, modelActions);4 O( U1 ~1 u- G5 w# T
# q$ w( b/ W0 E: B7 p' ~" v6 i return this;6 r- Q0 f" Z. R; s4 ~" ^
} |