Skip to content

Commit 814cd1a

Browse files
authored
Update ViewString for edge weights (#873)
* Added section to ViewString for edge weights * Fixed a quick typo in the edit I made * Added ViewString edits to testing * Updated edge-weighted section in testinstall * Some fixes on empty digraphs * Further updates to testing on weights.xml * Change of code location to avoid nesting issues * Some more fixes for the empty case * Changing order that attributes appear in testing * Fixed trailing whitespace issue
1 parent 2330871 commit 814cd1a

File tree

4 files changed

+61
-58
lines changed

4 files changed

+61
-58
lines changed

doc/weights.xml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
using <C>SetEdgeWeights</C> or <Ref Func="EdgeWeightedDigraph" />.<P/>
2828
<Example><![CDATA[
2929
gap> gr := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [15]]);
30-
<immutable digraph with 3 vertices, 3 edges>
30+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
3131
gap> EdgeWeights(gr);
3232
[ [ 5 ], [ 10 ], [ 15 ] ]
3333
gap> a := EdgeWeightsMutableCopy(gr);
@@ -60,9 +60,9 @@ Error, List Assignment: <list> must be a mutable list
6060
See <Ref Attr="EdgeWeights"/>.
6161
<Example><![CDATA[
6262
gap> g := EdgeWeightedDigraph(Digraph([[2], [1]]), [[5], [15]]);
63-
<immutable digraph with 2 vertices, 2 edges>
63+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
6464
gap> g := EdgeWeightedDigraph([[2], [1]], [[5], [15]]);
65-
<immutable digraph with 2 vertices, 2 edges>
65+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
6666
gap> EdgeWeights(g);
6767
[ [ 5 ], [ 15 ] ]
6868
]]></Example>
@@ -84,7 +84,7 @@ gap> EdgeWeights(g);
8484
<Example><![CDATA[
8585
gap> D := EdgeWeightedDigraph([[2], [1], [1, 2]],
8686
> [[12], [5], [6, 9]]);
87-
<immutable digraph with 3 vertices, 4 edges>
87+
<immutable edge-weighted digraph with 3 vertices, 4 edges>
8888
gap> EdgeWeightedDigraphTotalWeight(D);
8989
32]]></Example>
9090
</Description>
@@ -113,9 +113,9 @@ gap> EdgeWeightedDigraphTotalWeight(D);
113113
<Example><![CDATA[
114114
gap> D := EdgeWeightedDigraph([[2], [1], [1, 2]],
115115
> [[12], [5], [6, 9]]);
116-
<immutable digraph with 3 vertices, 4 edges>
116+
<immutable edge-weighted digraph with 3 vertices, 4 edges>
117117
gap> T := EdgeWeightedDigraphMinimumSpanningTree(D);
118-
<immutable digraph with 3 vertices, 2 edges>
118+
<immutable edge-weighted digraph with 3 vertices, 2 edges>
119119
gap> EdgeWeights(T);
120120
[ [ ], [ 5 ], [ 6 ] ]]]></Example>
121121
</Description>
@@ -175,12 +175,12 @@ gap> EdgeWeights(T);
175175
<Example><![CDATA[
176176
gap> D := EdgeWeightedDigraph([[2, 3], [4], [4], []],
177177
> [[5, 1], [6], [11], []]);
178-
<immutable digraph with 4 vertices, 4 edges>
178+
<immutable edge-weighted digraph with 4 vertices, 4 edges>
179179
gap> EdgeWeightedDigraphShortestPaths(D, 1);
180180
rec( distances := [ 0, 5, 1, 11 ], edges := [ fail, 1, 2, 1 ],
181181
parents := [ fail, 1, 1, 2 ] )
182182
gap> D := EdgeWeightedDigraph([[2], [3], [1]], [[1], [2], [3]]);
183-
<immutable digraph with 3 vertices, 3 edges>
183+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
184184
gap> EdgeWeightedDigraphShortestPaths(D);
185185
rec( distances := [ [ 0, 1, 3 ], [ 5, 0, 2 ], [ 3, 4, 0 ] ],
186186
edges := [ [ fail, 1, 1 ], [ 1, fail, 1 ], [ 1, 1, fail ] ],
@@ -211,7 +211,7 @@ rec( distances := [ [ 0, 1, 3 ], [ 5, 0, 2 ], [ 3, 4, 0 ] ],
211211
<Example><![CDATA[
212212
gap> D := EdgeWeightedDigraph([[2, 3], [4], [4], []],
213213
> [[5, 1], [6], [11], []]);
214-
<immutable digraph with 4 vertices, 4 edges>
214+
<immutable edge-weighted digraph with 4 vertices, 4 edges>
215215
gap> EdgeWeightedDigraphShortestPath(D, 1, 4);
216216
[ [ 1, 2, 4 ], [ 1, 1 ] ]
217217
gap> EdgeWeightedDigraphShortestPath(D, 3, 2);
@@ -263,7 +263,7 @@ fail]]></Example>
263263
See <Ref Attr="EdgeWeights" Func="EdgeWeightedDigraph"/>.
264264
<Example><![CDATA[
265265
gap> g := EdgeWeightedDigraph([[2, 2], [3], []], [[3, 2], [1], []]);
266-
<immutable multidigraph with 3 vertices, 3 edges>
266+
<immutable edge-weighted multidigraph with 3 vertices, 3 edges>
267267
gap> flow := DigraphMaximumFlow(g, 1, 3);
268268
[ [ 1, 0 ], [ 1 ], [ ] ]
269269
gap> Sum(flow[1]);
@@ -298,11 +298,11 @@ gap> Sum(flow[1]);
298298

299299
<Log><![CDATA[
300300
gap> RandomUniqueEdgeWeightedDigraph(5);
301-
<immutable digraph with 5 vertices, 21 edges>
301+
<immutable edge-weighted digraph with 5 vertices, 21 edges>
302302
gap> RandomUniqueEdgeWeightedDigraph(5, 1 / 2);
303-
<immutable digraph with 5 vertices, 14 edges>
303+
<immutable edge-weighted digraph with 5 vertices, 14 edges>
304304
gap> RandomUniqueEdgeWeightedDigraph(IsEulerianDigraph, 5, 1 / 3);
305-
<immutable digraph with 5 vertices, 6 edges>]]></Log>
305+
<immutable edge-weighted digraph with 5 vertices, 6 edges>]]></Log>
306306
</Description>
307307
</ManSection>
308308
<#/GAPDoc>

gap/digraph.gi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ function(D)
681681
fi;
682682
fi;
683683
fi;
684+
if HasEdgeWeights(D) then
685+
Append(str, "edge-weighted ");
686+
fi;
684687

685688
if IsMultiDigraph(D) then
686689
Append(str, "multi");

tst/standard/weights.tst

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ gap> DIGRAPHS_StartTest();
2222

2323
# create edge-weighted digraph
2424
gap> d := EdgeWeightedDigraph([[2], []], [[5], []]);
25-
<immutable digraph with 2 vertices, 1 edge>
25+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
2626
gap> d := EdgeWeightedDigraph(Digraph([[2], []]), [[5], []]);
27-
<immutable digraph with 2 vertices, 1 edge>
27+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
2828
gap> EdgeWeightedDigraphTotalWeight(d);
2929
5
3030

@@ -71,7 +71,7 @@ Error, the number of out-neighbours and weights for the vertex 1 must be equal\
7171

7272
# changing edge weights mutable copy
7373
gap> d := EdgeWeightedDigraph([[2], [1]], [[5], [10]]);
74-
<immutable digraph with 2 vertices, 2 edges>
74+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
7575
gap> m := EdgeWeightsMutableCopy(d);
7676
[ [ 5 ], [ 10 ] ]
7777
gap> m[1] := [25];
@@ -89,11 +89,11 @@ Error, List Assignment: <list> must be a mutable list
8989

9090
# negative edge weights
9191
gap> d := EdgeWeightedDigraph([[2], [1]], [[5], [10]]);
92-
<immutable digraph with 2 vertices, 2 edges>
92+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
9393
gap> IsNegativeEdgeWeightedDigraph(d);
9494
false
9595
gap> d := EdgeWeightedDigraph([[2], [1]], [[-5], [10]]);
96-
<immutable digraph with 2 vertices, 2 edges>
96+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
9797
gap> IsNegativeEdgeWeightedDigraph(d);
9898
true
9999

@@ -103,57 +103,57 @@ true
103103

104104
# not connnected digraph
105105
gap> d := EdgeWeightedDigraph([[1], [2]], [[5], [10]]);
106-
<immutable digraph with 2 vertices, 2 edges>
106+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
107107
gap> EdgeWeightedDigraphMinimumSpanningTree(d);
108108
Error, the argument <D> must be a connected digraph,
109109

110110
# digraph with one node
111111
gap> d := EdgeWeightedDigraph([[]], [[]]);
112-
<immutable empty digraph with 1 vertex>
112+
<immutable empty edge-weighted digraph with 1 vertex>
113113
gap> tree := EdgeWeightedDigraphMinimumSpanningTree(d);
114-
<immutable empty digraph with 1 vertex>
114+
<immutable empty edge-weighted digraph with 1 vertex>
115115
gap> EdgeWeightedDigraphTotalWeight(tree);
116116
0
117117

118118
# digraph with loop
119119
gap> d := EdgeWeightedDigraph([[1]], [[5]]);
120-
<immutable digraph with 1 vertex, 1 edge>
120+
<immutable edge-weighted digraph with 1 vertex, 1 edge>
121121
gap> EdgeWeightedDigraphMinimumSpanningTree(d);
122-
<immutable empty digraph with 1 vertex>
122+
<immutable empty edge-weighted digraph with 1 vertex>
123123

124124
# digraph with cycle
125125
gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [15]]);
126-
<immutable digraph with 3 vertices, 3 edges>
126+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
127127
gap> tree := EdgeWeightedDigraphMinimumSpanningTree(d);
128-
<immutable digraph with 3 vertices, 2 edges>
128+
<immutable edge-weighted digraph with 3 vertices, 2 edges>
129129
gap> EdgeWeightedDigraphTotalWeight(tree);
130130
15
131131

132132
# digraph with negative edge
133133
gap> d := EdgeWeightedDigraph([[2], []], [[-5], []]);
134-
<immutable digraph with 2 vertices, 1 edge>
134+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
135135
gap> EdgeWeightedDigraphMinimumSpanningTree(d);
136-
<immutable digraph with 2 vertices, 1 edge>
136+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
137137

138138
# digraph with negative cycle
139139
gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[-5], [-10], [-15]]);
140-
<immutable digraph with 3 vertices, 3 edges>
140+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
141141
gap> EdgeWeightedDigraphMinimumSpanningTree(d);
142-
<immutable digraph with 3 vertices, 2 edges>
142+
<immutable edge-weighted digraph with 3 vertices, 2 edges>
143143

144144
# digraph with parallel edges
145145
gap> d := EdgeWeightedDigraph([[2, 2, 2], [1]], [[10, 5, 15], [7]]);
146-
<immutable multidigraph with 2 vertices, 4 edges>
146+
<immutable edge-weighted multidigraph with 2 vertices, 4 edges>
147147
gap> EdgeWeightedDigraphMinimumSpanningTree(d);
148-
<immutable digraph with 2 vertices, 1 edge>
148+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
149149

150150
#############################################################################
151151
# 4. Shortest Path
152152
#############################################################################
153153

154154
# Shortest paths: one node
155155
gap> d := EdgeWeightedDigraph([[]], [[]]);
156-
<immutable empty digraph with 1 vertex>
156+
<immutable empty edge-weighted digraph with 1 vertex>
157157
gap> EdgeWeightedDigraphShortestPaths(d, 1);
158158
rec( distances := [ 0 ], edges := [ fail ], parents := [ fail ] )
159159

@@ -165,52 +165,52 @@ rec( distances := [ 0, fail ], edges := [ fail, fail ],
165165

166166
# Shortest paths: one node and loop
167167
gap> d := EdgeWeightedDigraph([[1]], [[5]]);
168-
<immutable digraph with 1 vertex, 1 edge>
168+
<immutable edge-weighted digraph with 1 vertex, 1 edge>
169169
gap> EdgeWeightedDigraphShortestPaths(d, 1);
170170
rec( distances := [ 0 ], edges := [ fail ], parents := [ fail ] )
171171

172172
# Shortest paths: two nodes and loop on second node
173173
gap> d := EdgeWeightedDigraph([[2], [1, 2]], [[5], [5, 5]]);
174-
<immutable digraph with 2 vertices, 3 edges>
174+
<immutable edge-weighted digraph with 2 vertices, 3 edges>
175175
gap> EdgeWeightedDigraphShortestPaths(d, 1);
176176
rec( distances := [ 0, 5 ], edges := [ fail, 1 ], parents := [ fail, 1 ] )
177177

178178
# Shortest paths: cycle
179179
gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[2], [3], [4]]);
180-
<immutable digraph with 3 vertices, 3 edges>
180+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
181181
gap> EdgeWeightedDigraphShortestPaths(d, 1);
182182
rec( distances := [ 0, 2, 5 ], edges := [ fail, 1, 1 ],
183183
parents := [ fail, 1, 2 ] )
184184

