HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:
; Z! Z/ ]5 t% j3 |1 ]' A! K' g- o
public Object buildActions () {
& m( @8 A3 v! F" D super.buildActions();( R! a2 N! |+ b' G# G
: G( b' {8 i4 O( t // Create the list of simulation actions. We put these in+ a% C3 b0 n* l x' c
// an action group, because we want these actions to be. w3 y- Q4 y! ^1 n
// executed in a specific order, but these steps should9 ?/ S. m) ^1 ?7 S- d
// take no (simulated) time. The M(foo) means "The message
' M8 e) ~0 O }: Y // called <foo>". You can send a message To a particular
! _) d# h4 ?8 h // object, or ForEach object in a collection.6 W! G( o# ?. P" ^- ^
% `! E) J% D4 z' Z7 @
// Note we update the heatspace in two phases: first run' s. _- Y: i q G/ m2 @: i
// diffusion, then run "updateWorld" to actually enact the
+ [, \! h6 v" d2 }$ Q4 n$ d // changes the heatbugs have made. The ordering here is( _4 T/ {) y, H' L+ S/ j
// significant!
. e! S8 T2 S0 ~5 X* {( b4 t : J2 U: ~7 c8 b. c
// Note also, that with the additional
: o' C! R3 H( z4 ~4 Q // `randomizeHeatbugUpdateOrder' Boolean flag we can
7 ^9 S- E! A& i2 p3 E // randomize the order in which the bugs actually run) k8 f0 B/ K3 H7 q- J8 l$ F5 D4 J
// their step rule. This has the effect of removing any K5 R+ I1 F$ p" j& K
// systematic bias in the iteration throught the heatbug. X! J. _5 t( X( M
// list from timestep to timestep
+ ?# t: ]6 ?% w# l
$ y) G9 z! [7 H // By default, all `createActionForEach' modelActions have
, W0 C+ w% c$ O4 V: ^" t7 ^5 o. C5 L+ p // a default order of `Sequential', which means that the
# w/ Z) r$ j* g9 u7 D: @ // order of iteration through the `heatbugList' will be! e1 Y! V( K3 T7 r: \
// identical (assuming the list order is not changed/ V, A% s5 q1 c
// indirectly by some other process).
1 v7 ^7 e/ i) V! R& Z/ l" U1 b7 N
! a O/ `% d+ o6 G9 s% V3 M modelActions = new ActionGroupImpl (getZone ());
' H1 g2 E& @9 W' W
: j" j3 K I1 @ try {3 `2 P7 J7 @+ T0 D3 A$ P K
modelActions.createActionTo$message( h$ h/ p: H) g
(heat, new Selector (heat.getClass (), "stepRule", false));
1 \1 h( j4 P! n6 f/ c } catch (Exception e) {
3 n* I; y% _, x( G+ d& } System.err.println ("Exception stepRule: " + e.getMessage ());/ h; }& Z" z9 ?9 k% x; S ]: k
}
2 ~7 \9 q& s' s5 \- i/ ~7 Z2 t' y; }* `0 F8 n
try {0 ]: H9 N% _' S
Heatbug proto = (Heatbug) heatbugList.get (0);
8 f9 x) \2 K8 L; A$ L# u) e% m Selector sel = ( |3 G: ~6 m( w2 x; \4 S5 }2 y2 Y( ?
new Selector (proto.getClass (), "heatbugStep", false);
% o0 d% h. Y0 I* A2 `1 ]0 A0 j actionForEach =
5 N. p/ {# O) D0 O) v8 E& R v modelActions.createFActionForEachHomogeneous$call) I" [0 n0 B, @! K$ H, `8 t
(heatbugList,
7 T0 u' p. |# d' Q! G7 g new FCallImpl (this, proto, sel,0 c# k+ p- }2 o; B8 M
new FArgumentsImpl (this, sel)));
4 { |' g% [# [7 R; g } catch (Exception e) {
% z. C3 D/ z7 {- n. O) F6 ~ e.printStackTrace (System.err);9 E V. s% D0 _/ S+ `% {3 }) E8 L
}+ p! g$ S8 ~ L8 h, W i
, m1 o2 v& B# H* d5 l) t" [+ N
syncUpdateOrder ();$ O( L5 Y& P& A* ?
5 B; I5 U. v- h* ?
try {+ _. c6 `8 V& ~# }# ?5 f
modelActions.createActionTo$message ; {, @+ d" P1 D L6 Y) m* f% ~
(heat, new Selector (heat.getClass (), "updateLattice", false));( D% r; V/ |8 R+ ]2 G
} catch (Exception e) {
& e+ t5 l( C( @6 n System.err.println("Exception updateLattice: " + e.getMessage ());- ?$ s% e1 v3 I, d
}
1 v8 Q. D t4 k / u; y# {$ v, m
// Then we create a schedule that executes the. X/ L* h% E# |
// modelActions. modelActions is an ActionGroup, by itself it7 M6 f! I. Y/ W) {! Q
// has no notion of time. In order to have it executed in
9 ]! p2 v) ]( T( r) z3 x: n // time, we create a Schedule that says to use the) [4 K1 B& S* l- G/ s7 E |" G
// modelActions ActionGroup at particular times. This
7 C5 l& r% E- W# v5 O2 m$ [4 R1 g // schedule has a repeat interval of 1, it will loop every, B4 S$ d: w' S' ]; j
// time step. The action is executed at time 0 relative to
& l% _! q/ b) L) G // the beginning of the loop.6 f4 {+ H% e; e; R5 o. b8 G
3 |% ~! ? } G
// This is a simple schedule, with only one action that is( ?1 P8 }- H" \) {2 S$ t, n% c
// just repeated every time. See jmousetrap for more) g Z2 O$ |: Q- O
// complicated schedules.
% I7 o+ M! Q, e, U, P7 o 0 J |/ F* _ b8 w9 G
modelSchedule = new ScheduleImpl (getZone (), 1);5 |" E& C$ _( f. F; ^# ?
modelSchedule.at$createAction (0, modelActions);" q0 O9 X0 e, V% H2 K3 I. J i/ L
; y3 g* E/ b! q, N- c$ b. W return this;
) A" x2 I! S. M2 `, G% k } |