HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:" c. { ]4 s0 i- H8 ], @
: U& Y, F y. K3 u0 B1 t
public Object buildActions () {
! j# j6 l* B4 V' D super.buildActions();
6 m5 o: Z5 }" }& w: P + {0 e' g- d7 @4 ~- j% e5 u
// Create the list of simulation actions. We put these in
: r0 X; ^& _2 A. | // an action group, because we want these actions to be
s0 H4 e2 W& c" W. m- g // executed in a specific order, but these steps should3 s$ ^. y" b1 L% \6 l$ }) W
// take no (simulated) time. The M(foo) means "The message
! t' C2 }6 Z- h1 Z( n6 l" Y // called <foo>". You can send a message To a particular6 E" e% J s: z- ^1 _! e
// object, or ForEach object in a collection.9 l6 [3 O0 M4 _! X5 n
1 n2 d0 O/ _4 F7 H) ? // Note we update the heatspace in two phases: first run9 M8 U7 y5 Q7 j. C
// diffusion, then run "updateWorld" to actually enact the! m! e) v8 ~1 }8 L U& a9 |, w
// changes the heatbugs have made. The ordering here is! P( E' s$ t! _/ U0 D
// significant!
: T1 b: E1 L2 s + O; f. G) L7 {
// Note also, that with the additional0 p/ Q$ P+ L/ u$ l* _
// `randomizeHeatbugUpdateOrder' Boolean flag we can
% p. P( b5 U7 A: v/ r, \ // randomize the order in which the bugs actually run0 i0 P, h }: }# R0 p! p0 F* ?9 G
// their step rule. This has the effect of removing any( W$ ~' G( c: q
// systematic bias in the iteration throught the heatbug5 {. M, h3 V* O `- z5 W* Y m
// list from timestep to timestep& \ N0 Y! `& }5 t# h' }) C
6 P8 g- S& b# {& a // By default, all `createActionForEach' modelActions have; n9 ^* v0 t) b+ v ~2 K6 Y
// a default order of `Sequential', which means that the
$ @# k; x5 |- L6 o% O0 D. Z e // order of iteration through the `heatbugList' will be
9 S/ m% k6 a5 t- k* p# A // identical (assuming the list order is not changed
* x/ |. K1 H4 S: T; s // indirectly by some other process).
+ y0 j, s) W5 X4 z , U& w( |; J; B+ R& H) X8 e1 G
modelActions = new ActionGroupImpl (getZone ());8 X- _+ G4 _) W9 c* C
- _0 r/ C1 h- e, f: B try {6 @; W6 Y/ h* f: E0 d. K9 z
modelActions.createActionTo$message8 C" k" s% B* Z6 x! s: z
(heat, new Selector (heat.getClass (), "stepRule", false));
3 R( Y3 ? j) K" v; |! [* x } catch (Exception e) {8 b, c8 v6 V J# g
System.err.println ("Exception stepRule: " + e.getMessage ());
( w) R9 {9 K, T4 m }8 B2 W! P' f' O
. K5 Q9 P5 V: n' I5 {% V6 f try {! O' M/ J+ z3 G% p' J
Heatbug proto = (Heatbug) heatbugList.get (0);" K5 b2 q% R* m
Selector sel = - n4 T# P7 o( w( ~! d3 t7 z
new Selector (proto.getClass (), "heatbugStep", false);
2 N4 m+ b' o7 Z# Q2 S actionForEach =
7 [; ~) E) w' Y$ P J( ~ modelActions.createFActionForEachHomogeneous$call' Z) I; U j' D0 D" l
(heatbugList,, N& \, F0 d/ C7 ? `4 a& X$ U
new FCallImpl (this, proto, sel,
& i0 @5 x! ^! T' V" r new FArgumentsImpl (this, sel)));) q. U/ H& \( K# q5 L
} catch (Exception e) {
" a: L% C6 e. U- j) S3 _. v e.printStackTrace (System.err);7 [+ m0 X) ^4 c. b( f
}9 |1 z4 l) \; n0 i- I
- J' a8 \2 \- Z) L7 f/ t syncUpdateOrder ();/ b1 G9 F/ t3 p! L
" a, n4 l7 }' w$ W: D1 e, {3 l try {5 J5 M; q5 g6 o9 K! ?5 f3 v, |+ k8 T
modelActions.createActionTo$message
/ i6 f: `% l7 F' C# w3 u (heat, new Selector (heat.getClass (), "updateLattice", false));
( |& O( ]7 \# @3 n } catch (Exception e) {4 a: [& C$ F* w! z
System.err.println("Exception updateLattice: " + e.getMessage ());3 x9 y8 [2 ^! F- M! L
}, F! u6 i! B* e& l' U
# r+ t& E' ?0 O6 w7 ~/ L7 D4 j // Then we create a schedule that executes the; M! U% I) V+ ^& C. M c, Y# w9 _
// modelActions. modelActions is an ActionGroup, by itself it
- K( V g: X+ T: Q // has no notion of time. In order to have it executed in: J! `; t( `( M1 Y
// time, we create a Schedule that says to use the) Y4 S# Y$ @# O: g/ g* A5 z/ K
// modelActions ActionGroup at particular times. This( t5 d4 q# @% I7 q& g2 n |
// schedule has a repeat interval of 1, it will loop every
+ M( ~. l# U/ e0 z) `- o // time step. The action is executed at time 0 relative to
: @# h' X7 u m6 |4 C" T2 i // the beginning of the loop.
2 c6 [1 V0 }2 R( o! w/ T4 R! {, t ]9 O+ F
// This is a simple schedule, with only one action that is
4 C) F# ^3 e# }4 H# b+ t/ f+ ? // just repeated every time. See jmousetrap for more
+ z2 M* e# r- r: N' e$ h4 F+ H8 H // complicated schedules.: G% H" d( z; b% v6 g
) Y* b. a# |/ A: G2 d
modelSchedule = new ScheduleImpl (getZone (), 1);& i5 w. n- W) d6 l( w' M
modelSchedule.at$createAction (0, modelActions);
4 R% o: U0 ]2 j; {. k
& a! j$ R% {4 D, o& A return this;7 a* \' z* |6 i' f" c! j6 K
} |