shanali-sg / npt

Network Path Tool
2 stars 0 forks source link

Broke latest version with a few bad nodes #7

Open barriejc opened 1 year ago

barriejc commented 1 year ago

If this is something that can't be trained away, can use "try/except" statements to feed users error messages with bad node numbers, etc. Here are the bad examples I tried. BTW I am using this within a virtual environment (virt) but I did also get an error message (not pasted below) that networkx was not installed -- before I remembered to activate the venv, that is:

(virt) [10:08] npt % python npt.py 3 7
Traceback (most recent call last):
  File "/Users/barrie/hackathon86/npt/virt/lib/python3.9/site-packages/networkx/algorithms/simple_paths.py", line 239, in all_simple_paths
    targets = set(target)
TypeError: 'int' object is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/barrie/hackathon86/npt/npt.py", line 39, in <module>
    paths = nx.all_simple_paths(G, u, v)
  File "/Users/barrie/hackathon86/npt/virt/lib/python3.9/site-packages/networkx/algorithms/simple_paths.py", line 241, in all_simple_paths
    raise nx.NodeNotFound(f"target node {target} not in graph") from err
networkx.exception.NodeNotFound: target node 7 not in graph
(virt) [10:10] npt % python npt.py 2 4
Shortest Path:
Shortest Path is                      :      2.000 [2, 1, 4]
Shortest Path Ref List is             :            [1, 3]

Diverse Paths:
Worker Path distance is               :      0.000 []
Worker Path Ref List is               :            []
Traceback (most recent call last):
  File "/Users/barrie/hackathon86/npt/npt.py", line 79, in <module>
    print("Protected path distance is            : ", f"{nx.path_weight(G, diversePathList[0], weight = 'distance'):9.3f}", diversePathList[0])
IndexError: list index out of range
(virt) [10:10] npt % python npt.py 3 5
Traceback (most recent call last):
  File "/Users/barrie/hackathon86/npt/npt.py", line 66, in <module>
    candidateShortestPath = nx.shortest_path(H, u, v, weight = 'distance')
  File "/Users/barrie/hackathon86/npt/virt/lib/python3.9/site-packages/networkx/algorithms/shortest_paths/generic.py", line 167, in shortest_path
    _, paths = nx.bidirectional_dijkstra(G, source, target, weight)
  File "/Users/barrie/hackathon86/npt/virt/lib/python3.9/site-packages/networkx/algorithms/shortest_paths/weighted.py", line 2309, in bidirectional_dijkstra
    raise nx.NodeNotFound(msg)
networkx.exception.NodeNotFound: Either source 3 or target 5 is not in G
shanali-sg commented 1 year ago

Wow!! Thank you Barrie since now the actual job is dominating every minute of my time... how about these advancements go into future hackathon ideas list...

1) Convert the program to a Web App with Drop down list of nodes (this will remove the bad node error from happening) 2) Optimize the existing algorithm to work on larger graph set. i.e. if the no. of graph node increase to 100 nodes it become very slow

This way this program can offer something to both algorithm developer or webUI developer :)