1 <!-- This file is part of Shapes. -->
3 <!-- Shapes is free software: you can redistribute it and/or modify -->
4 <!-- it under the terms of the GNU General Public License as published by -->
5 <!-- the Free Software Foundation, either version 3 of the License, or -->
6 <!-- any later version. -->
8 <!-- Shapes is distributed in the hope that it will be useful, -->
9 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
10 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -->
11 <!-- GNU General Public License for more details. -->
13 <!-- You should have received a copy of the GNU General Public License -->
14 <!-- along with Shapes. If not, see <http://www.gnu.org/licenses/>. -->
16 <!-- Copyright 2013, 2014 Henrik Tidefelt -->
18 <section id="types/graphs">
21 <p>A graph is a data structure with nodes and edges. They can be modeled in many ways, but <str-Shapes /> comes with one set built-in types that define the preferred way of representing graphs in <str-Shapes />. Since the types are built-in, the allow for a more efficient implementation than would could be obtained with user-defined types. The need for a graph data structure is discussed in the <a part="tutorial" id="chap-graphs" />.</p>
24 <coretype name="GraphKey">
26 <p>A key identifying some entity in a graph, like a node or a graph partition.</p>
29 <union-type><named-type name="Symbol" /><named-type name="Integer" /></union-type>
33 <coretype name="Node">
37 <p>Type of node values.</p>
42 <p>Type of edge values.</p>
47 <p>The <self /> type is a reference to a node belonging to a particular graph. It gives constant time access to the referenced graph node.</p>
50 <named-type name="Edge" /> <named-type name="Graph" /> <named-type name="NodeData" />
55 <type-field name="value">
56 <type><parameter-type name="N" /></type>
57 <description><p>The value associated with the node.</p></description>
59 <type-field name="key">
60 <type><named-type name="GraphKey" /></type>
61 <description><p>The key used to retrieve the <self /> from the <named-type name="Graph" />.</p></description>
63 <type-field name="partition">
64 <type><union-type><named-type name="GraphKey" /><named-type name="Void" /></union-type></type>
66 <p>Graph partition. Unless <value-the-void />, the node will not be adjacent to other nodes in the same partition.</p>
69 <type-field name="index">
70 <type><named-type name="Integer" /></type>
71 <description><p>Each node in the graph has a unique value in a range starting from zero. It is generally not identical to the <field name="key" /> even if all keys are of type <named-type name="Integer" />.</p></description>
73 <type-field name="u_degree">
74 <type><named-type name="Integer" /></type>
75 <description><p>Number of undirected edges incident to the node. Loop edges count twice.</p></description>
77 <type-field name="d_degree_in">
78 <type><named-type name="Integer" /></type>
79 <description><p>Number of directed edges with target at the node.</p></description>
81 <type-field name="d_degree_out">
82 <type><named-type name="Integer" /></type>
83 <description><p>Number of directed edges with source at the node.</p></description>
85 <type-field name="d_degree">
86 <type><named-type name="Integer" /></type>
87 <description><p>The sum of <field name="d_degree_in" /> and <field name="d_degree_out" />. Note that loop edges will count twice.</p></description>
89 <type-field name="degree">
90 <type><named-type name="Integer" /></type>
91 <description><p>The sum of <field name="u_degree" /> and <field name="d_degree" />.</p></description>
93 <type-field name="u_loop_count">
94 <type><named-type name="Integer" /></type>
95 <description><p>Number of undirected loop edges incident to the node. Each loop counts once.</p></description>
97 <type-field name="d_loop_count">
98 <type><named-type name="Integer" /></type>
99 <description><p>Number of directed loop edges incident to the node. Each loop counts once.</p></description>
101 <type-field name="loop_count">
102 <type><named-type name="Integer" /></type>
103 <description><p>The sum of <field name="u_loop_count"/> and <field name="d_loop_count"/>.</p></description>
105 <type-method name="u_edges">
109 <arg identifier="loops">
110 <type><named-type name="Boolean"/></type>
111 <default><value-the-true /></default>
116 <parameterized-type name="Seq">
117 <parameterized-type name="UEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
118 </parameterized-type>
122 <p>Finds all incident undirected edges. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />. Loop edges are only included once.</p>
127 <type-method name="u_multiedges">
131 <arg identifier="loops">
132 <type><named-type name="Boolean"/></type>
133 <default><value-the-true /></default>
138 <parameterized-type name="Seq">
139 <parameterized-type name="UMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
140 </parameterized-type>
144 <p>Similar to <field name="u_edges" />, but with parallel edges grouped as multiedges.</p>
149 <type-method name="d_edges_in">
153 <arg identifier="loops">
154 <type><named-type name="Boolean"/></type>
155 <default><value-the-true /></default>
160 <parameterized-type name="Seq">
161 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
162 </parameterized-type>
166 <p>Finds all incident directed edges with target at the current node. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />.</p>
171 <type-method name="d_multiedges_in">
175 <arg identifier="loops">
176 <type><named-type name="Boolean"/></type>
177 <default><value-the-true /></default>
182 <parameterized-type name="Seq">
183 <parameterized-type name="DMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
184 </parameterized-type>
188 <p>Similar to <field name="d_edges_in" />, but with parallel edges grouped as multiedges.</p>
193 <type-method name="d_edges_out">
197 <arg identifier="loops">
198 <type><named-type name="Boolean"/></type>
199 <default><value-the-true /></default>
204 <parameterized-type name="Seq">
205 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
206 </parameterized-type>
210 <p>Finds all incident directed edges with source at the curret node. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />.</p>
215 <type-method name="d_multiedges_out">
219 <arg identifier="loops">
220 <type><named-type name="Boolean"/></type>
221 <default><value-the-true /></default>
226 <parameterized-type name="Seq">
227 <parameterized-type name="DMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
228 </parameterized-type>
232 <p>Similar to <field name="d_edges_out" />, but with parallel edges grouped as multiedges.</p>
237 <type-method name="edges_in">
241 <arg identifier="loops">
242 <type><named-type name="Boolean"/></type>
243 <default><value-the-true /></default>
248 <parameterized-type name="Seq">
249 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
250 </parameterized-type>
254 <p>The union of edges obtained with <field name="u_edges" /> and <field name="d_edges_in" />.</p>
259 <type-method name="multiedges_in">
263 <arg identifier="loops">
264 <type><named-type name="Boolean"/></type>
265 <default><value-the-true /></default>
270 <parameterized-type name="Seq">
271 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
272 </parameterized-type>
276 <p>Similar to <field name="edges_in" />, but with parallel edges grouped as multiedges.</p>
281 <type-method name="edges_out">
285 <arg identifier="loops">
286 <type><named-type name="Boolean"/></type>
287 <default><value-the-true /></default>
292 <parameterized-type name="Seq">
293 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
294 </parameterized-type>
298 <p>The union of edges obtained with <field name="u_edges" /> and <field name="d_edges_out" />.</p>
303 <type-method name="multiedges_out">
307 <arg identifier="loops">
308 <type><named-type name="Boolean"/></type>
309 <default><value-the-true /></default>
314 <parameterized-type name="Seq">
315 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
316 </parameterized-type>
320 <p>Similar to <field name="edges_out" />, but with parallel edges grouped as multiedges.</p>
325 <type-method name="edges">
329 <arg identifier="loops">
330 <type><named-type name="Boolean"/></type>
331 <default><value-the-true /></default>
336 <parameterized-type name="Seq">
337 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
338 </parameterized-type>
342 <p>The results of <field name="u_edges" />, <field name="d_edges_in" />, and <field name="d_edges_out" /> taken together, except for directed loops that are only included once.</p>
347 <type-method name="multiedges">
351 <arg identifier="loops">
352 <type><named-type name="Boolean"/></type>
353 <default><value-the-true /></default>
358 <parameterized-type name="Seq">
359 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
360 </parameterized-type>
364 <p>Similar to <field name="multiedges" />, but with parallel edges grouped as multiedges.</p>
369 <type-method name="u_loops">
376 <parameterized-type name="Seq">
377 <parameterized-type name="UEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
378 </parameterized-type>
382 <p>All undirected loop edges incident to the node. Each loop edge is only included once.</p>
387 <type-method name="u_multiloops">
394 <parameterized-type name="Seq">
395 <parameterized-type name="UMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
396 </parameterized-type>
400 <p>Similar to <field name="u_loops" />, but with parallel edges grouped as multiedges. Note that the returned sequence will contain at most one element.</p>
405 <type-method name="d_loops">
412 <parameterized-type name="Seq">
413 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
414 </parameterized-type>
418 <p>All directed loop edges incident to the node. Each loop edge is only included once.</p>
423 <type-method name="d_multiloops">
430 <parameterized-type name="Seq">
431 <parameterized-type name="DMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
432 </parameterized-type>
436 <p>Similar to <field name="d_loops" />, but with parallel edges grouped as multiedges. Note that the returned sequence will contain at most one element.</p>
441 <type-method name="loops">
448 <parameterized-type name="Seq">
449 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
450 </parameterized-type>
454 <p>The union of edges obtained with <field name="u_loops" /> and <field name="d_loops" />.</p>
459 <type-method name="multiloops">
466 <parameterized-type name="Seq">
467 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
468 </parameterized-type>
472 <p>The union of multiedges obtained with <field name="u_multiloops" /> and <field name="d_multiloops" />.</p>
477 <type-method name="trace">
481 <arg identifier="edge">
484 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
485 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
492 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
496 <p>Get the <named-type name="Node" /> on the other side of <arg name="edge" />. It is an error if <arg name="edge" /> is not incident to the current node, or if <arg name="edge"/> is directed but does not have the current node as source.</p>
501 <type-method name="backtrace">
505 <arg identifier="edge">
508 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
509 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
516 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
520 <p>Get the <named-type name="Node" /> on the other side of <arg name="edge" />. It is an error if <arg name="edge" /> is not incident to the current node, or if <arg name="edge"/> is directed but does not have the current node as target.</p>
525 <type-method name="u_neighbors">
529 <arg identifier="loops">
530 <type><named-type name="Boolean"/></type>
531 <default><value-the-true /></default>
533 <arg identifier="parallel">
534 <type><named-type name="Boolean"/></type>
535 <default><value-the-true /></default>
540 <parameterized-type name="Seq">
541 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
542 </parameterized-type>
546 <p>All nodes on the other side of an undirected edge incident to the current node. Loop edges count twice, and each parallel edge counts once. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />, and setting <arg name="parallel"/> to <value-the-false /> gives only unique nodes in the result.</p>
551 <type-method name="d_neighbors_in">
555 <arg identifier="loops">
556 <type><named-type name="Boolean"/></type>
557 <default><value-the-true /></default>
559 <arg identifier="parallel">
560 <type><named-type name="Boolean"/></type>
561 <default><value-the-true /></default>
566 <parameterized-type name="Seq">
567 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
568 </parameterized-type>
572 <p>All nodes on the other side of a directed edge with target at the current node. Each parallel edge counts once, as do loop edges. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />, and setting <arg name="parallel"/> to <value-the-false /> gives only unique nodes in the result.</p>
577 <type-method name="d_neighbors_out">
581 <arg identifier="loops">
582 <type><named-type name="Boolean"/></type>
583 <default><value-the-true /></default>
585 <arg identifier="parallel">
586 <type><named-type name="Boolean"/></type>
587 <default><value-the-true /></default>
592 <parameterized-type name="Seq">
593 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
594 </parameterized-type>
598 <p>All nodes on the other side of a directed edge with source at the current node. Each parallel edge counts once, as do loop edges. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />, and setting <arg name="parallel"/> to <value-the-false /> gives only unique nodes in the result.</p>
603 <type-method name="neighbors_in">
607 <arg identifier="loops">
608 <type><named-type name="Boolean"/></type>
609 <default><value-the-true /></default>
611 <arg identifier="parallel">
612 <type><named-type name="Boolean"/></type>
613 <default><value-the-true /></default>
618 <parameterized-type name="Seq">
619 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
620 </parameterized-type>
624 <p>The results of <field name="u_neighbors"/> and <field name="d_neighbors_in"/> taken together. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />, and setting <arg name="parallel"/> to <value-the-false /> gives only unique nodes in the result.</p>
629 <type-method name="neighbors_out">
633 <arg identifier="loops">
634 <type><named-type name="Boolean"/></type>
635 <default><value-the-true /></default>
637 <arg identifier="parallel">
638 <type><named-type name="Boolean"/></type>
639 <default><value-the-true /></default>
644 <parameterized-type name="Seq">
645 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
646 </parameterized-type>
650 <p>The results of <field name="u_neighbors"/> and <field name="d_neighbors_out"/> taken together. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />, and setting <arg name="parallel"/> to <value-the-false /> gives only unique nodes in the result.</p>
655 <type-method name="neighbors">
659 <arg identifier="loops">
660 <type><named-type name="Boolean"/></type>
661 <default><value-the-true /></default>
663 <arg identifier="parallel">
664 <type><named-type name="Boolean"/></type>
665 <default><value-the-true /></default>
670 <parameterized-type name="Seq">
671 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
672 </parameterized-type>
676 <p>The results of <field name="u_neighbors"/>, <field name="d_neighbors_in"/>, and <field name="d_neighbors_out"/> taken together. Loops can be excluded by setting <arg name="loops" /> to <value-the-false />, and setting <arg name="parallel"/> to <value-the-false /> gives only unique nodes in the result.</p>
681 <type-method name="get_graph">
688 <parameterized-type name="Graph">
689 <parameter-type name="N"/><parameter-type name="E"/>
690 </parameterized-type>
694 <p>Get the graph to which the node belongs.</p>
702 <coretype name="Edge">
706 <p>Type of node values.</p>
711 <p>Type of edge values.</p>
716 <p>The <self /> type is a reference to an edge belonging to a particular graph. It gives constant time access to the referenced graph edge.</p>
719 <named-type name="Node" /> <named-type name="Graph" /> <named-type name="EdgeData" />
724 <type-field name="directed?">
725 <type><named-type name="Boolean" /></type>
726 <description><p>Whether the edge is directed or undirected.</p></description>
728 <type-field name="source">
729 <type><parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type></type>
730 <description><p>The source of a directed edge, or one of the nodes incident to an undirected edge. <field name="source" /> and <field name="target"/> are only identical for undirected edges in case of loops.</p></description>
732 <type-field name="target">
733 <type><parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type></type>
734 <description><p>The target of a directed edge, or one of the nodes incident to an undirected edge. <field name="source" /> and <field name="target"/> are only identical for undirected edges in case of loops.</p></description>
736 <type-field name="value">
737 <type><parameter-type name="E" /></type>
738 <description><p>The value associated with the edge.</p></description>
740 <type-field name="label">
741 <type><named-type name="GraphKey" /></type>
742 <description><p>A label which may be used in combination with <field name="source" /> and <field name="target" /> to identify the edge. Note that, in general, the label does not have to be unique, even for a given pair of <field name="source" /> and <field name="target" />.</p></description>
744 <type-field name="index">
745 <type><named-type name="Integer" /></type>
746 <description><p>Each edge in the graph has a unique value in a range starting from zero.</p></description>
748 <type-method name="get_graph">
755 <parameterized-type name="Graph">
756 <parameter-type name="N"/><parameter-type name="E"/>
757 </parameterized-type>
761 <p>Get the graph to which the edge belongs.</p>
769 <coretype name="UEdge">
773 <p>Type of node values.</p>
778 <p>Type of edge values.</p>
783 <p>An undirected edge.</p>
787 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
789 <field name="directed?">
790 <type><singleton-type><value-the-false /></singleton-type></type>
797 <coretype name="DEdge">
801 <p>Type of node values.</p>
806 <p>Type of edge values.</p>
811 <p>A directed edge.</p>
815 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
817 <field name="directed?">
818 <type><singleton-type><value-the-true /></singleton-type></type>
825 <coretype name="MultiEdge">
829 <p>Type of node values.</p>
834 <p>Type of edge values.</p>
839 <p>The <self /> type is set of parallel edges. It provides a simplified way of working with multigraphs when one is not interested in the multiplicity of parallel edges. Two edges (compare <named-type name="Edge" />) are parallel if and only if they are both directed or both undirected, and have the same source and target nodes.</p>
842 <named-type name="Edge" /> <named-type name="Graph" />
847 <type-field name="directed?">
848 <type><named-type name="Boolean" /></type>
849 <description><p>Whether the parallel edges are directed or undirected.</p></description>
851 <type-field name="source">
852 <type><parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type></type>
853 <description><p>The common source node of the parallel edges.</p></description>
855 <type-field name="target">
856 <type><parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type></type>
857 <description><p>The common target node of the parallel edges.</p></description>
859 <type-field name="count">
860 <type><named-type name="Integer" /></type>
861 <description><p>The multiplicity of the parallel edges. That is, the length of <field name="edges" />, which is always positive.</p></description>
863 <type-field name="edges">
865 <parameterized-type name="Seq">
866 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
867 </parameterized-type>
870 <p>The individual parallel edges, ordered by their <field name="index"/>.</p>
871 <p>There is always at least one edge in the sequence.</p>
874 <type-field name="u_edges">
876 <parameterized-type name="Seq">
877 <parameterized-type name="UEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
878 </parameterized-type>
880 <description><p>Identical to <field name="edges" />, except that it is only allowed when the parallel edges are undirected.</p></description>
882 <type-field name="d_edges">
884 <parameterized-type name="Seq">
885 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
886 </parameterized-type>
888 <description><p>Identical to <field name="edges" />, except that it is only allowed when the parallel edges are directed.</p></description>
890 <type-method name="get_graph">
897 <parameterized-type name="Graph">
898 <parameter-type name="N"/><parameter-type name="E"/>
899 </parameterized-type>
903 <p>Get the graph to which the parallel edges belongs.</p>
911 <coretype name="UMultiEdge">
915 <p>Type of node values.</p>
920 <p>Type of edge values.</p>
925 <p>An undirected multiedge.</p>
929 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
931 <field name="directed?">
932 <type><singleton-type><value-the-false /></singleton-type></type>
939 <coretype name="DMultiEdge">
943 <p>Type of node values.</p>
948 <p>Type of edge values.</p>
953 <p>A directed multiedge.</p>
957 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
959 <field name="directed?">
960 <type><singleton-type><value-the-true /></singleton-type></type>
967 <coretype name="Graph">
971 <p>Type of node values.</p>
976 <p>Type of edge values.</p>
981 <p>Graph of nodes and edges.</p>
984 <named-type name="Walk" />
989 <type-field name="undirected?">
990 <type><named-type name="Boolean"/></type>
991 <description><p>Whether <em>directed</em> edges are <em>not</em> allowed in the graph's domain.</p></description>
993 <type-field name="directed?">
994 <type><named-type name="Boolean"/></type>
995 <description><p>Whether <em>undirected</em> edges are <em>not</em> allowed in the graph's domain.</p></description>
997 <type-field name="mixed?">
998 <type><named-type name="Boolean"/></type>
999 <description><p>Whether both undirected and directed edges are allowed in the graph's domain. That is, the graph's domain is neither directed nor undirected.</p></description>
1001 <type-field name="loops?">
1002 <type><named-type name="Boolean"/></type>
1003 <description><p>Whether loop edges are allowed in the graph's domain.</p></description>
1005 <type-field name="parallel?">
1006 <type><named-type name="Boolean"/></type>
1007 <description><p>Whether parallel edges are allowed in the graph's domain.</p></description>
1009 <type-field name="partitioned?">
1010 <type><named-type name="Boolean"/></type>
1011 <description><p>Whether the graph's domain requires each node to belong to a partition.</p></description>
1014 <type-field name="key_is_index?">
1015 <type><named-type name="Boolean"/></type>
1016 <description><p>Whether node keys coincide with node indices.</p></description>
1018 <type-field name="key_is_range?">
1019 <type><named-type name="Boolean"/></type>
1020 <description><p>Whether node keys coincide with node indices plus <field name="key_offset" />.</p></description>
1022 <type-field name="key_offset">
1023 <type><named-type name="Integer"/></type>
1024 <description><p>Node key of node with index zero. It is an error to access this field unless <field name="key_is_range?" />.</p></description>
1026 <type-field name="partition_count">
1027 <type><named-type name="Integer"/></type>
1028 <description><p>Number of partitions, that is, the length of <field name="partitions" />. Note that a graph without any partitions may still contain nodes as long as it is not <field name="partitioned?"/>.</p></description>
1030 <type-field name="partitions">
1032 <parameterized-type name="Seq">
1033 <named-type name="GraphKey" />
1034 </parameterized-type>
1036 <description><p>The keys identifying the partitions of the graph, or empty if the graph is not <field name="partitioned?" />.</p></description>
1039 <type-field name="node_count">
1040 <type><named-type name="Integer"/></type>
1041 <description><p>Number of nodes.</p></description>
1043 <type-field name="u_edge_count">
1044 <type><named-type name="Integer"/></type>
1045 <description><p>Number of undirected edges, including loop edges.</p></description>
1047 <type-field name="d_edge_count">
1048 <type><named-type name="Integer"/></type>
1049 <description><p>Number of directed edges, including loop edges.</p></description>
1051 <type-field name="edge_count">
1052 <type><named-type name="Integer"/></type>
1053 <description><p>The sum of <field name="u_edge_count"/> and <field name="d_edge_count"/>.</p></description>
1055 <type-field name="u_loop_count">
1056 <type><named-type name="Integer"/></type>
1057 <description><p>Number of undirected loop edges.</p></description>
1059 <type-field name="d_loop_count">
1060 <type><named-type name="Integer"/></type>
1061 <description><p>Number of directed loop edges.</p></description>
1063 <type-field name="loop_count">
1064 <type><named-type name="Integer"/></type>
1065 <description><p>The sum of <field name="u_loop_count"/> and <field name="d_loop_count"/>.</p></description>
1067 <type-field name="nodes">
1069 <parameterized-type name="Seq">
1070 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1071 </parameterized-type>
1073 <description><p>All nodes in the graph, with each node appearing at the position given by its <field name="index"/>.</p></description>
1075 <type-field name="u_edges">
1077 <parameterized-type name="Seq">
1078 <parameterized-type name="UEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1079 </parameterized-type>
1081 <description><p>All undirected edges in the graph. If the graph is undirected, each edge will appear at the position given by its <field name="index"/>.</p></description>
1083 <type-field name="d_edges">
1085 <parameterized-type name="Seq">
1086 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1087 </parameterized-type>
1089 <description><p>All directed edges in the graph. If the graph is directed, each edge will appear at the position given by its <field name="index"/>.</p></description>
1091 <type-field name="edges">
1093 <parameterized-type name="Seq">
1094 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1095 </parameterized-type>
1097 <description><p>All edges in the graph, with each edge appearing at the position given by its <field name="index"/>.</p></description>
1099 <type-field name="u_multiedges">
1101 <parameterized-type name="Seq">
1102 <parameterized-type name="UMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1103 </parameterized-type>
1105 <description><p>All undirected multiedges in the graph.</p></description>
1107 <type-field name="d_multiedges">
1109 <parameterized-type name="Seq">
1110 <parameterized-type name="DMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1111 </parameterized-type>
1113 <description><p>All directed multiedges in the graph.</p></description>
1115 <type-field name="multiedges">
1117 <parameterized-type name="Seq">
1118 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1119 </parameterized-type>
1121 <description><p>All multiedges in the graph.</p></description>
1123 <type-method name="partition">
1127 <arg identifier="key">
1129 <named-type name="GraphKey" />
1135 <parameterized-type name="Seq">
1136 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1137 </parameterized-type>
1141 <p>All nodes in the given partition.</p>
1146 <type-method name="partition_node_count">
1150 <arg identifier="key">
1152 <named-type name="GraphKey" />
1157 <type><named-type name="Integer"/></type>
1160 <p>The number of nodes in the given partition.</p>
1166 <type-method name="item?">
1170 <arg identifier="item">
1173 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1174 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1175 <parameterized-type name="MultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1182 <named-type name="Boolean"/>
1186 <p>Test if an item such as a node, an edge, or a multiedge belongs to the graph.</p>
1191 <type-method name="key?">
1195 <arg identifier="key">
1196 <type><named-type name="GraphKey" /></type>
1201 <named-type name="Boolean"/>
1205 <p>Test if a node key is present in the graph.</p>
1211 <type-method name="index_node">
1215 <arg identifier="index">
1216 <type><named-type name="Integer" /></type>
1221 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1225 <p>Retrieves a node in the graph identified by its index.</p>
1230 <type-method name="index_edge">
1234 <arg identifier="index">
1235 <type><named-type name="Integer" /></type>
1240 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1244 <p>Retrieves an edge in the graph identified by its index.</p>
1250 <type-method name="find_node">
1254 <arg identifier="key">
1255 <type><named-type name="GraphKey" /></type>
1260 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1264 <p>Finds a node in the graph identified by its key.</p>
1269 <type-method name="find_u_edges">
1273 <arg identifier="source">
1275 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1277 <default><value-the-void /></default>
1279 <arg identifier="target">
1281 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1283 <default><value-the-void /></default>
1285 <arg identifier="label">
1287 <union-type><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1289 <default><value-the-void /></default>
1291 <arg identifier="loops">
1292 <type><named-type name="Boolean"/></type>
1293 <default><value-the-true /></default>
1298 <parameterized-type name="Seq">
1299 <parameterized-type name="UEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1300 </parameterized-type>
1304 <p>Finds all undirected edges that are incident to both <arg name="source" /> and <arg name="target"/>. The default value means any node.</p>
1305 <p>If <arg name="label" /> is a <named-type name="GraphKey" />, only edges with that label are returned. If <arg name="label" /> is <value-the-void />, any edge label will match; there is no way to only return edges that do not have a label (that is, the label being <value-the-void />).</p>
1306 <p>Loops can be excluded by setting <arg name="loops" /> to <value-the-false />. Loop edges are only included once.</p>
1311 <type-method name="find_d_edges">
1315 <arg identifier="source">
1317 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1319 <default><value-the-void /></default>
1321 <arg identifier="target">
1323 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1325 <default><value-the-void /></default>
1327 <arg identifier="label">
1329 <union-type><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1331 <default><value-the-void /></default>
1333 <arg identifier="loops">
1334 <type><named-type name="Boolean"/></type>
1335 <default><value-the-true /></default>
1340 <parameterized-type name="Seq">
1341 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1342 </parameterized-type>
1346 <p>Finds all directed edges from <arg name="source" /> to <arg name="target"/>. Analogous to <field name="find_u_edges"/>.</p>
1351 <type-method name="find_u_multiedges">
1355 <arg identifier="source">
1357 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1359 <default><value-the-void /></default>
1361 <arg identifier="target">
1363 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1365 <default><value-the-void /></default>
1367 <arg identifier="loops">
1368 <type><named-type name="Boolean"/></type>
1369 <default><value-the-true /></default>
1374 <parameterized-type name="Seq">
1375 <parameterized-type name="UMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1376 </parameterized-type>
1380 <p>Finds all undirected multiedges that are incident to both <arg name="source" /> and <arg name="target"/>. The default value means any node.</p>
1381 <p>Unlike <field name="find_u_edges" />, it is not possible to specify an edge label; a <named-type name="MultiEdge" /> will always contain all parallel edges.</p>
1382 <p>Loops can be excluded by setting <arg name="loops" /> to <value-the-false />. Loop edges are only included once.</p>
1387 <type-method name="find_d_multiedges">
1391 <arg identifier="source">
1393 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1395 <default><value-the-void /></default>
1397 <arg identifier="target">
1399 <union-type><named-type name="Node" /><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1401 <default><value-the-void /></default>
1403 <arg identifier="loops">
1404 <type><named-type name="Boolean"/></type>
1405 <default><value-the-true /></default>
1410 <parameterized-type name="Seq">
1411 <parameterized-type name="DMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1412 </parameterized-type>
1416 <p>Finds all directed multiedges from <arg name="source" /> to <arg name="target"/>. Analogous to <field name="find_u_multiedges"/>.</p>
1421 <type-method name="the_u_edge">
1425 <arg identifier="source">
1427 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1430 <arg identifier="target">
1432 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1435 <arg identifier="label">
1437 <union-type><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1439 <default><value-the-void /></default>
1444 <parameterized-type name="UEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1448 <p>Returns the only undirected edge incident to both <arg name="source" /> and <arg name="target"/>.</p>
1449 <p>If <arg name="label" /> is a <named-type name="GraphKey" />, only edges with that label are considered. If <arg name="label" /> is <value-the-void />, any edge label will match.</p>
1450 <p>It is an error if there is not exactly one matching edge.</p>
1455 <type-method name="the_d_edge">
1459 <arg identifier="source">
1461 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1464 <arg identifier="target">
1466 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1469 <arg identifier="label">
1471 <union-type><named-type name="GraphKey" /><named-type name="Void" /></union-type>
1473 <default><value-the-void /></default>
1478 <parameterized-type name="DEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1482 <p>Returns the only directed edge from <arg name="source" /> to <arg name="target"/>. Analogous to <field name="the_u_edge" />.</p>
1487 <type-method name="the_u_multiedge">
1491 <arg identifier="source">
1493 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1496 <arg identifier="target">
1498 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1504 <parameterized-type name="UMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1508 <p>Returns the undirected multiedge incident to both <arg name="source" /> and <arg name="target"/>.</p>
1509 <p>It is an error if there is no matching edge.</p>
1514 <type-method name="the_d_multiedge">
1518 <arg identifier="source">
1520 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1523 <arg identifier="target">
1525 <union-type><named-type name="Node" /><named-type name="GraphKey" /></union-type>
1531 <parameterized-type name="DMultiEdge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1535 <p>Returns the directed multiedge from <arg name="source" /> to <arg name="target"/>. Analogous to <field name="the_u_multiedge" />.</p>
1540 <type-method name="rekey_with_index">
1544 <arg identifier="offset">
1546 <named-type name="Integer"/>
1548 <default><inline>'0</inline></default>
1553 <parameterized-type name="Graph">
1554 <parameter-type name="N"/><parameter-type name="E"/>
1555 </parameterized-type>
1559 <p>Constructs a graph where each new node key is obtained by adding <arg name="offset"/> to the current node's <field name="index"/>. If <arg name="index" /> is left at its default, this will generate a graph where the node keys coincide with the node indices.</p>
1564 <type-method name="with_node_values">
1568 <arg identifier="values">
1570 <parameterized-type name="Seq">
1571 <named-type name="Value"/>
1572 </parameterized-type>
1578 <parameterized-type name="Graph">
1579 <parameter-type name="N"/><parameter-type name="E"/>
1580 </parameterized-type>
1584 <p>Constructs a graph with node values given by <arg name="values"/>. The order in <arg name="value" /> corresponds to node indices.</p>
1585 <p>The resulting graph will share most of its data except the node values with the original graph..</p>
1590 <type-method name="with_edge_values">
1594 <arg identifier="values">
1596 <parameterized-type name="Seq">
1597 <named-type name="Value"/>
1598 </parameterized-type>
1604 <parameterized-type name="Graph">
1605 <parameter-type name="N"/><parameter-type name="E"/>
1606 </parameterized-type>
1610 <p>Constructs a graph with edge values given by <arg name="values"/>. The order in <arg name="value" /> corresponds to edge indices.</p>
1611 <p>The resulting graph will share most of its data except the edge values with the original graph..</p>
1616 <type-method name="induced_subgraph">
1620 <arg identifier="nodes">
1622 <parameterized-type name="Seq">
1623 <parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1624 </parameterized-type>
1630 <parameterized-type name="Graph">
1631 <parameter-type name="N"/><parameter-type name="E"/>
1632 </parameterized-type>
1636 <p>Constructs the subgraph indiced by the specified nodes.</p>
1637 <p>The node indices in the resulting graph will correspond to the positions in <arg name="nodes" />. To just reorder the nodes of a graph, use this method with all nodes in <arg name="nodes"/>.</p>
1642 <type-method name="spanning_subgraph">
1646 <arg identifier="edges">
1648 <parameterized-type name="Seq">
1649 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1650 </parameterized-type>
1656 <parameterized-type name="Graph">
1657 <parameter-type name="N"/><parameter-type name="E"/>
1658 </parameterized-type>
1662 <p>Constructs the spanning subgraph with the specified edges.</p>
1663 <p>The nodes of the resulting graph are identical to those of the original graph (including their indices).</p>
1670 <p>The <self /> data structure is designed to fill the gap created by the functional language's restriction to non-recursive data structures. A recursive data structure is when a value either directly or indirectly contains a reference to itself, like a node with a reference to its neighbor, which in turn has a reference back to the first node. In an imperative language, it is possible to have nodes containing references to their adjacent nodes, and this is often the most natural and efficient way of modeling a graph.</p>
1671 <p>Since <str-Shapes /> is functional, however, there cannot be recursive data structures, and so one has to model graphs in a non-recursive manner. Of course, there are many such representations, one of the most common being some kind of adjacency matrix, where each non-zero entry in the matrix represents an edge in the graph, with the row in the matrix corresponding to the source node, and the column in the matrix corresponding to the target node. While such a matrix representation may be good for representing the graph structure alone, it is rather inconvenient when one wants values associated with the nodes and edges, and it may also be inefficient for certain operations depending on the details of the matrix representation.</p>
1672 <p><str-Shapes /> uses function calls to break the cycles that would otherwise result in recursive data structures. This sometimes turns out as member functions that are often called with no arguments, but that could still not be plain non-function fields.</p>
1676 <coretype name="Walk">
1678 <parameter name="N">
1680 <p>Type of node values.</p>
1683 <parameter name="E">
1685 <p>Type of edge values.</p>
1690 <p>The <self /> type is a walk in a particular graph. A walk has a start and an end node, and a sequence of edges that can be traced in order to get from the start node to the end node.</p>
1693 <named-type name="Graph" />
1698 <type-field name="start">
1699 <type><parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type></type>
1700 <description><p>The start node of the walk.</p></description>
1702 <type-field name="end">
1703 <type><parameterized-type name="Node"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type></type>
1704 <description><p>The end node of the walk.</p></description>
1706 <type-field name="edges">
1708 <parameterized-type name="Seq">
1709 <parameterized-type name="Edge"><parameter-type name="N"/><parameter-type name="E"/></parameterized-type>
1710 </parameterized-type>
1712 <description><p>The edges of the walk.</p></description>
1714 <type-field name="edge_count">
1715 <type><named-type name="Integer" /></type>
1716 <description><p>Number of edges in the walk, also known as the <em>length</em> of the walk.</p></description>
1719 <type-field name="closed?">
1720 <type><named-type name="Boolean" /></type>
1721 <description><p>The walk is closed if the start and end nodes are the same, that is, the opposite of being open.</p></description>
1723 <type-field name="open?">
1724 <type><named-type name="Boolean" /></type>
1725 <description><p>The walk is open if the start and end nodes are different, that is, the opposite of being closed.</p></description>
1727 <type-field name="simple?">
1728 <type><named-type name="Boolean" /></type>
1729 <description><p>The walk is simple if all nodes along the walk are distinct, except that the start and end nodes may be the same.</p></description>
1731 <type-field name="trail?">
1732 <type><named-type name="Boolean" /></type>
1733 <description><p>The walk is a trail if all edges are distinct.</p></description>
1735 <type-field name="node_cover?">
1736 <type><named-type name="Boolean" /></type>
1738 <p>The walk is a node cover if it visits every node of the graph it belongs to.</p>
1739 <p>For example, a Hamiltonian walk is a simple node cover.</p>
1742 <type-field name="edge_cover?">
1743 <type><named-type name="Boolean" /></type>
1745 <p>The walk is an edge cover if it traverses every edge of the graph it belongs to.</p>
1746 <p>Note that an Eulerian cycle is a closed trail that is also an edge cover.</p>
1749 <type-field name="graph">
1751 <parameterized-type name="Graph">
1752 <parameter-type name="N"/><parameter-type name="E"/>
1753 </parameterized-type>
1756 <p>Graph to which the walk belongs.</p>
1761 <p>A <self /> is the representation of a traversal of a graph along its edges. In general, nodes and edges may be visited zero or more times along the walk, but by placing constraints on the <named-type name="Boolean" /> properties of the walk, one obtains more specialized types of walks, such as trails or Eulerian cycles.</p>
1762 <example-with-output title="Graph walks" internal-id="types/graph-walk">
1763 <source file="doc/graph-walk.blank">
1764 <![CDATA[<!--#include depth="0" virtual="$(BUILDDIR)$(EXAMPLES)doc/graph-walk.blank" -->]]>
1767 <![CDATA[<!--#include depth="0" virtual="$(BUILDDIR)$(EXAMPLES)doc/graph-walk.stdout" -->]]>
1770 <p>Examining the properties and iterating over a <named-type name="Walk" />.</p>
1772 </example-with-output>
1776 <coretype name="NodeData">
1778 <parameter name="N">
1780 <p>Type of node values.</p>
1785 <p>The <self /> type is a structure holding data used to define a node during graph construction.</p>
1786 <p>Strictly speaking, the type only consists of the field <field name="key" />, since the other field may be omitted where <self /> is used to construct graphs. </p>
1789 <named-type name="Node" /> <value namespace="..Shapes..Data" name="graph" /> <named-type name="EdgeData" />
1794 <type-field name="key">
1795 <type><named-type name="GraphKey" /></type>
1796 <description><p>Node key.</p></description>
1798 <type-field name="value">
1799 <type><parameter-type name="N" /></type>
1800 <description><p>The value associated with the node.</p></description>
1802 <type-field name="partition">
1803 <type><union-type><named-type name="GraphKey" /><named-type name="Void" /></union-type></type>
1804 <description><p>Graph partition. Unless <value-the-void />, the node may not be connected to other nodes in the same partition.</p></description>
1809 <coretype name="EdgeData">
1811 <parameter name="E">
1813 <p>Type of edge values.</p>
1818 <p>The <self /> type is a structure holding data used to define an edge during graph construction.</p>
1819 <p>Strictly speaking, the type only consists of the fields <field name="source" /> and <field name="target" />, since the other fields have default values where <self /> is used to construct graphs. </p>
1822 <named-type name="Edge" /> <value namespace="..Shapes..Data" name="graph" /> <named-type name="NodeData" />
1827 <type-field name="source">
1828 <type><named-type name="GraphKey" /></type>
1829 <description><p>The source of a directed edge, or one of the nodes incident to an undirected edge.</p></description>
1831 <type-field name="target">
1832 <type><named-type name="GraphKey" /></type>
1833 <description><p>The target of a directed edge, or one of the nodes incident to an undirected edge.</p></description>
1835 <type-field name="value">
1836 <type><parameter-type name="E" /></type>
1837 <description><p>The value associated with the edge.</p></description>
1839 <type-field name="label">
1840 <type><named-type name="GraphKey" /></type>
1841 <description><p>A label which may be used in combination with <field name="source" /> and <field name="target" /> to identify the edge. Note that, in general, the label does not have to be unique, even for a given pair of <field name="source" /> and <field name="target" />.</p></description>
1843 <type-field name="directed">
1844 <type><named-type name="Boolean" /></type>
1845 <description><p>Whether the edge is directed or undirected.</p></description>