Skip to content

Allows weight functions in shortest path functions - #1690

Merged
dschult merged 1 commit into
networkx:masterfrom
jfinkels:shortest-path-weight-function
Feb 2, 2016
Merged

dschult merged 1 commit into
networkx:masterfrom
jfinkels:shortest-path-weight-function

Conversation

@jfinkels

Copy link
Copy Markdown
Contributor

This commit allows the user to provide an arbitrary function that
computes the weight of an edge instead of relying on an edge attribute.

This is a backwards-compatible change.

If this pull request is merged, then pull request #1555 should be updated in the manner described there.

This commit allows the user to provide an arbitrary function that
computes the weight of an edge instead of relying on an edge attribute.
@jfinkels
jfinkels force-pushed the shortest-path-weight-function branch from 996f38d to ee5421d Compare January 15, 2016 22:09
@hagberg hagberg modified the milestones: networkx-2.0, networkx-future Feb 2, 2016
@hagberg

hagberg commented Feb 2, 2016

Copy link
Copy Markdown
Member

This seems OK to me. It touches a few files so would someone else please review and verify?

@dschult

dschult commented Feb 2, 2016

Copy link
Copy Markdown
Member

This caught a bug and provides a feature not advertised--but perhaps worth expanding.

  • Squashed an unfound bug at line 729 for a multigraph self-loop where previous .get(weight,1) didn't check for multi-edges.
  • Enables screen of edges (essentially edge-subgraph for traversal) if the supplied weight function returns None for edges that are not allowed. Thus by using _dijkstra with the following provides the shortest_path using only "blue" edges. (see Feature request: edge coloring, and color-specific paths and iterators #1946)
    def weight(u, v, edata):
        return 1 if edata['color'] == "blue" else None

I'm going to merge this and separately commit the few small changes for this file I noticed on the way. Take up discussion of expanding this idea for edge restriction at #1946

dschult added a commit that referenced this pull request Feb 2, 2016
Allows weight functions in shortest path functions
@dschult
dschult merged commit 7ea24e3 into networkx:master Feb 2, 2016
dschult added a commit to dschult/networkx that referenced this pull request Feb 2, 2016
Fixed up some docs and whitespace noticed while reviewing networkx#1690.
One content change to get cost of uv-edge once in _dijkstra.
dschult added a commit to dschult/networkx that referenced this pull request Feb 2, 2016
Fixed up some docs and whitespace noticed while reviewing networkx#1690.
One content change to get cost of uv-edge once in _dijkstra.
@borisdan

Copy link
Copy Markdown

Thanks!
However, it doesn't work on dijkstra_path_length - the weight function is ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants