HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
l- `! X# R" O# |$ _! x
0 u, i+ r6 B8 W& u public Object buildActions () {% W0 J7 a3 t+ z( K/ h
super.buildActions();
: R1 [. [6 v. E9 K Q
6 b h: J! y# ^( T# h // Create the list of simulation actions. We put these in
* l+ B7 [, O9 i% R. H: V // an action group, because we want these actions to be. Z1 f/ E" {- G8 d; C: K
// executed in a specific order, but these steps should+ M3 _- o8 _' I$ B
// take no (simulated) time. The M(foo) means "The message
7 C6 M& b% g0 W // called <foo>". You can send a message To a particular. I: {; R6 L4 ^. G) ]* W) @, G
// object, or ForEach object in a collection.0 d N* K3 u' B' ^- G
5 f+ m- _& x' o& d( s
// Note we update the heatspace in two phases: first run
" Y. ^5 ]/ l! w8 T! R! u // diffusion, then run "updateWorld" to actually enact the, ~( ~$ k! m; H% H
// changes the heatbugs have made. The ordering here is
# Q5 P: y- m0 D$ w6 w // significant!; Q9 _3 E9 H* H# M1 |& S A" P
( Y# V% u9 H' ~' D0 b // Note also, that with the additional
- O. {! S1 F0 Y$ }2 b, M // `randomizeHeatbugUpdateOrder' Boolean flag we can1 h" T C" y! ^0 ], k
// randomize the order in which the bugs actually run" f! K) k8 I+ O$ I+ k
// their step rule. This has the effect of removing any* h4 g7 B2 j0 w' ~$ L1 Q% h- r
// systematic bias in the iteration throught the heatbug
" b8 F$ s8 @4 W9 M8 N. X: k4 a; j // list from timestep to timestep
8 G' C8 _3 S) d/ O D& p( V/ K6 Q+ D 3 n/ m! p8 q8 ~! g6 F
// By default, all `createActionForEach' modelActions have8 f' W6 j5 P4 ~6 O2 m* Z& }: {. {
// a default order of `Sequential', which means that the v7 A. Z* m+ O* A- D
// order of iteration through the `heatbugList' will be: G4 J5 I; { c9 l w7 j
// identical (assuming the list order is not changed/ `" r o0 t3 | t
// indirectly by some other process).
8 ]$ i$ u; Y* ] 4 G. j/ y, K$ y6 H T$ j# d
modelActions = new ActionGroupImpl (getZone ());
; ^6 w$ d$ L! C' M& f! k, g. J l
try {" H4 h7 A8 o! ?$ p- M
modelActions.createActionTo$message+ Q% V, C# x8 I* F9 N& D
(heat, new Selector (heat.getClass (), "stepRule", false));2 c8 a/ Y! ^' t2 A* b- d# C
} catch (Exception e) {- [: P6 p' \# S5 y1 b
System.err.println ("Exception stepRule: " + e.getMessage ());" \9 s1 T9 Q: L+ s W) i1 t( z
}
@6 X6 c* F. H+ D7 w. q* O5 _$ ]8 q% K9 V/ U$ X
try {! u! K( j3 ~6 P
Heatbug proto = (Heatbug) heatbugList.get (0);
$ J6 h8 v6 h$ I% _( Q Selector sel =
) g9 A( p# ]1 C+ G2 { new Selector (proto.getClass (), "heatbugStep", false);
$ r) r. j6 F% K5 S actionForEach =& N/ ~3 y* M G* f6 P2 m
modelActions.createFActionForEachHomogeneous$call* q' g, s/ y- J! @
(heatbugList,
, n1 O# ^# y; s! O; \' ~* s# I new FCallImpl (this, proto, sel,. {% i: _& J, M
new FArgumentsImpl (this, sel)));5 C$ L. `; ^8 X' G3 K9 X- }7 R& x
} catch (Exception e) {( B2 z- `* C2 E8 m# f7 H/ n
e.printStackTrace (System.err);% F8 v6 H; U5 j1 w
}* t* O2 h5 D3 @: u
2 T Y4 z, k2 Y& T' O
syncUpdateOrder ();, G5 h$ w* M, x$ |$ F
+ [5 p/ ]6 M* m) l; I+ Z1 \ try {
$ L4 j& D! a+ A7 l9 e5 |! O modelActions.createActionTo$message : o) C9 P# ^6 Z+ a( Q& m& `* A
(heat, new Selector (heat.getClass (), "updateLattice", false));
6 X# Q0 e: n8 V+ \- b, t8 ]" h8 m a } catch (Exception e) {( {! L) L: A5 s( X& n6 m
System.err.println("Exception updateLattice: " + e.getMessage ());( a0 W2 U# N" y$ `2 u* v8 H4 F
}
# O7 G! M$ {3 g5 ^$ \' P/ z$ Q
, z y1 o+ X6 o% h7 A G# q7 [: D // Then we create a schedule that executes the
/ J/ T3 a& B. e5 }+ J // modelActions. modelActions is an ActionGroup, by itself it/ n( v/ E: l; ~' ?
// has no notion of time. In order to have it executed in
4 @+ w. J. b+ B i' | // time, we create a Schedule that says to use the
1 m. V9 L0 S) M4 l: p: L' U // modelActions ActionGroup at particular times. This
/ t) [* Z/ d. R! G // schedule has a repeat interval of 1, it will loop every* a1 o( E, x. y% c/ Z1 A0 i
// time step. The action is executed at time 0 relative to0 o3 Y! ^2 s' ?0 G( s: e
// the beginning of the loop.
- ~: k8 g0 u! m- l$ t( k+ Y6 \$ P
Z k$ D+ `% u$ m: ~+ q( l // This is a simple schedule, with only one action that is7 w% u3 k! [5 @0 ?
// just repeated every time. See jmousetrap for more8 {8 Y; l+ a% k" K3 b6 ]
// complicated schedules., {0 l* Q& }9 u8 N4 T; d) h7 Q
1 a" R" p# D- ^$ b% s q! R; b3 u+ } modelSchedule = new ScheduleImpl (getZone (), 1);
# |6 K2 a' _ I7 Y" n: W2 A modelSchedule.at$createAction (0, modelActions);
, c$ V8 ^: ]9 k) ]2 p ; z. O5 k/ t7 Z i- d7 }6 U/ q
return this;% S: @3 x L+ u2 Z2 F& j
} |