HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下: Q2 l# j7 @+ i
( s+ u, N+ @5 x8 d( P public Object buildActions () {) O4 O4 g, W+ r7 ]
super.buildActions();' Z6 O( A; O) V C4 j
n, A2 a" ?" J: i8 d // Create the list of simulation actions. We put these in2 s; d. u y# ]% m* P* `, ~
// an action group, because we want these actions to be
( T$ w( m8 o+ J7 q8 d/ E+ s' d4 z // executed in a specific order, but these steps should* u g/ o: `2 O% s5 f
// take no (simulated) time. The M(foo) means "The message( ^! E' f* j1 P& b7 f+ z6 X
// called <foo>". You can send a message To a particular6 Y- g7 l( D/ e( C+ r p7 U
// object, or ForEach object in a collection.: _; l. b# y5 J) |0 N
: T" x# w3 W% z; m( K1 a# Q // Note we update the heatspace in two phases: first run' \) J' l- u4 ?5 E1 m. S
// diffusion, then run "updateWorld" to actually enact the, {+ c) P5 M2 _. S
// changes the heatbugs have made. The ordering here is
7 x H T8 i: Q" |$ O: U // significant!
/ L7 R7 I1 @% J" d4 o: E
- v% e9 G! e3 D7 p6 \" x! b' k // Note also, that with the additional
0 d2 Q. q. o) t' ?8 v // `randomizeHeatbugUpdateOrder' Boolean flag we can. k) Q$ h! U) G* T* _
// randomize the order in which the bugs actually run
" ?' A7 g o7 t2 N1 S8 V // their step rule. This has the effect of removing any9 A& @" L0 M) J8 j$ ~$ {# N6 U' {
// systematic bias in the iteration throught the heatbug
4 Z: ]( k2 L. C // list from timestep to timestep
" H( D6 \9 H" w 2 C2 s, f. F+ E
// By default, all `createActionForEach' modelActions have
" ]. ]0 q, Q4 K; _ // a default order of `Sequential', which means that the6 Q: ?3 e7 p1 T0 I
// order of iteration through the `heatbugList' will be4 h$ w7 I6 i7 k! H( H
// identical (assuming the list order is not changed
1 T7 T, O$ p8 }. t/ } // indirectly by some other process).' t! Q5 m4 q) |1 t5 I* k: g6 q5 B
9 {) ^9 q$ |( H3 I, ?8 d4 l- L
modelActions = new ActionGroupImpl (getZone ());
; c) S+ [+ i1 w6 E! e: Z' L# L: g2 P& p3 ?0 ^6 S& ^8 n* G
try {
K C1 Y7 [9 i6 X9 ? modelActions.createActionTo$message
4 ^+ C, t s2 q; r (heat, new Selector (heat.getClass (), "stepRule", false));; v" n1 \8 j3 @9 _ h9 ^
} catch (Exception e) {( o# V( J% p3 k" B5 M
System.err.println ("Exception stepRule: " + e.getMessage ());4 y: f# W+ ]( O6 Q4 v7 ?8 D2 v
}
1 `2 x$ S. G0 u# W* X/ e. ]" L E. c8 S$ L* d
try {
+ z# @8 f7 L: C/ j6 g: ` Heatbug proto = (Heatbug) heatbugList.get (0);2 m x7 ~: U/ W; B3 K# s$ P
Selector sel =
0 \- c A% F3 \* o+ L3 o2 ] T3 X new Selector (proto.getClass (), "heatbugStep", false);
. y1 q0 V" P* z/ o" J7 @" E5 R2 Z actionForEach =
5 b+ d3 j( y$ z: _" v: n modelActions.createFActionForEachHomogeneous$call7 \' {! `) \- x
(heatbugList,
' j% K* Y6 t0 I1 @3 h$ R7 @3 z new FCallImpl (this, proto, sel,: o4 E& E, c! N0 k5 Z2 P7 L
new FArgumentsImpl (this, sel)));9 }0 @6 u# }" S/ O* W
} catch (Exception e) {
; G% q/ [5 M5 P% R% C e.printStackTrace (System.err);- }. Q! W' L7 J; t3 O
}( Y; V4 S3 ]8 w. y
* k7 L* ^3 f2 J) Z& L' B syncUpdateOrder ();
6 c4 y% ]+ o H0 u' l3 H$ J& ^6 [" B# y+ u" ]/ H; T/ f! N! r
try {
0 d# f" t- j: m) x. Z4 j* k: k modelActions.createActionTo$message 4 {& D9 |) Y1 X" \5 u
(heat, new Selector (heat.getClass (), "updateLattice", false));5 C1 S5 H! T3 H
} catch (Exception e) {- a* ]' h; q$ D3 A: {
System.err.println("Exception updateLattice: " + e.getMessage ());$ n$ |/ g; k0 T
}
4 {, ?+ G* f$ Z; G 2 e4 g# ~2 k9 Y) x5 S6 S
// Then we create a schedule that executes the
- A- y+ @+ b5 s# S // modelActions. modelActions is an ActionGroup, by itself it Q& o5 l5 Z. B+ v% c
// has no notion of time. In order to have it executed in$ t" s8 `" l* `$ q/ [
// time, we create a Schedule that says to use the
+ H- f; v9 P+ R1 Y- l: d: r+ [ // modelActions ActionGroup at particular times. This
( q/ y& h1 t* V8 q* j // schedule has a repeat interval of 1, it will loop every
- r: A# |0 V( n6 E3 Q* A // time step. The action is executed at time 0 relative to
0 C" ^6 u4 i! [5 Z: C/ d; U- v // the beginning of the loop.
b7 W o; p6 A8 |' L: b" g, p
+ N x7 F, V/ i3 a9 U* M // This is a simple schedule, with only one action that is- O' N+ X! ^5 o( c1 K
// just repeated every time. See jmousetrap for more4 R( [& L& {0 }
// complicated schedules.
( N( R' G4 m: s 1 h+ \5 U& W- m
modelSchedule = new ScheduleImpl (getZone (), 1);% B4 g A u/ @6 C- a& I) L6 F
modelSchedule.at$createAction (0, modelActions);7 y) e# x" y C3 E
; M1 a9 W( X/ l
return this;4 ` r$ A" I* K0 B* b% _
} |