185185
# Shortest paths: parallel edges
186186
gap> d := EdgeWeightedDigraph([[2, 2, 2], [1]], [[10, 5, 15], [7]]);
187-
<immutable multidigraph with 2 vertices, 4 edges>
187+
<immutable edge-weighted multidigraph with 2 vertices, 4 edges>
188188
gap> EdgeWeightedDigraphShortestPaths(d, 1);
189189
rec( distances := [ 0, 5 ], edges := [ fail, 2 ], parents := [ fail, 1 ] )
190190

191191
# Shortest paths: negative edges
192192
gap> d := EdgeWeightedDigraph([[2], [1]], [[-2], [7]]);
193-
<immutable digraph with 2 vertices, 2 edges>
193+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
194194
gap> EdgeWeightedDigraphShortestPaths(d, 1);
195195
rec( distances := [ 0, -2 ], edges := [ fail, 1 ], parents := [ fail, 1 ] )
196196

197197
# Shortest paths: parallel negative edges
198198
gap> d := EdgeWeightedDigraph([[2, 2, 2], [1]], [[-2, -3, -4], [7]]);
199-
<immutable multidigraph with 2 vertices, 4 edges>
199+
<immutable edge-weighted multidigraph with 2 vertices, 4 edges>
200200
gap> EdgeWeightedDigraphShortestPaths(d, 1);
201201
rec( distances := [ 0, -4 ], edges := [ fail, 3 ], parents := [ fail, 1 ] )
202202

