UDST / pandana

Pandas Network Analysis by UrbanSim: fast accessibility metrics and shortest paths, using contraction hierarchies :world_map:
http://udst.github.io/pandana
GNU Affero General Public License v3.0
385 stars 84 forks source link

shortest path distance between non connected nodes #168

Open PyMap opened 3 years ago

PyMap commented 3 years ago

if node exists but not connected in the net (doesn't exists in links table) pandana returns a constant distance (different from zero, 4294967.295 is the value). So Pandana is providing a shortest path length, even if shortest path returns an empty list.

image

This function matches external idx with internal ones in the net object. The shortest path method uses this function to count nodes between origin/destination here. It returns empty list, so the internal/external idx are working fine.

But, when the same operation occurs here (nodes idx are the same as shown in shortest path calculation I mention above), I get a len value for nodes involved in the empty list output. In short, I'm getting a numeric value for shortest distance when both nodes are not connected.

The shortest_path_distance calculation is call from cyacces interface (not sure but I guess here)

While creating the net object by excluding non connected nodes, the shortest path will return a ValueError: cannot convert float NaN to integer when trying to look for these internal net node indexes (here). Nodes don't exist, so shortest path can't be calculated (which is ok).

Alternatives:

  1. including a warning to declare that there are non connected nodes after the net is created
  2. adding some if statement here to discriminate distance metric as follow:
    
    shortest_nodes = shortest_path(self, node_a, node_b, imp_name)

if len(shortest_nodes)==0: len=0 else: len = self.net.shortest_path_distance(node_a, node_b, imp_num)


(@smmaurer )