HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
$ \# E: U; U6 a7 Q& ~9 ~, F. v3 I( \' |+ r) s! n
public Object buildActions () {( A9 K4 f8 k& Q% j5 J" R5 {
super.buildActions();
# f' M) a1 s/ E7 L+ [
4 i% m2 I2 x* w& L // Create the list of simulation actions. We put these in h+ C& x+ i, T# j0 o) N
// an action group, because we want these actions to be; C+ j. @* r, z( b- X, n
// executed in a specific order, but these steps should$ S, s$ f8 T! E3 r
// take no (simulated) time. The M(foo) means "The message
- c# q- k+ J% C0 F // called <foo>". You can send a message To a particular
+ {9 ]/ r/ r- R, f- ~4 x L' V // object, or ForEach object in a collection.7 u2 K. i2 q! c) q9 U' L
+ q }+ J" v2 Q' y/ C; H3 ^* P
// Note we update the heatspace in two phases: first run
# L+ m. M" m+ y0 z3 T // diffusion, then run "updateWorld" to actually enact the
$ L6 l5 Q/ g/ c9 O; J! h // changes the heatbugs have made. The ordering here is3 g% d- o" P, D% }, _# h& E
// significant!: {4 y* l+ W/ N# {9 ^
! k9 S& `6 I- ?( v2 m' X // Note also, that with the additional
+ |1 \1 W K: { // `randomizeHeatbugUpdateOrder' Boolean flag we can/ D' L ^" T7 v7 W) X
// randomize the order in which the bugs actually run
0 X( V# p! O* Z3 q // their step rule. This has the effect of removing any, @0 B& i" L* B9 h/ v3 b
// systematic bias in the iteration throught the heatbug$ [* q1 y3 o( X2 V7 ?1 {
// list from timestep to timestep! h; ^1 g! `* R; [" g
: p+ |; w' \: W* f0 I" ?2 s
// By default, all `createActionForEach' modelActions have% K3 h [- b' f$ T% W1 \5 T
// a default order of `Sequential', which means that the. i- c, T4 Z2 d+ u2 _* H/ U
// order of iteration through the `heatbugList' will be* d$ I$ M9 g7 b$ a: D2 }5 N
// identical (assuming the list order is not changed: o3 i" I c2 r$ Q6 A: |0 x4 B1 t
// indirectly by some other process).) X$ H$ {! L5 e) |
. z5 e5 `3 A; l# G# Z* ` modelActions = new ActionGroupImpl (getZone ());
% Z" J' W5 N' g+ L% I
! O0 H+ j7 a7 b2 _ m3 W try {4 q' c n) T- i5 T/ b p; @
modelActions.createActionTo$message
, I( v; G" X( v& d0 h (heat, new Selector (heat.getClass (), "stepRule", false));$ j% g+ K$ h/ d
} catch (Exception e) {, P7 A( U" ^3 }: T( |5 ^
System.err.println ("Exception stepRule: " + e.getMessage ());
' v# @3 U* K+ P! h }, _3 ^8 Q v3 G- W4 P* T9 B
" x# D+ W' q* Z4 G. M try {
3 V/ a. U3 [ ] Heatbug proto = (Heatbug) heatbugList.get (0);
* `7 O; U' f7 H2 \7 j: x4 ^, N Selector sel =
% l- G+ n+ G9 v/ ` new Selector (proto.getClass (), "heatbugStep", false);
, I! k w# ?3 @7 \9 E3 o3 u actionForEach =
4 I" t! H4 w6 M% H modelActions.createFActionForEachHomogeneous$call
# Y% N; X2 q# r9 w0 e (heatbugList,
, q2 \' L S! n6 n+ V$ o C: g/ k new FCallImpl (this, proto, sel,
W6 j- D* h& \ n/ H) C new FArgumentsImpl (this, sel)));' B" m! t6 K. S( C! I- t5 `1 C
} catch (Exception e) {
% \6 L+ p; G. f* o) F e.printStackTrace (System.err);
& |- o* W1 u. q& O1 Y5 A }6 A+ e# w0 @( h
/ U( B" g; O. B0 X0 X0 [" N, Y. x
syncUpdateOrder ();
& D- F4 v# a' n) H
% V6 S! j6 E8 y! K4 B6 ~% f try {
1 L& y) M1 e3 a; z modelActions.createActionTo$message ! ~# c2 f6 P, |! {+ q( {) y: [
(heat, new Selector (heat.getClass (), "updateLattice", false));8 v- p5 e1 k( q! E7 m: k) F: i
} catch (Exception e) {- ^* v, M; D& c1 r, b
System.err.println("Exception updateLattice: " + e.getMessage ());
X! j3 }2 e; C$ l3 E' L% t }
9 e7 d. s; |1 t9 H8 y0 C" u ( s0 P. V3 a7 e G* ^ n
// Then we create a schedule that executes the$ T5 r. R4 L- f. u+ \
// modelActions. modelActions is an ActionGroup, by itself it# w+ j& G- g6 T
// has no notion of time. In order to have it executed in" k8 r8 {0 v$ w; l: q* M$ m7 E
// time, we create a Schedule that says to use the4 u9 p* Y! d' e" l; i) \
// modelActions ActionGroup at particular times. This
" ~( r4 S3 y4 Z5 _. v* e. u9 t // schedule has a repeat interval of 1, it will loop every
8 |( P! s; R; F // time step. The action is executed at time 0 relative to
3 P: F$ c& S( w/ Y8 w2 d; Z% H // the beginning of the loop.
4 ~, C" v9 ~! G, {8 S
; `3 F: N \$ {. F // This is a simple schedule, with only one action that is
* F0 G2 ?. s7 r5 X // just repeated every time. See jmousetrap for more$ q# b- p# m, `+ g
// complicated schedules.9 K0 K3 V/ b f2 H
. p4 k+ ?& F+ \( z. h) h# F modelSchedule = new ScheduleImpl (getZone (), 1);
' Q9 N, Q' G" x+ n m. r modelSchedule.at$createAction (0, modelActions);; b1 S% S- b: T
0 ]- t9 ?/ ]! g7 | return this;
5 w3 H! L5 U. \+ }' }: R } |