Skip to content

Commit 1f56fb0

Browse files
coraakedmtorpey
andauthored
Add UnitEdgeWeightedDigraph (#886)
* Add unitedgeweight digraph * Add 'edge-weighted' output to tests * gaplint checks implemented * fix trailing whitespace at line:86 * Make UnitEdgeWeightedDigraph more concise --------- Co-authored-by: Michael Young <mct25@st-andrews.ac.uk>
1 parent b8adb8a commit 1f56fb0

3 files changed

Lines changed: 24 additions & 0 deletions

File tree

gap/weights.gd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ DeclareGlobalFunction("EdgeWeightedDigraph");
1414
DeclareProperty("IsNegativeEdgeWeightedDigraph", IsDigraph and HasEdgeWeights);
1515
DeclareAttribute("EdgeWeightedDigraphTotalWeight",
1616
IsDigraph and HasEdgeWeights);
17+
DeclareAttribute("UnitEdgeWeightedDigraph", IsDigraph);
1718

1819
# 2. Edge Weight Copies
1920
DeclareOperation("EdgeWeightsMutableCopy", [IsDigraph and HasEdgeWeights]);

gap/weights.gi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ InstallMethod(EdgeWeightedDigraphTotalWeight,
7979
[IsDigraph and HasEdgeWeights],
8080
D -> Sum(EdgeWeights(D), Sum));
8181

82+
InstallMethod(UnitEdgeWeightedDigraph, "for a digraph",
83+
[IsDigraph],
84+
D -> EdgeWeightedDigraph(D, List(OutNeighbours(D),
85+
l -> ListWithIdenticalEntries(Length(l), 1))));
86+
8287
#############################################################################
8388
# 2. Copies of edge weights
8489
#############################################################################

tst/testinstall.tst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ gap> AutomorphismGroup(D)
541541
> = Group([(1, 2, 3), (1, 2), (4, 5, 6), (4, 5), (1, 4)(2, 5)(3, 6)]);
542542
true
543543

544+
# UnitEdgeWeightedDigraph
545+
gap> D := UnitEdgeWeightedDigraph(Digraph([[2], [1, 3], [1]]));
546+
<immutable edge-weighted digraph with 3 vertices, 4 edges>
547+
gap> EdgeWeights(D);
548+
[ [ 1 ], [ 1, 1 ], [ 1 ] ]
549+
gap> D := UnitEdgeWeightedDigraph(Digraph([[3, 4], [1, 3, 4], [2, 4], [1, 2, 3]]));
550+
<immutable edge-weighted digraph with 4 vertices, 10 edges>
551+
gap> EdgeWeights(D);
552+
[ [ 1, 1 ], [ 1, 1, 1 ], [ 1, 1 ], [ 1, 1, 1 ] ]
553+
gap> D := UnitEdgeWeightedDigraph(EmptyDigraph(4));
554+
<immutable empty edge-weighted digraph with 4 vertices>
555+
gap> EdgeWeights(D);
556+
[ [ ], [ ], [ ], [ ] ]
557+
gap> D := UnitEdgeWeightedDigraph(EdgeWeightedDigraph([[2], []], [[5], []]));
558+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
559+
gap> EdgeWeights(D);
560+
[ [ 1 ], [ ] ]
561+
544562
# SwapDigraphs
545563
gap> C := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);;
546564
gap> D := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);;

0 commit comments

Comments
 (0)