From 56626303096bcfb0dc66949680a5cbbf49457bf5 Mon Sep 17 00:00:00 2001 From: Devansh Chopra Date: Wed, 12 Feb 2025 15:32:41 +0000 Subject: [PATCH] Renamed DigraphDijkstra to DigraphShortestPaths and all tests pass. --- doc/oper.xml | 16 ++++++++-------- doc/z-chap4.xml | 2 +- gap/oper.gd | 4 ++-- gap/oper.gi | 6 +++--- tst/standard/oper.tst | 16 ++++++++-------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/doc/oper.xml b/doc/oper.xml index 8c55db1ac..d9aeb73ef 100644 --- a/doc/oper.xml +++ b/doc/oper.xml @@ -2026,14 +2026,14 @@ true <#/GAPDoc> -<#GAPDoc Label="DigraphDijkstra"> +<#GAPDoc Label="DigraphShortestPaths"> - - + + Two lists. If digraph is a digraph and source and target are - vertices of digraph, then DigraphDijkstra calculates the + vertices of digraph, then DigraphShortestPaths calculates the length of the shortest path from source to target and returns two lists. Each element of the first list is the distance of the corresponding element from source. If a vertex was not visited in @@ -2046,7 +2046,7 @@ true will be -1.

If the optional second argument target is not present, then - DigraphDijkstra returns the shortest path from source to + DigraphShortestPaths returns the shortest path from source to every vertex that is reachable from source. mat := [[0, 1, 1], [0, 0, 1], [0, 0, 0]]; [ [ 0, 1, 1 ], [ 0, 0, 1 ], [ 0, 0, 0 ] ] gap> D := DigraphByAdjacencyMatrix(mat); -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 ] ] ]]> diff --git a/doc/z-chap4.xml b/doc/z-chap4.xml index d0c764ab1..20e98a6db 100644 --- a/doc/z-chap4.xml +++ b/doc/z-chap4.xml @@ -86,7 +86,7 @@ <#Include Label="DigraphDegeneracyOrdering"> <#Include Label="HamiltonianPath"> <#Include Label="NrSpanningTrees"> - <#Include Label="DigraphDijkstra"> + <#Include Label="DigraphShortestPaths"> <#Include Label="DigraphCycleBasis"> diff --git a/gap/oper.gd b/gap/oper.gd index 5c9f6878a..c6685d4fa 100644 --- a/gap/oper.gd +++ b/gap/oper.gd @@ -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]); diff --git a/gap/oper.gi b/gap/oper.gi index 60e47745b..ed1d8c7ca 100644 --- a/gap/oper.gi +++ b/gap/oper.gi @@ -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]; @@ -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)); diff --git a/tst/standard/oper.tst b/tst/standard/oper.tst index 782bdd79f..bdc93ebb5 100644 --- a/tst/standard/oper.tst +++ b/tst/standard/oper.tst @@ -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); 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 @@ -2281,21 +2281,21 @@ gap> gr := DigraphByAdjacencyMatrix(mat); 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); -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); -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