graphstream / gs-core

Graphstream core
http://graphstream-project.org/
Other
401 stars 109 forks source link

Directed graph : unique edge for the two directions #102

Open alexisfasquel opened 10 years ago

alexisfasquel commented 10 years ago

Hi there! I'm trying to use graph stream for a project of mine, but I got some issue getting the results I want. Let say that I got the following code :

Graph graph = new SingleGraph("Tutorial 1");

Node a = graph.addNode("A");
Node b = graph.addNode("B");

a.setAttribute("xy", 0, 0);
a.setAttribute("xy", 1, 1);

graph.addEdge("AB", "A", "B", true);
graph.addEdge("BA", "B", "A", true);

graph.display(false);

As long as I stick with the "default" viewer, no problem : there is only one edge for the two direction.

screen shot 2013-11-30 at 10 55 51

But when I add above the previous code in order to use more advance css rules:

System.setProperty("org.graphstream.ui.renderer", "org.graphstream.ui.j2dviewer.J2DGraphRenderer");

The two edges get separated :

screen shot 2013-11-30 at 15 21 07

So I am not sure whether or not it is supposed to be the right behaviour, but is there a way to merge the two edges while using the "advanced" viewer ?

ThibautDemare commented 10 years ago

Hi,

Why do you use two edges if you just want a unique edge? Because you can replace the two "addEdge" by this :

graph.addEdge("AB-BA", "A", "B", false);

It will create one undirected edge. So, even with the J2DGraphRenderer, it will show just one edge. However, with this method, you will not have the arrows anymore...

Ant01n3 commented 10 years ago

Hi,

In fact there the feature allowing to show two edges when they exist does not yet exist in the basic viewer ! But it should !

Most of the time, as Thibaut said, we use to create a single undirected edge instead of two directed edges in each direction. However we could add an option to force two edges between the same nodes to be drawn as lines in the future (however, how to account for multi-graphs with three or more edges between two nodes ?).

alexisfasquel commented 10 years ago

Hi, thanks for the quick reply.

Why do you use two edges if you just want a unique edge?

Because the file I'm reading from describe each edge separately (with weight value), but I would like to render as it was only one edge so the graph looks "cleaner". I will work with that but still, I will have to add two distinct attributes : "weightAB" and "weightBA". It does not seem really appropriate, does it ? At least, it would be really nice to have the arrow-shape css property working with undirected edges, using the same values as for directed edges, but displaying an "arrow" on both end of the edge.

stuchl4n3k commented 7 years ago

+1 arrow for bidirectional edges

djahidaimene commented 5 years ago

I need a help, I need to make my graph directed which mean sometimes bidirectional and sometimes unidirectional how can I do it, by the way I uses graphStream please urgent and thnks this is my mail djahidaimy@gmail.com for contact me