Skip to content

Commit

Permalink
Linting and Codespell corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
mtorpey committed May 22, 2024
1 parent 8b126f3 commit 573552e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 83 deletions.
24 changes: 12 additions & 12 deletions doc/weights.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ gap> EdgeWeights(g);

See <Ref Attr="EdgeWeights" Func="EdgeWeightedDigraph"/>.
<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2],[1],[1,2]], [[12],[5],[6,9]]);
gap> g := EdgeWeightedDigraph([[2], [1], [1, 2]], [[12], [5], [6, 9]]);
<immutable digraph with 3 vertices, 4 edges>
gap> DigraphEdgeWeightedMinimumSpanningTree(g);
rec( mst := <immutable digraph with 3 vertices, 2 edges>, total := 11
Expand Down Expand Up @@ -115,14 +115,14 @@ rec( mst := <immutable digraph with 3 vertices, 2 edges>, total := 11

See <Ref Attr="EdgeWeights" Func="EdgeWeightedDigraph"/>.
<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2,3],[4],[4],[]],[[5,1],[6],[11],[]]);
gap> g := EdgeWeightedDigraph([[2, 3], [4], [4], []], [[5, 1], [6], [11], []]);
<immutable digraph with 4 vertices, 4 edges>
gap> DigraphEdgeWeightedShortestPath(g,1);
gap> DigraphEdgeWeightedShortestPath(g, 1);
rec( distances := [ 0, 5, 1, 11 ], edges := [ fail, 1, 2, 1 ],
parents := [ fail, 1, 1, 2 ] )
gap> ncg := EdgeWeightedDigraph([[2],[3],[1]],[[-1],[-2],[-3]]);
gap> ncg := EdgeWeightedDigraph([[2], [3], [1]], [[-1], [-2], [-3]]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphEdgeWeightedShortestPath(ncg,1);
gap> DigraphEdgeWeightedShortestPath(ncg, 1);
Error, negative cycle exists,
]]></Example>
</Description>
Expand All @@ -141,7 +141,7 @@ Error, negative cycle exists,

