diff --git a/BigBAG/bigBAG.py b/BigBAG/bigBAG.py new file mode 100644 index 0000000..6a51950 --- /dev/null +++ b/BigBAG/bigBAG.py @@ -0,0 +1,261 @@ +import random +import networkx as nx +import matplotlib.pyplot as plt +from tkinter import * +from PIL import ImageTk, Image +import shutil +from tkinter.ttk import Checkbutton +import math + +class GraphBarabasiAlbert: + + + def __init__(self): + self.V=[] + self.E=[] + self.G=nx.MultiGraph() + self.ME={} + self.LN={} + self.deg={} + + + def add_v(self): + + for v in self.V: + self.deg[v]= self.G.degree(v) - self.LN[v] - self.ME[v] + #print(self.deg) + us = selected.get() + #print(us) + sumDeg=0 + edgesCount=int(txtn.get()) + #print(self.V) + + for v in self.G.nodes(): + sumDeg+=self.deg[v] + + sumDeg=sumDeg//2 + ProbV = [] + #v0=self.BV[len(self.V)+1] + v0 = str(self.G.number_of_nodes()) + print(self.G.nodes()) + + colorMapNode=[] + for v in self.V: + colorMapNode.append('blue') + self.G.add_node(v0) + self.LN[v0]=0 + self.ME[v0]=0 + colorMapNode.append('green') + + strAddEdge = "" + + if ((us == 2)or(us == 4)): + loop=random.randint(0, edgesCount-1) + for i in range(loop): + self.G.add_edge(v0, v0) + strAddEdge+=(v0+'-'+v0+'\n') + nn=self.LN[v0]+2 + self.LN[v0] = nn + edgesCount-=loop + #print(self.LN) + + #print(self.V) + + + for v in self.V: + ProbV.append(self.deg[v]/(sumDeg*2)) + + for i in range(len(self.V)): + for j in range(len(self.V)-1): + if (ProbV[j]0): + mult = random.randint(0, L-1) + for j in range(mult): + self.G.add_edge(self.V[i], v0) + nn1 = self.ME[self.V[i]]+1 + self.ME[self.V[i]] = nn1 + nn1 = self.ME[v0]+1 + self.ME[v0] = nn1 + L-=mult + #print(self.ME) + + if ((us==1)or(us==2)): + for i in range(edgesCount): + self.G.add_edge(self.V[i], v0) + strAddEdge+=(self.V[i]+'-'+v0+'\n') + # if(us==1)and(('f','f') in (self.G.edges())): + # self.G.remove_edge('f','f') + + + colorMapEdge=[] + for i in range(self.G.number_of_edges()): + colorMapEdge.append('black') + + #print(self.G.edges()) + edgesG = [] + for ed in self.G.edges(): + edgesG.append(ed) + #print(self.G.edges()) + #print(colorMapEdge) + for i in range (len(edgesG)): + if v0 in edgesG[i]: + colorMapEdge[i]='red' + self.V.append(v0) + strFactDeg="" + strConnDeg="" + + + LoopText = "" + + nx.draw_circular(self.G,node_color=colorMapNode,edge_color = colorMapEdge ,with_labels = True) + plt.axis('on') + plt.savefig("st.png", dpi = 164) + plt.clf() + topImg1 = PhotoImage(file="st.png") + panel1.configure(image=topImg1) + panel1.image = topImg1 + + #print(self.LN) + + def new_g(self): + us1 = selected1.get() + plt.clf() + self.V=[] + self.E=[] + if (us1 == 1): + nodes=nx.read_adjlist("nodes1.txt") + edges=nx.read_edgelist('edges1.txt') + + elif (us1 == 2): + nodes=nx.read_adjlist("nodes2.txt") + edges=nx.read_edgelist('edges2.txt') + + elif (us1 == 3): + nodes=nx.read_adjlist("nodes3.txt") + edges=nx.read_edgelist('edges3.txt') + + elif (us1 == 4): + nodes=nx.read_adjlist("nodes4.txt") + edges=nx.read_edgelist('edges4.txt') + + self.G.clear() + self.G.add_nodes_from(nodes) + self.G.add_edges_from(edges.edges()) + for v in self.G.nodes(): + self.V.append(v) + print(self.G.edges()) + for e in self.G.edges(): + self.E.append(e) + strFactDeg="" + strConnDeg="" + for v in self.G.nodes(): + self.LN[v]=0 + self.ME[v]=0 + nx.draw(self.G, with_labels = True) + plt.axis('on') + plt.savefig("st.png", dpi = 164) + plt.clf() + topImg = PhotoImage(file="st.png") + panel1.configure(image=topImg) + panel1.image = topImg + +root1 = Tk() +root1.geometry('1500x2000') + +colors={"bgr":'#2F4F4F', 'bfr': '#696969', 'bfr1' : '#808080', 'bent':'#C0C0C0'} +root1["bg"] = colors['bgr'] + +g = GraphBarabasiAlbert() + +img = ImageTk.PhotoImage(Image.open("start2big.png")) +root1.title("Модель случайного графа Барабаши-Альберт") + +panel1 = Label(root1, image = img) +panel1.grid(column=0, row=0) + +panel1 = Label(root1, image = img) +panel1.grid(column=0, row=0) + +seedOpt = LabelFrame(text="затравка", width=400, height=170, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +seedOpt.place(x=1095, y=280) + +seedOpt1 = LabelFrame(seedOpt, width=350, height=30, background=colors['bfr']) +seedOpt2 = LabelFrame(seedOpt, width=350, height=30, background=colors['bfr']) +seedOpt3 = LabelFrame(seedOpt, width=350, height=30, background=colors['bfr']) +seedOpt4 = LabelFrame(seedOpt, width=350, height=30, background=colors['bfr']) + +seedOpt1.place(x=10, y=10) +seedOpt2.place(x=10, y=40) +seedOpt3.place(x=10, y=70) +seedOpt4.place(x=10, y=100) + +selected1 = IntVar() + +seedRad1 = Radiobutton(seedOpt1,text='10 вершин', value=1, variable=selected1, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +seedRad2 = Radiobutton(seedOpt2,text='15 вершин', value=2, variable=selected1, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +seedRad3 = Radiobutton(seedOpt3,text='20 вершин', value=3, variable=selected1, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +seedRad4 = Radiobutton(seedOpt4,text='100 вершин', value=4, variable=selected1, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') + +seedRad1.place(x=5, y=0) +seedRad2.place(x=5, y=0) +seedRad3.place(x=5, y=0) +seedRad4.place(x=5, y=0) + +EnterZnach = LabelFrame(text="ввод значений", width=400, height=80, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +EnterZnach.place(x=1095, y=5) + +EnterZnach1 = LabelFrame(EnterZnach, width=350, height=30, background=colors['bfr']) +EnterZnach1.place(x=10, y=10) + +TypeGraph = LabelFrame(text="способы работы", width=400, height=170, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +TypeGraph.place(x=1095, y=97) + +TypeGraph1 = LabelFrame(TypeGraph, width=350, height=30, background=colors['bfr']) +TypeGraph2 = LabelFrame(TypeGraph, width=350, height=30, background=colors['bfr']) +TypeGraph3 = LabelFrame(TypeGraph, width=350, height=30, background=colors['bfr']) +TypeGraph4 = LabelFrame(TypeGraph, width=350, height=30, background=colors['bfr']) + +TypeGraph1.place(x=10, y=10) +TypeGraph2.place(x=10, y=40) +TypeGraph3.place(x=10, y=70) +TypeGraph4.place(x=10, y=100) + +#Количество вершин +lbl = Label(EnterZnach1, text="колво рёбер:", font='Arial 10 bold', background=colors['bfr'],foreground='#ffffff') +lbl.place(x=0, y=0) +txtn = Entry(EnterZnach1, width=40, background=colors['bent']) +txtn.place(x=100, y=2) + +selected = IntVar() + +btn1 = Button(root1, text="заново", command=g.new_g, width=10, height=1, font='Arial 20 bold', background='#DC143C', foreground='#FFFFFF') +btn1.place(x=1095, y=462) + +btn2 = Button(root1, text="добавить", command=g.add_v, width=10, height=1, font='Arial 20 bold', background='#DC143C', foreground='#FFFFFF') +btn2.place(x=1318, y=462) + +rad1 = Radiobutton(TypeGraph1,text='граф', value=1, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad1.place(x=5, y=0) + +#Связность графа +rad2 = Radiobutton(TypeGraph2,text='псевдограф', value=2, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad2.place(x=5, y=0) + +#Планарность графа +rad3 = Radiobutton(TypeGraph3,text='мультиграф', value=3, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad3.place(x=5, y=0) + +#Присутствие треугольников +rad4 = Radiobutton(TypeGraph4,text='псевдомультиграф', value=4, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad4.place(x=5, y=0) + +root1.mainloop() \ No newline at end of file diff --git a/BigBAG/edges1.txt b/BigBAG/edges1.txt new file mode 100644 index 0000000..ecdc9cc --- /dev/null +++ b/BigBAG/edges1.txt @@ -0,0 +1,14 @@ +0 5 +1 5 +2 3 +2 4 +2 7 +2 8 +2 9 +3 4 +3 7 +3 8 +4 7 +5 6 +5 8 +6 7 diff --git a/BigBAG/edges2.txt b/BigBAG/edges2.txt new file mode 100644 index 0000000..f4cb8c2 --- /dev/null +++ b/BigBAG/edges2.txt @@ -0,0 +1,17 @@ +0 5 +1 4 +1 10 +1 11 +2 4 +2 8 +3 5 +3 13 +3 14 +4 9 +4 11 +4 14 +5 9 +6 14 +7 9 +8 10 +11 12 diff --git a/BigBAG/edges3.txt b/BigBAG/edges3.txt new file mode 100644 index 0000000..25e611e --- /dev/null +++ b/BigBAG/edges3.txt @@ -0,0 +1,28 @@ +0 2 +0 13 +0 16 +1 7 +1 10 +2 3 +2 9 +2 14 +3 12 +4 7 +4 9 +5 6 +5 14 +5 18 +7 12 +7 16 +8 12 +8 15 +8 19 +10 16 +11 16 +11 18 +12 15 +13 15 +13 17 +15 16 +15 18 +17 18 diff --git a/BigBAG/edges4.txt b/BigBAG/edges4.txt new file mode 100644 index 0000000..7519cf1 --- /dev/null +++ b/BigBAG/edges4.txt @@ -0,0 +1,218 @@ +0 23 +0 87 +0 96 +1 34 +1 54 +2 21 +2 44 +2 46 +2 48 +3 10 +3 37 +3 56 +4 18 +4 79 +4 81 +4 87 +4 97 +5 64 +5 83 +6 48 +6 53 +6 66 +6 71 +6 81 +6 85 +7 18 +7 27 +7 29 +7 43 +7 68 +8 47 +8 56 +8 67 +8 70 +8 78 +9 17 +9 59 +9 82 +9 95 +10 24 +10 43 +11 19 +11 52 +11 89 +12 37 +12 85 +12 87 +13 62 +13 65 +14 31 +14 34 +14 59 +15 39 +15 88 +16 35 +16 69 +16 97 +17 29 +17 38 +17 39 +18 28 +18 34 +18 46 +18 54 +18 84 +18 99 +19 97 +19 98 +20 72 +20 86 +21 38 +21 44 +21 55 +21 57 +21 70 +22 27 +22 29 +22 39 +22 69 +23 29 +23 69 +24 44 +24 83 +24 98 +25 51 +25 67 +25 73 +26 66 +26 77 +26 98 +27 32 +27 47 +27 52 +28 45 +28 49 +28 52 +29 30 +29 36 +29 41 +29 58 +29 63 +29 78 +29 84 +30 37 +30 46 +30 90 +31 46 +31 47 +31 67 +31 92 +32 39 +32 48 +32 78 +32 83 +32 88 +33 34 +33 60 +33 78 +33 94 +34 51 +34 66 +34 76 +35 50 +35 86 +36 43 +36 44 +36 98 +37 54 +37 86 +38 53 +38 72 +38 86 +38 97 +40 75 +40 81 +41 73 +42 54 +42 75 +43 66 +43 73 +44 48 +45 50 +45 73 +45 87 +45 98 +46 49 +47 57 +47 58 +47 62 +47 80 +48 64 +48 71 +49 71 +49 88 +50 68 +50 72 +50 77 +51 59 +51 74 +51 78 +51 81 +51 82 +52 77 +53 89 +54 62 +55 62 +55 66 +55 88 +55 89 +56 96 +57 64 +57 85 +57 87 +57 97 +57 98 +58 60 +59 68 +59 93 +61 81 +61 89 +61 90 +62 96 +63 80 +63 84 +63 96 +64 72 +64 78 +64 94 +64 95 +65 75 +66 71 +66 91 +67 85 +68 85 +68 91 +68 92 +69 70 +69 75 +69 95 +71 90 +72 78 +74 82 +76 82 +76 99 +77 80 +77 89 +77 96 +80 82 +83 90 +83 97 +84 89 +84 92 +85 91 +85 92 +87 91 +87 98 +89 93 +92 95 diff --git a/BigBAG/nodes1.txt b/BigBAG/nodes1.txt new file mode 100644 index 0000000..f55b5c9 --- /dev/null +++ b/BigBAG/nodes1.txt @@ -0,0 +1,10 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 \ No newline at end of file diff --git a/BigBAG/nodes2.txt b/BigBAG/nodes2.txt new file mode 100644 index 0000000..68135ed --- /dev/null +++ b/BigBAG/nodes2.txt @@ -0,0 +1,15 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 \ No newline at end of file diff --git a/BigBAG/nodes3.txt b/BigBAG/nodes3.txt new file mode 100644 index 0000000..d029198 --- /dev/null +++ b/BigBAG/nodes3.txt @@ -0,0 +1,20 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 \ No newline at end of file diff --git a/BigBAG/nodes4.txt b/BigBAG/nodes4.txt new file mode 100644 index 0000000..dcf1415 --- /dev/null +++ b/BigBAG/nodes4.txt @@ -0,0 +1,100 @@ +0 +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 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 \ No newline at end of file diff --git a/BigBRG/bigBRG.py b/BigBRG/bigBRG.py new file mode 100644 index 0000000..2da2251 --- /dev/null +++ b/BigBRG/bigBRG.py @@ -0,0 +1,243 @@ +import random +import networkx as nx +import matplotlib.pyplot as plt +from tkinter import * +from PIL import ImageTk, Image +import shutil +from tkinter.ttk import Checkbutton +import math + +class GraphBarabasiAlbert: + + + def __init__(self): + self.E=[] + self.G=nx.MultiGraph() + self.MainG=[] + self.deg={} + self.MainEdge={} + + + def add_v(self): + + colorMapEdge=[] + for i in range(self.G.number_of_edges()): + colorMapEdge.append('black') + colorMapEdge.append('black') + + colorMapNode=[] + for i in range (self.G.number_of_nodes()): + colorMapNode.append('blue') + colorMapNode.append('green') + + v0=self.G.number_of_nodes() + self.G.add_node(v0) + n=self.G.number_of_nodes() + textNumbNodes.configure(text="kn = "+str(n)) + #print(n) + + for v in self.G.nodes(): + if(v!=v0): + self.deg[v] = (self.G.degree(v)/(2*n-1)) + #print(self.deg[v]) + self.deg[v0] = 1/(2*n-1) + + + + + + V=[] + ProbV = [] + for v in self.G.nodes(): + V.append(v) + ProbV.append(self.deg[v]) + #print(ProbV) + + for i in range(len(V)): + for j in range(len(V)-1): + if (ProbV[j]ProbV[i+1]): + pk=i + else: + break + + #print(pk) + self.G.add_edge(V[pk], v0) + + edgesG = [] + for ed in self.G.edges(): + edgesG.append(ed) + + self.V.append(v0) + + for i in range (len(edgesG)): + if v0 in edgesG[i]: + colorMapEdge[i]='red' + + nx.draw(self.G, node_color=colorMapNode ,edge_color = colorMapEdge,with_labels = False) + plt.axis('on') + plt.savefig("st.png", dpi = 164) + plt.clf() + topImg1 = PhotoImage(file="st.png") + panel.configure(image=topImg1) + panel.image = topImg1 + + def new_g(self): + plt.clf() + self.V=[] + self.E=[] + + self.E=[] + #self.G=nx.MultiGraph() + self.MainG=[] + self.deg={} + self.MainEdge={} + + self.deg={} + + self.G.clear() + self.G.add_nodes_from(self.V) + self.G.add_edges_from(self.E) + + + nx.draw(self.G, with_labels = True) + plt.axis('on') + plt.savefig("st.png", dpi=164) + plt.clf() + + topImg = PhotoImage(file="st.png") + panel.configure(image=topImg) + panel.image = topImg + + def break_graph(self): + k=int(txtk.get()) + numG=self.G.number_of_nodes()//k + V=[] + E=[] + + for v in self.G.nodes(): + V.append(v) + for e in self.G.edges(): + E.append(e) + # for e in E: + # self.MainEdge[e] = 0 + + print(V[0]) + print(E[0]) + otsech=0 + + for i in range(numG): + MainEdges = {} + V1=[] + E1=[] + G1=nx.MultiGraph() + for j in range (i*k, (i+1)*k): + V1.append(V[j]) + G1.add_nodes_from(V1) + for e in E: + if ((e[0] in V1) and (e[1] in V1)): + E1.append(e) + G1.add_edges_from(E1) + + self.MainG.append(G1) + + nx.draw(G1, with_labels = False) + plt.axis('on') + #plt.show() + plt.clf() + print(len(self.MainG)) + for i in range(len(self.MainG)): + for j in range(i, len(self.MainG)): + self.MainEdge[tuple([i, j])] = 0 + for e in E: + e1 = -1 + e2 = -1 + for i in range (len(self.MainG)): + if e[0] in self.MainG[i]: + e1 = i + for i in range (len(self.MainG)): + if e[1] in self.MainG[i]: + e2 = i + t = self.MainEdge[tuple([e1, e2])] + 1 + self.MainEdge[tuple([e1, e2])] = t + print(self.MainEdge) + ITOG = nx.MultiGraph() + VI=[] + loopstr = "" + for i in range(len(self.MainG)): + VI.append(str(i)) + loopstr+= (str(i)+" : "+str(self.MainG[i].number_of_edges())+"\n") + ITOG.add_nodes_from(VI) + strMult = "" + for dk in self.MainEdge: + for i in range (self.MainEdge[dk]): + ITOG.add_edge(str(dk[0]), str(dk[1])) + strMult+=("("+str(dk[0])+','+str(dk[1])+') : '+str(self.MainEdge[dk])+'\n') + + + nx.draw(ITOG, with_labels = True) + plt.axis('on') + plt.savefig("stBRG.png", dpi = 164) + plt.clf() + + topImg = PhotoImage(file="stBRG.png") + panel.configure(image=topImg) + panel.image = topImg + + + + +root = Tk() +root.geometry('1500x2000') + +colors={"bgr":'#2F4F4F', 'bfr': '#696969', 'bfr1' : '#808080', 'bent':'#C0C0C0'} +root["bg"] = colors['bgr'] + +g = GraphBarabasiAlbert() + +img = ImageTk.PhotoImage(Image.open("start3big.png")) +root.title("Модель случайного графа Боллобаша-Риордана") +panel = Label(root, image = img) +panel.grid(column=0, row=0) + +panel = Label(root, image = img) +panel.grid(column=0, row=0) + +NumbNodes = LabelFrame(text="колво вершин", width=225, height=80, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +NumbNodes.place(x=1095, y=100) + +textNumbNodes = Label(NumbNodes, text = "kn = 0", font='Arial 14 bold', background=colors['bfr'],foreground='#ffffff', width=17, height=2) +textNumbNodes.place(x=2, y=2) + +EnterZnach = LabelFrame(text="ввод значений", width=400, height=80, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +EnterZnach.place(x=1095, y=5) + +EnterZnach1 = LabelFrame(EnterZnach, width=350, height=30, background=colors['bfr']) +EnterZnach1.place(x=10, y=10) + +lbl = Label(EnterZnach1, text="k:", font='Arial 10 bold', background=colors['bfr'],foreground='#ffffff') +lbl.place(x=0, y=0) +txtk = Entry(EnterZnach1, width=53, background=colors['bent']) +txtk.place(x=20, y=2) + +btn1 = Button(root, text="заново", command=g.new_g, width=10, height=1, font='Arial 20 bold', background='#DC143C', foreground='#FFFFFF') +btn1.place(x=1095, y=200) + +btn2 = Button(root, text="добавить", command=g.add_v, width=10, height=1, font='Arial 20 bold', background='#228B22', foreground='#FFFFFF') +btn2.place(x=1095, y=300) + +btn2 = Button(root, text="разбить", command=g.break_graph, width=10, height=1, font='Arial 20 bold', background='#DC143C', foreground='#FFFFFF') +btn2.place(x=1095, y=400) + + + +root.mainloop() \ No newline at end of file diff --git a/BigERG/bigERG.py b/BigERG/bigERG.py new file mode 100644 index 0000000..cc6f0ca --- /dev/null +++ b/BigERG/bigERG.py @@ -0,0 +1,227 @@ +import random +import networkx as nx +import matplotlib.pyplot as plt +from tkinter import * +from PIL import ImageTk, Image +import shutil +from tkinter.ttk import Checkbutton +import math + +def Get_data(): + val_map = {} + n=int(txtn.get()) + us =selected.get() + print(us) + if (us==1): + p=float(txtp.get()) + txtс.delete(0, END) + txtс.insert(0,'c') + elif (us==2): + c=float(txtс.get()) + p=c*(math.log(n)/n) + txtp.delete(first=0,last=END) + txtp.insert(0, str(p)) + elif (us==3): + c=float(txtс.get()) + p=c/n + txtp.delete(first=0,last=END) + txtp.insert(0, str(p)) + elif (us==4): + w=n/math.log(n) + p=w/n + txtp.delete(first=0,last=END) + txtp.insert(0, str(p)) + elif (us==5): + a=1/n + p=a/n + txtp.delete(first=0,last=END) + txtp.insert(0, str(p)) + elif (us==6): + p=1/(n**3) + txtp.delete(first=0,last=END) + txtp.insert(0, str(p)) + elif (us==7): + p=n*math.log(n)/n + txtp.delete(first=0,last=END) + txtp.insert(0, str(p)) + elif (us==8): + p=float(txtp.get()) + txtс.delete(0, END) + txtс.insert(0,'c') + f = open("BigERG/data.txt", "w") + f.write(str(n)+'\n') + f.write(str(p)+'\n') + + +def Show_Graph(): + G= nx.Graph() + edges = nx.read_edgelist('BigERG/edges.txt') + nodes = nx.read_adjlist("BigERG/nodes.txt") + G.add_edges_from(edges.edges()) + G.add_nodes_from(nodes) + + us =selected.get() + val_map = {} + + if (us==4): + all_cliques= nx.enumerate_all_cliques(G) + triad_cliques=[x for x in all_cliques if len(x)==3 ] + if (len(triad_cliques)!=0): + for v in triad_cliques[0]: + val_map[v]=0.1 + + all_cliques= nx.enumerate_all_cliques(G) + triad_cliques=[x for x in all_cliques if len(x)==3 ] + if (len(triad_cliques)!=0): + lbl3.configure(text='+', foreground='#008000') + else: + lbl3.configure(text='-', foreground='#ff0000') + + if (us==8): + for v in (max(nx.connected_components(G))): + val_map[v]=0.1 + + values = [val_map.get(node, 0.25) for node in G.nodes()] + + plt.clf() + if (nx.check_planarity(G, counterexample=False)[0]==True): + nx.draw_planar(G, cmap=plt.get_cmap('viridis'), node_color=values, with_labels=True, font_color='white') + lbl2.configure(text="+", foreground='#008000') + else: + nx.draw(G, cmap=plt.get_cmap('viridis'), node_color=values, with_labels=True, font_color='white') + lbl2.configure(text="-", foreground='#ff0000') + + if (nx.is_connected(G)): + lbl1.configure(text="+", foreground='#008000') + else: + lbl1.configure(text="-", foreground='#ff0000') + print(max(nx.connected_components(G))) + plt.axis('on') + plt.savefig("BigERG/st.png") + + + + #nx.draw(G,pos=nx.spring_layout(G) ,with_labels = False) + plt.show() + plt.clf() + +root = Tk() +colors={"bgr":'#2F4F4F', 'bfr': '#696969', 'bfr1' : '#808080', 'bent':'#C0C0C0'} +root.title("Модель случайного графа Эрдёша-Реньи") +root["bg"] = colors['bgr'] +root.geometry('750x500') + +selected = IntVar() + +#frame1 = LabelFrame(text="изображение графа", width=640, height=480, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +frame2 = LabelFrame(text="способы работы", width=400, height=280, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +frame3 = LabelFrame(text="ввод значений", width=400, height=180, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') +frame4 = LabelFrame(text="свойства графа", width=250, height=180, background=colors['bfr1'],foreground='#ffffff', font='Arial 12 bold') + +#frame1.place(x=5, y=5) +frame4.place(x=420, y=5) +frame3.place(x=5, y=300) +frame2.place(x=5, y=5) + +frame31 = LabelFrame(frame3, width=350, height=30, background=colors['bfr']) +frame32 = LabelFrame(frame3, width=350, height=30, background=colors['bfr']) +frame33 = LabelFrame(frame3, width=350, height=30, background=colors['bfr']) + +frame41 = LabelFrame(frame4, width=220, height=30, background=colors['bfr']) +frame42 = LabelFrame(frame4, width=220, height=30, background=colors['bfr']) +frame43 = LabelFrame(frame4, width=220, height=30, background=colors['bfr']) + +frame41.place(x=10, y=10) +frame42.place(x=10, y=60) +frame43.place(x=10, y=110) + +frame31.place(x=10, y=10) +frame32.place(x=10, y=60) +frame33.place(x=10, y=110) + +#Количество вершин +lbl = Label(frame31, text="колво вершин:", font='Arial 10 bold', background=colors['bfr'],foreground='#ffffff') +lbl.place(x=0, y=0) +txtn = Entry(frame31, width=40, background=colors['bent']) +txtn.place(x=100, y=2) + +#вероятность p +txtp = Entry(frame32,width=40, background=colors['bent']) +txtp.place(x=100, y=2) +lblp = Label(frame32, text="вероятность:", font='Arial 10 bold', background=colors['bfr'],foreground='#ffffff') +lblp.place(x=0, y=0) + +#задать с +txtс = Entry(frame33,width=40, background=colors['bent']) +txtс.place(x=100, y=2) +lblс = Label(frame33, text="с: ", font='Arial 10 bold', background=colors['bfr'],foreground='#ffffff') +lblс.place(x=0, y=0) + +frame21 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame22 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame23 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame24 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame25 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame26 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame27 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) +frame28 = LabelFrame(frame2, width=350, height=30, background=colors['bfr']) + +frame21.place(x=10, y=10) +frame22.place(x=10, y=40) +frame23.place(x=10, y=70) +frame24.place(x=10, y=100) +frame25.place(x=10, y=130) +frame26.place(x=10, y=160) +frame27.place(x=10, y=190) +frame28.place(x=10, y=220) + +rad1 = Radiobutton(frame21,text='задать вероятность', value=1, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad1.place(x=5, y=0) + +#Связность графа +rad2 = Radiobutton(frame22,text='связность(теорема 13)', value=2, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad2.place(x=5, y=0) + +#Планарность графа +rad3 = Radiobutton(frame23,text='планарность(теорема 26)', value=3, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad3.place(x=5, y=0) + +#Присутствие треугольников +rad4 = Radiobutton(frame24,text='присутствие треугольников (теорема 12)', value=4, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad4.place(x=5, y=0) + +#Отсутсвие треугольников +rad5 = Radiobutton(frame25,text='отсутствие треугольников (теорема 10)', value=5, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad5.place(x=5, y=0) + +#Феодальная раздробленность +rad6 = Radiobutton(frame26,text='феодальная раздробленность (стр. 48)', value=6, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad6.place(x=5, y=0) + +#Империя +rad7 = Radiobutton(frame27,text='империя (стр. 48)', value=7, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad7.place(x=5, y=0) + +#Гигантская компонента связности +rad8 = Radiobutton(frame28,text='Гигантская компонента связности', value=8, variable=selected, background=colors['bfr'],foreground='#ffffff', font='Arial 10 bold') +rad8.place(x=5, y=0) + +Label(frame41, text="cвязность", background=colors['bfr'], font='Arial 10 bold', foreground='#FFFFFF').place(x=5, y=0) +lbl1 = Label(frame41, text='-', font='Arial 12 bold', foreground='#ff0000', background=colors['bfr']) +lbl1.place(x=200, y=0) + +Label(frame42, text="планарность", background=colors['bfr'], font='Arial 10 bold', foreground='#FFFFFF').place(x=5, y=0) +lbl2 = Label(frame42, text='-', font='Arial 12 bold', foreground='#ff0000', background=colors['bfr']) +lbl2.place(x=200, y=0) + +Label(frame43, text="наличие треугольников", background=colors['bfr'], font='Arial 10 bold', foreground='#FFFFFF').place(x=5, y=0) +lbl3 = Label(frame43, text='-', font='Arial 12 bold', foreground='#ff0000', background=colors['bfr']) +lbl3.place(x=200, y=0) + +btn = Button(root, text="отправить", command=Get_data, width=10, height=1, font='Arial 20 bold', background='#228B22', foreground='#FFFFFF') +btn.place(x=460, y=380) + +btn = Button(root, text="показать", command=Show_Graph, width=10, height=1, font='Arial 20 bold', background='#DC143C', foreground='#FFFFFF') +btn.place(x=460, y=300) + +root.mainloop() \ No newline at end of file diff --git a/BigERG/data.txt b/BigERG/data.txt new file mode 100644 index 0000000..5a48b93 --- /dev/null +++ b/BigERG/data.txt @@ -0,0 +1,2 @@ +12 +0.1 diff --git a/BigERG/edges.txt b/BigERG/edges.txt new file mode 100644 index 0000000..7e676fb --- /dev/null +++ b/BigERG/edges.txt @@ -0,0 +1,5 @@ +2 5 +2 9 +3 11 +4 5 +5 6 diff --git a/BigERG/nodes.txt b/BigERG/nodes.txt new file mode 100644 index 0000000..c8ba052 --- /dev/null +++ b/BigERG/nodes.txt @@ -0,0 +1,12 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 \ No newline at end of file diff --git a/BigERG/st.png b/BigERG/st.png new file mode 100644 index 0000000..57e529c Binary files /dev/null and b/BigERG/st.png differ diff --git a/BigERG/test.cpp b/BigERG/test.cpp new file mode 100644 index 0000000..9e5d243 --- /dev/null +++ b/BigERG/test.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +using namespace std; + +int main(){ + srand(time(0)); + float p =1, p1; + int n = 100; + string ns, ps; + ofstream fout1, fout2; + ifstream fin; + fout1.open("nodes.txt"); + fout2.open("edges.txt"); + fin.open("data.txt"); + getline(fin, ns); + n = stoi(ns); + getline(fin, ps); + p = stof(ps); + for (int i=0; i< n; i++){ + fout1 << i; + if(i!= (n-1)) + fout1 << '\n'; + } + for (int i=0; i