HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:- ^) k1 c" _/ E& a2 [
% J" L4 [: ~) }6 T
public Object buildActions () {
+ o- |; k/ _$ s& E super.buildActions();
9 H4 o+ |+ A' B2 B8 I7 e! h# v ! B5 i8 d+ s3 s# k0 {' u! `
// Create the list of simulation actions. We put these in8 `/ q% b# U; L6 P* o! n
// an action group, because we want these actions to be0 m/ v, b+ b0 C2 d; w
// executed in a specific order, but these steps should
7 V( _4 K* H- i* @( r1 u8 m // take no (simulated) time. The M(foo) means "The message
; a$ M/ M1 S3 M% L // called <foo>". You can send a message To a particular
% |5 \( c3 W3 L; K" [4 ^" ~ // object, or ForEach object in a collection.
& b% ?+ h1 C i ! s# F9 B' ]9 q- c
// Note we update the heatspace in two phases: first run# y+ U, V5 G- \) S2 c1 @! } }
// diffusion, then run "updateWorld" to actually enact the
8 L Z$ y/ A$ |. n k0 s. B- Q' r // changes the heatbugs have made. The ordering here is
. W q q. j6 \+ v6 h: @% }: M1 k; c // significant!
$ x, `) ]) k5 Y7 ?, ^' w8 `5 T9 \ ' \7 n7 G6 f$ K
// Note also, that with the additional* s$ @! s0 Y: L, E
// `randomizeHeatbugUpdateOrder' Boolean flag we can# c) K' A( p/ V) [3 r0 f: b
// randomize the order in which the bugs actually run
8 E- H/ e9 `( J // their step rule. This has the effect of removing any' n! q* b7 D- i; Q& E7 t {- U
// systematic bias in the iteration throught the heatbug
( `6 R l8 ^5 A" o' a- \ // list from timestep to timestep
- s5 g! G+ n; c2 ^4 }
Y0 ]8 G. _! Q- P9 x // By default, all `createActionForEach' modelActions have
8 N$ W: n2 r6 F5 b }) F // a default order of `Sequential', which means that the! b1 o6 O0 D" H2 N
// order of iteration through the `heatbugList' will be" `( x; u5 y T9 h' C9 R
// identical (assuming the list order is not changed# Q ]& ~+ k1 r
// indirectly by some other process).1 n$ T2 Q2 d, k6 ^+ Z6 v
6 J! [! b& _ h" k modelActions = new ActionGroupImpl (getZone ());7 F2 R$ P [; H3 J% U$ {% G
# B0 e( \- _% K8 _" ^5 o
try {
+ k; C5 ?8 B- T# W) Q. n modelActions.createActionTo$message
6 n8 s5 F( u" W$ ]$ I4 V# o" P (heat, new Selector (heat.getClass (), "stepRule", false));
2 A, } B& a# c8 |6 z } catch (Exception e) {
# L7 }1 \; c3 Y- Q8 P' ~ System.err.println ("Exception stepRule: " + e.getMessage ());
" q" g1 q% G0 f# c }! E* {0 d. P" B
. G: V4 @5 S3 T& Q) J K try {
. H5 |; G4 t& H5 E3 f Heatbug proto = (Heatbug) heatbugList.get (0);
% w! x: W; Q9 n5 B3 i Selector sel = 9 z$ I& U4 Q* b# }0 I+ ^ H
new Selector (proto.getClass (), "heatbugStep", false);7 ?% E v* R0 l6 X
actionForEach =' i& v- x6 o* X, L% ]. m
modelActions.createFActionForEachHomogeneous$call. b& i: J# W& D' R: Y+ a+ E+ y; P
(heatbugList,
: ~$ Z' F% ]$ b# N( x7 a new FCallImpl (this, proto, sel,& I. \0 S9 U# m- L& {
new FArgumentsImpl (this, sel)));- V. y) \# P: P$ o8 J0 S
} catch (Exception e) {
0 o' i+ g; q. F, T% p e.printStackTrace (System.err);
, r$ T) h0 l) O7 v }
* }9 z, n9 E+ a! Y/ M4 V
1 V, L; P/ K4 _+ T% X syncUpdateOrder ();& B! z- l. o/ s( o
; O. I* v7 P) V4 ?: N
try {
" E6 K9 O+ t b8 s modelActions.createActionTo$message , s z& l' V. F7 o- |- a
(heat, new Selector (heat.getClass (), "updateLattice", false));
' I: K+ o' E1 X5 B3 i5 m } catch (Exception e) {% B# h8 c& W9 W; r8 i. O7 g n
System.err.println("Exception updateLattice: " + e.getMessage ());
' }. L9 ^; s4 C- h I# e5 W3 o! t% ? }3 V8 P/ p8 V3 `' ^' t+ O j
% ?# D9 W! c2 `- b- K; C0 ?6 X( u // Then we create a schedule that executes the
1 [7 w. [( |& b5 Q0 i+ i1 y2 J // modelActions. modelActions is an ActionGroup, by itself it
# i$ V( n: Y- ^, j3 A( C // has no notion of time. In order to have it executed in
. Y; Q; G8 V2 G* s9 k // time, we create a Schedule that says to use the9 \6 O. n- J2 W8 J2 t8 J4 [0 A) s8 ?
// modelActions ActionGroup at particular times. This& M1 s. h, |( a1 P' d8 S0 M
// schedule has a repeat interval of 1, it will loop every
3 x) T0 i4 j& Y7 B3 _ i // time step. The action is executed at time 0 relative to
; H m- h& [: o3 G* d& I, P* r9 k // the beginning of the loop.
/ z. u* m9 v, C7 }) \( S" l6 x. ? Y: F5 y* w, z
// This is a simple schedule, with only one action that is% m9 K6 C5 n3 h1 w. }
// just repeated every time. See jmousetrap for more
b% Q$ B- y! J // complicated schedules.
5 V) M+ P6 }2 D
% ?/ u/ X) `; |) b modelSchedule = new ScheduleImpl (getZone (), 1);
5 A1 _) o, R8 T! p& F5 v" ] modelSchedule.at$createAction (0, modelActions);3 i {# S( D; f" x. T$ }) l
" I- g* C# }0 H- K
return this;
+ m( Q( g! t5 `3 y! l } |