To make this more concrete, and encourage discussion, here is a proof of concept implementation that is slightly different from and slightly simpler than what I described above.
Its main limitations:
- bad performance
- no multigraph support
Here's how it works:
vprop[p][g]
will extract the vertex property p
of graph g
as a list. eprop
is similar, but for edges.
We can use it as follows. This is a graph with an EdgeCapacity
set.
rg = RandomGraph[{10, 20}, EdgeCapacity -> RandomReal[1, 20]];
Let us transform is as -Log[#]&
and transfer it to EdgeWeight
:
rg2 = edgeMap[-Log[#] &, rg, eprop[EdgeCapacity] -> EdgeWeight]
PropertyValue[rg2, EdgeWeight]
(* {1.0623, 1.07053, 0.852909, 0.0794914, 0.223707, 1.11785, \
0.757396, 1.52089, 1.01736, 0.563396, 0.854208, 0.859467, 0.446242, \
0.319857, 1.15751, 0.465928, 1.48121, 1.1758, 1.02566, 0.999962} *)
In this implementation, the LHS of ->
is always a function that can be applied to a graph. Thus we cannot use EdgeCapacity -> EdgeWeight
directly. We must transform EdgeCapacity
to a function by wrapping it with the edge property extractor: eprop[EdgeCapacity]
is now a proper function.
Similarly, we can size vertices based on their degree:
vertexMap[
.3 #^0.5 &,
RandomGraph@BarabasiAlbertGraphDistribution[50, 1],
VertexDegree -> VertexSize
]

(* no support for multigraphs *)
graphQ = GraphQ[#] && Not@MultigraphQ[#] &;
(* extract vertex properties *)
vprop[prop_][g_?graphQ] :=
Replace[PropertyValue[{g, #}, prop] & /@ VertexList[g], $Failed ->
Missing["Nonexistent"], {1}]
(* extract edge properties *)
eprop[prop_][g_?graphQ] :=
Replace[PropertyValue[{g, #}, prop] & /@ EdgeList[g], $Failed ->
Missing["Nonexistent"], {1}]
(* set vertex properties *)
setVProp[g_?graphQ, prop_, values_] :=
If[
Length[values] =!= VertexCount[g],
$Failed,
Fold[SetProperty[{#1, #2[[1]]}, prop -> #2[[2]]] &, g,
Transpose[{VertexList[g], values}]]
]
(* set edge properties *)
setEProp[g_?graphQ, prop_, values_] :=
If[
Length[values] =!= EdgeCount[g],
$Failed,
Fold[SetProperty[{#1, #2[[1]]}, prop -> #2[[2]]] &, g,
Transpose[{EdgeList[g], values}]]
]
ClearAll[vertexMap]
vertexMap[fun_, g_?graphQ, prop_] :=
vertexMap[fun, g, vprop[prop] -> prop]
vertexMap[fun_, g_?graphQ, gfun_ -> prop_] :=
setVProp[g, prop, Map[fun, gfun[g]]]
vertexMap[fun_, g_?graphQ, gfuns_List -> prop_] :=
setVProp[g, prop, MapThread[fun, Through[gfuns[g]]]]
ClearAll[edgeMap]
edgeMap[fun_, g_?graphQ, prop_] :=
vertexMap[fun, g, eprop[prop] -> prop]
edgeMap[fun_, g_?graphQ, gfun_ -> prop_] :=
setEProp[g, prop, Map[fun, gfun[g]]]
edgeMap[fun_, g_?graphQ, gfuns_List -> prop_] :=
setEProp[g, prop, MapThread[fun, Through[gfuns[g]]]]