I am using a networkx weighted graph in order to model a transportation network. I am attempting to find the shortest path in terms of the sum of weighted edges. I have used Dijkstra path in order to find this path. My problem occurs when there is a tie in terms of weighted edges. When this occurs I would always like to choose from the set of paths that tied, the path that has the least number of edges. Dijkstra path does not seem to be doing this.
Is there a way to ensure that I can choose the path with the least number of edges from a set of paths that are tied in terms of sum of weighted edges?
Instead of using floating points for weights, use tuples (weight, number_of_edges) with pairwise addition.  The lowest weight path using these new weights will have the lowest weight, and in the case of a tie, be the shortest path.
To define these weights I would make them a subclass of tuple with __add__ redefined.  Then you should be able to use your existing code.
Python: Shortest Weighted Path and Least Number of Edges