This is a self-contained version of something a bit bigger - going for brevity. It is a bit synthetic, but there are applications I have in mind where the {{1,2}} will be replaced with real data, more of it, and for a larger network.
g = CompleteGraph[4];
Scan[(PropertyValue[{g, #[[1]] <-> #[[2]] &}, EdgeWeight] = #[[1]] + #[[2]] &), {{1, 2}}]
The argument {{1,2}}
passed at the end is a subset of what I want to Scan
over (I expect that list of pairs to be large).
The Scan
appears to work, but when I read the EdgeWeight value for node 1<->2 afterwards, thus:
PropertyValue[{g, 1 <-> 2}, EdgeWeight]
I get $Failed
If I do manually what I am trying to Scan, and then read it, it works
PropertyValue[{g, 1 <-> 2}, EdgeWeight] = 3;
PropertyValue[{g, 1 <-> 2}, EdgeWeight]
(returns 3).
Clearly there's something wrong with my Scan, but without an error message I can't tell what that is.
Edit I am specifically looking to understand why my expression does not work. An edited working expression without indication of why my expression is flawed isn't instructive to me. For example, if my nested list of data at the end is shaped differently, ## is not going to work automatically. Yes - I can live with an answer that says "that will never work, here's why", but I am mostly looking for explanations - not just something that works.
I'd appreciate some pointers on Scan; if there's a better way to do it I'd like to know what that is.
EdgeWeight
have easier ways to set. You can eitherSetProperty[g, EdgeWeight -> {1,2,3}]
(for a graph with three edges), or explicitly assign to edges likeSetProperty[g, EdgeWeight -> {1<->2 -> 1, 2<->3 -> 2, 1<->3 -> 3}]
. This only works for builtin properties. $\endgroup$