1
$\begingroup$

Consider this graph, that I downloaded from the OpenConnectome project.

Graph[EdgeList[cElegans], DirectedEdges -> False] // DirectedGraphQ

outputs: True.

Which makes no sense to me. Is there any logic to this or is this a Mathematica bug?

PS: The same thing happens with SetProperty[Graph[EdgeList[cElegans]], DirectedEdges -> False] // DirectedGraphQ

edit: The original question was missing the call to EdgeList. Sorry for the mistake.

$\endgroup$
  • 1
    $\begingroup$ Please post only a small graph as your example. You surely don't need 300KB of data to show your point! $\endgroup$ – Dr. belisarius Mar 30 '16 at 0:22
  • $\begingroup$ g = Graph[{1 -> 2, 2 -> 3, 3 -> 1}, DirectedEdges -> False]; DirectedGraphQ[g] yields False as does g //DirectedGraphQ. $\endgroup$ – David G. Stork Mar 30 '16 at 0:30
  • 1
    $\begingroup$ Smaller example: imp = Import["http://awesome.cs.jhu.edu/data/static/graphs/worm/c.elegans_neural.male_1.graphml"]; g=Graph[EdgeList[imp][[;;5]],DirectedEdges->False];DirectedGraphQ[g] gives True. $\endgroup$ – kglr Mar 30 '16 at 0:38
  • 1
    $\begingroup$ a workaround: Graph[UndirectedEdge@@@EdgeList[imp]] $\endgroup$ – kglr Mar 30 '16 at 0:49
  • 1
    $\begingroup$ @andandandand, you could also use Graph[EdgeList[cElegans]/. DirectedEdge->UndirectedEdge]. $\endgroup$ – kglr Mar 30 '16 at 1:03
2
$\begingroup$

By documentation, DirectedEdges->False can be used to interpret rules (edges) as undirected edges in Graph. If you want to convert exsiting directed graphs to undirected graphs, you should use UndirectedGraph function.

g = UndirectedGraph[cElegans];

DirectedGraphQ[g]

False

|improve this answer|||||
$\endgroup$
  • $\begingroup$ By documentation (and its examples), DirectedEdges->False should create an undirected graph from a directed graph. It's not working with this file. $\endgroup$ – andandandand Mar 30 '16 at 3:04
  • $\begingroup$ @andandandand I see no such examples in the documentation. What halmir said is correct. You cannot use Graph[g, DirectedEdges -> False] to get an undirected graph is g is already a Graph expression. This option controls only how to generate a new graph (from a set of edges or otherwise), but it does not serve for modifying an existing graph. There is no bug here. $\endgroup$ – Szabolcs Mar 30 '16 at 7:08
  • $\begingroup$ @Szabolcs: The 2nd example of reference.wolfram.com/language/ref/DirectedEdges.html shows Graph[{1 -> 2, 2 -> 3, 3 -> 1}, DirectedEdges -> False]which works as expected (produces an undirected graph). Graph[EdgeList[cElegans], DirectedEdges -> False] produces a directed graph as DirectedGraphQ[Graph[EdgeList[cElegans], DirectedEdges -> False]] will confirm. Please try this, and convince yourself that this is a bug. $\endgroup$ – andandandand Mar 30 '16 at 15:32
  • $\begingroup$ @andandandand If you read my comment carefully, you will see that I said: "This option controls only how to generate a new graph (from a set of edges or otherwise)". {1 -> 2, 2 -> 3, 3 -> 1} is a set of edges (and not a Graph expression), so you can use DirectedEdges here. However, if you already have g=Graph[{1 -> 2, 2 -> 3, 3 -> 1}] (which is a Graph expression, not a list of edges), then you cannot use g2 = Graph[g, DirectedEdges -> False]. I hope this clears it up for you. $\endgroup$ – Szabolcs Mar 30 '16 at 16:20
  • 1
    $\begingroup$ A DirectedEdge is always directed and an UndirectedEdge is always undirected, as their names imply. They can be mixed within the same graph. A Rule has historically been used for both, so we still have the option to choose what it should represent. $\endgroup$ – Szabolcs Mar 30 '16 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.