Skip to content

Commit

Permalink
Renamed DigraphDijkstra to DigraphShortestPaths and all tests pass.
Browse files Browse the repository at this point in the history
  • Loading branch information
Devansh Chopra committed Feb 12, 2025
1 parent 10c4ed9 commit 5662630
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
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
4 changes: 2 additions & 2 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ 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]);

DeclareOperation("DigraphConnectedComponent", [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,
# 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

0 comments on commit 5662630

Please sign in to comment.