I wanted to have a way to filter the graph using vertices and edges custom properties in Mathematica 11.1. But this code doesn't work the way I expected:
g = GridGraph[{25, 50}];
PropertyValue[{g, #}, "myprop"] = "myval"; & /@ Range[0, 1250, 7];
f = ! PropertyValue[{g, #}, "myprop"] === "myval" &;
sg2 = Subgraph[g, _?f]
Sort[VertexList[sg2]] == Select[Range[25*50], Mod[#, 7] != 0 &]
It returns False
and the graph looks like this:
Interestingly if I run:
VertexList[sg2]
I see that the vertices that should be removed are in the end of the list. So somehow Subgraph
processed them, but didn't remove.
On the other hand if I use this code, where I remove every 7th vertex by its id:
g = GridGraph[{25, 50}];
sg = Subgraph[g, _?(Mod[#, 7] != 0 &)]
Sort[VertexList[sg]] == Select[Range[25*50], Mod[#, 7] != 0 &]
The result is True
and the graph looks like this:
Is this a bug or am I doing something wrong?
f
returningTrue
for all edges. $\endgroup$