Skip to content

Commit

Permalink
🐛 Prims start node
Browse files Browse the repository at this point in the history
  • Loading branch information
kutluhanazafli committed May 27, 2022
1 parent 0fbc66d commit 3e90818
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions Project-02/prims.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import matplotlib.pyplot as plt
import networkx as nx


class Graph():
def __init__(self, vertices):
self.V = vertices
Expand All @@ -20,7 +19,6 @@ def printMST(self, parent):
nodeNames += alphabet[i]
self.nodes = list(nodeNames)

print(self.nodes)
print("Edge \tWeight")
for i in range(1, self.V):
print(alphabet[parent[i]], "-", alphabet[i], "\t", self.graph[i][parent[i]])
Expand All @@ -47,6 +45,7 @@ def primMST(self):
mstSet = [False] * self.V

parent[0] = -1
alphabet = string.ascii_uppercase

for cout in range(self.V):

Expand All @@ -59,6 +58,7 @@ def primMST(self):
if self.graph[u][v] > 0 and mstSet[v] == False and key[v] > self.graph[u][v]:
key[v] = self.graph[u][v]
parent[v] = u
print(f'Başlangıç Node: {alphabet[key[0]]}\n')

self.printMST(parent)

Expand All @@ -69,10 +69,10 @@ def primMST(self):
[0, 1, 0, 1, 0, 4, 1, 0, 0, 0, 0, 0], #c
[0, 0, 1, 0, 0, 0, 1, 5, 0, 0, 0, 0], #d
[2, 0, 0, 0, 0, 5, 0, 0, 1, 0, 0, 0], #e
[4, 2, 4, 0, 5, 0, 3, 0, 1, 3, 0, 0], #f
[4, 2, 4, 0, 5, 0, 3, 0, 6, 3, 0, 0], #f
[0, 0, 1, 1, 0, 3, 0, 5, 0, 3, 3, 2], #g
[0, 0, 0, 5, 0, 0, 5, 0, 0, 0, 0, 2], #h
[0, 0, 0, 0, 1, 1, 0, 0, 0, 2, 0, 0], #i
[0, 0, 0, 0, 1, 6, 0, 0, 0, 2, 0, 0], #i
[0, 0, 0, 0, 0, 3, 3, 0, 2, 0, 3, 0], #j
[0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 4], #k
[0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 4, 0]] #l
Expand Down Expand Up @@ -115,7 +115,6 @@ def union(self, x, y):

pos = nx.spring_layout(D, seed=700)


# nodes
nx.draw_networkx_nodes(D, pos, node_size=400)

Expand Down

0 comments on commit 3e90818

Please sign in to comment.