We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › help noob construct edges between nodes using file
Page Index Toggle Pages: 1
help noob construct edges between nodes using file (Read 212 times)
help noob construct edges between nodes using file
Oct 31st, 2008, 7:36pm
 
Hi

i need some advice, though the problem is kind of complicated.

I am reading from a TSV file and creating "node" objects (using a custom class I made) from each entry or line within it. I have a second file which is explicit about which nodes should be connected to which other ones and it is in the following format:
source <tab> target <tab> weight
(some node name) <tab> (some other node name) <tab> (some double value)

What's a good way, once I have "constructed" my nodes using the first file, to equate each node that is mentioned in the "edges" file to its rightful source and target node? The edges I am constructing have their own rightful class and their constructor takes two nodes as its arguments.

here's what I had working in actionscript, though I am not sure if I could easily translate into java/processing:

for each(var o:Object in edges) {
data.nodes.visit(function(n:NodeSprite):void {
if(o.source == n.data.common) o.source = n;
if(o.target == n.data.common) o.target = n;
});
var es:EdgeSprite = new EdgeSprite(o.source,o.target);

SO I guess what's happening is that there are two arrays of objects, one nodes, the other edges, the edges with attributes that can refer to nodes' names, and if the two can be equated then a third group of objects, this time an edgesprite is created? Does that all make sense?

thanks!
Re: help noob construct edges between nodes using
Reply #1 - Oct 31st, 2008, 10:51pm
 
here's my two attempts, neither of which are working(one is commented out):

for (int row=1; row<rowCountWET; row++) {
   //float weight = weightedEdgesTable.getFloat(row,2);
   String source = weightedEdgesTable.getString(row,0);
   String target = weightedEdgesTable.getString(row,1);
   Node fromAnimal = new Node(source);
   Node toAnimal = new Node(target);
   println(fromAnimal);
   println(toAnimal);
   
   for (int i = 0; i<Animals.length-1; i++){
    if (Animals[i].common.equals(source)){
      fromAnimal = Animals[i];
    }
   }
   
   for (int i = 0; i<Animals.length-1; i++){
     if (Animals[i].common.equals(target)){
      toAnimal = Animals[i];
    }
   }
   
   Edge e = new Edge(fromAnimal, toAnimal);
   g.addEdge(e);
   
   /*
   for (int i = 0; i<Animals.length-1; i++){
    if (source == Animals[i].common){
      fromAnimal = Animals[i];
    }
   }
   
   for (int i = 0; i<Animals.length-1; i++){
     if (target == Animals[i].common){
      toAnimal = Animals[i];
    }
   }
*/
Edge e = new Edge(fromAnimal, toAnimal);
   g.addEdge(e);

I am getting a nullpointer exception, but it doesnt really give me any insight into what's wrong. I believe the error happens where I try to equate the two nodes I have created but I'm really baffled as to what's wrong...

help, please?
Page Index Toggle Pages: 1