def mold_growth(self, start, search_range): """ For finding all of the nodes around within a certain range, simulating mold exploring around itself for food """ food = list() # Find all nodes of food around the starting point, simulating the mold growing out in all directions for dist in range(search_range): current_found = Graph.find_vertices_n_away(graph, start, dist) if current_found not in food: food.append(current_found) return food
graph.add_edge('B', 'C') graph.add_edge('B', 'D') graph.add_edge('D', 'E') graph.add_edge('F', 'G') # Or, read a graph in from a file # graph = read_graph_from_file('test_files/graph_small_directed.txt') # Output the vertices & edges # Print vertices print(f'The vertices are: {graph.get_vertices()} \n') # Print edges print('The edges are:') for vertex_obj in graph.get_vertices(): for neighbor_obj in vertex_obj.get_neighbors(): print(f'({vertex_obj.get_id()} , {neighbor_obj.get_id()})') # Search the graph print('Performing BFS traversal...') graph.bfs_traversal('A') # Find shortest path print('Finding shortest path from vertex A to vertex E...') shortest_path = graph.find_shortest_path('A', 'E') print(shortest_path) # Find all vertices N distance away print('Finding all vertices distance 2 away...') vertices_2_away = graph.find_vertices_n_away('A', 2) print(vertices_2_away)