This repository has been archived by the owner on Oct 21, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from garborg/master
Update syntax for Julia 0.4, clean up whitespace
- Loading branch information
Showing
34 changed files
with
194 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,4 +159,3 @@ function topological_sort_by_dfs{V}(graph::AbstractGraph{V}) | |
|
||
reverse(visitor.vertices) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,71 @@ | ||
# Floyd Warshall algorithm to find shortest paths between all pairs of vertices | ||
|
||
|
||
function floyd_warshall!{W}(dists::AbstractMatrix{W}) # dists: minimum distance matrix (initialized to edge distances) | ||
function floyd_warshall!{W}(dists::AbstractMatrix{W}) # dists: minimum distance matrix (initialized to edge distances) | ||
|
||
# argument checking | ||
|
||
n = size(dists, 1) | ||
if size(dists, 2) != n | ||
throw(ArgumentError("dists should be a square matrix.")) | ||
end | ||
|
||
# initialize | ||
|
||
for i = 1 : n | ||
dists[i,i] = 0 | ||
end | ||
|
||
# main loop | ||
|
||
for k = 1 : n, i = 1 : n, j = 1 : n | ||
d = dists[i,k] + dists[k,j] | ||
if d < dists[i,j] | ||
dists[i,j] = d | ||
end | ||
end | ||
dists | ||
end | ||
end | ||
|
||
dists | ||
end | ||
|
||
|
||
function floyd_warshall!{W}( | ||
dists::AbstractMatrix{W}, # minimum distance matrix (initialized to edge distances) | ||
dists::AbstractMatrix{W}, # minimum distance matrix (initialized to edge distances) | ||
nexts::AbstractMatrix{Int}) # nexts(i,j) = the next hop from i when traveling from i to j via shortest path | ||
|
||
# argument checking | ||
|
||
n = size(dists, 1) | ||
if size(dists, 2) != n | ||
throw(ArgumentError("dists should be a square matrix.")) | ||
end | ||
|
||
if size(nexts) != (n, n) | ||
throw(ArgumentError("nexts should be an n-by-n matrix.")) | ||
end | ||
|
||
# initialize | ||
|
||
for i = 1 : n | ||
dists[i,i] = 0 | ||
end | ||
|
||
for j = 1 : n, i = 1 : n | ||
nexts[i,j] = isfinite(dists[i,j]) ? j : 0 | ||
end | ||
|
||
# main loop | ||
|
||
for k = 1 : n, i = 1 : n, j = 1 : n | ||
d = dists[i,k] + dists[k,j] | ||
if d < dists[i,j] | ||
dists[i,j] = d | ||
nexts[i,j] = nexts[i,k] | ||
end | ||
end | ||
dists | ||
end | ||
end | ||
|
||
dists | ||
end | ||
|
||
|
||
floyd_warshall(weights::AbstractMatrix) = floyd_warshall!(copy(weights)) | ||
|
Oops, something went wrong.