I am using Mathematica Version 8.0
I've tried variations of the following commands, in order to assign the weight $1/k$ for vertex $k$, for a graph defined on {1,2,..,n} via the edge rule $$(k,k') \in E~~\textrm{if and only if}~~LCM(k,k')>n$$ My goal is to calculate the maximal independent set in this graph with respect to these vertex weights. There are no weights assigned at all. Here's the code I used.
f[n_, i_, j_] := If[ (LCM[i, j] <= n), 1, 0];
MM[n_] :=
Table[Table[1 - f[n, i, j], {i, n}], {j,n}];
MM20 := MM[20]; G := AdjacencyGraph[Table[x, {x, 20}], MM20];
Gw :=
Graph[G, VertexWeight -> Table[1/x, {x, 1, 20}]];
I have tried not including the list of vertices in the MM20 definition, including the weights, all in one go, to no avail. If I ask
PropertyValue[{Gw, 3}, VertexWeight]
of mathematica, it just echoes the command back with no output and a graphical representation of the graph.
I don't want to enter the edges and weights explicitly (as 1<-> 2, etc) since I want to run this for much bigger graphs. There must be something subtly wrong about how I am using the Table command, maybe?
Edit: Here's a screenshot of the problematic output
{}
button above the edit window. The edit window help button?
is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful $\endgroup$PropertyValue
expression you mention returns1/3
when I execute it after evaluating the rest of your code. Is that not what you would like? (and thank you for formatting the question properly!) $\endgroup$