203203
# Shortest paths: negative cycle
204204
gap> d := EdgeWeightedDigraph([[2, 2, 2], [1]], [[-10, 5, -15], [7]]);
205-
<immutable multidigraph with 2 vertices, 4 edges>
205+
<immutable edge-weighted multidigraph with 2 vertices, 4 edges>
206206
gap> EdgeWeightedDigraphShortestPaths(d, 1);
207207
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
208208
Error, no 2nd choice method found for `EdgeWeightedDigraphShortestPaths' on 2 \
209209
arguments
210210
211211
# Shortest paths: source not in graph
212212
gap> d := EdgeWeightedDigraph([[2], [1]], [[2], [7]]);
213-
<immutable digraph with 2 vertices, 2 edges>
213+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
214214
gap> EdgeWeightedDigraphShortestPaths(d, 3);
215215
Error, the 2nd argument <source> must be a vertex of the 1st argument <D>,
216216
gap> EdgeWeightedDigraphShortestPath(d, 3, 1);
@@ -220,7 +220,7 @@ Error, the 3rd argument <dest> must be a vertex of the 1st argument <D>,
220220
221221
# Shortest paths: no path exists
222222
gap> d := EdgeWeightedDigraph([[1], [2]], [[5], [10]]);
223-
<immutable digraph with 2 vertices, 2 edges>
223+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
224224
gap> EdgeWeightedDigraphShortestPaths(d, 1);
225225
rec( distances := [ 0, fail ], edges := [ fail, fail ],
226226
parents := [ fail, fail ] )
@@ -229,7 +229,7 @@ fail
229229
230230
# Shortest paths: no path exists with negative edge weight
231231
gap> d := EdgeWeightedDigraph([[2], [2], []], [[-5], [10], []]);
232-
<immutable digraph with 3 vertices, 2 edges>
232+
<immutable edge-weighted digraph with 3 vertices, 2 edges>
233233
gap> r := EdgeWeightedDigraphShortestPaths(d, 1);;
234234
gap> r.distances = [0, -5, fail];
235235
true
@@ -240,7 +240,7 @@ true
240240
241241
# Shortest paths: parallel edges
242242
gap> d := EdgeWeightedDigraph([[2, 2, 2], []], [[3, 2, 1], []]);
243-
<immutable multidigraph with 2 vertices, 3 edges>
243+
<immutable edge-weighted multidigraph with 2 vertices, 3 edges>
244244
gap> EdgeWeightedDigraphShortestPaths(d, 1);
245245
rec( distances := [ 0, 1 ], edges := [ fail, 3 ], parents := [ fail, 1 ] )
246246
gap> EdgeWeightedDigraphShortestPaths(d);
@@ -252,7 +252,7 @@ gap> EdgeWeightedDigraphShortestPath(d, 1, 2);
252252
253253
# Shortest paths: negative cycle
254254
gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[-3], [-5], [-7]]);
255-
<immutable digraph with 3 vertices, 3 edges>
255+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
256256
gap> EdgeWeightedDigraphShortestPaths(d);
257257
Error, no method found! For debugging hints type ?Recovery from NoMethodFound
258258
Error, no 2nd choice method found for `EdgeWeightedDigraphShortestPaths' on 1 \
@@ -271,7 +271,7 @@ fail
271271
272272
# Shortest paths: Johnson
273273
gap> d := EdgeWeightedDigraph([[2], [3], [], [], []], [[3], [5], [], [], []]);
274-
<immutable digraph with 5 vertices, 2 edges>
274+
<immutable edge-weighted digraph with 5 vertices, 2 edges>
275275
gap> EdgeWeightedDigraphShortestPaths(d, 1);
276276
rec( distances := [ 0, 3, 8, fail, fail ], edges := [ fail, 1, 1, fail, fail ]
277277
, parents := [ fail, 1, 2, fail, fail ] )
@@ -296,61 +296,61 @@ gap> EdgeWeightedDigraphShortestPath(d, 1, 3);
296296
297297
# Maximum flow: empty digraphs
298298
gap> d := EdgeWeightedDigraph([], []);
299-
<immutable empty digraph with 0 vertices>
299+
<immutable empty edge-weighted digraph with 0 vertices>
300300
gap> DigraphMaximumFlow(d, 1, 1);
301301
Error, <start> must be a vertex of <D>,
302302
303303
# Maximum flow: single vertex (also empty digraphs)
304304
gap> d := EdgeWeightedDigraph([[]], [[]]);
305-
<immutable empty digraph with 1 vertex>
305+
<immutable empty edge-weighted digraph with 1 vertex>
306306
gap> DigraphMaximumFlow(d, 1, 1);
307307
[ [ ] ]
308308
309309
# Maximum flow: source = dest
310310
gap> d := EdgeWeightedDigraph([[2], []], [[5], []]);
311-
<immutable digraph with 2 vertices, 1 edge>
311+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
312312
gap> DigraphMaximumFlow(d, 1, 1);
313313
[ [ 0 ], [ ] ]
314314
315315
# Maximum flow: has loop
316316
gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
317-
<immutable digraph with 2 vertices, 2 edges>
317+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
318318
gap> DigraphMaximumFlow(d, 1, 2);
319319
[ [ 0, 10 ], [ ] ]
320320
321321
# Maximum flow: invalid source
322322
gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
323-
<immutable digraph with 2 vertices, 2 edges>
323+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
324324
gap> DigraphMaximumFlow(d, 5, 2);
325325
Error, <start> must be a vertex of <D>,
326326
327327
# Maximum flow: invalid sink
328328
gap> d := EdgeWeightedDigraph([[1, 2], []], [[5, 10], []]);
329-
<immutable digraph with 2 vertices, 2 edges>
329+
<immutable edge-weighted digraph with 2 vertices, 2 edges>
330330
gap> DigraphMaximumFlow(d, 1, 5);
331331
Error, <destination> must be a vertex of <D>,
332332
333333
# Maximum flow: sink not reachable
334334
gap> d := EdgeWeightedDigraph([[1], []], [[5], []]);
335-
<immutable digraph with 2 vertices, 1 edge>
335+
<immutable edge-weighted digraph with 2 vertices, 1 edge>
336336
gap> DigraphMaximumFlow(d, 1, 2);
337337
[ [ 0 ], [ ] ]
338338
339339
# Maximum flow: source has in neighbours
340340
gap> d := EdgeWeightedDigraph([[2], [3], []], [[5], [10], []]);
341-
<immutable digraph with 3 vertices, 2 edges>
341+
<immutable edge-weighted digraph with 3 vertices, 2 edges>
342342
gap> DigraphMaximumFlow(d, 2, 3);
343343
[ [ 0 ], [ 10 ], [ ] ]
344344
345345
# Maximum flow: sink has out-neighbours
346346
gap> d := EdgeWeightedDigraph([[2], [3], [2]], [[5], [10], [7]]);
347-
<immutable digraph with 3 vertices, 3 edges>
347+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
348348
gap> DigraphMaximumFlow(d, 2, 3);
349349
[ [ 0 ], [ 10 ], [ 0 ] ]
350350
351351
# Maximum flow: cycle
352352
gap> d := EdgeWeightedDigraph([[2], [3], [1]], [[5], [10], [7]]);
353-
<immutable digraph with 3 vertices, 3 edges>
353+
<immutable edge-weighted digraph with 3 vertices, 3 edges>
354354
gap> DigraphMaximumFlow(d, 1, 3);
355355
[ [ 5 ], [ 5 ], [ 0 ] ]
356356

0 commit comments

Comments
 (0)