HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:, A) G; e* O" g# v( T7 e& k
c' \+ ]3 T; i$ V
public Object buildActions () {+ Y, ^$ \! v1 o- U2 ~2 [5 W2 E& D
super.buildActions();2 K u1 {; k! u) A. W: x
6 c* f' k1 H! R h; _
// Create the list of simulation actions. We put these in1 d1 @& ]) r- N
// an action group, because we want these actions to be- j* M, T9 k% ?: f5 m
// executed in a specific order, but these steps should
5 M6 `; b% t" \* z! s @+ f // take no (simulated) time. The M(foo) means "The message: t$ K) i" ~8 |% a$ e+ G8 u
// called <foo>". You can send a message To a particular
1 i T ?- u; p1 f: o, x1 M // object, or ForEach object in a collection.; w: P {. x! V/ h; b
) Q* i5 m$ k6 h- W* s, q+ A# V F // Note we update the heatspace in two phases: first run6 D+ ~4 K( ?* I5 H9 c
// diffusion, then run "updateWorld" to actually enact the
) d& \7 b% g B7 S. X, E8 c' R$ \ // changes the heatbugs have made. The ordering here is
' }; Y( k2 H+ L9 T6 { // significant!! C- I, j( G6 f+ k6 z
' m( K7 F& j2 |; F // Note also, that with the additional2 Q" O* U' ]' t2 V
// `randomizeHeatbugUpdateOrder' Boolean flag we can
L$ J, _0 o3 @' p% X // randomize the order in which the bugs actually run5 y6 D8 Z, J; ]# P4 I# F& I, c L
// their step rule. This has the effect of removing any/ ^& y" C& g5 A8 c
// systematic bias in the iteration throught the heatbug2 N' c; Y5 x, ?8 ~
// list from timestep to timestep
! a$ g/ d4 ]# }$ d5 A" S3 _, o
1 B4 V0 d5 A5 M0 O/ q. R // By default, all `createActionForEach' modelActions have
- f2 r' c. j3 E$ r // a default order of `Sequential', which means that the5 K! {2 v3 Q; n9 ~3 q0 c
// order of iteration through the `heatbugList' will be
; S4 z( V1 W/ F. ^ ~ // identical (assuming the list order is not changed
! _6 W1 O4 G6 | R // indirectly by some other process).
' f! s3 C8 v. |0 T, u9 K
7 O: I& \+ ~& L' U$ f% D, S* U% s modelActions = new ActionGroupImpl (getZone ());: |6 K$ P {/ ]+ h) _
( I0 ^, ?9 f2 j8 V: A. `- C6 n
try {5 K! D) ^" V' N% ?
modelActions.createActionTo$message
- @" d# o8 a |7 F (heat, new Selector (heat.getClass (), "stepRule", false));
8 R. z8 |$ |. N: z } catch (Exception e) {
+ i+ g: v e0 W& c4 H+ F System.err.println ("Exception stepRule: " + e.getMessage ());8 ~) L7 R! @! v5 N- V& T. {
}
, H; ]* H% _" V9 x- e: ?/ C9 r. S( `8 A1 S9 L
try {
# p2 E/ v7 X3 v" v+ K Heatbug proto = (Heatbug) heatbugList.get (0);% |2 U% n \# N% U7 n
Selector sel = 6 I" m# I9 S: K3 |- y
new Selector (proto.getClass (), "heatbugStep", false);
4 V. W2 A4 c0 `. l0 @ actionForEach =& G+ }) q! ~$ [7 z& N+ g
modelActions.createFActionForEachHomogeneous$call
7 v m& ^6 Q5 J0 G (heatbugList,
6 @# |2 f- B: m. x/ R' x new FCallImpl (this, proto, sel,4 K; A7 j1 e7 S$ ~" Q
new FArgumentsImpl (this, sel)));+ q% v% ~0 g$ X6 M. r2 X
} catch (Exception e) {( W7 |0 D* D& o! V: s
e.printStackTrace (System.err);5 C- }$ p* f* T; B- k t# x- n$ o
}
/ R4 n- _2 o3 x% ] 6 h# J( A" g+ z2 G7 U9 J
syncUpdateOrder ();
) T, H4 M+ t. }3 q2 x, ]! r
1 Q9 n& H4 K# [ P$ c8 `% @6 T try {- p) o8 v, G3 ]& [0 c, ]. X; r/ c8 j9 S) A
modelActions.createActionTo$message
; V' a$ e4 i: B; E+ s8 W (heat, new Selector (heat.getClass (), "updateLattice", false));+ O1 q4 o% B% y! @- n5 s
} catch (Exception e) {) f. Z( r; G/ q
System.err.println("Exception updateLattice: " + e.getMessage ());
" p0 n% b8 E5 c# C }* E9 |, K0 s2 t8 a2 Q* H7 c3 Y3 d
$ m! F- ?* p0 R
// Then we create a schedule that executes the, b l5 }5 n" P- { t
// modelActions. modelActions is an ActionGroup, by itself it9 z7 q2 u' g' D/ j
// has no notion of time. In order to have it executed in
% R6 ~4 `5 ]- K" y // time, we create a Schedule that says to use the6 L# j4 E! W4 }" h( F7 N* A4 j! x
// modelActions ActionGroup at particular times. This
" ?/ U1 N+ ^) G: `0 B // schedule has a repeat interval of 1, it will loop every" p# W$ ]5 Q, S3 p
// time step. The action is executed at time 0 relative to5 ?% Y, i+ h7 V& E
// the beginning of the loop.; x8 L6 s+ I' x
& i3 ~5 e8 k }% p) [ // This is a simple schedule, with only one action that is! F: _' N Q+ L4 Q
// just repeated every time. See jmousetrap for more
5 I) P4 r# A7 K+ E // complicated schedules.+ w& N9 t' X7 U8 a
1 T9 j4 P! g1 [* r modelSchedule = new ScheduleImpl (getZone (), 1);& @; Z: Z6 Z6 w. ]! e9 i; y; @
modelSchedule.at$createAction (0, modelActions);
2 H( [* N% N! T D1 T
5 c; J/ C( { B; l7 b) B9 i5 }1 o return this;9 w- C1 T5 g. l1 J- [' i
} |