HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
* b1 [, r& ~1 _5 X* m/ e+ y5 G& H% L3 b) U
public Object buildActions () {
4 t" _, s' V0 r; [; h3 ~2 j$ v super.buildActions();
. ~4 X- h3 c3 n - ]+ o4 B! M5 c* b* b/ H! l
// Create the list of simulation actions. We put these in( b3 x5 _3 n& [; f8 K& {& j
// an action group, because we want these actions to be) B; f! L7 ?- N( U; S
// executed in a specific order, but these steps should
- g# T; ?8 w& z! Q // take no (simulated) time. The M(foo) means "The message8 C4 n) N; l. h N8 |( }
// called <foo>". You can send a message To a particular" C! l- {; \& W: n/ ?8 @2 @
// object, or ForEach object in a collection.
- U5 h" }* h5 P1 _# d+ Y
' _2 K1 |3 D9 Y x1 p // Note we update the heatspace in two phases: first run
6 \/ P8 T1 V5 G: ^% f // diffusion, then run "updateWorld" to actually enact the. N- ^6 S( q( j* l" A7 I; ^
// changes the heatbugs have made. The ordering here is" Y& e7 a6 g$ R; y8 X" Y- m
// significant!& M; V7 e' n0 b6 N/ [: x% c) {) M
# T# P% `- Q/ P( A // Note also, that with the additional
! U5 R: u2 A5 F! t- Y) ` // `randomizeHeatbugUpdateOrder' Boolean flag we can
8 p" v9 i" X, P1 o // randomize the order in which the bugs actually run
! ]/ N1 S5 h2 [' [5 A // their step rule. This has the effect of removing any
0 n* F, ^3 z( o$ X; x8 p- [6 T // systematic bias in the iteration throught the heatbug0 v4 r4 t$ H0 I2 _
// list from timestep to timestep/ D7 y8 i% {3 Z# O
) j6 k9 [! a/ X, S( A8 ?9 y // By default, all `createActionForEach' modelActions have/ E- }7 y' R' X, V
// a default order of `Sequential', which means that the! F9 ~( v2 W: E: J0 j. }2 J# S/ w
// order of iteration through the `heatbugList' will be- @4 g& ^ Z* _) A0 R! d: K
// identical (assuming the list order is not changed
0 v9 `7 ]* |! X2 \0 v7 Z5 ? // indirectly by some other process).' N7 o* i4 T( ~# @, b5 X. u
" p6 t( q+ f- h9 D) y' r8 C modelActions = new ActionGroupImpl (getZone ());4 ^( r, H" s4 k5 ]0 E
3 N; L' h$ Y6 Q% q try {; F: ?) [7 f$ T9 g3 T/ T
modelActions.createActionTo$message5 G+ V, [! o* q. N5 t* z# q
(heat, new Selector (heat.getClass (), "stepRule", false));; q6 B7 K b! F2 H3 c
} catch (Exception e) {
8 i5 |2 r1 ^5 z: f& C System.err.println ("Exception stepRule: " + e.getMessage ());
0 _" \0 N; D N6 V% H }
( q( S7 |* l( R, E$ f& B# w: q, C t, y( u$ n& T
try {
7 f7 Y) x1 V# t& T5 a# H7 g6 i Heatbug proto = (Heatbug) heatbugList.get (0);
/ n+ f& x9 I' O6 f9 X& p" Z1 h! i Selector sel = ) J) _2 {0 u, P" S
new Selector (proto.getClass (), "heatbugStep", false);* o. q: @1 u; ]5 @, l" J
actionForEach =% j5 Q9 @# `6 O3 p9 a6 |
modelActions.createFActionForEachHomogeneous$call; b6 Q3 }5 z8 \6 R* h! r- }/ u
(heatbugList,
; j; c- s$ }! G new FCallImpl (this, proto, sel,/ F9 w( X) x- M# Y$ l, L
new FArgumentsImpl (this, sel)));
/ [ H6 e: m8 A( s9 z$ _! | } catch (Exception e) {
& b, I! y m" y5 e e.printStackTrace (System.err);
' G [7 l# L% I- E }
! L% {1 ~- \6 @$ {+ I
2 ]( G3 n. D$ ~: s3 ]7 s9 m syncUpdateOrder ();1 W$ F. }( t- `: h! U; Y+ j
/ o/ c" j, u- H/ B+ H* O: |
try {
5 R9 ^7 ~5 i' o% ?+ [$ E modelActions.createActionTo$message
& B, c! N9 r$ c% F5 q% s, E (heat, new Selector (heat.getClass (), "updateLattice", false));
9 [! S- ^ y+ `. G, D } catch (Exception e) {
* A; y9 D( H9 I9 ~/ D4 {) N System.err.println("Exception updateLattice: " + e.getMessage ());
& |5 Z( H+ A9 M6 v6 v! m }
_6 C* ]2 A; @% ]
5 a% l# O9 [* l$ E+ H1 h; z$ A // Then we create a schedule that executes the
9 h) H9 N! f6 O+ n // modelActions. modelActions is an ActionGroup, by itself it
* b2 Z. l; M' M. |0 D1 ^ // has no notion of time. In order to have it executed in
' a& q$ N( d) q8 U9 x0 D- S; `8 H // time, we create a Schedule that says to use the9 p l8 N% N: {! s8 L0 m
// modelActions ActionGroup at particular times. This# {" M7 g* c6 y0 Z3 k* b
// schedule has a repeat interval of 1, it will loop every
+ C3 V2 X. w3 N [2 x) q7 `3 N // time step. The action is executed at time 0 relative to
1 ~; d9 |: q' v7 Y/ V // the beginning of the loop.
' F) V Z/ X- N* |9 K9 f) m1 I; ?/ ]+ [& r
// This is a simple schedule, with only one action that is7 ^4 O8 w: X' ]2 p& x
// just repeated every time. See jmousetrap for more
' K# N) O& Z+ @* N; O // complicated schedules.
. p& g% X& j6 B9 A6 L
# Z& k, R0 s: H8 s) [" X- b modelSchedule = new ScheduleImpl (getZone (), 1);
# q6 H7 J8 W s* e1 J; U$ A X( V/ k modelSchedule.at$createAction (0, modelActions);7 M* w* q& D% O
1 p: W9 x8 ~# L& o5 E return this;
6 y1 c2 w% w: ^, z9 A+ L& b7 G } |