Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
I believe that if you want a complete answer you should provide the txt file and, if you can, the Graph associated with it. –  Öskå May 8 at 21:51
    
I've uploaded my data here. I don't have a correct Graph of it, that is what I am trying to make. –  Daniel May 8 at 22:31
    
What about the lines in there is only node ID? How do they fit into your graph? –  m_goldberg May 8 at 22:48
    
Well this is my original data where the line number doesn't mean anything. To turn it into a 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. –  Daniel May 8 at 23:10
add comment

1 Answer 1

It's basically similar but slightly different parsing:

adj = Import["http://pastebin.com/download.php?i=rUVwKWBv", "Table"];
edges = Flatten[Thread[#1 <-> {##2}] & @@@ adj];
g = Graph[edges];

BetweennessCentrality[g] // Short

{7070.,5660.,4248.,2834.,<<1412>>,5524.19,2341.22,1418.,0.}

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.