Menu

Finding an edge or vertex based on userdata

Saravanan
2005-05-27
2013-05-29
  • Saravanan

    Saravanan - 2005-05-27

    Hi there,

    I have a network graph with 200-300 nodes and the differentiator between the vertex is the ip addresses. The ip address is stored in the vertices as a user data.

    Is there anyway we can find a vertex or an edge in the graph based on the user data values? I searched through the documentation for this, but did not find any pointers.

    Thanks
    Saravanan

     
    • Joshua O'Madadhain

      Saravanan:

      There is no automatic/built-in way to find a vertex/edge given a user data value; this is because there can, in the general case, be > 1 vertex/edge with the same user data value.

      You will need to establish some kind of mapping between IP addresses and vertices; the easiest way to do this is when the vertices are being created.  One method involves creating a Map from IP addresses to Vertices; you can then optionally store this Map in the Graph's user data for later retrieval.

      Joshua

       
    • Saravanan

      Saravanan - 2005-05-27

      Thanks for your reply Joshua,

      I have a suggestion. Currently, the edges and vertices has an integer id attribute which is being used internally. Would it be acceptable to have this 'id' overloaded? This would give us a very good extensibility.

      For user who don't would like to use the default implementation, we can continue the hash map. But, for users with specific needs, the user has to specify the user attribute that has to be used as a key.

       
      • Joshua O'Madadhain

        I'm not sure exactly what you're proposing. 

        If you want to know whether you can create a version of JUNG that defines id in a different way, of course you can; it's an open-source project.  :)  However, you should be careful: id, in our current implementations, is bound up with the definition of equals() and hashCode(), and if the id you assign is not unique, various parts of the library will fail in strange ways.  (For instance, only one vertex with a given id can be part of a graph, or in fact any collection which enforces uniqueness, such as a Set.)

        In any case, you can always create an extension of the Vertex implementation you're using that has any fields you want, just as you can with any (non-final) Java class:

        public class IPVertex extends SimpleDirectedSparseVertex
        {
            long IP;
            public SimpleDirectedSparseVertex(long IP)
            {
                this.IP = IP;
            }
        }

        and so on. 

        Let me know if I haven't answered your question.  You may also want to look at the JUNG Manual's chapter on User Data, which discusses different ways of attaching data to JUNG elements.

        Joshua

         

Log in to post a comment.