HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下: g/ y$ n0 [' ?( ?8 h
7 A7 e$ T/ N" h1 m6 @$ M
public Object buildActions () {
0 a8 V; k. X' N: a @* D, P super.buildActions();5 R( c; ^1 O1 a! ]" D
/ A5 a" F: L$ W. i Z // Create the list of simulation actions. We put these in
# y0 y2 @7 y% U5 P0 \% B2 y5 V // an action group, because we want these actions to be
9 j$ w! n4 \- S // executed in a specific order, but these steps should
5 @1 ^ b- [* o4 z8 A# \. H // take no (simulated) time. The M(foo) means "The message0 |' c' I' f& c; K: K$ t! b4 t
// called <foo>". You can send a message To a particular: f- V7 P' a4 H& `! _6 V
// object, or ForEach object in a collection.# a8 E) e3 i+ m# z6 K5 p8 k2 T
N; G7 y. `6 ~; z; s
// Note we update the heatspace in two phases: first run
! }5 _0 h! x! l. J& V( O( Y8 h/ i // diffusion, then run "updateWorld" to actually enact the( D. B, x% Q9 W% ~% V, I& r
// changes the heatbugs have made. The ordering here is, f4 Q# F) O9 m! k7 i( p' G
// significant!
) ~ {( O% }. a+ d/ G* I8 d& ]
( l- O! H4 b! s3 A9 [' s // Note also, that with the additional
1 f& E: T G- T/ s2 V2 U // `randomizeHeatbugUpdateOrder' Boolean flag we can
9 l$ T1 z, k, v* V% H // randomize the order in which the bugs actually run
7 P7 H. _: x) P3 V // their step rule. This has the effect of removing any
5 `; U1 q: ]' L# t$ m // systematic bias in the iteration throught the heatbug
* P& q% g v) l% l% I // list from timestep to timestep
' D: N5 _( j8 F3 _) ~# u
$ a, h5 b/ {& @ // By default, all `createActionForEach' modelActions have
. L. X1 K L# v1 m* k+ e; c // a default order of `Sequential', which means that the
4 I4 _8 ?, I0 y2 \ // order of iteration through the `heatbugList' will be9 B0 z: p6 f9 K4 f
// identical (assuming the list order is not changed2 o8 Q5 c; j7 R; J: C
// indirectly by some other process).
4 k7 R* M7 ~" b5 K
0 n5 q" k+ }2 F c8 H& p modelActions = new ActionGroupImpl (getZone ());1 A" m9 v8 `8 o: D2 @
( _4 U" H+ i/ H5 ?! k& E+ d* R try {
; T9 \3 i& G Y+ u modelActions.createActionTo$message/ l( g3 [7 E1 v
(heat, new Selector (heat.getClass (), "stepRule", false));
9 b( K. o6 j( O6 l" \+ ` } catch (Exception e) {' {5 c$ p$ R9 r; {, r
System.err.println ("Exception stepRule: " + e.getMessage ());5 ]; I- A; f- U! l; A. N& C8 [
}
. f Z" g% Z4 Y# }# k6 Y) M$ E j6 {" D0 h5 J8 q5 Q/ B
try {
2 ]* p1 n: p. l Heatbug proto = (Heatbug) heatbugList.get (0);5 \3 _% k1 u" Q! A2 w
Selector sel =
1 `( j/ z* D# _ new Selector (proto.getClass (), "heatbugStep", false);) y/ g% a/ a) J
actionForEach =
7 O$ v- P; a# d, ?/ B8 P7 F: B modelActions.createFActionForEachHomogeneous$call' r8 |3 L' {1 D
(heatbugList,8 |# B" H6 W0 D: F
new FCallImpl (this, proto, sel,; D* n2 y* x2 }* X* F& K; X$ |
new FArgumentsImpl (this, sel)));
$ @/ W' S, g' T- f. u W' N } catch (Exception e) {
5 j6 u; n( E- _2 b e.printStackTrace (System.err);: Y: _+ C% S2 d) W S7 q9 }% y
}
" g& R( D+ ~, M0 P' B
, w& A) ^; `+ E& N* U syncUpdateOrder ();1 g% { c. U I1 s. o- Z1 m
0 |. c( y% @- ?# N; K; Z try {( e/ J6 G1 ~1 I9 n; M! X% x
modelActions.createActionTo$message 0 k2 p# E5 d/ W$ b3 G
(heat, new Selector (heat.getClass (), "updateLattice", false));
( M- t& v" X X: J7 N! | } catch (Exception e) {! E/ l2 v! ~: l4 S; x; u
System.err.println("Exception updateLattice: " + e.getMessage ());
& H0 H+ |( T3 P/ r8 m( S1 f }
& g# |0 u1 `0 {1 }% M$ m; Q : j# d4 F0 }/ j
// Then we create a schedule that executes the
5 I d, r) @7 T8 B8 j // modelActions. modelActions is an ActionGroup, by itself it
+ R4 [" Q5 f" D% Z | // has no notion of time. In order to have it executed in
) \5 V+ V' H. d) T // time, we create a Schedule that says to use the7 `2 v' a8 k% k5 ^
// modelActions ActionGroup at particular times. This
4 X" o- `% b' r+ X9 K8 s9 X# L // schedule has a repeat interval of 1, it will loop every
1 `2 n0 {& G) `1 n6 r7 I // time step. The action is executed at time 0 relative to# N; e. g$ G$ w Z7 }6 `; B# z. P" W
// the beginning of the loop.7 s7 @) {. ?3 c, i7 t
1 j/ F2 r4 n( x" G5 ^ // This is a simple schedule, with only one action that is
2 f# }+ Q) ?/ ` // just repeated every time. See jmousetrap for more. d, I, u. x. I- H& v! V0 g* Z6 C! M
// complicated schedules.1 I1 f" O+ p' N. u+ _) b3 p3 O
4 s& H3 y; I3 \7 @( F9 E) M5 O modelSchedule = new ScheduleImpl (getZone (), 1);: c' C/ O; U4 e3 U5 B
modelSchedule.at$createAction (0, modelActions);, R' E+ i; ^' t6 t; ]0 {2 P
2 ~$ x( T& m% |/ e return this;
5 X" D R6 v; }/ c- |/ Q } |