HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
0 u, u& v* z3 `
# l) |1 ^5 ^0 ?3 P @3 T public Object buildActions () {0 @, b$ h1 F, C q
super.buildActions();
* x' s$ _% a) J6 @: c" b; F " |. |+ F; i. z7 {, j' C
// Create the list of simulation actions. We put these in
+ c+ |- k5 m' }! M8 F! I. B! c // an action group, because we want these actions to be& p" O8 c. |# k5 B y
// executed in a specific order, but these steps should1 B, p; Q" y1 b, z
// take no (simulated) time. The M(foo) means "The message( u, h5 V# r% ?, O2 r q" F, V
// called <foo>". You can send a message To a particular0 `; Z' _' T1 Z8 l4 n) I9 N1 j# H
// object, or ForEach object in a collection.
* Q/ ~; ^1 X( ?# a4 W & b9 B4 \# S* u! u2 }/ `& H% b0 _
// Note we update the heatspace in two phases: first run
8 `5 d; P3 b! g5 e // diffusion, then run "updateWorld" to actually enact the
- v; e6 L% W, f, K) @. y // changes the heatbugs have made. The ordering here is
/ z5 W; s( e2 j* z2 P- W% y4 H // significant!
0 b& F" g4 b- b* r4 m1 k% j 5 `' h0 }1 \: k; [* @' j8 p* p/ Y5 c
// Note also, that with the additional6 \4 _2 c9 n: h y& }8 E
// `randomizeHeatbugUpdateOrder' Boolean flag we can
- i) A1 z8 ?* B& X2 K // randomize the order in which the bugs actually run
; _* q V$ D6 J; J // their step rule. This has the effect of removing any1 g s* }9 K/ w+ k3 |* U% w, c
// systematic bias in the iteration throught the heatbug
( f& X0 M) E; k' T) p: u // list from timestep to timestep7 f, l5 m& s& B( ~2 G n4 l
5 C$ F. Y9 ~! k( e' ~0 D* p // By default, all `createActionForEach' modelActions have
; _% m- }9 L+ \9 K. T& x // a default order of `Sequential', which means that the" s: B4 q, k2 `( [. e, i( v
// order of iteration through the `heatbugList' will be) s' A, s4 L; s. j$ A
// identical (assuming the list order is not changed
6 @" Z- Y2 B* H, ^$ m // indirectly by some other process).
8 ^% M! w5 v/ D9 V
# R( v/ F2 y! Z$ C modelActions = new ActionGroupImpl (getZone ());
4 K: o$ O- k6 G
: ?* m# x8 r$ b' {( V try {% |3 e" N# y9 c& D+ n. V5 o
modelActions.createActionTo$message* h8 o8 s8 R/ T( K
(heat, new Selector (heat.getClass (), "stepRule", false));3 p# s6 `2 a, J% b. z* Y1 F
} catch (Exception e) {+ ~7 H- `- u" k5 H
System.err.println ("Exception stepRule: " + e.getMessage ());
/ }8 W. z3 W8 b- I }
( `5 D6 ^$ X& R# ]
: ^: T& h0 q8 V try {
) P* a4 A# {3 O Heatbug proto = (Heatbug) heatbugList.get (0);) ]# r) W+ Y* @$ ~0 q+ S y
Selector sel = ( f7 U5 x. b/ e. V
new Selector (proto.getClass (), "heatbugStep", false);
" }" S. t8 p1 L! A actionForEach =2 V8 [+ u. v" X( G. E
modelActions.createFActionForEachHomogeneous$call
- W" _6 d9 u# t3 S3 ] (heatbugList,
$ @" G8 x5 q) U8 m new FCallImpl (this, proto, sel,
4 t0 S# C m( r' R' Y5 E new FArgumentsImpl (this, sel)));! [4 l, D# s0 a, z- l6 S5 w
} catch (Exception e) {7 ^6 M( w# ?+ M# i% p% C
e.printStackTrace (System.err);: K \% D/ m1 A
}- Y* z, X+ c% g' d* K v: p6 {$ j
7 V+ j/ }- J- a syncUpdateOrder ();% Q( R+ b8 d# v* n7 z1 q
) E3 u, d$ n! o" G' V7 B" |" ^
try {6 m. p/ Z# o5 E% ?8 O7 P
modelActions.createActionTo$message
6 C- h7 h& [0 D5 m! D (heat, new Selector (heat.getClass (), "updateLattice", false));, N! q$ r6 b) Q/ N
} catch (Exception e) {, ~& A" X7 p1 e
System.err.println("Exception updateLattice: " + e.getMessage ());
; @+ Q; Z9 j- R, D5 D( s1 g }- b" N8 B4 ^" l0 _! H& N T- x
1 n" ]. [. m- h9 e6 L, w8 u
// Then we create a schedule that executes the' x. g7 F! y( |% T8 d
// modelActions. modelActions is an ActionGroup, by itself it
# c- A7 R% q( K" L# p- g // has no notion of time. In order to have it executed in
`/ {, d8 O& r. l // time, we create a Schedule that says to use the. f) S8 `2 H5 h$ k5 g" H
// modelActions ActionGroup at particular times. This0 o0 Y/ M" n4 O/ u6 r
// schedule has a repeat interval of 1, it will loop every
+ ?+ b$ k! F3 I9 P" Q4 L( f // time step. The action is executed at time 0 relative to
% w1 D- X. V" a" `: W+ R // the beginning of the loop.
' `& j9 Y% ]* @8 x" g4 M; b% z T! O/ _" ~/ u; O# m. z
// This is a simple schedule, with only one action that is
) u8 B! L- p! I9 v2 S; C) ] // just repeated every time. See jmousetrap for more* Y3 ?2 t. G( j# a2 X* i
// complicated schedules.7 O* O. N8 }1 W* Q1 k# p+ U3 T
" }- F9 o! B# l& ?: L/ J; ?
modelSchedule = new ScheduleImpl (getZone (), 1);
, n5 G8 Q& s* x) B* n. C7 L3 K, W- j modelSchedule.at$createAction (0, modelActions);
' {+ L+ X; g7 C' x+ X3 R
( X) q& j1 t/ ^% J# Y/ E return this;
( }" S/ @% I" C2 Q* R } |