Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import networkx as nx
- #from networkx.algorithms import isomorphism
- from graph_tool.all import *
- import graph_tool.all as gt
- #from collections import Counter
- import time
- ti=time.time()
- # read graphs from file.
- def readGraphFile(graphFile):
- G_list = []
- indice = []
- v_indice = []
- e_indice=[]
- frequence_list = []
- frequentgraphs = []
- frequentfreqs=[]
- #appearance = [] #store the appearance of the frequent pattern
- fp = open(graphFile, "r+")
- lines = [line for line in fp.read().splitlines() if line]
- for line in lines:
- data = line.split()
- if data[0] == 't':
- vdic={}
- vdic.clear()
- if (len(data) < 3):
- print("Graph header line error...")
- else:
- g = Graph()
- v_label = g.new_vertex_property("int")
- v_num = g.new_vertex_property("int")
- e_label = g.new_edge_property("int")
- G_list.append(g)
- indice.append(int(data[2]))
- #G_list[ map(int, data[4:])] = g
- elif data[0] == 'v':
- data = line.split()
- if (len(data) < 3):
- print 'Node data line error...'
- else:
- #g.add_node(data[1], attrib = data[2])
- v=g.add_vertex()
- v_num[v]= int(data[1])
- v_label[v] = int(data[2])
- vdic[int(data[1])]=int(data[2])
- #as node graph transaction format is single value, use attrib as a common noun for all attrib
- elif data[0] == 'e':
- if (len(data) < 4):
- print 'Edge data line error...'
- else:
- #print(vdic)
- v1=g.add_vertex()
- #vdic[int(data[1])]
- v_label[v1] = vdic[int(data[1])]
- v2=g.add_vertex()
- v_label[v2] = vdic[int(data[2])]
- e1 = g.add_edge(v1,v2)
- e_label[e1]=int(data[3])
- #else:
- #print line
- #print '!!! Invalid graph data line...!!!'
- graphdic = dict(zip(G_list, indice))
- #print(graphdic)
- print '= = = = = Finished reading {} graphs from the file'.format(len(G_list)) + '= = = = ='
- ####Frequency Algorithm #####
- ta=time.time()
- i=0
- cnt=0
- #inc=0;
- for gr in G_list:
- for c in G_list:
- if (gt.isomorphism(gr,c)):
- cnt+= 1
- print("iso")
- print ("graph:{} frequence:{} ".format(i,cnt))
- frequence_list.append(cnt)
- cnt=0
- i+= 1
- print("-----------------------")
- freqdic = dict(zip(G_list,frequence_list))
- print("\n=x=x=x=x=x=x=x=x=x=x=x=x=")
- #try: seuil=float(raw_input('Entrer un Sieul:'))
- #except ValueError: print ("float")
- for gr, fr in freqdic.iteritems():
- if fr >= 2:
- frequentgraphs.append(gr)
- frequentfreqs.append(fr)
- frequentgraphsdic= dict(zip(frequentgraphs,frequentfreqs))
- print("\n=x=x=x=x=x=x=x=x=x=x=x=x=\n frequent items:{}\n".format(len(frequentgraphs)))
- #print(frequentgraphsdic)
- print("* * * * * D O N E * * * * * ")
- print("RUNNING TIME: {}s".format(time.time()-ti))
- print("Reading from file: {}s".format(ta-ti))
- print("Algo: {}s".format(time.time()-ta))
- #############################
- #programme pricipale
- def main():
- readGraphFile("5.txt")
- if __name__ == '__main__': main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement