Skip to content

Renamed DigraphDijkstra to DigraphShortestPaths #730

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2026,14 +2026,14 @@ true
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphDijkstra">
<#GAPDoc Label="DigraphShortestPaths">
<ManSection>
<Oper Name="DigraphDijkstra" Arg="digraph, source, target" Label="for a source and target"/>
<Oper Name="DigraphDijkstra" Arg="digraph, source" Label="for a source"/>
<Oper Name="DigraphShortestPaths" Arg="digraph, source, target" Label="for a source and target"/>
<Oper Name="DigraphShortestPaths" Arg="digraph, source" Label="for a source"/>
<Returns>Two lists.</Returns>
<Description>
If <A>digraph</A> is a digraph and <A>source</A> and <A>target</A> are
vertices of <A>digraph</A>, then <C>DigraphDijkstra</C> calculates the
vertices of <A>digraph</A>, then <C>DigraphShortestPaths</C> calculates the
length of the shortest path from <A>source</A> to <A>target</A> and returns
two lists. Each element of the first list is the distance of the
corresponding element from <A>source</A>. If a vertex was not visited in
Expand All @@ -2046,19 +2046,19 @@ true
will be <C>-1</C>.<P/>

If the optional second argument <A>target</A> is not present, then
<C>DigraphDijkstra</C> returns the shortest path from <A>source</A> to
<C>DigraphShortestPaths</C> returns the shortest path from <A>source</A> to
every vertex that is reachable from <A>source</A>.

<Example><![CDATA[
gap> mat := [[0, 1, 1], [0, 0, 1], [0, 0, 0]];
[ [ 0, 1, 1 ], [ 0, 0, 1 ], [ 0, 0, 0 ] ]
gap> D := DigraphByAdjacencyMatrix(mat);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphDijkstra(D, 2, 3);
gap> DigraphShortestPaths(D, 2, 3);
[ [ infinity, 0, 1 ], [ -1, -1, 2 ] ]
gap> DigraphDijkstra(D, 1, 3);
gap> DigraphShortestPaths(D, 1, 3);
[ [ 0, 1, 1 ], [ -1, 1, 1 ] ]
gap> DigraphDijkstra(D, 1, 2);
gap> DigraphShortestPaths(D, 1, 2);
[ [ 0, 1, 1 ], [ -1, 1, 1 ] ]
]]></Example>
</Description>
Expand Down
2 changes: 1 addition & 1 deletion doc/z-chap4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<#Include Label="DigraphDegeneracyOrdering">
<#Include Label="HamiltonianPath">
<#Include Label="NrSpanningTrees">
<#Include Label="DigraphDijkstra">
<#Include Label="DigraphShortestPaths">
<#Include Label="DigraphCycleBasis">
</Section>

