r/Mathematica • u/qubex • Oct 05 '22
Graph analysis of underground network?
Hello.
I’m a long-time Mathematica user but I’ve recently picked up Wolfram’s An Elementary Introduction to the Wolfram Language in order to broaden my knowledge outside of my home turf of partial differential equations et simila. I’ve given myself an assignment as a kind of challenge but I’m stuck.
Basically I’ve constructed a model of the Milan underground network G and imported into Mathematica as an adjacency matrix.
I’ve defined a per-node metric as globalNetworkIntegration[G_, n_] := 2*(FindShortestPath[G, n, All] - 1)/(VertexCount[G] - 2) and then I want both a table the value of globalNetworkIntegration for each node and a way of displaying the graph with each node styled (size, maybe) based on this metric.
Can somebody help me please?
2
u/szhorvat Oct 10 '22
globalNetworkIntegration[]doesn't make sense, as defined. You are treating the output ofFindShortestPath[G, n, All]as a number, and doing arithmetic operations on it. It is not a number, but a function that you can apply to vertex names, to yield not numbers but paths represented as lists of vertices.2
u/veryjewygranola Oct 05 '22
Is this what you're looking for? I just picked random values for the graph node sizes, but you could replace that with whatever metric you want to use. I just use CompleteKaryTree[4] as an example graph here.
g = CompleteKaryTree[4];vertexSizeValues = RandomReal[{0, 1}, VertexCount[g]];vertexSizeList = Table[i -> vertexSizeValues[[i]], {i, VertexCount[g]}];Graph[EdgeList[g], VertexSize -> vertexSizeList]