A few weeks ago I asked this question. I am trying to upload my data which is an adjacency list for an undirected, unweighed graph and find the betweenness centrality. At the time I tried to use the answer given by user halmir but the output data I got was not right. I have since examined his steps more closely and realized that his data was formatted differently from mine at the start.
This is an excerpt of my data showing how it is formatted:
45171 60598
60598 61940
61940 21435
21435
14914
4502 61344 40355 3656 22250 28859
The first number of each row is a node ID and any numbers after are the node IDs of nodes adjacent to the first node. As you can see, node 60598 is adjacent to nodes 45171 and 61940. Only node 61940 is after 60598 though because the adjacency between nodes 60598 and 45171 is already expressed in node 45171's row.
This is how I believe user halmir's data was formatted before using adjlist = ImportString["data.txt", "Table"]
:
2 10
1 8 9
6 7 8 9
5 8
4 9
3 8 9
3 10
2 3 4 6
2 3 5 6 10
1 7 9
There are two differences between his formatting and mine:
1. His data uses the line number as the node id for each row.
2. Each adjacency in his data is expressed twice, once in each node's row.
I am about to whip up some Python code to format my data to take care of the first difference. It's going to be a little tricky since the node IDs in my data don't start from one and when in order are not consecutive. I'll probably change all the node IDs to start from one and increment and I will have to manually refer to a key to figure out which node is which. Will this even work since the second difference isn't addressed? Is there another way I can make my data work with BetweennessCentrality
in Mathematica?
txt
file and, if you can, theGraph
associated with it. $\endgroup$Graph
of it, that is what I am trying to make. $\endgroup$Graph
the way user halmir did it I'm going to have to alter the data so that the line number represents the node ID that all numbers in that line are adjacent to. $\endgroup$