See <Ref Attr="EdgeWeights" Func="EdgeWeightedDigraph"/>.
<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2],[3],[1]],[[1],[2],[3]]);
gap> g := EdgeWeightedDigraph([[2], [3], [1]], [[1], [2], [3]]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphEdgeWeightedShortestPaths(g);
rec( distances := [ [ 0, 1, 3 ], [ 5, 0, 2 ], [ 3, 4, 0 ] ],
Expand All @@ -159,7 +159,7 @@ rec( distances := [ [ 0, 1, 3 ], [ 5, 0, 2 ], [ 3, 4, 0 ] ],
Given an edge weighted <A>digraph</A>, this returns a record with 3 components.
The first component is the flow inbound into vertex v which is a list of lists.
If there are multiple edges, the algorithm will fill up the edges sequentially so
if there are 3 edges outbound from u to v with capacities, 5,10,15 and there is a flow of 15, it will fill the first two edges 5 and 10.
if there are 3 edges outbound from u to v with capacities, 5, 10, 15 and there is a flow of 15, it will fill the first two edges 5 and 10.
If there is a flow of 9, then the flow will contain a list with flows 5 and 4. <P/>

This can be coupled with the second component which is a list of list of the vertices that each flow comes from. Using this,
Expand All @@ -169,7 +169,7 @@ rec( distances := [ [ 0, 1, 3 ], [ 5, 0, 2 ], [ 3, 4, 0 ] ],

See <Ref Attr="EdgeWeights" Func="EdgeWeightedDigraph"/>.
<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2,2],[3],[]],[[3,2],[1],[]]);
gap> g := EdgeWeightedDigraph([[2, 2], [3], []], [[3, 2], [1], []]);
<immutable multidigraph with 3 vertices, 3 edges>
gap> DigraphMaximumFlow(g, 1, 3);
rec( flows := [ [ ], [ 1, 0 ], [ 1 ] ], maxFlow := 1,
Expand All @@ -180,7 +180,7 @@ rec( flows := [ [ ], [ 1, 0 ], [ 1 ] ], maxFlow := 1,

<#GAPDoc Label="RandomUniqueEdgeWeightedDigraph">
<ManSection>
<Attr Name="RandomUniqueEdgeWeightedDigraph" Arg="[filt, ]n[,p]"/>
<Attr Name="RandomUniqueEdgeWeightedDigraph" Arg="[filt, ]n[, p]"/>
<Returns>An edge weighted digraph.</Returns>
<Description>
&STANDARD_FILT_TEXT;
Expand Down Expand Up @@ -223,7 +223,7 @@ gap> g := RandomUniqueEdgeWeightedDigraph(5, 1);
to all other vertices.

<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2],[3],[]],[[2],[1],[]]);
gap> g := EdgeWeightedDigraph([[2], [3], []], [[2], [1], []]);
<immutable digraph with 3 vertices, 2 edges>
gap> sp := DigraphEdgeWeightedShortestPath(g, 1);
rec( distances := [ 0, 2, 3 ], edges := [ fail, 1, 1 ],
Expand All @@ -245,7 +245,7 @@ gap> sd := DigraphFromPaths(g, sp);
to <A>dest</A> vertex.

<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2],[3],[]],[[2],[1],[]]);
gap> g := EdgeWeightedDigraph([[2], [3], []], [[2], [1], []]);
<immutable digraph with 3 vertices, 2 edges>
gap> sp := DigraphEdgeWeightedShortestPath(g, 1);
rec( distances := [ 0, 2, 3 ], edges := [ fail, 1, 1 ],
Expand Down Expand Up @@ -276,7 +276,7 @@ gap> sd := DigraphFromPath(g, sp, 2);
An empty record may be passed as a parameters, in which case the default values will be used.

<Example><![CDATA[
gap> g := EdgeWeightedDigraph([[2],[3],[]],[[2],[1],[]]);
gap> g := EdgeWeightedDigraph([[2], [3], []], [[2], [1], []]);
<immutable digraph with 3 vertices, 2 edges>
gap> sp := DigraphEdgeWeightedShortestPath(g, 1);
rec( distances := [ 0, 2, 3 ], edges := [ fail, 1, 1 ],
Expand Down
5 changes: 2 additions & 3 deletions gap/digraph.gi
Original file line number Diff line number Diff line change
Expand Up @@ -1372,9 +1372,8 @@ InstallMethod(RandomDigraphCons, "for IsConnectedDigraph and an integer",
InstallMethod(RandomDigraphCons,
"for IsStronglyConnectedDigraph, an integer, and a rational",
[IsStronglyConnectedDigraph, IsInt],
function(filt, n)
return RandomDigraphCons(IsStronglyConnectedDigraph, n, Float(Random([0 .. n])) / n);
end);
{_, n} ->
RandomDigraphCons(IsStronglyConnectedDigraph, n, Float(Random([0 .. n])) / n));

InstallMethod(RandomDigraphCons, "for IsAcyclicDigraph and an integer",
[IsAcyclicDigraph, IsInt],
Expand Down
3 changes: 2 additions & 1 deletion gap/display.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

DeclareAttribute("DotDigraph", IsDigraph);
DeclareOperation("DotColoredDigraph", [IsDigraph, IsList, IsList]);
DeclareOperation("DotColoredEdgeWeightedDigraph", [IsDigraph, IsList, IsList, IsList]);
DeclareOperation("DotColoredEdgeWeightedDigraph",
[IsDigraph, IsList, IsList, IsList]);
DeclareOperation("DotVertexColoredDigraph", [IsDigraph, IsList]);
DeclareOperation("DotEdgeColoredDigraph", [IsDigraph, IsList]);
DeclareOperation("DotVertexLabelledDigraph", [IsDigraph]);
Expand Down
9 changes: 6 additions & 3 deletions gap/display.gi
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,17 @@ function(D, vert, edge)
fi;
end);

# https://graphs.grevian.org/example
InstallMethod(DotColoredEdgeWeightedDigraph, "for a digraph by out-neighbours and three lists",
InstallMethod(DotColoredEdgeWeightedDigraph,
"for a digraph by out-neighbours and three lists",
[IsDigraphByOutNeighboursRep, IsList, IsList, IsList],
function(D, vert, edge, weight)
# https://graphs.grevian.org/example
local vert_func, edge_func;
if DIGRAPHS_ValidVertColors(D, vert) and DIGRAPHS_ValidEdgeColors(D, edge) then
vert_func := i -> StringFormatted("[color={}, style=filled]", vert[i]);
edge_func := {i, j} -> StringFormatted("[color={}, label={}]", edge[i][j], weight[i][j]);
edge_func := {i, j} -> StringFormatted("[color={}, label={}]",
edge[i][j],
weight[i][j]);
return DIGRAPHS_DotDigraph(D, [vert_func], [edge_func]);
fi;
end);
Expand Down
20 changes: 13 additions & 7 deletions gap/weights.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,28 @@ DeclareProperty("IsNegativeEdgeWeightedDigraph", IsDigraph and HasEdgeWeights);
DeclareOperation("EdgeWeightsMutableCopy", [IsDigraph and HasEdgeWeights]);

# 3. Minimum Spanning Trees
DeclareAttribute("DigraphEdgeWeightedMinimumSpanningTree", IsDigraph and HasEdgeWeights);
DeclareAttribute("DigraphEdgeWeightedMinimumSpanningTree",
IsDigraph and HasEdgeWeights);

# 4. Shortest Path
DeclareOperation("DigraphEdgeWeightedShortestPath", [IsDigraph and HasEdgeWeights, IsPosInt]);
DeclareAttribute("DigraphEdgeWeightedShortestPaths", IsDigraph and HasEdgeWeights);
DeclareOperation("DigraphEdgeWeightedShortestPath",
[IsDigraph and HasEdgeWeights, IsPosInt]);
DeclareAttribute("DigraphEdgeWeightedShortestPaths",
IsDigraph and HasEdgeWeights);

# 5. Maximum Flow
DeclareOperation("DigraphMaximumFlow", [IsDigraph and HasEdgeWeights, IsPosInt, IsPosInt]);
DeclareOperation("DigraphMaximumFlow",
[IsDigraph and HasEdgeWeights, IsPosInt, IsPosInt]);
DeclareAttribute("DigraphMinimumCuts", IsDigraph);

# 6. Random Edge Weighted Digraph
DeclareOperation("RandomUniqueEdgeWeightedDigraph",[IsPosInt]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph", [IsPosInt]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph", [IsPosInt, IsFloat]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph", [IsPosInt, IsRat]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph", [IsFunction, IsPosInt, IsFloat]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph", [IsFunction, IsPosInt, IsRat]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph",
[IsFunction, IsPosInt, IsFloat]);
DeclareOperation("RandomUniqueEdgeWeightedDigraph",
[IsFunction, IsPosInt, IsRat]);

# 7. Painting Edge Weighted Digraph
DeclareOperation("DigraphFromPaths", [IsDigraph, IsRecord]);
Expand Down
35 changes: 14 additions & 21 deletions gap/weights.gi
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ function(digraph)

weights := EdgeWeights(digraph);

# create a list of edges containining u-v
# create a list of edges containing u-v
# w: the weight of the edge
# u: the start vertex
# v: the finishing vertex of that edge
Expand Down Expand Up @@ -214,7 +214,7 @@ DIGRAPHS_Edge_Weighted_Dijkstra := function(digraph, source)
digraphVertices := DigraphVertices(digraph);
nrVertices := Size(digraphVertices);

# Create an adjacancy map for the edges with their associated weight
# Create an adjacency map for the edges with their associated weight
adj := HashMap();
for u in digraphVertices do
adj[u] := HashMap();
Expand Down Expand Up @@ -415,7 +415,7 @@ DIGRAPHS_Edge_Weighted_FloydWarshall := function(digraph)
nrVertices := Size(digraphVertices);
outs := OutNeighbors(digraph);

# Create adjacancy matrix
# Create adjacency matrix
adjMatrix := EmptyPlist(nrVertices);
parents := EmptyPlist(nrVertices);
edges := EmptyPlist(nrVertices);
Expand Down Expand Up @@ -873,40 +873,32 @@ end;

InstallMethod(RandomUniqueEdgeWeightedDigraph,
"for a pos int", [IsPosInt],
function(n)
return DIGRAPHS_Random_Edge_Weighted_Digraph_N(n);
end);
DIGRAPHS_Random_Edge_Weighted_Digraph_N);

InstallMethod(RandomUniqueEdgeWeightedDigraph,
"for a pos int and a float", [IsPosInt, IsFloat],
function(n, p)
return DIGRAPHS_Random_Edge_Weighted_Digraph_N_P(n, p);
end);
{n, p} -> DIGRAPHS_Random_Edge_Weighted_Digraph_N_P(n, p));

InstallMethod(RandomUniqueEdgeWeightedDigraph,
"for a pos int and a rational", [IsPosInt, IsRat],
function(n, p)
return DIGRAPHS_Random_Edge_Weighted_Digraph_N_P(n, p);
end);
{n, p} -> DIGRAPHS_Random_Edge_Weighted_Digraph_N_P(n, p));

InstallMethod(RandomUniqueEdgeWeightedDigraph,
"for a func, a pos int, and a float", [IsFunction, IsPosInt, IsFloat],
function(filt, n, p)
return DIGRAPHS_Random_Edge_Weighted_Digraph_Filt_N_P(filt, n, p);
end);
{filt, n, p} -> DIGRAPHS_Random_Edge_Weighted_Digraph_Filt_N_P(filt, n, p));

InstallMethod(RandomUniqueEdgeWeightedDigraph,
"for a func, a pos int, and a rational", [IsFunction, IsPosInt, IsRat],
function(filt, n, p)
return DIGRAPHS_Random_Edge_Weighted_Digraph_Filt_N_P(filt, n, p);
end);
{filt, n, p} -> DIGRAPHS_Random_Edge_Weighted_Digraph_Filt_N_P(filt, n, p));

#############################################################################
# 7. Painting Edge Weighted Digraph
#############################################################################
InstallMethod(DigraphFromPath, "for a digraph, a record, and a pos int",
[IsDigraph, IsRecord, IsPosInt],
function(digraph, record, destination)
function(_, record, destination)
# TODO: digraph is not used, which is surprising and may suggest
# confusion in design. We should work this out.
local idx, distances, edges, p, parents,
nrVertices, outNeighbours, vertex;

Expand All @@ -923,7 +915,7 @@ function(digraph, record, destination)
od;

vertex := destination;
# while vertex isnt the start vertex
# while vertex isn't the start vertex
while parents[vertex] <> fail do
p := parents[vertex]; # parent of vertex is p

Expand All @@ -936,7 +928,8 @@ end);

InstallMethod(DigraphFromPaths,
"for a digraph, and a record", [IsDigraph, IsRecord],
function(digraph, record)
function(_, record)
# TODO: digraph is not used - see DigraphFromPath
local idx, distances, edges, parents, nrVertices, outNeighbours,
u, v;

Expand Down
Loading

0 comments on commit 573552e

Please sign in to comment.