9
$\begingroup$

I have tried running the example given in the neat examples section of 'Subgraph' function in Mathematica 12.0 (windows 10) and the example does not run properly for any number of tries.

The same example however works fine in 11.3. is anyone else observing this problem? Is there a problem with the NeighborhoodGraph function on which the example depends on?

$\endgroup$
12
$\begingroup$
sg = Subgraph[g,
 Complement[VertexList[g],
   VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]]];

The issue seems to be that Subgraph inherits the GraphLayout option value from the parent graph:

PropertyValue[sg, GraphLayout]

{"GridEmbedding", "Dimension" -> {25, 50}}

and, somehow, the vertex layout defaults to something weird when the number of vertices do not match the length of the coordinate list produced by the layout procedure.

So, you can

  1. add the option GraphLayout -> Automatic (or use your desired setting):

SetProperty[sg, GraphLayout -> "SpringElectricalEmbedding"]

enter image description here

  1. remove the GraphLayout property from g:

Subgraph[RemoveProperty[g, GraphLayout],
  Complement[VertexList[g],
    VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]]]

enter image description here

  1. use the option VertexCoordinates to retain vertex coordinates in g:

Subgraph[g,
 Complement[VertexList[g],
  VertexList[NeighborhoodGraph[g, RandomSample[VertexList[g], 25], 1]]], 
 VertexCoordinates -> {v_ :> PropertyValue[{g, v}, VertexCoordinates]}]

enter image description here

$\endgroup$
  • $\begingroup$ Ahh thanks. so they made changes to how the graphs are displayed ! $\endgroup$ – Ali Hashmi Jun 17 at 23:03
  • $\begingroup$ @Ali, it seem so. The issue arises when the automatic layout of the original graph has parameters that depend on the vertex count. Other examples where the same issue arises are CompleteGraph[{3,5,7}], KnightTourGraph[5, 5]. $\endgroup$ – kglr Jun 18 at 8:54
2
$\begingroup$

How about filing a bug with Wolfram Research? It only takes a few minutes. In a notebook, click Help, Give feedback..., fill out the rest of the form (most is completed for you), and then click "Submit." You don't need a service contract to file a bug, and there is no guarantee the Wolfram will see this Stack Exchange entry.

$\endgroup$

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.