HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
+ V: w+ F% u( ?0 y; o( ?
1 \ [! N4 v3 \/ r$ T$ D public Object buildActions () {
3 u1 u' _1 J8 l: O2 I. n! C super.buildActions();: d! j( o- p+ \- e/ V I
5 J; T3 K) _& I0 V3 h: x6 H // Create the list of simulation actions. We put these in
/ q- x& R- ]3 \6 X5 g( } // an action group, because we want these actions to be
% r9 Q. K; F. \& a" j t$ u+ `$ q // executed in a specific order, but these steps should
1 G4 V. H" i$ @; `/ P // take no (simulated) time. The M(foo) means "The message
1 i! D, |1 R0 H5 X$ l- c/ o! } // called <foo>". You can send a message To a particular4 g! m/ i4 x% |/ M: \6 f
// object, or ForEach object in a collection.
. c9 S* f# D# ^& @2 r2 | * w9 M! ?; B+ p B
// Note we update the heatspace in two phases: first run! C: @. Z3 J8 y& `. t( d- A
// diffusion, then run "updateWorld" to actually enact the6 B: a h! D9 h
// changes the heatbugs have made. The ordering here is
7 ?" \7 A$ {& X // significant!
2 W2 u' r+ | A; ~7 \' {1 ?9 f& m
! _) K, ~, t$ D) A: `8 r- n // Note also, that with the additional; v- {& j$ [; Z2 F# Z
// `randomizeHeatbugUpdateOrder' Boolean flag we can
( |- f% r+ |/ S' n // randomize the order in which the bugs actually run1 m: j H/ C( G! Y/ p" m9 T
// their step rule. This has the effect of removing any- p8 O1 E- q% {, v& \
// systematic bias in the iteration throught the heatbug8 a8 B4 U9 I5 p3 R& ]) [( k" ~
// list from timestep to timestep
9 h& k, ~0 ^8 p( i9 u - i" i8 {6 L( n3 b6 |! D
// By default, all `createActionForEach' modelActions have8 j; A6 X$ u C1 k7 T w7 f* j& N
// a default order of `Sequential', which means that the
3 D1 u1 {9 t! z: x+ e: k // order of iteration through the `heatbugList' will be# [) P6 |8 d4 b/ t; y
// identical (assuming the list order is not changed" a, v9 Z* s7 Y+ c% ?. U: g
// indirectly by some other process).
8 t8 o/ E$ Z( _+ N6 H 2 c4 r/ y- e3 t3 ]& r# q. @& k, W! l
modelActions = new ActionGroupImpl (getZone ());( _: A* J+ U* N& M! v/ k C
9 V$ |$ P9 @6 o: ]. W' |8 } try {8 W. J0 A* `1 G! n5 P5 Y
modelActions.createActionTo$message
$ ^8 [/ o/ Q* c; z* }7 x2 y8 [ (heat, new Selector (heat.getClass (), "stepRule", false));
. Z% |, a9 U$ t } catch (Exception e) { c7 N2 {$ w1 K4 g3 |) ?& n
System.err.println ("Exception stepRule: " + e.getMessage ());
$ @. r8 I6 G# d4 Z5 ?- \$ k }9 J' n1 q% d$ y4 f* X
- K1 I4 A. H5 K* t+ _% _4 B S) a
try {, y1 ?) K2 E( }" i# G, Q* k0 ~4 L
Heatbug proto = (Heatbug) heatbugList.get (0);
6 L8 \8 c, V) C& t4 v Selector sel =
1 z6 f7 O- R1 z" d5 H0 i new Selector (proto.getClass (), "heatbugStep", false);+ ]9 l* l" W, E
actionForEach =' ?) E* g4 p0 E. i. d/ h1 f+ K5 ^0 y
modelActions.createFActionForEachHomogeneous$call
0 S. K+ K- N6 _% y (heatbugList,: Q6 ^' q' c( r2 |( G6 J
new FCallImpl (this, proto, sel,/ a1 c& C! B( {
new FArgumentsImpl (this, sel)));/ V* f# h. I+ J4 [. ?1 ]8 }; h0 a
} catch (Exception e) {2 s1 ^7 I0 t7 w, W' k9 t3 M: b6 f
e.printStackTrace (System.err);
. d) S; ?0 C3 [! y# V }4 r) W& R8 K/ T0 X" g; \1 S, O
9 m% H$ J- h! Q8 K5 |% C syncUpdateOrder ();
# I6 k) q& d( {$ k# D/ G4 s5 b6 R) ~3 e* l& p
try {
4 s# N- h4 j/ p( ]3 {5 } modelActions.createActionTo$message 9 O' O9 U0 X t" ~
(heat, new Selector (heat.getClass (), "updateLattice", false));
- w8 n) B) x7 Q3 t, A* d, A+ j } catch (Exception e) {
1 Y/ Q8 K- e4 j1 H System.err.println("Exception updateLattice: " + e.getMessage ());# I# y" l% `/ O) m+ V, V9 s& g
}
& e5 p; T' p& Y. @7 |& R 1 _6 ~ {5 P+ V( z, B; x( z
// Then we create a schedule that executes the$ W# r/ F- d( d. N" b
// modelActions. modelActions is an ActionGroup, by itself it
1 t7 u( w4 \1 b4 }$ Z. y5 M // has no notion of time. In order to have it executed in* j9 r& [) `' z0 D m& \
// time, we create a Schedule that says to use the8 ]5 N7 D2 q' I* U0 Y$ d
// modelActions ActionGroup at particular times. This
1 W7 M% a$ u9 b( { // schedule has a repeat interval of 1, it will loop every
1 G3 a# v2 E& f$ r# g // time step. The action is executed at time 0 relative to
* v: M3 ], z& R/ x: R0 a! A // the beginning of the loop.
+ E" Z, D6 S/ Y$ {6 Z9 q* R. ^1 b7 A0 H! ]& l
// This is a simple schedule, with only one action that is) u% k4 i( [. a% J% J4 G& |% e' L+ a
// just repeated every time. See jmousetrap for more; M9 ]. A1 W2 }# g8 ]2 F4 {6 ?
// complicated schedules. S, [ |1 Q. t; e# m" c
- N3 f2 a% F7 h& |- O
modelSchedule = new ScheduleImpl (getZone (), 1);# M" J7 Z3 ]2 q3 {
modelSchedule.at$createAction (0, modelActions);, W) ?& ]% Z$ y5 P
# X- m3 _. x5 e
return this;
8 `- s7 t6 k5 O6 [) U } |