HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:' u! n& o2 p( I6 H" G
2 ]. z8 c6 y# C! [ public Object buildActions () {: `4 u) K$ G: ?- i& X
super.buildActions();0 v8 M5 H. ? w8 k! R3 P; O
7 r9 M! @: U, K: E2 F& x% m // Create the list of simulation actions. We put these in
# d! j0 j0 P4 R // an action group, because we want these actions to be
- r8 A K' T$ N; d // executed in a specific order, but these steps should
5 V; l* P y& N: Z: O2 d // take no (simulated) time. The M(foo) means "The message
- d3 i4 \9 ~( n // called <foo>". You can send a message To a particular5 M- G* f+ {6 F/ Y, }4 \2 `2 ?
// object, or ForEach object in a collection.
. ^( b) v( S+ X7 m4 B t" C" _+ N/ O
// Note we update the heatspace in two phases: first run. l) K8 m4 s3 r! x6 T9 F
// diffusion, then run "updateWorld" to actually enact the
6 F5 s6 m' ^) t, C- p+ k // changes the heatbugs have made. The ordering here is
" V* Y4 [$ L B4 m6 i // significant!! z; r7 b. t, d: \9 [, E: B
+ Y$ Y2 X& [$ ?) b // Note also, that with the additional+ S* d" O$ O9 B# d; ~1 R! h
// `randomizeHeatbugUpdateOrder' Boolean flag we can
! m6 h2 O( x: K7 W- W! V2 { // randomize the order in which the bugs actually run' T+ T) t" u. N. R% O
// their step rule. This has the effect of removing any
5 F7 y: ]$ J! x/ Q // systematic bias in the iteration throught the heatbug
( F; i: Q, Q/ }4 \7 V // list from timestep to timestep. m* r4 S( o' D/ N& m& c
- d/ J: P' J- b+ n. @4 E+ B$ v9 g* z
// By default, all `createActionForEach' modelActions have
8 U! ?' G0 T) P& c // a default order of `Sequential', which means that the- q7 G) I4 F' H4 W4 x$ e8 v
// order of iteration through the `heatbugList' will be
+ F$ T; U4 l1 Q! c7 u- n/ B // identical (assuming the list order is not changed
) D5 J# H2 V- G0 m) M // indirectly by some other process).
( q& |% B' v" w6 Y" U Y9 k2 S1 Q8 u
5 g2 t7 s) x( I modelActions = new ActionGroupImpl (getZone ());0 ~. P% }+ ~6 U$ T- M- u
1 o/ H- q5 y2 R% c try {% t" w+ x0 p3 v: o. Y: W: m
modelActions.createActionTo$message
) X2 V4 d) F6 s# S$ F. _ (heat, new Selector (heat.getClass (), "stepRule", false));
) v G/ Y: d* a } catch (Exception e) {% x+ K% p% w/ b! D
System.err.println ("Exception stepRule: " + e.getMessage ());
8 U( X* G1 o- w" u$ e$ b9 a }
& ~- ~% [" B/ x# y
4 X& Z7 `' T8 X8 e- n: r: l try {
/ N- Z/ b+ O; g5 u( f, k Heatbug proto = (Heatbug) heatbugList.get (0);: j# S$ ]7 r9 s/ r3 R
Selector sel = - m1 T9 y* a) L0 B
new Selector (proto.getClass (), "heatbugStep", false);
/ t( B) N2 i- L/ N) m; Z actionForEach =, D8 s# B% C7 H$ ~
modelActions.createFActionForEachHomogeneous$call0 m- C' d L2 n( _2 W
(heatbugList,) S2 B4 k/ _- v
new FCallImpl (this, proto, sel, z( p4 w! X$ a/ I5 F
new FArgumentsImpl (this, sel))); M* v+ g1 w9 m1 i( R0 @
} catch (Exception e) {
4 j4 R) c& m" w* L0 ` e.printStackTrace (System.err);
5 i9 ]+ d* i o3 ~ }
! h8 S* O& h* R2 D& {. |9 Q0 c 0 H! f, d' J8 m
syncUpdateOrder ();
) K; Y# G9 O" A3 { @- l% Y+ F* ?& O
try {" H3 d/ l$ [) Z# x8 _. B8 `
modelActions.createActionTo$message
6 ]: K% ^+ J Z) H; q (heat, new Selector (heat.getClass (), "updateLattice", false));0 B# V3 _; D0 E& K9 Q
} catch (Exception e) {
" H! D' G h, p K7 ? System.err.println("Exception updateLattice: " + e.getMessage ());
" x6 a+ [: O' `# k8 n5 V }% m4 G/ {9 f& n' C# n: P
" D9 H: \3 K! q5 A5 [ // Then we create a schedule that executes the
- T& O3 n, n8 }+ ]: b* D // modelActions. modelActions is an ActionGroup, by itself it
6 J$ r4 n" [2 s // has no notion of time. In order to have it executed in8 F) r% a2 ~( H
// time, we create a Schedule that says to use the' L% s; f( E% u8 |/ B/ z# ?! Z) w5 H
// modelActions ActionGroup at particular times. This/ d2 r; B9 K! a+ p0 l
// schedule has a repeat interval of 1, it will loop every7 {! M( W* _. g
// time step. The action is executed at time 0 relative to" w$ T) Z: Q+ p
// the beginning of the loop.
6 ~. s! N% u5 @/ a/ ]$ z' s) F( d0 ?6 s7 E" g
// This is a simple schedule, with only one action that is1 ~) K, }# ^ J' G8 ~3 |
// just repeated every time. See jmousetrap for more: e4 z3 ]4 e0 [: B u/ ?
// complicated schedules.
+ M. e. g3 L+ p; B+ I % P/ Z$ O) _/ e9 x: E0 w+ ?" g
modelSchedule = new ScheduleImpl (getZone (), 1);
! M0 f. J+ B8 V Q ]; w+ l) L7 F: k modelSchedule.at$createAction (0, modelActions);# ~1 E/ I$ l. {- O+ {/ }4 @) `
$ Y$ Q9 y' B; O2 |' R. O7 [; H5 M
return this;
. Y" L& U* S, u! V! P- o. X6 q% x8 j } |