# DirectedEdges -> False not working

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.

• Please post only a small graph as your example. You surely don't need 300KB of data to show your point! – Dr. belisarius Mar 30 '16 at 0:22
• g = Graph[{1 -> 2, 2 -> 3, 3 -> 1}, DirectedEdges -> False]; DirectedGraphQ[g] yields False as does g //DirectedGraphQ. – David G. Stork Mar 30 '16 at 0:30
• 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. – kglr Mar 30 '16 at 0:38
• a workaround: Graph[UndirectedEdge@@@EdgeList[imp]] – kglr Mar 30 '16 at 0:49
• @andandandand, you could also use Graph[EdgeList[cElegans]/. DirectedEdge->UndirectedEdge]. – kglr Mar 30 '16 at 1:03

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

• By documentation (and its examples), DirectedEdges->False should create an undirected graph from a directed graph. It's not working with this file. – andandandand Mar 30 '16 at 3:04
• @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. – Szabolcs Mar 30 '16 at 7:08
• @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. – andandandand Mar 30 '16 at 15:32
• @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. – Szabolcs Mar 30 '16 at 16:20
• 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. – Szabolcs Mar 30 '16 at 16:50