1
$\begingroup$

I need to make a K7,2 partite graph , with deleting 2 vertices and plus 2 more random edges , and after that my vertices should be green color. I made the graph K7,2 and deleted 2 vertices with this code : Needs["Combinatorica`"]; a = CompleteGraph[7, 2]; b = Fold[DeleteVertex, a, {3, 4}]; ShowGraph[b, VertexLabel -> (Style[#, 18] & /@ Drop[Range[9], {3, 4}]), ImageSize -> 200]
But now i need something which can delete 2 more random edges , and plus color my vertices green

Thanks,

$\endgroup$
1
  • $\begingroup$ Angel, welcome to Mathematica.SE! I suggest that: 1) You take the introductory tour. 2) When you see good questions and answers, vote them up by clicking the gray triangles. (3) Please remember to accept the answer that solves your problem, by clicking the checkmark sign. 4) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – kglr May 23 '15 at 13:37
1
$\begingroup$
Needs["Combinatorica`"]
a = CompleteGraph[7, 2];
b = DeleteVertices[a, {3, 4}];

The functions you need to delete randomly selected two edges are the built-in function RandomChoice and the Combinatorica functions Edges and DeleteEdges.

deletededges = RandomChoice[Edges[b], 2];
c = DeleteEdges[b, deletededges];

Row[{ShowGraph[a, VertexStyle -> Disk[.05], VertexColor -> Green, 
   VertexLabel -> True, BaseStyle -> Large, ImageSize -> 300,
   PlotLabel -> Style[#, 16] &@"CompleteGraph[7,2]"], 
  ShowGraph[b, VertexStyle -> Disk[.05], VertexColor -> Green, 
   VertexLabel -> True, BaseStyle -> Large, ImageSize -> 300,
   PlotLabel -> Row[Style[#, 16] & /@ {"Deleted vertices: " , {3, 4}}]],
  ShowGraph[c, VertexStyle -> Disk[.05], VertexColor -> Green, 
   VertexLabel -> True, BaseStyle -> Large, ImageSize -> 300,
   PlotLabel -> Row[Style[#, 16] & /@ {"Deleted edges: " , 
       ToString /@ deletededges}]]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ thanks a lot dude , you made my day +1 $\endgroup$ – Guzelov Angel May 23 '15 at 13:24
  • $\begingroup$ Angel, my pleasure; glad it worked for your needs. Welcome to mma.se. $\endgroup$ – kglr May 23 '15 at 13:38

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.