-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Dijkstra version for digraph with edges weights #319
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1365,6 +1365,37 @@ InstallMethod(DigraphDijkstra, "for a digraph, and a vertex", | |
[IsDigraph, IsPosInt], | ||
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail)); | ||
|
||
InstallMethod(DigraphDijkstraSTWeights, "for a digraph, a vertex, a vertex, and a list of weights", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest using your new version
if a list of weights is given, and if no list of weights is given then we could do:
|
||
[IsDigraph, IsPosInt, IsPosInt, IsList], | ||
function(digraph, source, target, weights) | ||
local dist, prev, queue, u, v, alt; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check that the |
||
|
||
dist := []; | ||
prev := []; | ||
queue := BinaryHeap({x, y} -> x[1] < y[1]); | ||
|
||
for v in DigraphVertices(digraph) do | ||
dist[v] := infinity; | ||
prev[v] := -1; | ||
od; | ||
|
||
dist[source] := 0; | ||
Push(queue, [0, source]); | ||
|
||
while not IsEmpty(queue) do | ||
u := Pop(queue); | ||
u := u[2]; | ||
for v in OutNeighbours(digraph)[u] do | ||
alt := dist[u] + weights[u][v]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would become |
||
if alt < dist[v] then | ||
dist[v] := alt; prev[v] := u; | ||
Push(queue, [dist[v], v]); | ||
fi; | ||
od; | ||
od; | ||
return [dist, prev]; | ||
end); | ||
|
||
InstallMethod(IteratorOfPaths, | ||
"for a digraph by out-neighbours and two pos ints", | ||
[IsDigraphByOutNeighboursRep, IsPosInt, IsPosInt], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would become