-
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
Conversation
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using your new version DigraphDijkstraSTWeights
as the code of DIGRAPHS_DijkstraST
, with one change: the argument weights
could be a function like:
weights := function(u, v)
return list_of_weights[u][v];
end;
if a list of weights is given, and if no list of weights is given then we could do:
weights := function(u, v)
return 1;
end;
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 comment
The reason will be displayed to describe this comment to others. Learn more.
would become weights(u, v)
instead of weights[u][v]
@@ -1365,6 +1365,37 @@ InstallMethod(DigraphDijkstra, "for a digraph, and a vertex", | |||
[IsDigraph, IsPosInt], | |||
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail)); |
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.
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail))
would become
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail, {u, v} -> 1))
InstallMethod(DigraphDijkstraSTWeights, "for a digraph, a vertex, a vertex, and a list of weights", | ||
[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 comment
The reason will be displayed to describe this comment to others. Learn more.
Check that the weights
have the same "shape" as OutNeighbours(digraph)
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.
Please update as discussed.
No description provided.