[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I schedule the methods of updated members in a list?
From: |
Marcus G. Daniels |
Subject: |
Re: How can I schedule the methods of updated members in a list? |
Date: |
12 Aug 2000 15:19:39 -0700 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "KY" == Kazuko Yamasaki <address@hidden> writes:
KY> If I write following code in ModelSwarm, the methods of updated
KY> members in the list are not scheduled, but the methods of initial
KY> members in the list are scheduled.
The problem is here:
KY> actionForEach = modelActions.createFActionForEachHomogeneous$call
(The use of ForEachHomogeneous rather than ForEach.)
Here's an example of a ForEach action where the set of target objects get
updated each time step by the method "swarmStep".
import swarm.objectbase.Swarm;
import swarm.objectbase.SwarmImpl;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.activity.Activity;
import swarm.activity.ActionGroup;
import swarm.activity.ActionGroupImpl;
import swarm.defobj.Zone;
import java.util.List;
import java.util.LinkedList;
import swarm.Globals;
import swarm.Selector;
class Agent {
int id;
Agent (int id) {
this.id = id;
}
public void agentStep () {
System.out.println (id + "@" + Globals.env.getCurrentTime ());
}
}
public class TestForEach extends SwarmImpl {
Schedule schedule;
ActionGroup actionGroup;
List list;
int lastAgentId = 0;
TestForEach (Zone aZone) {
super (aZone);
list = new LinkedList ();
swarmStep ();
actionGroup = new ActionGroupImpl (aZone);
schedule = new ScheduleImpl (aZone);
try {
Selector aSel = new Selector (Agent.class, "agentStep", false);
Selector sSel = new Selector (TestForEach.class, "swarmStep", false);
actionGroup.createActionForEach$message (list, aSel);
actionGroup.createActionTo$message (this, sSel);
schedule.at$createAction (0, actionGroup);
schedule.at$createAction (1, actionGroup);
schedule.at$createAction (2, actionGroup);
} catch (Exception e) {
e.printStackTrace (System.err);
System.exit (1);
}
}
public void swarmStep () {
list.add (new Agent (lastAgentId));
lastAgentId++;
}
public Activity activateIn (Swarm context) {
super.activateIn (context);
schedule.activateIn (this);
return getActivity ();
}
public static void main (String[] args) {
Globals.env.initSwarm ("TestForEach", "0.0", "address@hidden", args);
Swarm swarm = new TestForEach (Globals.env.globalZone);
swarm.activateIn (null).run ();
}
}
==================================
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.