networkx/networkx — pull request #744 by chebee7i (2012-07-28 20:36:48+00:00)
Title: Shortest path with only a target specified.

Presently, calling

```python
G = nx.path_graph(5)
nx.shortest_path(G, target=4)
```

returns an exception even though it is clear what the user would like. Namely, a dictionary keyed by sources with values representing paths from the source to the specified target:

```
{0: [0, 1, 2, 3, 4], 1: [1, 2, 3, 4], 2: [2, 3, 4], 3: [3, 4], 4: [4]}
```

This pull request implements target-only calls to nx.shortest_path(). As part of it, I added a reverse() operator to NetworkX, and now, algorithms use that operator rather than using the reverse() method on the classes. My guess is that this particular change will be the most controversial. Some comments:

1. Having a reverse() operator is consistent with the other operators that NetworkX provides (union, complement, etc).
2. There does not exist a union (or complement or ...) method on the graph classes. This actually makes it seem that there should not even be a reverse method, but since it has been there since the beginning, removing it is probably not an option.
3. Downstream, classes derived from NetworkX classes can reimplement the reverse() method in a manner which fits their use case. As an example, a reverse method on a DFA class might return the minimal DFA which recognizes its reverse language. If algorithms used G.reverse(), then functions like nx.shortest_path() would not work correctly. Although this same argument could be applied to other graph methods, it seems more likely for the reverse method than for others. Reversing, in principle, can mean many things to different domains, whereas add_node, does not vary as much.

Comments are appreciated.