HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:" s8 m$ K' b, p# y8 o
; Y: e' K! g: @, b public Object buildActions () {
1 s z* z2 d( A1 P' T super.buildActions();3 r( a/ j3 g, }0 v% l/ ~: [
' G) d& d2 d% P1 J // Create the list of simulation actions. We put these in
7 v: M) s( t0 L) W // an action group, because we want these actions to be% ~, f1 S# G7 s# H
// executed in a specific order, but these steps should
6 X7 V/ h$ I4 P1 s7 M, x1 X; G // take no (simulated) time. The M(foo) means "The message
# v p% h0 k) {5 {2 l // called <foo>". You can send a message To a particular
0 O' V$ Y; h: g- A // object, or ForEach object in a collection.' y* Y f" k5 F8 @5 p
: E- X: Q, m% Q, G _+ h8 H // Note we update the heatspace in two phases: first run
4 ]. N, _/ f) d, G0 n) I) M // diffusion, then run "updateWorld" to actually enact the
% ^ k; Y5 K: g" {4 L2 S // changes the heatbugs have made. The ordering here is- {* a3 W: b+ ] l* x. P' E: ]. I
// significant!' ^) ]' I' H9 W# I5 O3 D
3 R+ u, }; U9 ~8 N6 L. b
// Note also, that with the additional
: [ d5 v, {# B* [: k+ X# q6 t // `randomizeHeatbugUpdateOrder' Boolean flag we can+ T) }% c- s) E
// randomize the order in which the bugs actually run
. ?8 f- E$ O1 e% K0 d& ^ // their step rule. This has the effect of removing any
0 ]) U9 p, n9 w# P$ U. q4 S }3 Z // systematic bias in the iteration throught the heatbug
6 Z! }' N2 }! g // list from timestep to timestep. g1 |! v; @7 H9 I
0 Z7 X' D. A Y& T
// By default, all `createActionForEach' modelActions have* q) t* w- Y' d) t2 _
// a default order of `Sequential', which means that the
4 k, q- m: _9 J/ ?( e // order of iteration through the `heatbugList' will be. b' E4 b+ r0 X# b
// identical (assuming the list order is not changed
; o2 b! Y* m. j3 ^ U: c // indirectly by some other process).
8 B7 e* A% h# p, Z ( w( E% ^/ l* j
modelActions = new ActionGroupImpl (getZone ());5 \! [5 ?% Z/ V( U1 P0 f" @
7 ?; M4 D( |9 k- m6 Y$ z' r9 e* ~0 l try {
6 U4 P' u+ W* l) o7 v modelActions.createActionTo$message+ h1 y, o* {2 O8 ~; M$ B. `2 N! ]) |
(heat, new Selector (heat.getClass (), "stepRule", false));9 s# m6 l0 M, ]9 D. N5 O
} catch (Exception e) {
+ O! m7 s8 X2 [8 I" Q System.err.println ("Exception stepRule: " + e.getMessage ());
1 P, j2 ] ^4 w$ @5 s }
, G: f& T1 b7 O# E! g# j: A }2 i% `& a+ K
try {" K. @1 o- v W l' G3 I7 ]8 W
Heatbug proto = (Heatbug) heatbugList.get (0);* R6 b* X3 j2 {/ c
Selector sel =
! [! }( K6 q- i0 D/ ^" U( C new Selector (proto.getClass (), "heatbugStep", false);/ _' p; `4 L3 Z1 S; e/ r8 t/ K
actionForEach =
1 e, C; m- | ^6 s$ O0 V modelActions.createFActionForEachHomogeneous$call( ?) s' b% [+ B J: s0 |
(heatbugList,
4 R. T( E% @& a! P new FCallImpl (this, proto, sel,$ [0 j+ G2 x7 J# S( v! [) f
new FArgumentsImpl (this, sel)));
( g5 L7 `$ O) ]- n } catch (Exception e) {
) _) f% r; {: g5 P" x5 C" E e.printStackTrace (System.err);
9 F/ `4 Y% w6 c# o r }
" Y# f: m' _$ w5 s6 y& p: w; } . V5 Z' |1 n: ]9 W$ m( i
syncUpdateOrder ();3 O7 H4 G1 U7 @* H# Q
/ d; C7 u, ]0 e
try {
7 ^& t( [) v F7 [6 u% Y modelActions.createActionTo$message / i8 `" ]9 X2 ?! I$ S
(heat, new Selector (heat.getClass (), "updateLattice", false));) L8 K7 X' m% B
} catch (Exception e) {2 ~! f9 f. F: X% g
System.err.println("Exception updateLattice: " + e.getMessage ());9 L# M+ E5 J$ P6 E& {# _, U
}' a8 a6 p" l7 s/ k
. Y% N$ y' r! [6 O& y5 K" S
// Then we create a schedule that executes the. Z# K8 T5 k9 \3 n; s2 k
// modelActions. modelActions is an ActionGroup, by itself it
9 X9 Q- i6 T" G, l) H* l // has no notion of time. In order to have it executed in% R# P) t: P& k; u$ P! N
// time, we create a Schedule that says to use the
* i% o! n7 k2 J7 }& T( h4 x) _ // modelActions ActionGroup at particular times. This
* Y# p9 S# J9 V" r3 P0 w // schedule has a repeat interval of 1, it will loop every8 g1 k6 m# ?' g: m: Y l" d/ t
// time step. The action is executed at time 0 relative to
# g# }9 \. l: f2 [8 V- j s) E1 X& ~ // the beginning of the loop.
' Y; l7 O9 j3 j- j) }8 k. S& N! {1 ~1 I; i9 A( @. _( y
// This is a simple schedule, with only one action that is- ?1 E K6 ~ w/ X- e
// just repeated every time. See jmousetrap for more
3 ]* R7 l2 S/ I# u% O% H& @# R // complicated schedules.* s, U- f" ~; M8 @' L, Z+ [+ i
* z' U5 J2 i$ m3 \5 A6 E
modelSchedule = new ScheduleImpl (getZone (), 1);
5 |2 K! I$ W# K- E modelSchedule.at$createAction (0, modelActions);
% T) L' M' Y& j
; b: Q( x4 c& B/ ?3 y, W return this;
/ v3 Y/ M) |: @; F! O9 O+ c } |