I wonder, if it's possible to delete graph edges on the base of their weights.
In other words, can patterns in the function EdgeDelete[g,patt]
include weights of edges to delete? WM Documentation doesn't describe these options.
1 Answer
$\begingroup$
$\endgroup$
1
You can use the pattern
_?(yourCondition @ PropertyValue[{g, #}, EdgeWeight] &)
or the pattern
e_ /; (yourCondition @ PropertyValue[{g, e}, EdgeWeight]
Examples:
g1 = CompleteGraph[4, EdgeWeight -> Range[6],
VertexLabels -> Automatic, EdgeLabels -> "EdgeWeight"]
g2 = EdgeDelete[g1, _?(OddQ @ PropertyValue[{g1, #}, EdgeWeight] &)];
(* or g2 = EdgeDelete[g1, e_ /; (OddQ @ PropertyValue[{g1, e}, EdgeWeight])]; *)
Graph[g2, VertexCoordinates -> GraphEmbedding[g1]]
forbiddenweights = {1, 3, 4};
g3 = EdgeDelete[g1, _?(MatchQ[Alternatives @@ forbiddenweights]@
PropertyValue[{g1, #}, EdgeWeight] &)];
Graph[g3, VertexCoordinates -> GraphEmbedding[g1]]