HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:5 x6 T' x8 F) }
3 [8 H4 P/ D3 |' [9 N' S7 z( c; W
public Object buildActions () {
3 e* G$ j3 x6 c. E) q* Y super.buildActions();$ ~3 S# j) r. z- T" ~" b- t2 \6 L
" q" z* J0 U" E) `1 X // Create the list of simulation actions. We put these in
' t6 n; m9 V4 {; y // an action group, because we want these actions to be
3 _5 k% w6 c( a; i0 Q' F // executed in a specific order, but these steps should$ c3 s; w+ g* s8 o) n0 `
// take no (simulated) time. The M(foo) means "The message+ V Y4 O7 I" f5 ^3 }
// called <foo>". You can send a message To a particular
( f s7 C* ]& s7 O/ ^ // object, or ForEach object in a collection." y1 O9 k1 h; y: ^- n: b2 @
% W _0 A1 J1 q6 ^/ g# }
// Note we update the heatspace in two phases: first run
" e2 q+ W8 r0 U1 y3 b // diffusion, then run "updateWorld" to actually enact the( B) \! }3 _3 H/ j7 v( z% W1 p
// changes the heatbugs have made. The ordering here is. O4 G) `3 d: c
// significant!3 h' f3 _, j" U4 q5 d; S4 r; `
* q, t9 [4 s! @1 c7 V6 e; L! g' |# r1 I
// Note also, that with the additional* p3 d7 j' H3 P& V4 v. d- ?
// `randomizeHeatbugUpdateOrder' Boolean flag we can+ z. Q( t/ K- `& N' j
// randomize the order in which the bugs actually run
/ v1 L/ t; H8 \; T5 J0 L+ D2 P+ T // their step rule. This has the effect of removing any
0 Z" C! s' V! V6 ^: Q // systematic bias in the iteration throught the heatbug
! D- a/ B# Z* a0 k$ ^ // list from timestep to timestep
+ U* s6 g# D7 t4 \ ! m) g0 N4 t) V- M7 P
// By default, all `createActionForEach' modelActions have
1 n& C9 c7 Q6 T1 l; R3 q* v+ t7 D // a default order of `Sequential', which means that the, G0 g. f: B7 \! h5 z
// order of iteration through the `heatbugList' will be/ }8 K* ]1 n: R; A
// identical (assuming the list order is not changed
: B" @4 K' A4 N1 E0 S // indirectly by some other process).2 s6 S4 i8 f3 x2 m+ e+ ^: S
~, c- v' U2 V2 |
modelActions = new ActionGroupImpl (getZone ());
# x4 p* j# H) e \: @! B2 X% u- i, R2 \, K
try {
: Y* n' P' ^( j. i7 W modelActions.createActionTo$message: L5 l& y1 ^" i- W; p# t% a& L
(heat, new Selector (heat.getClass (), "stepRule", false));/ X: q/ a& b( h2 f4 Z6 A; }
} catch (Exception e) {
9 x( c; Z. l% d* \ System.err.println ("Exception stepRule: " + e.getMessage ());
) ^( J6 A+ W9 F/ B2 c8 b }
3 Z$ _. b$ R/ j$ d& A4 B' i$ c9 j7 L3 f0 ]7 E
try {% a+ {5 p* h3 T* L9 v
Heatbug proto = (Heatbug) heatbugList.get (0);
6 d! S* R/ c9 s" n2 N) e: z Selector sel =
$ h/ s" X2 T5 L* K$ O. z new Selector (proto.getClass (), "heatbugStep", false);. ?, N. Z" Y" o8 O% d
actionForEach =& ]) C5 O+ E% Z1 o
modelActions.createFActionForEachHomogeneous$call
) I6 Y5 a/ Q1 o6 Z( F* Q+ X. R) i (heatbugList,. Z6 N' D& Y' |& h
new FCallImpl (this, proto, sel,% a: M7 H$ s; K" p0 F$ D1 ]
new FArgumentsImpl (this, sel)));
4 E# k# T9 W5 a$ C* x) k } catch (Exception e) {, D) H3 X, D1 O
e.printStackTrace (System.err);) v9 ~8 ?0 G$ J& E' \
}7 v7 N1 K8 s/ z
9 c: H6 Q" \4 P& |! ?( r- Q) s+ {. s syncUpdateOrder ();( X v* e. [7 ]) k/ f% c
& u2 ^$ T8 t9 n$ ~( r# P try {* c8 T* p1 _9 o7 j4 X }+ h* p2 T4 y
modelActions.createActionTo$message
- b9 |, s+ g3 s0 F2 _ (heat, new Selector (heat.getClass (), "updateLattice", false));
+ Y9 @8 b3 C! K2 x+ D4 F/ a- t1 F! C } catch (Exception e) {9 p9 `5 Z/ f/ @. P
System.err.println("Exception updateLattice: " + e.getMessage ());$ P. q% W2 |# Z
}
# w: f6 C+ v0 Q( | B! ]0 b6 b# k* N$ d+ L6 h3 S
// Then we create a schedule that executes the
# H& x) M8 L @ // modelActions. modelActions is an ActionGroup, by itself it$ q( \% P8 C: F d) l' k
// has no notion of time. In order to have it executed in7 T! z) C( H% S e2 ?$ b" T9 I# F
// time, we create a Schedule that says to use the
$ n. X& Z: }9 h" X0 g X4 X/ ? // modelActions ActionGroup at particular times. This8 ?3 B, s$ O$ e( |# k) f( C: O
// schedule has a repeat interval of 1, it will loop every
: v3 Z, G8 J H& o // time step. The action is executed at time 0 relative to1 y! ~$ g. ]9 C' A
// the beginning of the loop.: R7 _& i8 O E# y: u; C$ k) A) J
1 C1 e# T* M7 T // This is a simple schedule, with only one action that is) k2 d, x4 |2 s" K9 X0 H
// just repeated every time. See jmousetrap for more
5 D0 }/ }# u7 M* z# W // complicated schedules.& ~0 m$ |+ _6 @9 j
& @2 h% Q7 Q( r0 f0 b2 ? V. E5 d
modelSchedule = new ScheduleImpl (getZone (), 1);4 a* k, f( I& N+ f5 t
modelSchedule.at$createAction (0, modelActions);* T! k' f0 s3 H6 x
, H% o* W$ u' k. c
return this;
q& \0 |/ B" Y/ q2 G } |