swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simulation order


From: Marcus G. Daniels
Subject: Re: Simulation order
Date: 20 Dec 1999 12:34:52 -0800
User-agent: Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4

>>>>> "DR" == david ROBIN <address@hidden> writes:

DR> i am using swarm in java under NT, and i want to know if it is
DR> possible to give the simulation orders(start, stop next, save, and
DR> quit) in the java code ,without the control panel.

You can send an Activity (the object you get back from activateIn) the
the messages run, terminate, step, next, and stop.  In a simulation
set up to run in batch, you then may need to introduce some way to
restart it (e.g.  wait on standard input and then call run again).

Otherwise, if you have a non-batch simulation and want an programmed
way to stop the simulation, here's an example.  (See the
swarm.simtoolsgui.ControlPanel reference for the other messages.)

import swarm.Globals;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.simtoolsgui.GUISwarm;
import swarm.activity.Activity;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.ActionGroup;
import swarm.activity.ActionGroupImpl;
import swarm.objectbase.Swarm;
import swarm.defobj.Zone;
import swarm.Selector;

public class TestControlPanel extends GUISwarmImpl {
  class Agent {
    Agent () {
      super ();
    }
    public Object step () {
        System.out.println (this + " step " + Globals.env.getCurrentTime ());
        return this;
    }
  }

  Agent agent;
  Schedule schedule;
  ActionGroup group;
  Schedule stopSchedule;
  Selector sel;

  TestControlPanel (Zone aZone) {
    super (aZone);
  }

  public Object buildObjects () {
    super.buildObjects ();

    agent = new Agent ();

    return this;
  }

  public Object buildActions () {
    super.buildActions ();

    schedule = new ScheduleImpl (this, 1);
    group = new ActionGroupImpl (this);

    stopSchedule = new ScheduleImpl (this);

    try {
      group.createActionTo$message
        (agent, 
         new Selector (agent.getClass (), "step", false));
      group.createActionTo$message
        (getActionCache (),
         new Selector (getActionCache ().getClass (), "doTkEvents", true));
      stopSchedule.at$createActionTo$message
        (10, getControlPanel (),
         new Selector (getControlPanel ().getClass (), 
                       "setStateStopped",
                       true));
      
    } catch (Exception e) {
      e.printStackTrace (System.err);
    }
    schedule.at$createAction (0, group);
    return this;
  }
  
  public Activity activateIn (Swarm swarmContext) {
    super.activateIn (swarmContext);
    
    schedule.activateIn (this);
    stopSchedule.activateIn (this);
    return getActivity ();
  }

  static void main (String []args) {
    Globals.env.initSwarm ("TestControlPanel", "0.0", "address@hidden", args);

    GUISwarm guiSwarm = new TestControlPanel (Globals.env.globalZone);

    guiSwarm.buildObjects ();
    guiSwarm.buildActions ();
    guiSwarm.activateIn (null);
    guiSwarm.go ();
  }
}

                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]