import networkx as nx
import matplotlib.pyplot as plt
import pandas as pd
from igraph import *
import igraph as ig
from pylab import mpl
mpl.rcParams['font.sans-serif'] = ['SimHei']
datatu=pd.read_excel('2015年.xlsx',sheet_name='2015年')
row = datatu.iloc[:, 0].size
jiedianlist = []
G = nx.MultiDiGraph()
for i in range(row):
jiedian2 = datatu.iloc[i, 0]
jiedian3 = datatu.iloc[i, 1]
G.add_node(jiedian2)
G.add_node(jiedian3)
G.add_edge(jiedian2,jiedian3)
path = dict(nx.all_pairs_shortest_path(G))
#print(path)
values = list(path.values())
#print(values)
bianzonglist=[]
for i in values:
#print(i)
bianlist=list(i.values())
for bian in bianlist:
#print(bian)
bian2='+'.join(bian)
bianzonglist.append(bian2)
print(bianzonglist)
def delete2(list2):
#删除重叠字符串
for i in list2:
for j in list2:
if j in i and len(j)<len(i):
list2.remove(j)
else:
pass
continue
for i in list2:
if list2.count(i) > 1:
list2.remove(i)
return list2
bianzonglist2=delete2(bianzonglist)
bianzonglist3=delete2(bianzonglist2)
with open('有向图链路.txt', "w+") as f:
for lianlu in bianzonglist3:
f.write(lianlu)
f.write('\r\n')