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
1 change: 1 addition & 0 deletions gap/weights.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ DeclareGlobalFunction("EdgeWeightedDigraph");
DeclareProperty("IsNegativeEdgeWeightedDigraph", IsDigraph and HasEdgeWeights);
DeclareAttribute("EdgeWeightedDigraphTotalWeight",
IsDigraph and HasEdgeWeights);
DeclareAttribute("UnitEdgeWeightedDigraph", IsDigraph);

# 2. Edge Weight Copies
DeclareOperation("EdgeWeightsMutableCopy", [IsDigraph and HasEdgeWeights]);
Expand Down
9 changes: 9 additions & 0 deletions gap/weights.gi
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ InstallMethod(EdgeWeightedDigraphTotalWeight,
[IsDigraph and HasEdgeWeights],
D -> Sum(EdgeWeights(D), Sum));

InstallMethod(UnitEdgeWeightedDigraph,
"for a digraph",
[IsDigraph],
function(D)
local x, unitweights;
unitweights := List(DigraphVertices(D), x -> ListWithIdenticalEntries(OutDegreeOfVertex(D, x), 1));
return(EdgeWeightedDigraph(D, unitweights));
end);

#############################################################################
# 2. Copies of edge weights
#############################################################################
Expand Down
18 changes: 18 additions & 0 deletions tst/testinstall.tst
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,24 @@ gap> AutomorphismGroup(D)
> = Group([(1, 2, 3), (1, 2), (4, 5, 6), (4, 5), (1, 4)(2, 5)(3, 6)]);
true

# UnitEdgeWeightedDigraph
gap> D := UnitEdgeWeightedDigraph(Digraph([[2],[1,3],[1]]));
<immutable edge-weighted digraph with 3 vertices, 4 edges>
gap> EdgeWeights(D);
[ [ 1 ], [ 1, 1 ], [ 1 ] ]
gap> D := UnitEdgeWeightedDigraph(Digraph([[3,4],[1,3,4],[2,4],[1,2,3]]));
<immutable edge-weighted digraph with 4 vertices, 10 edges>
gap> EdgeWeights(D);
[ [ 1, 1 ], [ 1, 1, 1 ], [ 1, 1 ], [ 1, 1, 1 ] ]
gap> D := UnitEdgeWeightedDigraph(EmptyDigraph(4));
<immutable empty edge-weighted digraph with 4 vertices>
gap> EdgeWeights(D);
[ [ ], [ ], [ ], [ ] ]
gap> D := UnitEdgeWeightedDigraph(EdgeWeightedDigraph([[2], []], [[5], []]));
<immutable edge-weighted digraph with 2 vertices, 1 edge>
gap> EdgeWeights(D);
[ [ 1 ], [ ] ]

# SwapDigraphs
gap> C := Digraph(IsMutableDigraph, [[4], [5], [1, 2], [], []]);;
gap> D := Digraph(IsMutableDigraph, [[2, 3, 4], [1, 3, 4, 5], [1, 2], [5], [4]]);;
Expand Down
Loading