HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
' A% D! Y6 I3 ]4 |. i$ Q* f; q
' c$ v# R6 e/ Q public Object buildActions () {! P2 q; [4 v+ c2 N- A- G* T7 y/ m
super.buildActions();5 R' l) S# e* Z5 J& J9 r
: ^3 q( ?2 L+ Y3 F
// Create the list of simulation actions. We put these in
+ q; m, N& y& `1 J1 `* G# D+ w // an action group, because we want these actions to be
' E4 a1 k! F+ U4 l. ~, g // executed in a specific order, but these steps should
H+ U7 K1 n | F) h$ C4 u // take no (simulated) time. The M(foo) means "The message
* @0 L, n) i2 }# k/ }# R/ n' ? Q // called <foo>". You can send a message To a particular
6 y) z0 v' e+ g. [ // object, or ForEach object in a collection.7 c' k0 f9 y8 n" _
/ [0 z4 W0 l1 c. [7 i& i m
// Note we update the heatspace in two phases: first run7 Z! I4 X! {/ E7 i3 h: k7 V) u
// diffusion, then run "updateWorld" to actually enact the
; A: ?' x6 l/ C o9 ]$ q // changes the heatbugs have made. The ordering here is
6 P9 T" K/ g0 Y0 r/ d. o5 A- k. m. { // significant!
! E, N) C) R$ b. I2 [ / Y1 d# _, v2 v* |- _8 k
// Note also, that with the additional6 U% ~2 W% }3 T8 R: X. [
// `randomizeHeatbugUpdateOrder' Boolean flag we can
( J Z' B% |0 M6 X# w% N // randomize the order in which the bugs actually run1 ]. f. ?( N9 G
// their step rule. This has the effect of removing any4 C1 F5 ~$ a2 o) i5 A% c- U
// systematic bias in the iteration throught the heatbug
: a7 r } C8 [. a, q8 _ // list from timestep to timestep
8 q# g. M( \' J1 _; o 6 `0 c: A0 H: G% G/ D
// By default, all `createActionForEach' modelActions have0 w+ |5 j& ^& l- k. x7 Q, \# D
// a default order of `Sequential', which means that the
& e1 e( W7 F2 P0 p // order of iteration through the `heatbugList' will be& e1 I4 s$ U O! d' F$ y2 [
// identical (assuming the list order is not changed: Z9 z5 L7 i' K p- v# P& V8 S& E, ^
// indirectly by some other process)." N* }. h9 N( X8 J' I
' }5 d6 z9 F/ ] s/ u; e+ O9 C { modelActions = new ActionGroupImpl (getZone ());" Z. O9 R6 a, w! v/ Q# f8 A$ A
2 M) l* V/ A7 ? t. H4 a2 ~. l
try {
2 w4 Q- S1 p( ? modelActions.createActionTo$message
# D3 l* ^9 R: d9 Z+ S" q (heat, new Selector (heat.getClass (), "stepRule", false));2 `( C- k3 T5 H- P# S
} catch (Exception e) {
" I7 E1 K# S! }0 y: U ~! q. ` System.err.println ("Exception stepRule: " + e.getMessage ());
+ }. }) `4 d2 n! d. N6 k2 v }
& d& A( k9 S0 V" S# S# U; ~; R3 b! e9 q+ _! z+ n, b' K* r
try {
" C% b0 P. `" h7 P w, Z Heatbug proto = (Heatbug) heatbugList.get (0);6 w4 j0 e( A" t- d( ~6 ~& I, o
Selector sel = : j6 W0 S1 F% v5 I( Z8 `* `
new Selector (proto.getClass (), "heatbugStep", false);
1 w- Y& S0 ?- e% g4 U3 l/ Z! k% | actionForEach =- ]0 w* n1 R9 p; F5 Z0 R
modelActions.createFActionForEachHomogeneous$call$ Y( d" z4 ^! ~! P4 T5 S9 H+ }
(heatbugList,
- X; A7 I+ [7 }, R new FCallImpl (this, proto, sel,& M2 t! s: F Z8 E" U6 r
new FArgumentsImpl (this, sel)));
6 B3 Z Q& @4 W# p9 T7 t4 y } catch (Exception e) {
5 {( n& o+ ~2 ]* z e.printStackTrace (System.err);
! v) r* k/ E0 t! d; @. K; L }% U) V" S; H: X& C3 c" Q7 K$ [
; _7 \9 p' q/ L4 O z/ z/ N
syncUpdateOrder ();
1 }. B; M N# c% ^1 M) o% t: g7 }2 y$ T" z% H9 G# R/ V& n2 E
try {
! o; N( \! b% Q' b, ^ modelActions.createActionTo$message ! r. p! v/ w U6 O* B2 r
(heat, new Selector (heat.getClass (), "updateLattice", false));
- O$ r @; }2 n- u } catch (Exception e) {6 q. N' W9 u' u1 G
System.err.println("Exception updateLattice: " + e.getMessage ());0 ]* e4 x8 Z! ^# v8 h& x& G, d
}4 l* C* c* y: G" h
3 T( r2 _, n$ d$ k" M1 h // Then we create a schedule that executes the
" c$ R5 o. {: N2 d- { // modelActions. modelActions is an ActionGroup, by itself it
- p% v' S; x W" l( O1 ?& n // has no notion of time. In order to have it executed in
* N8 S7 A$ {7 L, J // time, we create a Schedule that says to use the
0 v; z6 c& }0 [+ m( L) V7 y& S, w // modelActions ActionGroup at particular times. This# P0 {/ R3 X. S8 b9 d
// schedule has a repeat interval of 1, it will loop every* Z! r0 u( y8 ?
// time step. The action is executed at time 0 relative to
& }4 f' s4 s2 K // the beginning of the loop.
/ H; Z6 ?" K8 X, g c3 N, ?. t
2 c$ s2 h; _' m( y$ M // This is a simple schedule, with only one action that is
% _; i D) ^0 X8 i2 [( H$ P$ I // just repeated every time. See jmousetrap for more
* Z3 C5 a5 v! \. } // complicated schedules.( M x' \1 a/ ^8 F+ Z5 P0 C6 _; X
C3 ]: N2 i4 f modelSchedule = new ScheduleImpl (getZone (), 1);6 `) G9 J$ @& {5 m" j( m
modelSchedule.at$createAction (0, modelActions);% x- X2 K+ W6 s2 h
5 g4 i7 b* I: D1 d& c6 k$ { return this;$ B! d* c( n; Z; y @) @
} |