I am currently struggling with a problem in Mathematica.
I have a randomly generated weighted Barabasi-Albert graph and a corresponding demand matrix of the same size. I'm generating the graph with the following code:
generateBarabasiAlbertGraph[n_, l_] /; n >= 3 :=
Module[{g = CycleGraph[3], vc, vl, el},
Do[
vc = VertexCount[g];
vl = VertexList[g];
el = EdgeList[g];
ec = EdgeCount[g];
wl = RandomInteger[{5, 20}, {ec}];
graph = Graph[el, EdgeWeight -> wl, EdgeWeight -> "EdgeWeight"];
el = Map[UndirectedEdge[vc + 1, #] &,
RandomSample[VertexDegree[g] -> vl, Min[l, vc]]
];
g = Graph[Join[EdgeList[g], el],
VertexLabels -> Placed["Name", Before]], {n - 3}];
g;
];
v = RandomInteger[{5, 10}];
l = RandomInteger[{1, 2}];
generateBarabasiAlbertGraph[v, l];
I then calculate the shortest path from each vertex a
to vertex b
if vertex a
has a demand from vertex b
.
Now I would like to create a shortest-path link matrix for all shortest paths in the graph. (A similar graph appears in this paper by Kelly).
This is what I already figured out:
TableForm[Array[0 &, {EdgeCount[graph], 1}], TableHeadings -> {EdgeList[graph], {sp}}]
As you can see, I have the shortest-path 3-1-4 and need to replace the 0 at the corresponding row if this edge is used in the shortest path. So in this case I need a 1
in row 3 and 4
Any ideas?
Best, Julian