[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Java--Passing selector arguments to EZGraph
From: |
Marcus G. Daniels |
Subject: |
Re: Java--Passing selector arguments to EZGraph |
Date: |
23 Mar 2001 17:02:55 -0800 |
User-agent: |
Gnus/5.070084 (Pterodactyl Gnus v0.84) Emacs/20.4 |
>>>>> "TW" == Tom Wainwright <address@hidden> writes:
TW> I need to use a method with an argument in an EZGraph call, and
TW> can't quite see how to do it in Java. The idea is to have EZGraph
TW> call a method with a string argument used to select a particular
TW> data series from several options.
Paul Johnson recently added a setUnsignedArg method that can be used
for most things (directly or indirectly). It's in the current
javaswarm.dll/swarm.jar files at
ftp://ftp.swarm.org/pub/swarm/binaries/w32/latest.
Here's an example:
import swarm.Globals;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.defobj.Zone;
import swarm.activity.Activity;
import swarm.objectbase.Swarm;
import swarm.activity.Schedule;
import swarm.activity.ScheduleImpl;
import swarm.analysis.EZGraphImpl;
import swarm.analysis.EZGraph;
import swarm.analysis.EZSequence;
import swarm.Selector;
import java.util.LinkedList;
import java.util.List;
public class TestEZGraph extends GUISwarmImpl {
EZSequence sequence, averagingSequence;
class Agent {
double value;
Agent (double value) {
this.value = value;
}
void newValue () {
value = Globals.env.uniformDblRand.getDoubleWithMin$withMax (.1, 1);
}
public double getAgentValue (int scale) {
return value * scale;
}
}
List list;
Schedule schedule;
EZGraph ezgraph;
Agent standaloneAgent;
TestEZGraph (Zone aZone) {
super (aZone);
}
void addValueToList () {
double v = Globals.env.uniformDblRand.getDoubleWithMin$withMax (.1, 1);
list.add (new Agent (v));
}
public void step () {
standaloneAgent.newValue ();
addValueToList ();
sequence.setUnsignedArg (Globals.env.getCurrentTime ());
averagingSequence.setUnsignedArg (Globals.env.getCurrentTime () - 20);
ezgraph.step ();
getActionCache ().doTkEvents ();
}
public Object buildObjects () {
super.buildObjects ();
list = new LinkedList ();
addValueToList ();
standaloneAgent = new Agent (1.0);
ezgraph = new EZGraphImpl (getZone (), "setUnsignedArg Demo",
"t", "prob.",
"ezgraph");
try {
Selector sel = new Selector (Agent.class,
"getAgentValue",
false);
sequence =
ezgraph.createSequence$withFeedFrom$andSelector ("standalone",
standaloneAgent,
sel);
averagingSequence =
ezgraph.createAverageSequence$withFeedFrom$andSelector ("av(list)",
list,
sel);
} catch (Exception e) {
e.printStackTrace (System.err);
System.exit (1);
}
return this;
}
public Object buildActions () {
super.buildActions ();
schedule = new ScheduleImpl (getZone (), 1);
try {
Selector sel = new Selector (getClass (), "step", false);
schedule.at$createActionTo$message (0, this, sel);
} catch (Exception e) {
e.printStackTrace (System.err);
System.exit (1);
}
return this;
}
public Activity activateIn (Swarm swarmContext) {
super.activateIn (swarmContext);
schedule.activateIn (this);
return getActivity ();
}
static void main (String []args) {
Globals.env.initSwarm ("TestEZGraph", "0.0", "address@hidden", args);
TestEZGraph ezgraphTest = new TestEZGraph (Globals.env.globalZone);
ezgraphTest.buildObjects ();
ezgraphTest.buildActions ();
ezgraphTest.activateIn (null);
ezgraphTest.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.
- Re: FunctionGraph, Marcus G. Daniels, 2001/03/13
- Re: FunctionGraph, Pietro Terna, 2001/03/13
- printing lists (java), Matteo Richiardi, 2001/03/13
- Java--Passing selector arguments to EZGraph, Tom Wainwright, 2001/03/23
- Re: Java--Passing selector arguments to EZGraph,
Marcus G. Daniels <=
- Re: Java--Passing selector arguments to EZGraph, Tom Wainwright, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Marcus G. Daniels, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Tom Wainwright, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Marcus G. Daniels, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Tom Wainwright, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Marcus G. Daniels, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Tom Wainwright, 2001/03/26
- Re: Java--Passing selector arguments to EZGraph, Marcus G. Daniels, 2001/03/26
- Building from source on RedHat 7 (was: Re: Java--Passing selector arguments to EZGraph), Tom Wainwright, 2001/03/26
- Re: Building from source on RedHat 7 (was: Re: Java--Passing selector arguments to EZGraph), Marcus G. Daniels, 2001/03/26