예제 #1
0
def generate_timely_graph(visited: List[str], string2candidate: Dict[str, CandidateFeature]):
	#generate id
	id2candidate: Dict[str, int] = {}
	for counter in range(len(visited)):
		id2candidate[visited[counter]] = counter

	import gexf

	gexf = gexf.Gexf('Felix Neutatz', '28-11-2012')
	# make an undirected dynamical graph
	graph = gexf.addGraph('directed', 'dynamic', '28-11-2012')
	edge_counter = 0
	current_time = 0

	id2candidate['__root__'] = -1
	graph.addNode(-1, '__root__', start=str(0.0))

	for v_i in range(len(visited)):
		id2candidate[visited[v_i]] = v_i
		graph.addNode(v_i, visited[v_i], start=str(current_time))

		current_candidate = string2candidate[visited[v_i]]
		current_time += string2candidate[str(current_candidate)].runtime_properties['execution_time']
		if not isinstance(current_candidate, RawFeature):
			for p in current_candidate.parents:
				graph.addEdge(edge_counter, id2candidate[str(p)], id2candidate[str(current_candidate)], start=str(current_time))
				edge_counter += 1
		else:
			graph.addEdge(edge_counter, id2candidate['__root__'], id2candidate[str(current_candidate)], start=str(current_time))

	gexf.write(open('/tmp/dynamic_graph.gexf', "wb+"))
예제 #2
0
    open("C:\Users\CRAZY\PycharmProjects\Small_Projects\NMProject\MonthData.csv", "rb"))

rowno = 0
for row in monthreader:
    if rowno == 0:
        rowno += 1
        continue
    if rowno == 1:
        rowno += 1
        month = monthreader[2]
        G = networkx.DiGraph()
        G.add_node(monthreader[0])
        G.add_node(monthreader[1])
        G.add_edge(monthreader[0],monthreader[1],weight=monthreader[3])
    else:
        if monthreader[2] == month:
            if not G.has_node(monthreader[0])
            G.add_node(monthreader[0])
            G.add_node(monthreader[1])
            G.add_edge(monthreader[0], monthreader[1], weight=monthreader[3])

gexf = gexf.Gexf('Your Name','28-11-2012')
#make an undirected dynamical graph
graph = gexf.addGraph('undirected','dynamic','28-11-2012',timeformat='date')
#you add nodes with a unique id
graph.addNode(Source,"source_id")
#make edge with unique id, the edge has time duration from start to end
graph.addEdge(edge_id,Source,Target,start = Date , end = Date)
#write the gexf format to fileout
gexf.write(fileOut)
예제 #3
0
cols.remove('Article URL.1')

gexf = Gexf("emCOMP", "Article Similarity")
graph = gexf.addGraph("undirected", "static", "Article Similarity")

#add nodes
for r in rows:
    graph.addNode(r, dates.loc[r, "updated_domain"])

#add edges
count = 0
count_r = 0
for r in rows:
    print("r" + str(count_r))
    for c in cols:
        #can be adapted for directed graph
        if (df.loc[r, c] > .85):
            r_date = datetime.datetime.strptime(str(dates.loc[r, "first_ts"]),
                                                '%Y-%m-%d %H:%M:%S')
            c_date = datetime.datetime.strptime(str(dates.loc[c, "first_ts"]),
                                                '%Y-%m-%d %H:%M:%S')
            if (r < c):
                graph.addEdge(count, r, c, df.loc[r, c])
            else:
                graph.addEdge(count, c, r, df.loc[r, c])
            count = count + 1
    count_r = count_r + 1

output_file = open("edge_matrix.gexf", "w")
gexf.write(output_file)