//This program requires Swarm 2001-18-01 or newer, because it uses //argument-passing to EZSequences. 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 Object step () { standaloneAgent.newValue (); addValueToList (); sequence.setUnsignedArg (Globals.env.getCurrentTime ()); averagingSequence.setUnsignedArg (Globals.env.getCurrentTime () - 20); ezgraph.step (); getActionCache ().doTkEvents (); return this; } 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", "bug-swarm@swarm.org", args); TestEZGraph ezgraphTest = new TestEZGraph (Globals.env.globalZone); ezgraphTest.buildObjects (); ezgraphTest.buildActions (); ezgraphTest.activateIn (null); ezgraphTest.go (); } }