HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
1 Z. m# _% C. ]/ Z3 ]: n; E0 E$ y3 _ E) G4 Y
public Object buildActions () {
. f$ m4 {. G5 ^( V% z4 p9 i0 l super.buildActions();
( S( Z4 E& q% y! J$ f6 K. L9 R0 G( L 8 m$ a# ]" d" d6 Q+ Z
// Create the list of simulation actions. We put these in3 x- O5 G% Y, A+ W' N
// an action group, because we want these actions to be" c" c+ ^0 y$ P6 m
// executed in a specific order, but these steps should: U4 N p# I" |7 j/ N, N! n
// take no (simulated) time. The M(foo) means "The message9 g3 r0 L- J6 n+ v8 p, D
// called <foo>". You can send a message To a particular# o* v6 i7 C* _5 H3 u+ E* V" |
// object, or ForEach object in a collection.- O& z2 P E2 f
& ], O0 r& e1 f+ }
// Note we update the heatspace in two phases: first run
4 O+ H% r$ C# ^' N3 l4 C: | // diffusion, then run "updateWorld" to actually enact the
& |. ~; K2 x5 h6 h0 v6 R1 O // changes the heatbugs have made. The ordering here is d2 z( W/ Y$ Q: @& W
// significant!
0 a5 B+ S+ n2 [% D# ?9 C . a- b; Q, d' x. l' `
// Note also, that with the additional" G& W4 P$ W& e# x
// `randomizeHeatbugUpdateOrder' Boolean flag we can9 z/ G2 N6 E; s) T
// randomize the order in which the bugs actually run
. J/ i2 u7 d! |1 j! y // their step rule. This has the effect of removing any
9 ~7 S9 V) o) c: i2 ^1 i$ | // systematic bias in the iteration throught the heatbug, s. M, E( O8 M5 P q( @- S
// list from timestep to timestep H7 K6 M- z9 t+ U
6 \) j6 C$ r$ ?& a5 ] X
// By default, all `createActionForEach' modelActions have {+ |8 x4 N, r% Q1 ~/ y
// a default order of `Sequential', which means that the, _) L. C- W$ J' }, c0 l
// order of iteration through the `heatbugList' will be5 [6 ~. F; [4 _6 H
// identical (assuming the list order is not changed Z5 |; q. o+ k3 N5 W
// indirectly by some other process).
. \3 B) {3 v; L S! Z* y- n
x$ r( `8 h2 ]/ t8 D* L' ~1 L* b" B modelActions = new ActionGroupImpl (getZone ());! `9 s. ~$ E- `6 i5 v
4 s, x' j( ?' a$ {5 x! a
try {1 {- x; \3 ~! p) N
modelActions.createActionTo$message5 t7 l) n; d, _0 n7 J6 Q9 d
(heat, new Selector (heat.getClass (), "stepRule", false));* E4 D" _9 G8 f0 @( u x
} catch (Exception e) {
' m% I! B; x- h System.err.println ("Exception stepRule: " + e.getMessage ());
5 N; C, ?( y5 w: _ }
& A! g* D: k' Y: A5 p
/ h$ x3 G, c2 h- L' p$ q try {
1 P: G* U) L3 \ G Heatbug proto = (Heatbug) heatbugList.get (0);
- s3 i3 E% F5 {$ h Selector sel =
. [& o/ M3 g1 o) g0 X new Selector (proto.getClass (), "heatbugStep", false);4 ~$ z9 x) C/ L! `7 Z+ U
actionForEach =9 U/ ]$ G9 I2 h, d0 s. d4 L
modelActions.createFActionForEachHomogeneous$call1 `1 h3 M0 b) |
(heatbugList,/ j7 b1 A3 d& m5 K
new FCallImpl (this, proto, sel,
) L$ ~; `8 }. ?; O5 `$ R, b ~' ? new FArgumentsImpl (this, sel)));" `8 N; K8 j( r
} catch (Exception e) {$ s C1 E" q& j& d. |' ^
e.printStackTrace (System.err);( O0 Y0 i: ], Z, @: H* Q
}
! F/ j# {$ ~6 H' O , R/ n$ ~) D* I5 L5 J% s
syncUpdateOrder ();
5 I* x0 Q1 ? ]4 Z
+ O( a/ ^* i+ a* u: A* f try {
" b- a3 r0 W# m0 R+ w modelActions.createActionTo$message - |* m. q) r) v X f
(heat, new Selector (heat.getClass (), "updateLattice", false));
2 Y$ y& K) ]7 S4 Q& d& g } catch (Exception e) {
( S# Q7 }6 m1 ]$ c; b3 a System.err.println("Exception updateLattice: " + e.getMessage ());
9 z* A! }, ]0 g* [9 k; n }$ W9 y+ X: R3 x) m
9 G) H4 o4 U8 {9 e |7 Y2 g) W
// Then we create a schedule that executes the1 j3 L6 n* T! c ^: M) x
// modelActions. modelActions is an ActionGroup, by itself it
3 L1 ]' U: n' ^- O. Q0 L5 t // has no notion of time. In order to have it executed in
6 X! m, t. r& G& m" k // time, we create a Schedule that says to use the
, H5 ^3 a6 d5 m. q( C4 C" O- g! S- x // modelActions ActionGroup at particular times. This
s: Z) a0 ~2 d$ [0 e. O' V D) `' O // schedule has a repeat interval of 1, it will loop every
* T3 a% g3 O/ y9 g' I C$ \4 | // time step. The action is executed at time 0 relative to
1 u) P0 a- U/ e1 T* ~ // the beginning of the loop.0 r$ t p) U- s. |# C8 |
- K. i, P; W5 J( N // This is a simple schedule, with only one action that is9 C2 R& N1 Z! q6 r4 O* P# q
// just repeated every time. See jmousetrap for more' [2 E8 ~/ T5 r b
// complicated schedules.
* n5 W( F! o+ f6 G, L7 D
$ E- n/ w/ k0 F4 r7 b P( {% n0 } modelSchedule = new ScheduleImpl (getZone (), 1);
" y" _ y0 Q$ T/ O7 v' ~) Z1 A) u/ @ modelSchedule.at$createAction (0, modelActions);" I- r) n8 z! S* F. ^
: @% A; x V3 J1 i5 p0 e& I return this;: v" c* |# T" \0 f0 x9 Z" E. ?2 [
} |