Menu

Jung 1.7.....Simple questions by a newbie

Sgotenks
2007-09-19
2013-05-29
  • Sgotenks

    Sgotenks - 2007-09-19

    Sorry if someone has already answered to these questions.(and sorry for my english)

    I would like to know 3 things:

    1)Is it possible to display 2 diferent graphs in a unique visualization viewer?

       Example : i have a graph G1 with his nodes and edges, and another graph G2 with his nodes and edges.
                 I create a Pluggable renderer PR, and a Visualization viewer VV  how i display both the graphs?

                 Generally i do Layout L = new Layout(G1)
                 vv =  new VisualizationViewer(L, PR)

                 but to add also the second graph??????

    2)I have 2 classes that extend Vertex(add some variables), one called Car, and anothe called Driver.My graph is composed by both these classes, so sometimes i add a Car to my graph and sometimes a Driver. Is it possible to add a code(a constraint or similar) in the 2 subclasses, so that when i add a Car in the Graph it is automatically displaied in BLUE with a certain size() and Driver is automatically displaied in another color and another size, so i can distinguish them?

    3)Last Questions, Is it possible to add a costraint that prevent to link a Car node with another Car node, and a Driver node with another Driver node, but only Car with Driver?

    Thanks all....

     
    • Joshua O'Madadhain

      To answer your questions...

      (1) Not sure if it's possible to do precisely what you stated; I'll defer to Tom, who knows the visualization end better than I do.
      One thing you could do is copy G1 and G2 into a new graph and visualize that.

      (2) Yes, you can do this.  You'll need to write a VertexShapeFunction that provides different Shapes (and thus sizes) for Cars and Drivers, and similarly for VertexPaintFunction.

      (3) Yes.  See KPartiteGraph (interface) and KPartiteSparseGraph (implementation).  The vertex Predicates you'd supply would presumably check to see whether the vertex was an instance of {Car, Driver}.

      Joshua

       
      • Tom Nelson

        Tom Nelson - 2007-09-19

        for question #1, jung 1.7 allows only one layout per
        visualization. Jung2 has a class called AggregateLayout
        that allows multiple layouts to be used by the same
        visualization.

        Tom Nelson

         
    • Sgotenks

      Sgotenks - 2007-09-20

      Ok, thanks, for your answer, but i need still some informations about the 3 over questions.

      1)To resolve the problem, i could make something like this, i put G1 and G2 i 2 different viewers(and 2 different layout and renderer), than i copy G1 in G2 and i keep only one viewer.But i need to do a merge, so i need that if in G1  i have Driver:Shumacker link with Car:Ferrari and in G2 i have Driver:Raikonen link with Car: Ferrari, when i copy g1 in g2, my program see that the vertex Labeled with the name FERRARI already exists and not copy it.

      So that g2 become composed of 3 vertex: one car FERRARI and 2 driver:Shumaker and rikonen, both link to Ferrari.Is this possible? 

      2)Second point it's ok :)

      3)So i have to use a bipartite Graph, i have never used it, but ther is an example, and i will look it(but seems difficut to use), and propably is the better solution to prevent to link Car with Car and Driver with Driver , but in the Jung Manual i have seen that i spossible to use Contraints and do for example edge_constraints.add(Graph.Not_PARALLEL_EDGE); doesn't exist a constraint that prevent to link vertex of the same type?(so i have not to use k-partire graph)?

      And Is there somewhere a list of all constraints that i can use?

      Sorry for all this questions.

       
      • Joshua O'Madadhain

        (1) GraphUtils.union() will do what you want to do.  Or you can use Tom's suggestion and do an AggregatedLayout.

        (3) The k-partite graph defines the constraints that you need for you, based on the vertex partitions that you provide.

        JUNG doesn't define very many constraints (and, incidentally, this mechanism does not exist in JUNG 2.0).  Directed, undirected, parallel edge, and the k-partite graph edge constraint may be about it.  However, you can define your own constraints if you like.

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-09-25

      1)Ok, still one questions, i have seen the BipartiteGraph demo.And The code is very long, because is very complex as example(there are too many class and methods not inherent with bipartite graph and so i'm not able to understand which code lines are necessary and  wich not for a simple use of bipartite graph).Is there another exampe of bipartite graph but more simple, without complex layout or method ?

      2)BipartiteGraph accept only undirectedsparseEdge, instead i need to use directed Edge.What i have to do?Remake BipartiteGraph Class identical to this one  but that extend DirectedSparseGraph instead oh undirected is a good idea?

      3)Generally in bipartithe graph all the vertex are of the same type, but are divided in 2 partitions,  Instead i have Car and Driver that are 2 subclasses of Vertex,so in the 3 partitions i have 2 different kind of vertex, is this a problem?

      Sorry for my english :)

       
      • Joshua O'Madadhain

        Don't use BipartiteGraph and the associated classes.  These have been deprecated and in fact should have been deleted at this point if they haven't already.  As I said in my earlier email, use KPartiteGraph (interface) and KPartiteSparseGraph (implementation).

        KPartiteSparseGraph accepts both directed and undirected edges by default.

        We don't currently have another sample that shows how to create a bipartite graph, although you could look at BipartiteGraphReader to get an idea.

        Your question (3) doesn't make sense to me.  Bipartite graphs have 2 partitions (and k-partite graphs have k partitions).  You describe two mutually exclusive types (Car and Driver), each of which I would expect to be in one partition.

        In any case, each partition needs to be defined by a single Predicate, and these Predicates must be mutually exclusive.

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-09-25

      So BipartiteGraph CLass is deprecated, why?Is it a implementations of Kpartite where k = 2(and in my program  k =2), so why not use it?

      I use kpartiteGraph(but there are not example of this class), but something is not clear.This is the constructor

      KPartiteSparseGraph(Collection partitions, boolean subsets)
                Creates a KPartiteSparseGraph whose partitions are specified by the predicates in the partitions array.

      but i don't understan what i have to insert as PARTITIONS.

      I have 2 classes

      Public class Car extends sparse vertex
      and
      Public class Driver extends sparse vertex
      (i need this 2 classes because each has different variables)
      1)What i have to insert in the constructor so that there are 2 partions(k=2), one maden by cars and anothers by drivers?

      2)In bipartithe graph i create a bipartithe graph and then i choice where add a vertex with the command
      BipartiteGraph bpg = new BipartiteGraph;
      Vertex va = bpg.addVertex( new UndirectedSparseVertex(), BipartiteGraph.CLASSA );
      Vertex vb = bpg.addVertex( new UndirectedSparseVertex(), BipartiteGraph.CLASSB );
      bpg.addBipartiteEdge( new BipartiteEdge( va, vb ));)

      Here instead what i have to do for insert a node in partition A instead of partitions B Or C or.....?

      Sorry for all this questions, i have understood a lot of thing looking demo(for example how to create a graph interactively, how to change shape of vertex ecc .....)but without example i have a lot of problem.

       
      • Joshua O'Madadhain

        Please note that at least some of the questions that you're asking can be easily answered by looking at the Javadoc documentation.  We are happy to help people use JUNG but we do appreciate it if you put in at least a little effort to handle the easy ones for yourself.  Also, some of these questions have already been answered in previous emails.  (Really.  :) )

        BipartiteGraph is not an implementation of KPartiteGraph, which is pretty obvious when you look at the two together.  BipartiteGraph is in fact based on a completely different design that requires that you use special-purpose edge and vertex implementations; this is why KPartiteGraph was created, which makes no such restrictions.

        KPartiteSparseGraph needs to know how to tell which partition each incoming vertex is assigned to.  You do this by giving it a collection of mutually exclusive Predicates, each of which uniquely defines a partition: when you insert a vertex, each of these Predicates is checked to make sure that it satisfies exactly one of them.  (If you don't understand Predicates, please take a look at the commons-collections documentation.)

        In your case, the Predicates would probably be InstanceofPredicate instances; again, take a look at the c-c documentation for details.

        Once you've given the Predicates to the graph constructor, you just add the vertices as you would with any other Graph implementation; no extra arguments are necessary.  (Again, take a look at BipartiteGraphReader to see this in action.)

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-09-25

      Another thing,so my question is more clear(and is more clear what i have to do), when i call the constructor kpartitegraph, my graph has not vertex at the beginning(i must create an empty graph).After interactively with the mouse i craete my graph.I click, a popupmenu must appears and i choose if i want to create a car or a driver.After i picking mode i select 2 vertex of 2 different partitions and, i click with mouse and a popup menu ask to me if i want to make a edge betwen the vertex that must be of different partitions.(this is what i have to do).
      i choose personally what kind of vertex to create.But I need kpartite graph beacause if in picking mode i select a lot of vertex the popup menu ask me if i want to add an edge only for legal braces.

       
      • Joshua O'Madadhain

        I think I was with you right up until your last sentence: I have no idea what you mean by "...only for legal braces".

        If you try to add an 'illegal' edge to a KPartiteSparseGraph, a ConstraintViolationException will be thrown.

        If you want to make sure that addEdge() is never called with legal arguments, you can use the Predicates that you supplied to the KPartiteSparseGraph constructor: if a single one of these Predicates returns 'true' for both vertices, then they're in the same partition.  Or you can just do an instanceof check yourself.

        I'm really not sure what you want the bipartite graph implementation to do for you.

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-09-25

      Sorry, i don't know some english words, so i put them in google transaltor, but it doesn't work very well(ex legal braces).
      i wanted to say that if in picking mode i select 3 nodes :n1,n2 in car partition and n3 in driver partition, and i click on with the mouse, must appears a popupmenu that ask me if i want to add one of these edges:n1 to n3 or n2 to n3.

      To make it easy do you remember the graph editor Demo?.I have to do the same thing, with the only difference that i can chose what kind of vertex create when i click(car or driver), and that when i add an edge it must link vertex in different partition.STOP

      Now i will read commons collection documentation to find what i need.

       
      • Joshua O'Madadhain

        Yeah, automatic translations can do terrible things to technical terms.  :)

        OK, I think I understand what you're trying to do now.  For this purpose, you don't really need a bipartite graph implementation, because you're doing the "hard part" yourself up front rather than letting the implementation do it.  So all you really need to do is this:

        for every possible pair of vertices (v, w) in the list of selected vertices
           if ((v instanceof Car && w instanceof Driver) || (v instanceof Driver && w instanceof Car))
              // add (v,w) to the list of possible edge locations
        // display the list in your popup

        Now, in my opinion, this is going to be kind of a mess in the user interface if you let people do this with any number of vertices, but that's your problem.  :)

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-09-25

      I'm happy that you have understood what i have to do, and probably what you suggest is the better solution, so i have not to use kpartite graph, but remains still one problem.If you remember in graph editor there is another way to create an edge.it is possible toclick on a vertex, keep the mouse pressed and move it on another vertex.Then release it so an edge appears between the two nodes.But probably also in this situation is sufficient that i make a test to see if two nodes are different.

      Just for curiosity, you live in California, right?What time is it? in italy is very late :)

       
      • Joshua O'Madadhain

        I believe that you're correct: in that case you can also check to see if the two nodes are of different types.

        I used to live in California; now I live in Seattle--same time zone.  I think you're 9 hours ahead, so actually it's now early where you are. :)  (Where in Italy are you?) 

        Glad your problem is sorted out.

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-10-10

      i'm back, thanks to you, now all works.My graph editor works well, but now i have to improve it, and i need again your help.
      In a first time i wanted that CAR vertex was painted green, and DRIVER vertex in blue, and i wrote this

      private final class MyColor implements VertexPaintFunction
          {
              protected InstanceofPredicate iop = new InstanceofPredicate(Utente.class );
              protected PickedInfo pi;
               
             
              public MyColor(PickedInfo pi)
              {
                  this.pi = pi;
              }

                    
              public Paint getDrawPaint(Vertex v)
              {
                  return Color.BLACK;
              }
             
              public Paint getFillPaint(Vertex v)
              {
                 
                  if (pi.isPicked(v))
                  {
                      return Color.YELLOW;
                  }
                  else
                  {
                      if (iop.evaluate(v))
                     
                          return Color.BLUE;
                      else
                        
                          return Color.GREEN;
                  }
                     
              }
          }

      This code works well, but i don't like it very mutch.So i have thought that was better paint Car nodes with the icon of  a car(always the same)an Driver node with the icon of a Man(always the same)
      I have read the unicodLabel Demo and the VertexImageShaperDemo, and that examples use a map do so:vertex, icon
                                                                                                        vertex, icon
                                                                                                        ......,..... ecc

      Now, as you know may grap is created interactively,so at the beginning i have not an array of vertex that i can assign to icons,so every time that i create a vertex clicking with the mouse, instead to add it to a map and assign a icon to it, i'have thought was better to do so....

        public static class MyVertexIconFunction implements VertexIconFunction
          {
              protected InstanceofPredicate iop = new InstanceofPredicate(Car.class );
         
              public MyVertexIconFunction()
         
              {}
             
              public Icon getIcon(ArchetypeVertex v)
         
              {
                  try
                  {
                  if (iop.evaluate(v))
             
                          return new ImageIcon(getClass().getResource("/Cer.gif"));
             
                  else
                        
                          return new ImageIcon(getClass().getResource("/Driver.jpg"));
                  }
                  catch(Exception e){System.err.println("file not found");
                  return null;
                  }
              }
         
          }

      MyVertexIconFunction visf = new MyVertexIconFunction();
      pr.setVertexIconFunction(visf);

      Now my questions:

      1)Instead of implementing VertexiconFunction, i've tried to extend VertexIconAndShapeFunction with the same code written above, but implementing VertexIconFunction it works, instead Extending VertexIconAndShapeFunction it' doesn't work and it do nothing, why?(i want to know this only for curiosity)

      2)(THE REAL QUESTION)The code above works, and when i create my graph interactively, instead of normal node i see icons(and this it's ok), but i have two problems:

               2.1)WhenI create a directed edge from one icon to another, i can't see the arrow of the edge because the                 arrow stay under the icon.
               2.2)When i use normal nodes instead of icons, i can click everywhere over the node,and the programm understands that i'm clicking on it and ask me if i want to make an adge from this node to another, instead when i use icons, the programm understand that i'm clicking on it only if i click in the perfect middle of the icon,if i click over the icon but not perfectly in the midlle, but just a little left\right\up\down from the center, the programm think that i'm clicking in a place where there is not a node and ask me if i want to create one.I would like 
      that i could click everywhere on the icon.

      Sorry if my questions is very long, but i prefer to be clear, so is more sample for you give me an answer.

      Byez

       
      • Joshua O'Madadhain

        You need to incorporate code which calculates the shape of the icon, so that JUNG knows where to make the edges stop, and where you can click to select a vertex.  Take a look at the demos which use icons, in particular VertexImageShaperDemo, which addresses this specific problem.

        Joshua

         
    • Sgotenks

      Sgotenks - 2007-10-10

      OK, i'have done, now it works, i have extended the vertexiconandshapefunction with the code above but i'have added also the getshape method to calculates the shape of the icon.Thanks

       
    • Sgotenks

      Sgotenks - 2007-10-25

      Hi, i have another question.From the last time i have written a lot of code, now my programm can also create a graph automatically taking information from a forum.It create a vertex for every thread in the forum,and link these with user that create the thread and with users that answer to the thread.But i have this problem:

      To create my graph i have a for like this:
            FOR(i = 0;i < number of thread in the forum, i++)

                                      newVertex1 = new VertexThread();
                                 
                                  Point p1 = new Point(w,q);
                                  w = w +25;
                                  q = q+ 40;
                           
                                  vertexLocations.setLocation(newVertex1, vv.inverseTransform(p1));

      My problem is this: in a forum there are  a lot of threads, so the code above create a lot of vertexes.Every node is painted a little left and a little down(w = w +25;  q = q+ 40), so a lot of nodes are not visible, because are painted out from the visible zone of my panel and i can't scroll to see the complete graph,i have to un-zoom with      - button;

      final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
              add(panel);

      I also have a GraphZoomScrooPane, but it only work if i click on + button zooming, instead doesn't work in the case above.Why????

       
      • Joshua O'Madadhain

        Personally I wouldn't set the locations manually like that; this is what the layout algorithms are for.

        Your question isn't quite clear, but it sounds as though the zooming isn't working after you do a number of updates.  I'd guess that you're not also updating the Layout dimensions; this may be the problem.

        Joshua

        PS: Please create a new thread for new questions, whose title describes the problem you're asking about.  Thanks.

         

Log in to post a comment.