sybbk 发表于 2008-5-25 02:15:22

问jheatbugs-2001-03-28中某些代码

HeatbugModelSwarm中buildActions部分,3个try分别是做什么?查了下refbook-java-2.2,解释太简略,还是不懂,高手指点,谢谢!代码如下:

public Object buildActions () {
    super.buildActions();
   
    // Create the list of simulation actions. We put these in
    // an action group, because we want these actions to be
    // executed in a specific order, but these steps should
    // take no (simulated) time. The M(foo) means "The message
    // called <foo>". You can send a message To a particular
    // object, or ForEach object in a collection.
      
    // Note we update the heatspace in two phases: first run
    // diffusion, then run "updateWorld" to actually enact the
    // changes the heatbugs have made. The ordering here is
    // significant!
      
    // Note also, that with the additional
    // `randomizeHeatbugUpdateOrder' Boolean flag we can
    // randomize the order in which the bugs actually run
    // their step rule.This has the effect of removing any
    // systematic bias in the iteration throught the heatbug
    // list from timestep to timestep
      
    // By default, all `createActionForEach' modelActions have
    // a default order of `Sequential', which means that the
    // order of iteration through the `heatbugList' will be
    // identical (assuming the list order is not changed
    // indirectly by some other process).
   
    modelActions = new ActionGroupImpl (getZone ());

    try {
      modelActions.createActionTo$message
      (heat, new Selector (heat.getClass (), "stepRule", false));
    } catch (Exception e) {
      System.err.println ("Exception stepRule: " + e.getMessage ());
    }

    try {
      Heatbug proto = (Heatbug) heatbugList.get (0);
      Selector sel =
      new Selector (proto.getClass (), "heatbugStep", false);
      actionForEach =
      modelActions.createFActionForEachHomogeneous$call
      (heatbugList,
         new FCallImpl (this, proto, sel,
                        new FArgumentsImpl (this, sel)));
    } catch (Exception e) {
      e.printStackTrace (System.err);
    }
   
    syncUpdateOrder ();

    try {
      modelActions.createActionTo$message
      (heat, new Selector (heat.getClass (), "updateLattice", false));
    } catch (Exception e) {
      System.err.println("Exception updateLattice: " + e.getMessage ());
    }
      
    // Then we create a schedule that executes the
    // modelActions. modelActions is an ActionGroup, by itself it
    // has no notion of time. In order to have it executed in
    // time, we create a Schedule that says to use the
    // modelActions ActionGroup at particular times.This
    // schedule has a repeat interval of 1, it will loop every
    // time step.The action is executed at time 0 relative to
    // the beginning of the loop.

    // This is a simple schedule, with only one action that is
    // just repeated every time. See jmousetrap for more
    // complicated schedules.

    modelSchedule = new ScheduleImpl (getZone (), 1);
    modelSchedule.at$createAction (0, modelActions);
      
    return this;
}
页: [1]
查看完整版本: 问jheatbugs-2001-03-28中某些代码