SHARE
TWEET

Untitled

a guest Dec 6th, 2019 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pandas as pd
  2. import numpy as np
  3. import networkx as nx
  4.  
  5. %matplotlib inline
  6. %config InlineBackend.figure_format = 'retina'
  7. import matplotlib.pyplot as plt
  8. from pylab import rcParams
  9. from queue import Queue
  10.  
  11. # Import starter files
  12.  
  13. G = nx.from_numpy_matrix(np.array(adjacency_matrix))
  14.  
  15. MST = nx.minimum_spanning_tree(G)
  16.  
  17. # directed graph, bfe_tree and dfs_tree are the same
  18. directed_MST = nx.bfs_tree(MST, 0)
  19.  
  20. nodeTA = {}
  21.  
  22. for node in directed_MST.nodes:
  23.     for home in list_of_homes:
  24.         if nx.has_path(directed_MST, node, int(home)):
  25.             nodeTA[node] = nodeTA.get(node, 0) + 1
  26.            
  27.  
  28. queue = Queue()
  29. queue.put(starting_car_location)
  30. visitedNodes = []
  31.  
  32. while not queue.empty():
  33.     node = queue.get()
  34.     numTA = nodeTA.get(node, 0)
  35.  
  36.     if numTA > 1:
  37.         neighbors = directed_MST.neighbors(node)
  38.         for neighbor in neighbors:
  39.             queue.put(neighbor)
  40.         visitedNodes.append(node)
  41.        
  42. print(visitedNodes)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top