# [0, 1, 1, 1], # [1, 0, 1, 1], # [1, 1, 0, 1], # [1, 1, 1, 0] # ] graph.list_arc_from_matr_adj() graph.list_adj_from_matix_adj() graph.matrix_incedent_from_matix_adj() graph.add_vert() graph.add_arc(4, 1) graph.show() #graph.greedy_coloring() g.add_edges_from(graph.list_arc) print("DFS") print(graph.DFS(0)) print("BFS") print(bfs(visited, graph.list_adj, 0)) d = graph.greedy_coloring(g) print("coloring by row") coloring_by_manapulating_rows(graph.matrix_adj) print("coloring greedy algo") print("=================================================================") print(d) print("=================================================================") draw(g, with_labels=True) show()
for neighbour in self.list_adj[v]: if neighbour not in visited: print(str(v) + "->" + str(neighbour), end=' ') self.DFSUtil(neighbour, visited) print(str(neighbour) + '->' + str(v), end=' ') def DFS(self, start_vert): visited = set() self.DFSUtil(start_vert, visited) def add_arc(self, vert1, vert2): self.list_arc.append([vert1, vert2]) self.list_adj_from_list_arc() self.matr_adj_from_list_adj() self.matrix_incedent_from_list_arc() graph = Graph() graph.matrix_adj = [[0, 1, 0, 1], [0, 0, 1, 1], [0, 1, 0, 1], [1, 0, 1, 0]] graph.list_arc_from_matr_adj() graph.list_adj_from_matix_adj() graph.matrix_incedent_from_matix_adj() graph.add_vert() graph.add_arc(4, 1) graph.show() g.add_edges_from(graph.list_arc) print(graph.DFS(4)) draw(g, with_labels=True) show()