Skip to content
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
36 changes: 25 additions & 11 deletions doc/oper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2247,15 +2247,15 @@ false]]></Example>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphDijkstra">
<#GAPDoc Label="DigraphShortestPaths">
<ManSection>
<Oper Name="DigraphDijkstra" Arg="digraph, source, target"
<Oper Name="DigraphShortestPaths" 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" 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 @@ -2265,28 +2265,42 @@ false]]></Example>
second list gives the previous vertex in the shortest path
from <A>source</A> to the corresponding vertex. For
<A>source</A> and for any vertices that remained unvisited this
will be <C>-1</C>.<P/>
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
every vertex that is reachable from <A>source</A>.
If the optional second argument <A>target</A> is not present, then
<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>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="DigraphDijkstra">
<ManSection>
<Oper Name="DigraphDijkstra" Arg="digraph, source, target"
Label="for a source and target"/>
<Oper Name="DigraphDijkstra" Arg="digraph, source" Label="for a source"/>
<Returns>Two lists.</Returns>
<Description>
This is an obsolete synonym for
<Ref Oper="DigraphShortestPaths" Label="for a source"/> and will
be removed in a future version.
</Description>
</ManSection>
<#/GAPDoc>

<#GAPDoc Label="ModularProduct">
<ManSection>
<Oper Name="ModularProduct" Arg="D1, D2"/>
Expand Down
1 change: 1 addition & 0 deletions doc/z-chap4.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<#Include Label="DigraphDegeneracyOrdering">
<#Include Label="HamiltonianPath">
<#Include Label="NrSpanningTrees">
<#Include Label="DigraphShortestPaths">
<#Include Label="DigraphDijkstra">
<#Include Label="DigraphVertexConnectivity">
<#Include Label="DigraphEdgeConnectivity">
Expand Down
4 changes: 3 additions & 1 deletion gap/obsolete.gi
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ function(oldname, func)
Info(InfoWarning, 1, "use \"", NameFunction(func), "\" instead");
return CallFuncList(func, arg);
end);
end);
end);

DIGRAPHS_DeclareObsoleteSynonym("DigraphDijkstra", DigraphShortestPaths);
4 changes: 2 additions & 2 deletions gap/oper.gd
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ DeclareOperation("DigraphKings", [IsDigraph, IsPosInt]);

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 @@ -1900,7 +1900,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 DigraphShortestPaths,
# but do we care?
if u = target then
return [dist, prev];
Expand All @@ -1917,10 +1917,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
29 changes: 21 additions & 8 deletions tst/standard/oper.tst
Original file line number Diff line number Diff line change
Expand Up @@ -2351,18 +2351,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 @@ -2374,23 +2374,36 @@ 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 ] ]

# DigraphShortestPaths - called by obsolete synonym DigraphDijkstra
gap> L := InfoLevel(InfoWarning);;
gap> SetInfoLevel(InfoWarning, 1);;
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> DigraphDijkstra(gr, 2, 3) = DigraphShortestPaths(gr, 2, 3);
#I "DigraphDijkstra" is obsolete and will be removed in a future version;
#I use "DigraphShortestPaths" instead
true
gap> SetInfoLevel(InfoWarning, L);;

# ModularProduct
gap> ModularProduct(NullDigraph(0), CompleteDigraph(10));
<immutable empty digraph with 0 vertices>
Expand Down
Loading