3
$\begingroup$

I'm very new to Mathematica and am currently trying the VertexDelete function, but after using it, my graph isn't drawing.

Input:

a = CompleteGraph[{7, 2}]
a = VertexDelete[a, {3, 4}]

As the output I get

Graph["small default graph picture", vertex count:7 and edge count:10]

The vertex count and edge count are correct, so the removal is done, but why doesn't it evaluate to a graph drawing?

$\endgroup$
  • 1
    $\begingroup$ Interesting - seems something breaks - you can get result by taking vertex and edge lists of result and making new graph with appropriate options for bipartite rendering... will ponder further, might be a bug (I had two kernel crashes fiddling with it on 9.x) $\endgroup$ – ciao May 22 '15 at 23:40
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$ – bbgodfrey May 23 '15 at 1:06
5
$\begingroup$

CompleteGraph[a,b] set GraphLayout to be "MultipartiteLayout".

a = CompleteGraph[{7, 2}];

a // Options

{GraphLayout -> {"MultipartiteLayout", "VertexPartition" -> {7, 2}}}

and this layout carried over to new graph.

a = VertexDelete[a, {3, 4}];
a // Options

{GraphLayout -> {"MultipartiteLayout", "VertexPartition" -> {7, 2}}}

You could do what David suggested or you could add one more step to set up coordinate..

a = CompleteGraph[{7, 2}];
a = SetProperty[a, VertexCoordinates -> GraphEmbedding[a]];
a = VertexDelete[a, {3, 4}];

a

enter image description here

$\endgroup$
  • $\begingroup$ Do you have any comment on this? $\endgroup$ – Szabolcs Jun 2 '15 at 9:01
  • $\begingroup$ @Szabolcs you could send a report to Wolfram Tech Support $\endgroup$ – halmir Jun 2 '15 at 20:05
  • $\begingroup$ I did, just wanted to make sure I didn't miss anything. E.g. first I was thinking that somehow one empty graph is marked as directed and the other as undirected, but (unlike other packages) Mathematica doesn't appear to make that distinction. Both DirectedGraphQ and UndirectedGraphQ give True on empty graphs. I asked because I thought you may have some insight. $\endgroup$ – Szabolcs Jun 3 '15 at 8:46
2
$\begingroup$

A bit inelegant, but it works:

Graph[VertexDelete[a, {3, 4}], 
 DeleteCases[EdgeList[a], (3 | 4) <-> _ | _ <-> (3 | 4)], 
 VertexLabels -> "Name",
 VertexCoordinates -> 
  Drop[AbsoluteOptions[a, VertexCoordinates][[1, 2]], {3, 4}]]

enter image description here

$\endgroup$
  • $\begingroup$ That kind of breaks the whole point of a k-partite display of the OP... $\endgroup$ – ciao May 22 '15 at 23:40
  • $\begingroup$ Good fix! +1... $\endgroup$ – ciao May 23 '15 at 0:54
  • 1
    $\begingroup$ +1. Going back to 8.0.1, I've run into many odd bugs with the internal representation of graphs getting messed up after calling any graph modification functions. The most robust solution is to write what a C++ programmer would call a copy constructor, and use it after any sequence of graph mutation operations. $\endgroup$ – xcah May 23 '15 at 2:12

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.