-
Notifications
You must be signed in to change notification settings - Fork 0
/
Arena.py
69 lines (61 loc) · 1.62 KB
/
Arena.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import tkinter as tk
import matplotlib.pyplot as plt
# top=tk.Tk()
# top.mainloop()
import networkx as nx
from GenerateMatrix import GenerateMatrix as gm
import string
import pylab
pylab.ion()
import random
from threading import Thread
# matrix_obj=gm(10,10)
# matrix_obj.prepare()
# A=matrix_obj.get_matrix()
# # print(A)
# G=nx.from_numpy_matrix(A)
# print(nx.node_link_data(G))
# nx.draw(G)
# plt.ion()
import time
class Arena():
def __init__(self):
Thread.__init__(self)
None
def reset(self,matrix):
# if matrix is None:
# matrix=self.matrix
self.G=nx.from_numpy_matrix(matrix)
pylab.clf()
print(matrix.shape)
self.G=nx.create_empty_copy(self.G)
self.pos=nx.random_layout(self.G)
nx.draw_networkx_nodes(self.G,self.pos,edge_color='w')
# plt.hold(False)
# plt.ion()
def add_edge(self,node1,node2):
# edges=self.G.edges()
# self.G.remove_edge(node1,node2)
self.G.add_edge(node1,node2,color='g',weight=5)
# pos=nx.get_node_attributes(self.G,'pos')
nx.draw_networkx_edges(self.G,self.pos)
# self.G.draw()
# self.G.updte
# plt.clf()
# nx.draw_random(self.G)
# plt.show()
def run(self):
pylab.show()
while(True):
pylab.draw()
plt.pause(2)
# if __name__=='__main__':
# a=Arena()
# a.reset()
# pylab.show()
# while(True):
# node1=random.randint(0,5)
# node2=random.randint(5,10)
# a.add_edge(node1,node2)
# # pylab.draw()
# plt.pause(0.2)