HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:: j; P0 n% ~7 l; A% S& p
. c' h$ w M6 }) o public Object buildActions () {
5 y/ e7 m1 w4 T super.buildActions();
* w. G ^# Q4 a; L6 ? ; @- c6 ?5 \" w! \ n6 [$ {5 Y
// Create the list of simulation actions. We put these in; G: f& A# R0 D. O! ?0 ~; E
// an action group, because we want these actions to be2 X# t5 c; I* ^. a* Y9 Q
// executed in a specific order, but these steps should* {- d- e, C! W
// take no (simulated) time. The M(foo) means "The message6 X- U7 i3 B" \( h) H" j
// called <foo>". You can send a message To a particular
% V0 G: v3 n. g // object, or ForEach object in a collection. u3 T1 k, ^: x0 R( H6 g+ ~8 o) \
0 z1 ?/ [5 ~2 A+ X; _+ F
// Note we update the heatspace in two phases: first run
$ T0 B3 n) [* w8 ]3 e, i // diffusion, then run "updateWorld" to actually enact the8 Q- U9 P" s0 k" V- o; u u* v0 X
// changes the heatbugs have made. The ordering here is. e+ X7 r& p; @0 |' o& J0 k" L
// significant!4 K$ }/ J& p4 f& O) b
* f7 w" T7 I8 } E // Note also, that with the additional. O7 g% |- g0 v2 f2 a* K* @
// `randomizeHeatbugUpdateOrder' Boolean flag we can$ v Z8 B& K' a
// randomize the order in which the bugs actually run
; X. H6 y' p; _% J2 f // their step rule. This has the effect of removing any8 Y6 |8 T7 c) `! x, Q$ s7 {7 W
// systematic bias in the iteration throught the heatbug; D- c5 H% U9 B
// list from timestep to timestep
6 o3 N8 O4 B9 f( Z" U 5 }; l/ Y2 O0 M' V4 _ j% `+ S5 d/ n
// By default, all `createActionForEach' modelActions have
- H$ ]) m% X7 p& x/ w // a default order of `Sequential', which means that the3 B" |0 L. ^% g, |2 B! k6 A
// order of iteration through the `heatbugList' will be L* x% ]: ^. n# D
// identical (assuming the list order is not changed
9 [1 b" f6 H. Q; m7 | S5 d // indirectly by some other process).
4 {: r8 U; w$ W) M 8 Y7 w% A& G7 @! z" U7 A
modelActions = new ActionGroupImpl (getZone ());1 t( [1 i& p! G0 x+ I6 I: G. b
# c& E6 u4 U5 k$ S |. _' T( s try {. ?( r( J; a9 \' }1 F" v
modelActions.createActionTo$message! }0 J0 t; R* n- H- d
(heat, new Selector (heat.getClass (), "stepRule", false));; i" U X6 W1 m. E7 I
} catch (Exception e) {
8 Q% o' |) R3 ^- F; P5 o System.err.println ("Exception stepRule: " + e.getMessage ());. F- T% U. v, S- W( v8 _1 x$ o
}
7 f& D7 _: d( U/ l) o# }7 J+ z4 J% j' t% g- L* z! o2 }# q
try {7 _: c. T/ ?9 q6 A. M
Heatbug proto = (Heatbug) heatbugList.get (0);
# k; W7 I! Z3 B/ Y2 O Selector sel = 6 P" O( O5 M8 o1 Z2 N7 {/ l% h
new Selector (proto.getClass (), "heatbugStep", false);
5 S7 }4 D! H3 N/ w0 e( r actionForEach =
8 {' o* J8 M: H) ^3 R# D modelActions.createFActionForEachHomogeneous$call
. E) H. C. T ` (heatbugList,% [1 p- p: L. h6 K: O
new FCallImpl (this, proto, sel,
: ]& ]% S2 M; W$ Y$ U1 n7 v* u new FArgumentsImpl (this, sel)));
# T3 x* B# r* o2 x } catch (Exception e) {5 p/ W* Y2 D: G4 c/ m
e.printStackTrace (System.err);. E) b6 o8 A# [8 @2 f
}* D2 ]& ^1 N0 N, v# b% e
% W3 V: ^+ N( c( k6 n \6 V syncUpdateOrder ();7 j! {, s$ T- h' e$ t. F
) i" @) g' G0 t2 ]4 I
try {. |4 H d- R( v" l) E8 F( I
modelActions.createActionTo$message
& f/ ~: `) X7 y1 C$ M# P (heat, new Selector (heat.getClass (), "updateLattice", false));
9 B" G9 e8 J& ?" ]4 u- p) |! r) E+ U/ P } catch (Exception e) {4 |! F; J+ k+ @2 k8 c3 Y* p) z
System.err.println("Exception updateLattice: " + e.getMessage ());
- N1 e$ k% i$ D }7 D$ A3 w3 t- Z2 P6 f; Y- }
3 ]& I, Z6 S7 h0 c6 Y8 O // Then we create a schedule that executes the9 b7 z3 P5 E9 F$ Q
// modelActions. modelActions is an ActionGroup, by itself it
- [( f' V# y4 K& O, U& D3 O" b7 \ // has no notion of time. In order to have it executed in
) b* x; ]- f+ y r. F3 S* ? // time, we create a Schedule that says to use the
( M) u! ?. V( y // modelActions ActionGroup at particular times. This+ y1 i( g$ E c" C- H7 D
// schedule has a repeat interval of 1, it will loop every6 E" J7 f" }( e2 u Z$ [8 |
// time step. The action is executed at time 0 relative to
4 q* E9 F# k- Q0 j/ ~- ^. ?, { Z // the beginning of the loop.
8 u, `4 j( J4 {5 R& Q; Y& e. L" x. m, l- Q
// This is a simple schedule, with only one action that is
& l* C' G( j: J0 y // just repeated every time. See jmousetrap for more
* F; _3 m+ `0 J* a) y; ^4 [ // complicated schedules.
2 j6 ~4 o: K: ~7 w
5 r9 N& D# O. h! J. v modelSchedule = new ScheduleImpl (getZone (), 1);: Q2 n( S Y% `# L7 w( }
modelSchedule.at$createAction (0, modelActions);
5 N# G) W5 b: l y' {) \' w" M6 F: B- k/ b
return this;( \* \8 p( t! K( y$ N v
} |