title: Networkx shortest path with condition on edges - python
body: <p>Let's consider the following <code>Graph</code>:</p>
  
  <pre class="lang-py prettyprint-override"><code>G = nx.Graph()
  G.add_nodes_from(['A', 'B', 'C', 'D', 'E', 'F'])
  G.add_edges_from([('A', 'B', {'walk': 3, 'time': 3}), ('A', 'C', {'metro': 4, 'time': 4}), ('A', 'D', {'walk': 3, 'time': 3}), 
                    ('C', 'E', {'walk': 3, 'time': 3}), ('D', 'E', {'walk': 3, 'time': 3}), ('B', 'F', {'walk': 3, 'time': 3}), 
                    ('D', 'F', {'metro': 4, 'time': 4}), ('E', 'F', {'walk': 3, 'time': 3})])
  nx.draw(G, with_labels=True, font_color='white')
  </code></pre>
  
  <p>Three attributes can be seen for edges:</p>
  
  <ul>
  <li><code>walk</code> is the time taken to walk for one stop to the other (when it is possible).</li>
  <li><code>metro</code> is the time taken to go from a stop to the other by taking the subway.</li>
  <li><code>time</code> is equal to <code>walk</code> or <code>metro</code> and is the weight I use for <code>nx.shortest_path</code> (that allows my to get the path that takes the less time by not having to either chose between subway or walking).</li>
  </ul>
  
  <p>I now would like to get the <code>nx.shortest_path(G, 'A', 'F', weight='time')</code> between nodes <code>A</code> and <code>F</code> with a condition on the path: I want to have the <code>shortest_path</code> with the less <code>walk</code> edges as possible.</p>
  
  <p>In this case, the only <code>shortest_path</code> considered as good would be <code>A -&gt; D -&gt; F</code> since there is only 1 <code>walk</code> edge while the others have at least two (even though the total <code>time</code> for some edges are shorter).</p>
  
  <p>Is there a way to do that?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> I tried using <code>nx.all_shortest_paths()</code> to get several <code>shortest_paths</code> and then select the one that fits my requirements but it does not work. <code>nx.all_shortest_paths()</code> indeed gives me a higher amount of short paths possible between a <code>source</code> and a <code>target</code> however all of them already have too many <code>walk edges</code> in them.
  A solution would be to get what are considered to be the <code>shortest of shortest paths</code> and the one that are less short to maybe have more choice.
  I, however, have no ideas how I should be going about this.</p>