# Program - Community Detection using Hierchical Clustering using Jaccard coefficient
# as a measure of similarity
# By - Rohan Bose (Jalpaiguri Govt. Engg. College)
import networkx
import matplotlib.pyplot as plt
import time
def hierchical_clustering(G):
E = list(G.edges())
J = networkx.jaccard_coefficient(G, E)
clusters= [-1]*len(G)
cluster_number=-1
# print "Please choose a threshold value by looking at the jaccard similarity value"
# for u, v, k in J:
# print '(%d, %d) -> %.8f' % (u, v, k)
threshold_value = 0.4
total_number_of_iterations = 0
while(True):
total_number_of_iterations+=1
# length = networkx.all_pairs_shortest_path_length(G)
# length = dict(length)
# value = 9000000 # set this as infinity
# final_s = -1
# final_t = -1
# for source in length:
# for target in length[source]:
# val = length[source][target]
# if val!=0 and value > val:
# value = val
# final_s = source
# final_t = target
# min_node = min(final_s, final_t)
# max_node = max(final_s, final_t)
all_nodes = list(G.nodes())
final_s = -1
final_t = -1
parent_mini=9999999999999999999999
# start of for
for source in all_nodes:
# print source
lengths = networkx.single_source_shortest_path_length(G, source)
mini = 999999999999999999
dest = -1
for j in lengths:
if lengths[j]threshold_value and k