HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
2 J0 q4 O$ S4 k0 E# T1 K5 I+ L4 m/ X8 u4 \
public Object buildActions () {1 D/ t4 Z. @# `1 @
super.buildActions();
: U/ M; M" n& U# g5 m( q& j 5 d. I; m& Z) I, c
// Create the list of simulation actions. We put these in- h& N/ L) G& d# p/ q9 Y$ L
// an action group, because we want these actions to be
) L( M9 ^5 B' Y# { // executed in a specific order, but these steps should" P6 d% T1 D- M% b4 C% f
// take no (simulated) time. The M(foo) means "The message1 H( [+ q9 a0 W4 F( l: |$ X
// called <foo>". You can send a message To a particular( w4 N2 E3 f8 L& I. _
// object, or ForEach object in a collection.4 w! N! L$ W `" U) D$ D
2 U- X2 {: E: ^5 Z% S7 b( l // Note we update the heatspace in two phases: first run
3 r! B! Q1 h! L! Y // diffusion, then run "updateWorld" to actually enact the
2 D- _& W8 e3 s0 y% j. F, Q // changes the heatbugs have made. The ordering here is" C- h' e" y, y3 t R* e
// significant!
6 M* t& H, d8 Q1 @6 w% S & U% t) G2 u9 c, S( j
// Note also, that with the additional
8 Q+ e# p( I* G) d0 X. ]2 r+ O // `randomizeHeatbugUpdateOrder' Boolean flag we can- t/ `5 P/ T3 S% l ~0 o7 w4 s: G% R
// randomize the order in which the bugs actually run* r0 e9 S! q; ^) N( A
// their step rule. This has the effect of removing any
9 j: s- c* \/ D4 K! L+ Y+ G // systematic bias in the iteration throught the heatbug
" w! H2 @9 P. q ]) o! ?1 y- P' J // list from timestep to timestep
3 D. {: T- J3 A- k' e0 r, a
1 F% H5 y( b" F/ S // By default, all `createActionForEach' modelActions have
. l, S+ N! [6 H // a default order of `Sequential', which means that the
7 X9 k# ^8 }4 Y // order of iteration through the `heatbugList' will be6 U2 }+ Q$ i& W" o; e+ _: e
// identical (assuming the list order is not changed
- @. a9 B7 c! Y$ |' F' E% ` // indirectly by some other process).# f' i1 @3 t4 e# A y
a. Q6 |( G8 S3 {9 }. |! E
modelActions = new ActionGroupImpl (getZone ());4 O4 p! f% B2 v
- U% T" ]% X& A. k4 g8 U( |0 M" G try {
1 y0 a; U b' ]. K, L. J2 q modelActions.createActionTo$message
* k8 ^6 S( @% } (heat, new Selector (heat.getClass (), "stepRule", false));
8 ~& z* b9 R# f2 j/ s } catch (Exception e) {2 Z# p) M9 p8 B, \$ r% r2 [4 I* g
System.err.println ("Exception stepRule: " + e.getMessage ());
A' j5 ?9 `& V8 B8 S7 Q; ]4 P }
% k4 ^4 D* b! y3 K$ g, N+ K+ R' n+ I
try {
1 m. g" A7 X% J: V/ [, i Heatbug proto = (Heatbug) heatbugList.get (0);
, n9 s% I( u. q. Y. h+ x& I Selector sel = 1 B( I& N9 }! s
new Selector (proto.getClass (), "heatbugStep", false);
, J- ^( L" ~7 M2 l actionForEach =' s1 G+ Z! ?4 ~' y5 h9 l1 K
modelActions.createFActionForEachHomogeneous$call
" r3 W0 @: w1 R3 } (heatbugList,
# A2 O7 q8 M p- \3 i new FCallImpl (this, proto, sel,
. w( j1 l0 I7 P new FArgumentsImpl (this, sel)));
; \& h+ Y( ^5 e } catch (Exception e) {
; o K/ d! p( O. _8 j9 N q, M e.printStackTrace (System.err);5 p5 {: B5 H( D
}% F( C1 H6 b |& r/ ^
# ?+ U% I7 ?8 [$ ]6 O: f syncUpdateOrder ();0 | Q6 a- v6 H3 T1 e
$ ]: v T5 ~ B$ F; S try {
6 b7 A! V! L! Z9 c( v% T0 ` modelActions.createActionTo$message # P" {( G! d0 E& g
(heat, new Selector (heat.getClass (), "updateLattice", false));
. B9 U* ~9 x4 e# ]+ |- Y3 K } catch (Exception e) {9 o, E+ {5 E; c8 s2 G
System.err.println("Exception updateLattice: " + e.getMessage ());) r, \8 d6 A+ L5 i! k) ]
}1 W: t6 f/ ~# t' {( [& } P0 F9 D
/ r2 h6 X" P7 c H% _
// Then we create a schedule that executes the
m9 n" }# d4 D // modelActions. modelActions is an ActionGroup, by itself it8 l7 p; w, `9 H, _
// has no notion of time. In order to have it executed in
h P' i% V) N6 {/ W/ D4 G5 { // time, we create a Schedule that says to use the2 ?4 f6 G8 x4 \
// modelActions ActionGroup at particular times. This
% G- c: j8 _3 a! _1 e // schedule has a repeat interval of 1, it will loop every _0 D* T0 ]3 x Q$ o
// time step. The action is executed at time 0 relative to
! V5 E5 ]: l$ ?4 {4 C: I+ c2 ] // the beginning of the loop./ }2 M5 C/ R) M1 K6 ~
, \- K& h6 ^5 L; m+ P4 x
// This is a simple schedule, with only one action that is: K2 k& H: a3 o
// just repeated every time. See jmousetrap for more# |+ y5 b5 A& \7 n
// complicated schedules.5 i" u/ P3 N- A( w Z/ \
- g4 A. o" ]& L. G1 k1 u: ~
modelSchedule = new ScheduleImpl (getZone (), 1);
/ \4 P; U. |" W! M9 W: a: w modelSchedule.at$createAction (0, modelActions);; g9 C+ i, ^. W- X+ C5 Z: d8 i
$ L+ ?$ ?9 n+ ~6 ^- A( z3 N- @
return this;
- Q' ?& T) w4 X$ d } |