# How can you delete a list of vertices from a GridGraph?

Given a grid graph: and delete the vertices {3, 4, 5, 11, 14, 15, 16, 17, 18, 19, 21, 23, 26, 27, 30} and preserve the structure. There is the VertexDelete command but I am unable to get it working while preserving the structure.

SeedRandom;
dimension = 5;
coDimension = 10;
percProbability = 0.7;
deleteMe =
Pick[Table[i, {i, 1, 30}], Table[RandomReal[] > 0.5, {i, 30}]]

G = GridGraph[{dimension, coDimension}, VertexLabels -> "Name",


How can you delete a list of vertices from a GridGraph?

p.s. Related to this percolation puzzle here for which I want to solve this.

• "while preserving the structure." <- What do you mean by "structure"? Jul 9, 2016 at 20:46
• @Szabolcs I want to get the vertex-induced graph of the grid-graph above where the vertices of the list and the incident edges deleted -- and I want to see the graph as a grid, not all vertices jammed together.
– hhh
Jul 9, 2016 at 20:48
• If you mean vertex coordinates, do g = SetProperty[g, VertexCoordinates -> GraphEmbedding[g]] before deleting vertices. Jul 9, 2016 at 20:48
• @Szabolcs Thank you! Over 4 months, I haven't been able to do this and now I learnt it :D
– hhh
Jul 9, 2016 at 20:50

Big Thank You to Szalbocs! You need to have

G = SetProperty[G, VertexCoordinates -> GraphEmbedding[G]];


just before

VertexDelete[G, deleteMe] SeedRandom;
dimension = 5;
coDimension = 10;
percProbability = 0.7;
deleteMe =
Pick[Table[i, {i, 1, 30}], Table[RandomReal[] > 0.5, {i, 30}]];
G = GridGraph[{dimension, coDimension}, VertexLabels -> "Name",
G = SetProperty[G, VertexCoordinates -> GraphEmbedding[G]];
VertexDelete[G, deleteMe]


and on the percolation example with more efficient deteleMe as given by m_goldberg

SeedRandom;
dimension = 5;
coDimension = 10;
percProbability = 0.7;
deleteMe =
With[{n = dimension coDimension}, The two examples demonstrate the SetProperty to preserve the structure.