1 (kill(all), load(graphs), 0);
4 /* a helper macro to capture output to a string ("print to string") */
5 (p2s([L])::=buildq([L, f: gensym()],
6 block([f: make_string_output_stream()],
7 with_stdout(f, splice(L)),
8 get_output_stream_string(f))), 'done);
11 p2s(print_graph(create_graph([1,2,3], [[1,2], [2,3], [1,3]])));
13 Graph on 3 vertices with 3 edges.
20 p2s(print_graph(create_graph(
28 Digraph on 4 vertices with 4 arcs.
36 p2s(print_graph(circulant_graph(10, [1, 3])));
38 Graph on 10 vertices with 20 edges.
52 (g:create_graph([1,2,3,4,5],[[1,2],[2,3],[1,3],[4,5]]), 0);
59 [[4,5],[1,3],[2,3],[1,2]];
70 connected_components(g);
73 vertex_distance(1,5,g);
76 (g:create_graph([1,2,3,4,5],[[1,2],[2,3],[1,3],[3,4],[4,5]]), 0);
85 biconnected_components(g);
86 [[1,2,3],[3,4],[4,5]];
88 vertex_distance(1,5,g);
94 is_connected(empty_graph(1));
97 is_connected(empty_graph(0));
100 is_connected(complete_graph(4));
103 max_clique(complete_graph(5));
106 max_clique(empty_graph(5));
109 max_clique(empty_graph(0));
112 is_bipartite(flower_snark(4));
115 chromatic_number(flower_snark(4));
118 chromatic_index(flower_snark(4));
121 is_bipartite(flower_snark(5));
124 chromatic_number(flower_snark(5));
127 chromatic_index(flower_snark(5));
130 is_bipartite(empty_graph(1));
133 is_bipartite(empty_graph(0));
136 is_bipartite(complete_graph(0));
139 chromatic_number(empty_graph(0));
142 chromatic_number(empty_graph(1));
145 chromatic_number(empty_graph(2));
148 chromatic_number(complete_graph(2));
151 chromatic_index(empty_graph(3));
154 chromatic_index(cycle_graph(3));
157 chromatic_index(cycle_graph(4));
160 girth(flower_snark(4));
163 girth(flower_snark(5));
166 girth(flower_snark(6));
169 girth(flower_snark(7));
172 odd_girth(flower_snark(4));
175 odd_girth(flower_snark(5));
178 odd_girth(flower_snark(6));
181 odd_girth(flower_snark(7));
184 is_isomorphic(empty_graph(0), empty_graph(0));
187 is_isomorphic(empty_digraph(0), empty_digraph(0));
190 is_isomorphic(empty_graph(1), empty_graph(1));
193 is_isomorphic(graph_product(path_graph(3), path_graph(5)), graph_product(path_graph(5), path_graph(3)));
196 is_isomorphic(graph_union(cycle_graph(3), cycle_graph(3)), cycle_graph(6));
199 is_isomorphic(petersen_graph(), complement_graph(line_graph(complete_graph(5))));
202 is_planar(empty_graph(0));
205 is_planar(empty_graph(2));
208 is_planar(dodecahedron_graph());
211 is_planar(flower_snark(5));
214 is_planar(complete_graph(4));
217 is_planar(complete_graph(5));
220 is_planar(complete_graph(6));
223 is_planar(complete_bipartite_graph(3,3));
226 is_planar(complete_bipartite_graph(2,4));
229 is_tree(empty_graph(0));
232 is_tree(empty_graph(1));
235 is_tree(empty_graph(2));
238 is_tree(path_graph(4));
241 is_tree(cycle_graph(4));
244 (g:graph_union(cycle_graph(3), cycle_graph(4)), 0);
247 vertex_connectivity(g);
250 edge_connectivity(g);
253 (add_edge([0,3], g), 0);
256 vertex_connectivity(g);
259 edge_connectivity(g);
265 (add_edge([0,4], g), 0);
268 vertex_connectivity(g);
274 edge_connectivity(g);
277 (g: graph_union(complete_graph(5), complete_graph(5)), connect_vertices([5,6],[2,3,4], g), 0);
280 vertex_connectivity(g);
283 vertex_connectivity(path_graph(2));
286 edge_connectivity(path_graph(2));
289 vertex_connectivity(empty_graph(1));
292 edge_connectivity(empty_graph(1));
295 (g:graph6_decode("H|twgsN"),0);
301 vertex_connectivity(g);
304 edge_connectivity(g);
324 topological_sort(path_digraph(3));
327 topological_sort(cycle_digraph(3));
330 /* Check for edge weight copying on digraphs (Bug 2541) */
331 block([dg: cycle_digraph(3), dg2],
332 set_edge_weight([0,1], 100, dg),
334 is (get_edge_weight([0,1], dg2) = get_edge_weight([0,1], dg)));
337 edge_coloring(cycle_graph(4));
338 [2,[[[0,1],2],[[1,2],1],[[2,3],2],[[0,3],1]]]$
340 edge_coloring(petersen_graph());
342 [[[0,5],3],[[5,7],1],[[0,1],1],[[1,6],2],[[6,8],1],[[1,2],3],[[2,7],4],
343 [[7,9],2],[[2,3],2],[[3,8],3],[[5,8],2],[[3,4],1],[[4,9],4],[[6,9],3],
346 /* larger example which triggers ADJUST-ARRAY
347 * this example is to ensure that result of shortest_weighted_path doesn't change
349 block ([g200_20 : petersen_graph(200, 20)],
350 for e in edges(g200_20) do set_edge_weight(e, e[1]+e[2], g200_20),
351 shortest_weighted_path(0, 100, g200_20));
352 [3100, [0, 200, 220, 240, 260, 280, 300, 100]];
354 /* test vertex labels */
356 (vv: [[17, "foo"], [29, "foo"], [1729, "bar"], 2, 4, 6, 8],
357 G: create_graph (vv, []),
358 get_unique_vertex_by_label ("bar", G));
361 get_unique_vertex_by_label ("baz", G);
364 errcatch (get_unique_vertex_by_label ("foo", G));
367 get_all_vertices_by_label ("foo", G);
370 (for v in [2, 17, 29, 4, 6] do set_vertex_label (v, "baz", G),
371 get_all_vertices_by_label ("baz", G));
374 makelist (get_vertex_label (v, G), v, [8, 2, 4, 6, 1729, 17, 29]);
375 [false, "baz", "baz", "baz", "bar", "baz", "baz"];