Forrest Edge Case

Trust networks with multiple connected components where there is a tie across connected components.


In [21]:
import sys, os
import networkx as nx
from nxpd import draw
sys.path.insert(0, os.path.join('..'))

Build Forrest


In [25]:
G = nx.DiGraph()
edges = [('a', 'c'),
         ('c', 'a'),
         ('b', 'a'),
         ('f', 'c'),
         ('h', 'i'),
         ('i', 'j'),
         ('j', 'k')]
for i, j in edges: 
    G.add_edge(i, j, topic='dummy')
draw(G, show='ipynb')


Out[25]:

In [26]:
from socialgraph.socialgraph import elect_committee, paint_graph, compute_powers
committee = elect_committee(G, 2)

In [27]:
draw(paint_graph(G, committee), show='ipynb')


Out[27]:

In [28]:
print(committee)


{'a': ['a', 'c', 'b', 'f'], 'k': ['i', 'h', 'k', 'j']}

In [29]:
from pprint import pprint
pprint(compute_powers(G))


({'a': 4, 'b': 1, 'c': 4, 'f': 1, 'h': 1, 'i': 2, 'j': 3, 'k': 4},
 {'a': ['a', 'c', 'b', 'f'],
  'b': ['b'],
  'c': ['a', 'c', 'b', 'f'],
  'f': ['f'],
  'h': ['h'],
  'i': ['i', 'h'],
  'j': ['i', 'h', 'j'],
  'k': ['i', 'h', 'k', 'j']})