Expand Down
5 changes: 3 additions & 2 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,11 @@ DeclareOperation("IsDigraphPath", [IsDigraph, IsList]);
# 9. Connectivity . . .
DeclareOperation("DigraphFloydWarshall",
[IsDigraph, IsFunction, IsObject, IsObject]);
DeclareOperation("DigraphDijkstra",
DeclareOperation("DigraphShortestPaths",
[IsDigraph, IsPosInt]);
DeclareOperation("DigraphDijkstra",
DeclareOperation("DigraphShortestPaths",
[IsDigraph, IsPosInt, IsPosInt]);
DeclareSynonym("DigraphDijkstra", DigraphShortestPaths);

DeclareOperation("DigraphConnectedComponent", [IsDigraph, IsPosInt]);
DeclareOperation("DigraphStronglyConnectedComponent", [IsDigraph, IsPosInt]);
Expand Down
6 changes: 3 additions & 3 deletions gap/oper.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ function(digraph, source, target)
while not IsEmpty(queue) do
u := Pop(queue);
u := u[2];
# TODO: this has a small performance impact for DigraphDijkstraS,
# TODO: this has a small performance impact for DigraphShortestPathsS,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be a typo that you've preserved with find-and-replace!

# but do we care?
if u = target then
return [dist, prev];
Expand All @@ -1797,10 +1797,10 @@ function(digraph, source, target)
return [dist, prev];
end);

InstallMethod(DigraphDijkstra, "for a digraph, a vertex, and a vertex",
InstallMethod(DigraphShortestPaths, "for a digraph, a vertex, and a vertex",
[IsDigraph, IsPosInt, IsPosInt], DIGRAPHS_DijkstraST);

InstallMethod(DigraphDijkstra, "for a digraph, and a vertex",
InstallMethod(DigraphShortestPaths, "for a digraph, and a vertex",
[IsDigraph, IsPosInt],
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail));

Expand Down
16 changes: 8 additions & 8 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2258,18 +2258,18 @@ gap> OutNeighbours(C);
[ [ 5, 6, 7 ], [ 7 ], [ 7 ], [ 7 ], [ 1, 6, 7 ], [ 1, 5, 7 ],
[ 3, 2, 1, 6, 5, 4 ] ]

# DigraphDijkstra - when there is one path to target
# DigraphShortestPaths - when there is one path to target
gap> mat := [[0, 1, 1], [0, 0, 1], [0, 0, 0]];
[ [ 0, 1, 1 ], [ 0, 0, 1 ], [ 0, 0, 0 ] ]
gap> gr := DigraphByAdjacencyMatrix(mat);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphShortestDistance(gr, 2, 3);
1
gap> DigraphDijkstra(gr, 2, 3);
gap> DigraphShortestPaths(gr, 2, 3);
[ [ infinity, 0, 1 ], [ -1, -1, 2 ] ]
gap> DigraphDijkstra(gr, 1, 3);
gap> DigraphShortestPaths(gr, 1, 3);
[ [ 0, 1, 1 ], [ -1, 1, 1 ] ]
gap> DigraphDijkstra(gr, 1, 2);
gap> DigraphShortestPaths(gr, 1, 2);
[ [ 0, 1, 1 ], [ -1, 1, 1 ] ]
gap> DigraphShortestDistance(gr, 1, 3);
1
Expand All @@ -2281,21 +2281,21 @@ gap> gr := DigraphByAdjacencyMatrix(mat);
<immutable digraph with 3 vertices, 2 edges>
gap> DigraphShortestDistance(gr, 2, 3);
fail
gap> DigraphDijkstra(gr, 2, 3);
gap> DigraphShortestPaths(gr, 2, 3);
[ [ infinity, 0, infinity ], [ -1, -1, -1 ] ]
gap> mat := [[0, 1, 1, 1], [0, 0, 1, 1], [0, 1, 0, 0], [1, 0, 0, 0]];
[ [ 0, 1, 1, 1 ], [ 0, 0, 1, 1 ], [ 0, 1, 0, 0 ], [ 1, 0, 0, 0 ] ]
gap> gr := DigraphByAdjacencyMatrix(mat);
<immutable digraph with 4 vertices, 7 edges>
gap> DigraphDijkstra(gr, 1, 4);
gap> DigraphShortestPaths(gr, 1, 4);
[ [ 0, 1, 1, 1 ], [ -1, 1, 1, 1 ] ]
gap> mat := [[0, 1, 1, 1], [0, 0, 1, 1], [0, 1, 0, 0], [1, 0, 0, 0]];
[ [ 0, 1, 1, 1 ], [ 0, 0, 1, 1 ], [ 0, 1, 0, 0 ], [ 1, 0, 0, 0 ] ]
gap> gr := DigraphByAdjacencyMatrix(mat);
<immutable digraph with 4 vertices, 7 edges>
gap> DigraphDijkstra(gr, 1, 2);
gap> DigraphShortestPaths(gr, 1, 2);
[ [ 0, 1, 1, 1 ], [ -1, 1, 1, 1 ] ]
gap> DigraphDijkstra(gr, 1, 3);
gap> DigraphShortestPaths(gr, 1, 3);
[ [ 0, 1, 1, 1 ], [ -1, 1, 1, 1 ] ]

# ModularProduct
Expand Down
Loading