HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
0 H: r; g1 e. ^* C
) b Q4 }$ s: s& h3 ^5 o- }4 ~1 X1 N8 @ public Object buildActions () {! \. }# s1 c+ m: I
super.buildActions();
/ H: F0 @* m& R" U) S / p7 k( q$ J' F
// Create the list of simulation actions. We put these in
( g" G# L+ d( J5 {9 ?, y5 |, [ // an action group, because we want these actions to be
+ s3 h1 [1 W' ]7 \( H // executed in a specific order, but these steps should
+ p8 y7 M: \1 A, L( }* O. v // take no (simulated) time. The M(foo) means "The message
" ^- u+ M$ F7 O5 x // called <foo>". You can send a message To a particular
" o" W+ ~; V0 G" [# k3 s3 v) h // object, or ForEach object in a collection.. ]# G$ R- C. A0 Y! n
- B! W/ B9 A- w( ]/ r0 p# S) j // Note we update the heatspace in two phases: first run+ G/ s- N4 a* _, G" T
// diffusion, then run "updateWorld" to actually enact the+ ^9 h x, b H2 Q% N! w
// changes the heatbugs have made. The ordering here is
- g/ p0 _- n7 L& J4 [ // significant!# l4 k! x3 Z% R/ |! ^8 A
m7 F" F2 t, p
// Note also, that with the additional! Y. z4 @8 b$ V0 m: e( ^6 v' E, h
// `randomizeHeatbugUpdateOrder' Boolean flag we can
* P7 K& N7 `0 O: T7 `! g // randomize the order in which the bugs actually run$ {! u: G7 A" u" T0 f/ ^' g" r" J
// their step rule. This has the effect of removing any
7 c: V @. G* r1 w // systematic bias in the iteration throught the heatbug7 y; m3 z' E- |: v. _. l
// list from timestep to timestep k ]: S) ]; \) M4 p+ U
0 t$ T0 H, O0 I5 H& a // By default, all `createActionForEach' modelActions have! c2 r: m: b2 y" l2 [! L) Q1 U
// a default order of `Sequential', which means that the1 Q. M* e8 J2 s+ ^( R2 W* o7 x
// order of iteration through the `heatbugList' will be2 ?1 ?$ O, E. u9 Y: b
// identical (assuming the list order is not changed4 @/ U% q' r, A) S1 m0 B7 R
// indirectly by some other process).) S+ o+ u8 `7 Z
% G! M" r' f% h F4 g+ k modelActions = new ActionGroupImpl (getZone ());- b$ M5 X, M9 v& {, U5 I
* O. Z# d3 f5 v# |2 P
try {
! V+ y" _$ m! j9 b modelActions.createActionTo$message) v! O B; A0 g! q9 b$ ~' F+ t
(heat, new Selector (heat.getClass (), "stepRule", false));
8 @" X0 T }7 G% u: P4 G } catch (Exception e) {
/ C/ s* S! l8 W; e4 R System.err.println ("Exception stepRule: " + e.getMessage ());
) E. p3 \5 n! @5 b) c0 L* q }' S4 |0 `2 b7 H: k
6 g/ [) Q! a& k. E
try {# O6 }- @ Y, c% ]. o
Heatbug proto = (Heatbug) heatbugList.get (0);& M- \2 N2 J5 N7 C& G; {( S5 m
Selector sel =
/ A$ ?5 J+ ?0 l# S O- M* E. V3 D new Selector (proto.getClass (), "heatbugStep", false);+ u' i/ @. h& o8 v5 h
actionForEach =
, Q# g' N, ^( S5 g6 ]4 O! n modelActions.createFActionForEachHomogeneous$call
. o, v) n+ \% T7 ^ (heatbugList,/ C' O. K9 v7 ^; e
new FCallImpl (this, proto, sel,/ k7 v! I. d y- X: }
new FArgumentsImpl (this, sel)));8 s- K( |3 P0 w: D0 d
} catch (Exception e) {
! @8 M3 N7 H" l6 r, m, B* Y k: R- u e.printStackTrace (System.err);1 ? ]8 a1 N$ u. x2 w8 I$ }& _& \
}
; h( [! o5 ^% o, f
# S" f# m! i& u! m" G syncUpdateOrder ();8 Y6 F! o0 F) e+ R( F# _( U7 _
# P2 }; o$ M5 w& q. d+ k
try {
) |1 {+ d3 Q( ^- W2 r) Q9 G modelActions.createActionTo$message 8 N' ^1 x2 I& f5 ]' Q; z7 ?/ u4 L
(heat, new Selector (heat.getClass (), "updateLattice", false)); E' ~9 u/ ~6 C: Y' V( E
} catch (Exception e) {
: k, L5 h+ n. o: v2 e$ C System.err.println("Exception updateLattice: " + e.getMessage ()); M: ]" _& w" Q! I8 E* O/ Q
}
) A! _ l1 }% E) c2 C! [ 8 P6 w. t: f- k5 Q( g6 M5 [
// Then we create a schedule that executes the' P' A; Q& p) }" L
// modelActions. modelActions is an ActionGroup, by itself it
7 R. i; f6 J$ p2 Y$ w // has no notion of time. In order to have it executed in: }2 ~" I* f( {9 K7 X c
// time, we create a Schedule that says to use the* O: r0 `6 P- I* ?0 O8 D; D( e
// modelActions ActionGroup at particular times. This
: P- Q8 d/ ?2 {" U/ T9 C, M( G) z // schedule has a repeat interval of 1, it will loop every6 [6 M. _6 a' T6 f$ {) k# Y7 M5 ]
// time step. The action is executed at time 0 relative to
& |9 `# u( ^! |& T4 D // the beginning of the loop.! u- \2 i3 V1 U
; ?: A8 G# |1 K. g* X/ \7 a8 l* C
// This is a simple schedule, with only one action that is, K7 `" l2 T4 l8 w# v
// just repeated every time. See jmousetrap for more
2 J a' E5 z/ h# E7 A2 J+ I. y // complicated schedules.( _. n$ z( C( k( }8 D9 j% p
# I5 Z3 {5 n. w( z4 k9 R! a modelSchedule = new ScheduleImpl (getZone (), 1);0 C9 m1 }, `7 y X- p0 K- G& s% q' U
modelSchedule.at$createAction (0, modelActions);
5 I' N( S e" F1 X$ K0 u; r
$ S9 V6 v, S' [) a- L; a' g' e return this; w. v1 t& b# q! f. P2 r: w0 {, F; M; ^
} |