-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathattr.xml
More file actions
2869 lines (2635 loc) · 103 KB
/
attr.xml
File metadata and controls
2869 lines (2635 loc) · 103 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#############################################################################
##
#W attr.xml
#Y Copyright (C) 2014-19 James D. Mitchell
##
## Licensing information can be found in the README file of this package.
##
#############################################################################
##
<#GAPDoc Label="DigraphVertices">
<ManSection>
<Attr Name="DigraphVertices" Arg="digraph"/>
<Returns>A list of positive integers.</Returns>
<Description>
Returns the vertices of the digraph <A>digraph</A>. <P/>
Note that the vertices of a digraph are always the range of
positive integers from <C>1</C> to the number of vertices of the
graph, <Ref Attr="DigraphNrVertices"/>.
Arbitrary <E>labels</E> can be assigned to the vertices of a digraph;
see <Ref Oper="DigraphVertexLabels"/> for more information about this.
<Example><![CDATA[
gap> gr := Digraph(["a", "b", "c"],
> ["a", "b", "b"],
> ["b", "c", "a"]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphVertices(gr);
[ 1 .. 3 ]
gap> gr := Digraph([1, 2, 3, 4, 5, 7],
> [1, 2, 2, 4, 4],
> [2, 7, 5, 3, 7]);
<immutable digraph with 6 vertices, 5 edges>
gap> DigraphVertices(gr);
[ 1 .. 6 ]
gap> DigraphVertices(RandomDigraph(100));
[ 1 .. 100 ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphVertices(D);
[ 1 .. 3 ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphNrVertices">
<ManSection>
<Attr Name="DigraphNrVertices" Arg="digraph"/>
<Returns>An non-negative integer.</Returns>
<Description>
Returns the number of vertices of the digraph <A>digraph</A>. <P/>
<Example><![CDATA[
gap> gr := Digraph(["a", "b", "c"],
> ["a", "b", "b"],
> ["b", "c", "a"]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphNrVertices(gr);
3
gap> gr := Digraph([1, 2, 3, 4, 5, 7],
> [1, 2, 2, 4, 4],
> [2, 7, 5, 3, 7]);
<immutable digraph with 6 vertices, 5 edges>
gap> DigraphNrVertices(gr);
6
gap> DigraphNrVertices(RandomDigraph(100));
100
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphNrVertices(D);
3
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphEdges">
<ManSection>
<Attr Name="DigraphEdges" Arg="digraph"/>
<Returns>A list of lists of two positive integers.</Returns>
<Description>
Returns a list of edges of the digraph <A>digraph</A>,
where each edge is a pair of elements of <Ref Attr="DigraphVertices"/> of
the form <C>[source,range]</C>.
<P/>
<!-- TODO remove this paragraph when multidigraphs are removed -->
The entries of <C>DigraphEdges(</C><A>digraph</A><C>)</C> are in one-to-one
correspondence with the edges of <A>digraph</A>. Hence
<C>DigraphEdges(</C><A>digraph</A><C>)</C> is duplicate-free if and only if
<A>digraph</A> contains no multiple edges. <P/>
The entries of <C>DigraphEdges</C> are guaranteed to be sorted by their
first component (i.e. by the source of each edge), but they are not
necessarily then sorted by the second component.
<Example><![CDATA[
gap> gr := DigraphFromDiSparse6String(".DaXbOe?EAM@G~");
<immutable multidigraph with 5 vertices, 16 edges>
gap> edges := ShallowCopy(DigraphEdges(gr));; Sort(edges);
gap> edges;
[ [ 1, 1 ], [ 1, 3 ], [ 1, 3 ], [ 1, 4 ], [ 1, 5 ], [ 2, 1 ],
[ 2, 2 ], [ 2, 3 ], [ 2, 5 ], [ 3, 2 ], [ 3, 4 ], [ 3, 5 ],
[ 4, 2 ], [ 4, 4 ], [ 4, 5 ], [ 5, 1 ] ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphEdges(D);
[ [ 1, 2 ], [ 2, 3 ], [ 3, 1 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphNrEdges">
<ManSection>
<Attr Name="DigraphNrEdges" Arg="digraph"/>
<Returns>An integer.</Returns>
<Description>
Returns the number of edges of the digraph <A>digraph</A>.
<Example><![CDATA[
gap> gr := Digraph([
> [1, 3, 4, 5], [1, 2, 3, 5], [2, 4, 5], [2, 4, 5], [1]]);;
gap> DigraphNrEdges(gr);
15
gap> gr := Digraph(["a", "b", "c"],
> ["a", "b", "b"],
> ["b", "a", "a"]);
<immutable multidigraph with 3 vertices, 3 edges>
gap> DigraphNrEdges(gr);
3
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphNrEdges(D);
3
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphNrAdjacencies">
<ManSection>
<Attr Name="DigraphNrAdjacencies" Arg="digraph" />
<Returns>An integer.</Returns>
<Description> Returns the number of sets <M>\{u, v\}</M> of vertices of the digraph <A>digraph</A>, such that
either <M>(u, v)</M> or <M>(v, u)</M> is an edge. The following equality holds for
any digraph <C>D</C> with no multiple edges: <C>DigraphNrAdjacencies(D) * 2 - DigraphNrLoops(D)
= DigraphNrEdges(DigraphSymmetricClosure(D))</C>.
<Example><![CDATA[
gap> gr := Digraph([
> [1, 3, 4, 5], [1, 2, 3, 5], [2, 4, 5], [2, 4, 5], [1]]);;
gap> DigraphNrAdjacencies(gr);
13
gap> DigraphNrAdjacencies(gr) * 2 - DigraphNrLoops(gr) =
> DigraphNrEdges(DigraphSymmetricClosure(gr));
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphNrAdjacenciesWithoutLoops">
<ManSection>
<Attr Name="DigraphNrAdjacenciesWithoutLoops" Arg="digraph" />
<Returns>An integer.</Returns>
<Description> Returns the number of sets <M>\{u, v\}</M> of vertices of the digraph <A>digraph</A>, such that
<M>u \neq v</M> and either <M>(u, v)</M> or <M>(v, u)</M> is an edge. The following equality holds for
any digraph <C>D</C> with no multiple edges: <C>DigraphNrAdjacenciesWithoutLoops(D) * 2 + DigraphNrLoops(D)
= DigraphNrEdges(DigraphSymmetricClosure(D))</C>.
<Example><![CDATA[
gap> gr := Digraph([
> [1, 3, 4, 5], [1, 2, 3, 5], [2, 4, 5], [2, 4, 5], [1]]);;
gap> DigraphNrAdjacenciesWithoutLoops(gr);
10
gap> DigraphNrAdjacenciesWithoutLoops(gr) * 2 + DigraphNrLoops(gr) =
> DigraphNrEdges(DigraphSymmetricClosure(gr));
true
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphNrLoops">
<ManSection>
<Attr Name="DigraphNrLoops" Arg="digraph"/>
<Returns>An integer.</Returns>
<Description>
This function returns the number of loops of the digraph <A>digraph</A>. See <Ref Prop="DigraphHasLoops"/>. <P/>
<Example><![CDATA[
gap> D := Digraph([[2, 3], [1, 4], [3, 3, 5], [], [2, 5]]);
<immutable multidigraph with 5 vertices, 9 edges>
gap> DigraphNrLoops(D);
3
gap> D := EmptyDigraph(5);
<immutable empty digraph with 5 vertices>
gap> DigraphNrLoops(D);
0
gap> D := CompleteDigraph(5);
<immutable complete digraph with 5 vertices>
gap> DigraphNrLoops(D);
0
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="RangeSourceDigraph">
<ManSection>
<Attr Name="DigraphRange" Arg="digraph"/>
<Attr Name="DigraphSource" Arg="digraph"/>
<Returns>A list of positive integers.</Returns>
<Description>
<C>DigraphRange</C> and <C>DigraphSource</C> return the range and source of
the digraph <A>digraph</A>. More precisely, position <C>i</C> in
<C>DigraphSource(<A>digraph</A>)</C> and
<C>DigraphRange(<A>digraph</A>)</C> give, respectively, the source and
range of the <C>i</C>th edge of <A>digraph</A>.
<Example><![CDATA[
gap> gr := Digraph([
> [2, 1, 3, 5], [1, 3, 4], [2, 3], [2], [1, 2, 3, 4]]);
<immutable digraph with 5 vertices, 14 edges>
gap> DigraphSource(gr);
[ 1, 1, 1, 1, 2, 2, 2, 3, 3, 4, 5, 5, 5, 5 ]
gap> DigraphRange(gr);
[ 2, 1, 3, 5, 1, 3, 4, 2, 3, 2, 1, 2, 3, 4 ]
gap> DigraphEdges(gr);
[ [ 1, 2 ], [ 1, 1 ], [ 1, 3 ], [ 1, 5 ], [ 2, 1 ], [ 2, 3 ],
[ 2, 4 ], [ 3, 2 ], [ 3, 3 ], [ 4, 2 ], [ 5, 1 ], [ 5, 2 ],
[ 5, 3 ], [ 5, 4 ] ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphRange(D);
[ 2, 3, 1 ]
gap> DigraphSource(D);
[ 1, 2, 3 ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="OutNeighbours">
<ManSection>
<Attr Name="OutNeighbours" Arg="digraph"/>
<Attr Name="OutNeighbors" Arg="digraph"/>
<Oper Name="OutNeighboursMutableCopy" Arg="digraph"/>
<Oper Name="OutNeighborsMutableCopy" Arg="digraph"/>
<Returns>The adjacencies of a digraph.</Returns>
<Description>
<C>OutNeighbours</C> returns the list <C>out</C> of out-neighbours of
each vertex of the digraph <A>digraph</A>.
<!-- TODO update the following sentence once multidigraphs are gone -->
More specifically, a vertex <C>j</C> appears in <C>out[i]</C> each time
there exists the edge <C>[i, j]</C> in <A>digraph</A>. <P/>
The function <C>OutNeighbours</C> returns an immutable list of
lists, whereas the function <C>OutNeighboursMutableCopy</C> returns a copy
of <C>OutNeighbours</C> which is a mutable list of mutable lists. <P/>
Note that the entries of <C>out</C> are not guaranteed to be sorted in any
particular order.
<Example><![CDATA[
gap> gr := Digraph(["a", "b", "c"],
> ["a", "b", "b"],
> ["b", "a", "c"]);
<immutable digraph with 3 vertices, 3 edges>
gap> OutNeighbours(gr);
[ [ 2 ], [ 1, 3 ], [ ] ]
gap> gr := Digraph([[1, 2, 3], [2, 1], [3]]);
<immutable digraph with 3 vertices, 6 edges>
gap> OutNeighbours(gr);
[ [ 1, 2, 3 ], [ 2, 1 ], [ 3 ] ]
gap> gr := DigraphByAdjacencyMatrix([
> [1, 2, 1],
> [1, 1, 0],
> [0, 0, 1]]);
<immutable multidigraph with 3 vertices, 7 edges>
gap> OutNeighbours(gr);
[ [ 1, 2, 2, 3 ], [ 1, 2 ], [ 3 ] ]
gap> OutNeighboursMutableCopy(gr);
[ [ 1, 2, 2, 3 ], [ 1, 2 ], [ 3 ] ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> OutNeighbours(D);
[ [ 2 ], [ 3 ], [ 1 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="InNeighbours">
<ManSection>
<Attr Name="InNeighbours" Arg="digraph"/>
<Attr Name="InNeighbors" Arg="digraph"/>
<Oper Name="InNeighboursMutableCopy" Arg="digraph"/>
<Oper Name="InNeighborsMutableCopy" Arg="digraph"/>
<Returns>A list of lists of vertices.</Returns>
<Description>
<C>InNeighbours</C> returns the list <C>inn</C> of in-neighbours of each
vertex of the digraph <A>digraph</A>.
<!-- TODO update the following sentence once multidigraphs are gone -->
More specifically, a vertex <C>j</C> appears in <C>inn[i]</C> each time
there exists an edge <C>[j,i]</C> in <A>digraph</A>. <P/>
The function <C>InNeighbours</C> returns an immutable list of
lists, whereas the function <C>InNeighboursMutableCopy</C> returns a copy
of <C>InNeighbours</C> which is a mutable list of mutable lists. <P/>
Note that the entries of <C>inn</C> are not necessarily sorted into
ascending order, particularly if <A>digraph</A> was constructed via
<Ref Oper="DigraphByInNeighbours"/>.
<Example><![CDATA[
gap> gr := Digraph(["a", "b", "c"],
> ["a", "b", "b"],
> ["b", "a", "c"]);
<immutable digraph with 3 vertices, 3 edges>
gap> InNeighbours(gr);
[ [ 2 ], [ 1 ], [ 2 ] ]
gap> gr := Digraph([[1, 2, 3], [2, 1], [3]]);
<immutable digraph with 3 vertices, 6 edges>
gap> InNeighbours(gr);
[ [ 1, 2 ], [ 1, 2 ], [ 1, 3 ] ]
gap> gr := DigraphByAdjacencyMatrix([
> [1, 2, 1],
> [1, 1, 0],
> [0, 0, 1]]);
<immutable multidigraph with 3 vertices, 7 edges>
gap> InNeighbours(gr);
[ [ 1, 2 ], [ 1, 1, 2 ], [ 1, 3 ] ]
gap> InNeighboursMutableCopy(gr);
[ [ 1, 2 ], [ 1, 1, 2 ], [ 1, 3 ] ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> InNeighbours(D);
[ [ 3 ], [ 1 ], [ 2 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphAdjacencyFunction">
<ManSection>
<Attr Name="DigraphAdjacencyFunction" Arg="digraph"/>
<Returns>A function.</Returns>
<Description>
If <A>digraph</A> is a digraph, then <C>DigraphAdjacencyFunction</C> returns
a function which takes two integer parameters <C>x, y</C> and returns
<K>true</K> if there exists an edge from vertex <C>x</C> to vertex <C>y</C>
in <A>digraph</A> and <K>false</K> if not.
<Example><![CDATA[
gap> digraph := Digraph([[1, 2], [3], []]);
<immutable digraph with 3 vertices, 3 edges>
gap> foo := DigraphAdjacencyFunction(digraph);
function( u, v ) ... end
gap> foo(1, 1);
true
gap> foo(1, 2);
true
gap> foo(1, 3);
false
gap> foo(3, 1);
false
gap> gr := Digraph(["a", "b", "c"],
> ["a", "b", "b"],
> ["b", "a", "a"]);
<immutable multidigraph with 3 vertices, 3 edges>
gap> foo := DigraphAdjacencyFunction(gr);
function( u, v ) ... end
gap> foo(1, 2);
true
gap> foo(3, 2);
false
gap> foo(3, 1);
false
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> foo := DigraphAdjacencyFunction(D);
function( u, v ) ... end
gap> foo(1, 2);
true
gap> foo(2, 1);
false
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="AdjacencyMatrix">
<ManSection>
<Attr Name="AdjacencyMatrix" Arg="digraph"/>
<Oper Name="AdjacencyMatrixMutableCopy" Arg="digraph"/>
<Returns>A square matrix of non-negative integers.</Returns>
<Description>
This function returns the adjacency matrix <C>mat</C> of the digraph
<A>digraph</A>.
<!-- Update the following sentence when multidigraphs are gone -->
The value of the matrix entry <C>mat[i][j]</C> is the number of edges
in <A>digraph</A> with source <C>i</C> and range <C>j</C>. If <A>digraph</A>
has no vertices, then the empty list is returned. <P/>
The function <C>AdjacencyMatrix</C> returns an immutable list of
lists, whereas the function <C>AdjacencyMatrixMutableCopy</C> returns a copy
of <C>AdjacencyMatrix</C> that is a mutable list of mutable lists. <P/>
<Example><![CDATA[
gap> gr := Digraph([
> [2, 2, 2], [1, 3, 6, 8, 9, 10], [4, 6, 8],
> [1, 2, 3, 9], [3, 3], [3, 5, 6, 10], [1, 2, 7],
> [1, 2, 3, 10, 5, 6, 10], [1, 3, 4, 5, 8, 10],
> [2, 3, 4, 6, 7, 10]]);
<immutable multidigraph with 10 vertices, 44 edges>
gap> mat := AdjacencyMatrix(gr);;
gap> Display(mat);
[ [ 0, 3, 0, 0, 0, 0, 0, 0, 0, 0 ],
[ 1, 0, 1, 0, 0, 1, 0, 1, 1, 1 ],
[ 0, 0, 0, 1, 0, 1, 0, 1, 0, 0 ],
[ 1, 1, 1, 0, 0, 0, 0, 0, 1, 0 ],
[ 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 ],
[ 0, 0, 1, 0, 1, 1, 0, 0, 0, 1 ],
[ 1, 1, 0, 0, 0, 0, 1, 0, 0, 0 ],
[ 1, 1, 1, 0, 1, 1, 0, 0, 0, 2 ],
[ 1, 0, 1, 1, 1, 0, 0, 1, 0, 1 ],
[ 0, 1, 1, 1, 0, 1, 1, 0, 0, 1 ] ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> Display(AdjacencyMatrix(D));
[ [ 0, 1, 0 ],
[ 0, 0, 1 ],
[ 1, 0, 0 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="BooleanAdjacencyMatrix">
<ManSection>
<Attr Name="BooleanAdjacencyMatrix" Arg="digraph"/>
<Oper Name="BooleanAdjacencyMatrixMutableCopy" Arg="digraph"/>
<Returns>A square matrix of booleans.</Returns>
<Description>
If <A>digraph</A> is a digraph with a positive number of vertices
<C>n</C>, then <C>BooleanAdjacencyMatrix(</C><A>digraph</A><C>)</C>
returns the boolean adjacency matrix <C>mat</C> of <A>digraph</A>.
<!-- TODO Update the following sentence when multidigraphs are gone -->
The
value of the matrix entry <C>mat[j][i]</C> is <K>true</K> if and only if
there exists an edge in <A>digraph</A> with source <C>j</C> and range
<C>i</C>. If <A>digraph</A> has no vertices, then the empty list is
returned. <P/>
<!-- TODO Remove this sentence when multidigraphs are gone -->
Note that the boolean adjacency matrix loses information about multiple
edges. <P/>
The attribute <C>BooleanAdjacencyMatrix</C> returns an immutable list of
immutable lists, whereas the function
<C>BooleanAdjacencyMatrixMutableCopy</C> returns a copy of the
<C>BooleanAdjacencyMatrix</C> that is a mutable list of mutable lists. <P/>
<Example><![CDATA[
gap> gr := Digraph([[3, 4], [2, 3], [1, 2, 4], [4]]);
<immutable digraph with 4 vertices, 8 edges>
gap> PrintArray(BooleanAdjacencyMatrix(gr));
[ [ false, false, true, true ],
[ false, true, true, false ],
[ true, true, false, true ],
[ false, false, false, true ] ]
gap> gr := CycleDigraph(4);;
gap> PrintArray(BooleanAdjacencyMatrix(gr));
[ [ false, true, false, false ],
[ false, false, true, false ],
[ false, false, false, true ],
[ true, false, false, false ] ]
gap> BooleanAdjacencyMatrix(EmptyDigraph(0));
[ ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> PrintArray(BooleanAdjacencyMatrix(D));
[ [ false, true, false ],
[ false, false, true ],
[ true, false, false ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DegreeMatrix">
<ManSection>
<Attr Name="DegreeMatrix" Arg="digraph"/>
<Returns>A square matrix of non-negative integers.</Returns>
<Description>
Returns the out-degree matrix <C>mat</C> of the digraph
<A>digraph</A>. The value of the <C>i</C>th diagonal matrix entry is the
out-degree of the vertex <C>i</C> in <A>digraph</A>. All off-diagonal
entries are <C>0</C>.
If <A>digraph</A> has no vertices, then the empty list is returned. <P/>
See <Ref Attr="OutDegrees"/> for more information.
<Example><![CDATA[
gap> D := Digraph([[1, 2, 3], [4], [1, 3, 4], []]);
<immutable digraph with 4 vertices, 7 edges>
gap> PrintArray(DegreeMatrix(D));
[ [ 3, 0, 0, 0 ],
[ 0, 1, 0, 0 ],
[ 0, 0, 3, 0 ],
[ 0, 0, 0, 0 ] ]
gap> D := CycleDigraph(5);;
gap> PrintArray(DegreeMatrix(D));
[ [ 1, 0, 0, 0, 0 ],
[ 0, 1, 0, 0, 0 ],
[ 0, 0, 1, 0, 0 ],
[ 0, 0, 0, 1, 0 ],
[ 0, 0, 0, 0, 1 ] ]
gap> DegreeMatrix(EmptyDigraph(0));
[ ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> Display(DegreeMatrix(D));
[ [ 1, 0, 0 ],
[ 0, 1, 0 ],
[ 0, 0, 1 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="LaplacianMatrix">
<ManSection>
<Attr Name="LaplacianMatrix" Arg="digraph"/>
<Returns>A square matrix of integers.</Returns>
<Description>
Returns the out-degree Laplacian matrix <C>mat</C> of the
digraph <A>digraph</A>. The out-degree Laplacian matrix is defined as
<C>DegreeMatrix(digraph) - AdjacencyMatrix(digraph)</C>. If
<A>digraph</A> has no vertices, then the empty list is returned. <P/>
See <Ref Attr="DegreeMatrix"/> and <Ref Attr="AdjacencyMatrix"/> for more
information.
<Example><![CDATA[
gap> gr := Digraph([[1, 2, 3], [4], [1, 3, 4], []]);
<immutable digraph with 4 vertices, 7 edges>
gap> PrintArray(LaplacianMatrix(gr));
[ [ 2, -1, -1, 0 ],
[ 0, 1, 0, -1 ],
[ -1, 0, 2, -1 ],
[ 0, 0, 0, 0 ] ]
gap> LaplacianMatrix(EmptyDigraph(0));
[ ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> Display(LaplacianMatrix(D));
[ [ 1, -1, 0 ],
[ 0, 1, -1 ],
[ -1, 0, 1 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="OutDegrees">
<ManSection>
<Attr Name="OutDegrees" Arg="digraph"/>
<Attr Name="OutDegreeSequence" Arg="digraph"/>
<Attr Name="OutDegreeSet" Arg="digraph"/>
<Returns>A list of non-negative integers.</Returns>
<Description>
Given a digraph <A>digraph</A> with <M>n</M> vertices, the function
<C>OutDegrees</C> returns an immutable list <C>out</C> of length <M>n</M>, such that
for a vertex <C>i</C> in <A>digraph</A>, the value of <C>out[i]</C> is the
out-degree of vertex <C>i</C>.
See <Ref Oper="OutDegreeOfVertex"/>. <P/>
The function <C>OutDegreeSequence</C> returns the same list,
after it has been sorted into non-increasing order. <P/>
The function <C>OutDegreeSet</C> returns the same list, sorted into
increasing order with duplicate entries removed. <P/>
<Example><![CDATA[
gap> D := Digraph([[1, 3, 2, 2], [], [2, 1], []]);
<immutable multidigraph with 4 vertices, 6 edges>
gap> OutDegrees(D);
[ 4, 0, 2, 0 ]
gap> OutDegreeSequence(D);
[ 4, 2, 0, 0 ]
gap> OutDegreeSet(D);
[ 0, 2, 4 ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> OutDegrees(D);
[ 1, 1, 1 ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="InDegrees">
<ManSection>
<Attr Name="InDegrees" Arg="digraph"/>
<Attr Name="InDegreeSequence" Arg="digraph"/>
<Attr Name="InDegreeSet" Arg="digraph"/>
<Returns>A list of non-negative integers.</Returns>
<Description>
Given a digraph <A>digraph</A> with <M>n</M> vertices, the function
<C>InDegrees</C> returns an immutable list <C>inn</C> of length <M>n</M>, such that
for a vertex <C>i</C> in <A>digraph</A>, the value of <C>inn[i]</C> is
the in-degree of vertex <C>i</C>.
See <Ref Oper="InDegreeOfVertex"/>. <P/>
The function <C>InDegreeSequence</C> returns the same list,
after it has been sorted into non-increasing order. <P/>
The function <C>InDegreeSet</C> returns the same list, sorted into
increasing order with duplicate entries removed. <P/>
<Example><![CDATA[
gap> D := Digraph([[1, 3, 2, 2, 4], [], [2, 1, 4], []]);
<immutable multidigraph with 4 vertices, 8 edges>
gap> InDegrees(D);
[ 2, 3, 1, 2 ]
gap> InDegreeSequence(D);
[ 3, 2, 2, 1 ]
gap> InDegreeSet(D);
[ 1, 2, 3 ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> InDegrees(D);
[ 1, 1, 1 ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphSources">
<ManSection>
<Attr Name="DigraphSources" Arg="digraph"/>
<Returns>A list of vertices.</Returns>
<Description>
This function returns an immutable list of the sources of the digraph
<A>digraph</A>.
A source of a digraph is a vertex with in-degree zero.
See <Ref Oper="InDegreeOfVertex"/>.
<Example><![CDATA[
gap> gr := Digraph([[3, 5, 2, 2], [3], [], [5, 2, 5, 3], []]);
<immutable multidigraph with 5 vertices, 9 edges>
gap> DigraphSources(gr);
[ 1, 4 ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphSources(D);
[ ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphSinks">
<ManSection>
<Attr Name="DigraphSinks" Arg="digraph"/>
<Returns>A list of vertices.</Returns>
<Description>
This function returns a list of the sinks of the digraph
<A>digraph</A>.
A sink of a digraph is a vertex with out-degree zero.
See <Ref Oper="OutDegreeOfVertex"/>.
<Example><![CDATA[
gap> gr := Digraph([[3, 5, 2, 2], [3], [], [5, 2, 5, 3], []]);
<immutable multidigraph with 5 vertices, 9 edges>
gap> DigraphSinks(gr);
[ 3, 5 ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphSinks(D);
[ ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphStronglyConnectedComponents">
<ManSection>
<Attr Name="DigraphStronglyConnectedComponents" Arg="digraph"/>
<Attr Name="DigraphNrStronglyConnectedComponents" Arg="digraph"/>
<Returns>A record.</Returns>
<Description>
This function returns the record <C>scc</C> corresponding to the strongly
connected components of the digraph <A>digraph</A>. Two vertices of
<A>digraph</A> are in the same strongly connected component whenever they
are equal, or there is a directed path from each vertex to the other. The
set of strongly connected components is a partition of the vertex set of
<A>digraph</A>.
<P/>
The record <C>scc</C> has 2 components: <C>comps</C> and <C>id</C>.
The component <C>comps</C> is a list of the strongly connected components
of <A>digraph</A> (each of which is a list of vertices).
The component <C>id</C> is a list such that the vertex <C>i</C> is an
element of the strongly connected component <C>comps[id[i]]</C>. <P/>
The method used in this function is a non-recursive version of Gabow's
Algorithm <Cite Key="Gab00"/> and has complexity <M>O(m+n)</M> where
<M>m</M> is the number of edges (counting multiple edges as one) and
<M>n</M> is the number of vertices in the digraph. <P/>
<C>DigraphNrStronglyConnectedComponents(<A>digraph</A>)</C> is simply a
shortcut for
<C>Length(DigraphStronglyConnectedComponents(<A>digraph</A>).comps)</C>,
and is no more efficient.
<Example><![CDATA[
gap> gr := Digraph([[2], [3, 1], []]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphStronglyConnectedComponents(gr);
rec( comps := [ [ 3 ], [ 1, 2 ] ], id := [ 2, 2, 1 ] )
gap> DigraphNrStronglyConnectedComponents(gr);
2
gap> D := DigraphDisjointUnion(CycleDigraph(4), CycleDigraph(5));
<immutable digraph with 9 vertices, 9 edges>
gap> DigraphStronglyConnectedComponents(D);
rec( comps := [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8, 9 ] ],
id := [ 1, 1, 1, 1, 2, 2, 2, 2, 2 ] )
gap> DigraphNrStronglyConnectedComponents(D);
2
gap> D := CycleDigraph(IsMutableDigraph, 2);
<mutable digraph with 2 vertices, 2 edges>
gap> G := CycleDigraph(3);
<immutable cycle digraph with 3 vertices>
gap> DigraphDisjointUnion(D, G);
<mutable digraph with 5 vertices, 5 edges>
gap> DigraphStronglyConnectedComponents(D);
rec( comps := [ [ 1, 2 ], [ 3, 4, 5 ] ], id := [ 1, 1, 2, 2, 2 ] )
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphConnectedComponents">
<ManSection>
<Attr Name="DigraphConnectedComponents" Arg="digraph"/>
<Attr Name="DigraphNrConnectedComponents" Arg="digraph"/>
<Returns>A record.</Returns>
<Description>
This function returns the record <C>wcc</C> corresponding to the weakly
connected components of the digraph <A>digraph</A>. Two vertices of
<A>digraph</A> are in the same weakly connected component whenever they are
equal, or there exists a directed path (ignoring the orientation of edges)
between them. More formally, two vertices are in the same weakly connected
component of <A>digraph</A> if and only if they are in the same strongly
connected component (see <Ref Attr="DigraphStronglyConnectedComponents"/>)
of the <Ref Oper="DigraphSymmetricClosure"/> of <A>digraph</A>. <P/>
The set of weakly connected components is a partition of
the vertex set of <A>digraph</A>. <P/>
The record <C>wcc</C> has 2 components: <C>comps</C> and <C>id</C>.
The component <C>comps</C> is a list of the weakly connected components
of <A>digraph</A> (each of which is a list of vertices).
The component <C>id</C> is a list such that the vertex <C>i</C> is an
element of the weakly connected component <C>comps[id[i]]</C>. <P/>
The method used in this function has complexity <M>O(m+n)</M>, where
<M>m</M> is the number of edges and
<M>n</M> is the number of vertices in the digraph. <P/>
<C>DigraphNrConnectedComponents(<A>digraph</A>)</C> is simply a shortcut
for <C>Length(DigraphConnectedComponents(<A>digraph</A>).comps)</C>,
and is no more efficient.
<Example><![CDATA[
gap> gr := Digraph([[2], [3, 1], []]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphConnectedComponents(gr);
rec( comps := [ [ 1, 2, 3 ] ], id := [ 1, 1, 1 ] )
gap> gr := Digraph([[1], [1, 2], []]);
<immutable digraph with 3 vertices, 3 edges>
gap> DigraphConnectedComponents(gr);
rec( comps := [ [ 1, 2 ], [ 3 ] ], id := [ 1, 1, 2 ] )
gap> DigraphNrConnectedComponents(gr);
2
gap> gr := EmptyDigraph(0);
<immutable empty digraph with 0 vertices>
gap> DigraphConnectedComponents(gr);
rec( comps := [ ], id := [ ] )
gap> D := CycleDigraph(IsMutableDigraph, 2);
<mutable digraph with 2 vertices, 2 edges>
gap> G := CycleDigraph(3);
<immutable cycle digraph with 3 vertices>
gap> DigraphDisjointUnion(D, G);
<mutable digraph with 5 vertices, 5 edges>
gap> DigraphConnectedComponents(D);
rec( comps := [ [ 1, 2 ], [ 3, 4, 5 ] ], id := [ 1, 1, 2, 2, 2 ] )
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphTopologicalSort">
<ManSection>
<Attr Name="DigraphTopologicalSort" Arg="digraph"/>
<Returns>A list of positive integers, or <K>fail</K>.</Returns>
<Description>
If <A>digraph</A> is a digraph whose only directed cycles are loops, then
<C>DigraphTopologicalSort</C> returns the vertices of <A>digraph</A> ordered
so that every edge's source appears no earlier in the list than its range.
If the digraph <A>digraph</A> contains directed cycles of length greater
than <M>1</M>, then this operation returns <K>fail</K>.
<P/>
See Section <Ref Subsect="Definitions" Style="Number" /> for the definition
of a directed cycle, and the definition of a loop.
<P/>
The method used for this attribute has complexity <M>O(m+n)</M> where
<M>m</M> is the number of edges (counting multiple edges as one) and
<M>n</M> is the number of vertices in the digraph. <P/>
<Example><![CDATA[
gap> D := Digraph([
> [2, 3], [], [4, 6], [5], [], [7, 8, 9], [], [], []]);
<immutable digraph with 9 vertices, 8 edges>
gap> DigraphTopologicalSort(D);
[ 2, 5, 4, 7, 8, 9, 6, 3, 1 ]
gap> D := Digraph(IsMutableDigraph, [[2, 3], [3], [4], []]);
<mutable digraph with 4 vertices, 4 edges>
gap> DigraphTopologicalSort(D);
[ 4, 3, 2, 1 ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphDegeneracy">
<ManSection>
<Attr Name="DigraphDegeneracy" Arg="digraph"/>
<Returns>A non-negative integer, or <K>fail</K>.</Returns>
<Description>
If <A>digraph</A> is a symmetric digraph without multiple edges - see
<Ref Prop="IsSymmetricDigraph"/> and <Ref Prop="IsMultiDigraph"/> - then
this attribute returns the degeneracy of <A>digraph</A>. <P/>
The degeneracy of a digraph is the least integer <C>k</C> such
that every induced of <A>digraph</A> contains a vertex whose number of
neighbours (excluding itself) is at most <C>k</C>. Note that this means
that loops are ignored.<P/>
If <A>digraph</A> is not symmetric or has multiple edges then this
attribute returns <K>fail</K>.
<Example><![CDATA[
gap> D := DigraphSymmetricClosure(ChainDigraph(5));;
gap> DigraphDegeneracy(D);
1
gap> D := CompleteDigraph(5);;
gap> DigraphDegeneracy(D);
4
gap> D := Digraph([[1], [2, 4, 5], [3, 4], [2, 3, 4], [2], []]);
<immutable digraph with 6 vertices, 10 edges>
gap> DigraphDegeneracy(D);
1
gap> D := GeneralisedPetersenGraph(IsMutableDigraph, 10, 3);
<mutable digraph with 20 vertices, 60 edges>
gap> DigraphDegeneracy(D);
3
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphDegeneracyOrdering">
<ManSection>
<Attr Name="DigraphDegeneracyOrdering" Arg="digraph"/>
<Returns>A list of integers, or <K>fail</K>.</Returns>
<Description>
If <A>digraph</A> is a digraph for which
<C>DigraphDegeneracy(</C><A>digraph</A><C>)</C> is a non-negative integer
<C>k</C> - see <Ref Attr="DigraphDegeneracy"/> - then this attribute
returns a degeneracy ordering of the vertices of the vertices of
<A>digraph</A>.<P/>
A degeneracy ordering of <A>digraph</A> is a list <C>ordering</C> of the
vertices of <A>digraph</A> ordered such that for any
position <C>i</C> of the list, the vertex <C>ordering[i]</C> has at most
<C>k</C> neighbours in later position of the list.<P/>
If <C>DigraphDegeneracy(</C><A>digraph</A><C>)</C> returns <K>fail</K>,
then this attribute returns <K>fail</K>.
<Example><![CDATA[
gap> D := DigraphSymmetricClosure(ChainDigraph(5));;
gap> DigraphDegeneracyOrdering(D);
[ 5, 4, 3, 2, 1 ]
gap> D := CompleteDigraph(5);;
gap> DigraphDegeneracyOrdering(D);
[ 5, 4, 3, 2, 1 ]
gap> D := Digraph([[1], [2, 4, 5], [3, 4], [2, 3, 4], [2], []]);
<immutable digraph with 6 vertices, 10 edges>
gap> DigraphDegeneracyOrdering(D);
[ 1, 6, 5, 2, 4, 3 ]
gap> D := GeneralisedPetersenGraph(IsMutableDigraph, 3, 1);
<mutable digraph with 6 vertices, 18 edges>
gap> DigraphDegeneracyOrdering(D);
[ 6, 5, 4, 1, 3, 2 ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphShortestDistances">
<ManSection>
<Attr Name="DigraphShortestDistances" Arg="digraph"/>
<Returns>A square matrix.</Returns>
<Description>
If <A>digraph</A> is a digraph with <M>n</M> vertices, then this
function returns an <M>n \times n</M> matrix <C>mat</C>, where each entry is
either a non-negative integer, or <K>fail</K>. If <M>n = 0</M>, then an
empty list is returned. <P/>
If there is a directed path from vertex <C>i</C> to vertex <C>j</C>, then
the value of <C>mat[i][j]</C> is the length of the shortest such directed
path. If no such directed path exists, then the value of <C>mat[i][j]</C> is
<C>fail</C>. We use the convention that the distance from every vertex to
itself is <C>0</C>, i.e. <C>mat[i][i] = 0</C> for all vertices <C>i</C>.
<P/>
The method used in this function is a version of the Floyd-Warshall
algorithm, and has complexity <M>O(n^3)</M>.
<Example><![CDATA[
gap> D := Digraph([[1, 2], [3], [1, 2], [4]]);
<immutable digraph with 4 vertices, 6 edges>
gap> mat := DigraphShortestDistances(D);;
gap> PrintArray(mat);
[ [ 0, 1, 2, fail ],
[ 2, 0, 1, fail ],
[ 1, 1, 0, fail ],
[ fail, fail, fail, 0 ] ]
gap> D := CycleDigraph(IsMutableDigraph, 3);
<mutable digraph with 3 vertices, 3 edges>
gap> DigraphShortestDistances(D);
[ [ 0, 1, 2 ], [ 2, 0, 1 ], [ 1, 2, 0 ] ]
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphDiameter">
<ManSection>
<Attr Name="DigraphDiameter" Arg="digraph"/>
<Returns>An integer or <C>fail</C>.</Returns>
<Description>
This function returns the diameter of the digraph <A>digraph</A>.
<P/>
If a digraph <A>digraph</A> is strongly connected and has at least 1
vertex, then the <E>diameter</E> is the maximum shortest distance between
any pair of distinct vertices. Otherwise then the diameter of
<A>digraph</A> is undefined, and this function returns the value
<C>fail</C>. <P/>
See <Ref Attr="DigraphShortestDistances"/>. <P/>
<Example><![CDATA[
gap> D := Digraph([[2], [3], [4, 5], [5], [1, 2, 3, 4, 5]]);
<immutable digraph with 5 vertices, 10 edges>
gap> DigraphDiameter(D);
3
gap> D := ChainDigraph(2);
<immutable chain digraph with 2 vertices>
gap> DigraphDiameter(D);
fail
gap> IsStronglyConnectedDigraph(D);
false
gap> D := GeneralisedPetersenGraph(IsMutableDigraph, 6, 2);
<mutable digraph with 12 vertices, 36 edges>
gap> DigraphDiameter(D);
4
]]></Example>
</Description>
</ManSection>
<#/GAPDoc>
<#GAPDoc Label="DigraphGirth">
<ManSection>
<Attr Name="DigraphGirth" Arg="digraph"/>
<Returns>An integer, or <K>infinity</K>.</Returns>
<Description>
This attribute returns the <E>girth</E> of the digraph <A>digraph</A>.
The <E>girth</E> of a digraph is the length of its shortest simple circuit.
See Section <Ref Subsect="Definitions" Style="Number" /> for the definitions
of simple circuit, directed cycle, and loop.
<P/>
If <A>digraph</A> has no directed cycles, then this function will return
<K>infinity</K>. If <A>digraph</A> contains a loop, then this function will
return <C>1</C>.
<P/>
In the worst case, the method used in this function is a version of the
Floyd-Warshall algorithm, and has complexity <C>O(<A>n</A> ^ 3)</C>, where
<A>n</A> is the number of vertices in <A>digraph</A>. If the digraph has