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.

Say you have the skeleton of a graph:

fullSkele = PolyhedronData["GreatRhombicosidodecahedron", "SkeletonRules"]

and you've an arbitrary list of some fraction of those nodes, say extantNodes = {1, 5, 8, 72, 101}, which you want to turn into the list of all nodes connected directly to those extantNodes (along with the number of extantNodes each is connected to).

With,

connCheckTool[node1_, node2_] := Count[fullSkele, (node1 -> node2)] + Count[fullSkele,(node2 -> node1)]

The following function achieves this:

DeleteCases[
   DeleteCases[
    Transpose@{Range[120], 
       Total /@ 
    Table[connCheckTool[i, extantNodes[[z]]], {i, 1, 120, 1}, {z, 
      1, Length@extantNodes}]} /. {x_Integer, 0} -> delete, delete], {x_, y_} /; 
MemberQ[extantNodes, x] == True];

However, the inner connCheckTool is not very efficient, especially with larger graphs.

Can anyone think of a way to accomplish this in a better way?

I suspect it will involve the AdjacencyMatrix of the original, whole graph, as opposed to the list-search mechanism, but can't quite get it...

share|improve this question
    
Checked AdjacencyList in the docs? And NeighborhoodGraph and SubGraph? –  kguler Apr 10 at 10:30
    
I had an apparently undue paranoia of using Graph objects more than needed. Thank you for correcting that. –  Ghersic Apr 11 at 2:58

1 Answer 1

up vote 1 down vote accepted
Tally[Join @@ (AdjacencyList[Graph[fullSkele], #] & /@ extantNodes)]

gives

(* {{1, 1}, {4, 1}, {5, 1}, {6, 1}, {7, 1}, {11, 1}, {17, 1},
     {20,  1}, {41, 1}, {52, 1}, {71, 1}, {76, 1}, {105, 1},{109, 1}, {113, 1}} *)
share|improve this answer

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.