swarm-support
[Top][All Lists]
Advanced

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

Re: [Swarm-Support] Java Swarm With Graphs


From: durga bhavani
Subject: Re: [Swarm-Support] Java Swarm With Graphs
Date: Wed, 16 Nov 2005 13:07:38 -0800 (PST)

Hello,
 
Sorry to bother you, I am trying to learn swarm
 
This example works fine
But  in my case what I did is I wrote a program where it calcalutes and stores the result in a Two-Dimensional array. And then with the data in the array I am able to print a Graph.
 
But the method where I wrote the code that method I am calling  from ModelSwarm it does plot the Graph with the array values but it also creats a new graph for each iteration.
 
Here is the piece of code
public void Print1(){
         String colors[]={"red","green","blue"};
                double value[]=new double[8];
                int min=1;
                int max=7;
                int t=Globals.env.getCurrentTime();
                   Graph graph = new GraphImpl (getZone ());
        graph.setWindowTitle ("A Graph");
        graph.pack ();
         for (int i = 1; i < 8; i++) {
          GraphElement ge = graph.createElement ();
           ge.setLabel ("Time Step" + i);
          ge.setWidth (2);
          ge.setColor (colors[i % 3]);
    System.out.println(i);
              //ge.addX$Y ((5 - i) ^ 2, 1 + i);
          //ge.addX$Y (i + 9, 10 * Math.sin (Math.PI * i / 10));
       //         System.out.println(value[k]);
        for(int k=0;k<4;k++){
                for(int l=0;l<8;l++){
           ge.addX$Y(k,CL_log[k][l][t+1]);
              ge.addX$Y(k+1,CL_log[k][l][t+1]); 
        }
      }
}     
}
 
Model Swarm
try {
        //System.out.println("Trying to create an instance of SimF");
        SimF protoLeader = (SimF) leaderList2.get(0);
        //System.out.println("created a Instance");
      Selector sel1 = new Selector (protoLeader.getClass (), "Print1", false);
        //System.out.println("Loading Loader");
      actionForEach[3] = modelActions.createActionForEach$message(leaderList2, sel1);
}
         catch (SignatureNotFoundException e) {
        e.printStackTrace();
 //    e.printStackTrace (System.err);
        System.out.println("Exception has occured here signature");
        //System.exit(1);
}
                catch(Exception e1)
        {
        e1.printStackTrace();
        }
 
Is there a way were I can print a graph only one time
 
 
Regards,
Durga

 
 


"Marcus G. Daniels" <address@hidden> wrote:
durga bhavani wrote:

> No I need to add 100 curves each in different time steps.

If you mean: "Can I use I have arbitrary X and Y coordinates?", the
answer is yes.
I think Paul's remarks are well taken, though.




import swarm.Globals;
import swarm.simtoolsgui.GUISwarmImpl;
import swarm.defobj.Zone;
import swarm.gui.Graph;
import swarm.gui.GraphElement;
import swarm.gui.GraphImpl;
import swarm.Selector;

public class TestGraph extends GUISwarmImpl {
TestGraph (Zone aZone) {
super (aZone);
}

public Object buildObjects () {
super.buildObjects ();
String colors[] = { "red", "green", "blue" };

Graph graph = new GraphImpl (getZone ());

graph.setWindowTitle ("A Graph");
graph.pack ();

for (int i = 1; i < 9; i++) {
GraphElement ge = graph.createElement ();

ge.setLabel ("#" + i);
ge.setWidth (1);
ge.setColor (colors[i % 3]);

ge.addX$Y ((5 - i) ^ 2, 1 + i);
ge.addX$Y (i + 9, 10 * Math.sin (Math.PI * i / 10));
}

return this;
}

public static void main (String []args) {
Globals.env.initSwarm ("TestGraph", "0.0", "address@hidden",
args);
TestGraph testGraph = new TestGraph (Globals.env.globalZone);

testGraph.buildObjects ();
testGraph.buildActions ();
testGraph.activateIn (null);
testGraph.go ();
}
}
_______________________________________________
Support mailing list
address@hidden
http://www.swarm.org/mailman/listinfo/support

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


reply via email to

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