HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
! e3 x* a0 h. I7 T, ~! R$ |+ V; Q0 g, ?3 g1 L& A# n- G
public Object buildActions () {
8 |1 e. b* _4 e# K. ?+ g, z- L0 N4 \' t super.buildActions();# R3 K4 ` }$ d1 R
5 {) |4 ` Y0 C8 |" Y4 K // Create the list of simulation actions. We put these in
( f R+ h5 t- m. `: V; V7 l( @ // an action group, because we want these actions to be
a+ z1 `/ D ? // executed in a specific order, but these steps should
# h* h+ ]- {6 m0 _- I // take no (simulated) time. The M(foo) means "The message9 m& B1 f5 [/ n
// called <foo>". You can send a message To a particular
/ \. H; M) p" S5 e* a; K // object, or ForEach object in a collection.
6 ^5 z3 L$ y& A- L 4 D2 l' C& ]' U5 L* [
// Note we update the heatspace in two phases: first run
0 j# Q& T# C: L( A2 _3 c // diffusion, then run "updateWorld" to actually enact the
; @3 @* Z' i5 O // changes the heatbugs have made. The ordering here is
7 }7 s( K7 u) u) C' B0 r // significant!' J2 @4 U+ q/ P9 F9 a, A
& F/ E5 d" p3 ^ // Note also, that with the additional: U! ]3 H6 G! m2 a O* g! {8 q" P
// `randomizeHeatbugUpdateOrder' Boolean flag we can
1 R9 a# L* M4 \5 C3 K // randomize the order in which the bugs actually run9 ~' U1 U4 @9 e% {# I( u' t
// their step rule. This has the effect of removing any8 p7 c6 g U7 w3 N9 T7 }
// systematic bias in the iteration throught the heatbug
5 @) s8 ]$ J+ \7 P5 K: E // list from timestep to timestep8 L; Z% }! X! i" d- f# J$ n
' ^7 K+ Z8 k, G5 S \% m/ [7 \9 ]
// By default, all `createActionForEach' modelActions have+ K) [, a# z# x5 T" @
// a default order of `Sequential', which means that the
# d3 U, {+ f7 q, v // order of iteration through the `heatbugList' will be
: Z- ?8 C2 u* m! {% h" T: | // identical (assuming the list order is not changed
- Z2 x5 X; E4 b // indirectly by some other process)., n9 X% K& Y- ~
. T4 }$ M8 R5 {) \5 o0 \% u modelActions = new ActionGroupImpl (getZone ());
4 v) f# @. p: ?3 N3 K# N6 A' W6 b. {: j# K+ N
try {
% B! T q0 `3 l' L- Q E- j modelActions.createActionTo$message6 ^3 B. `& y9 J3 {6 T6 B
(heat, new Selector (heat.getClass (), "stepRule", false));( N' p2 }0 R: U) @( c
} catch (Exception e) {
4 i& N6 t, D: u! d System.err.println ("Exception stepRule: " + e.getMessage ());& E! g) I0 _6 |: |" l( U
}
! B7 Q }3 Z) |
+ O1 ?& F! S! H# L$ r/ V% R try {
4 u9 y E* T5 g* Z9 Z, f Heatbug proto = (Heatbug) heatbugList.get (0);
# J$ T$ x4 ^! O, w) I Selector sel =
# e1 j' d$ O3 ]. a new Selector (proto.getClass (), "heatbugStep", false);
- b+ f7 U p6 [ actionForEach =, r2 ?! j4 W$ k9 k9 E2 }
modelActions.createFActionForEachHomogeneous$call" Q" e8 S& ^7 ^- l% R
(heatbugList,
5 N' U( u7 \7 ?/ x. F new FCallImpl (this, proto, sel, G& a) C) g3 Z% ]0 {/ X. s3 G; Q, k
new FArgumentsImpl (this, sel)));" j+ m) `7 Z$ Y+ W. [
} catch (Exception e) {
) @' V& a2 A" {; \2 U6 |- j e.printStackTrace (System.err);
& y! ?5 \4 _2 L p }4 k1 J4 n& X% p- @" J' J
% d$ V, `4 x! w
syncUpdateOrder ();( x. |, d0 s: L2 n* ^$ x
r" W; n9 D, }" v8 K5 G ^8 @
try {7 F; M! G7 _& z8 ~2 i: k' s
modelActions.createActionTo$message / M8 I8 Q" S+ @) a9 Q8 j( M
(heat, new Selector (heat.getClass (), "updateLattice", false));9 ]3 j" O8 e3 @ w& K
} catch (Exception e) {+ H6 ?" x/ n) ~+ g6 L$ i" l# N7 {" m
System.err.println("Exception updateLattice: " + e.getMessage ());
# K' z9 o8 b1 I/ r+ d4 h0 B }
. i5 l7 ^! E" N( d ! x) A. `0 ?7 M7 _
// Then we create a schedule that executes the
) b3 H8 ~4 A/ D- @% j& c // modelActions. modelActions is an ActionGroup, by itself it7 D2 ]' E4 K# O3 h
// has no notion of time. In order to have it executed in3 z8 o4 d# ]3 Y1 n* G r
// time, we create a Schedule that says to use the
6 ~5 `4 J6 r* |: ?& [8 I // modelActions ActionGroup at particular times. This
6 j$ p4 c. _4 y1 L$ J // schedule has a repeat interval of 1, it will loop every( S# }1 r5 Y& W$ C) ^8 @9 Y: ]
// time step. The action is executed at time 0 relative to3 `/ B5 u7 v+ h" i# l
// the beginning of the loop.' d, H1 H- t5 o$ E
) x$ ~" D4 q) Q% e% g3 _# Y
// This is a simple schedule, with only one action that is+ l" v3 X7 B. B _) ^
// just repeated every time. See jmousetrap for more
9 S# r4 j2 ?! a$ U. ?8 |6 U // complicated schedules." w; G8 R$ D( z' V
# J% M1 t) @9 t. V/ U, S) K
modelSchedule = new ScheduleImpl (getZone (), 1);7 y1 A5 |3 u& }' U/ p" t5 Y( s
modelSchedule.at$createAction (0, modelActions);8 ? ]5 }$ K* w0 _# M
2 s) L8 [0 P; q |$ [ return this;
; C9 z @; f. \2 G' n } |