Digraphs icon indicating copy to clipboard operation
Digraphs copied to clipboard

Add new variant/sibling of `DigraphByEdges` that can accept edges defined in terms of labelled vertices

Open wilfwilson opened this issue 6 months ago • 1 comments

@RussWoodroofe, at GAP Days Summer 2025 in Koper, was wanting to create the Petersen digraph, in the way that was most intuitive to him.

You can think of the Petersen graph as the graph with ten points, where the vertices are the 2-element subsets of [1 .. 5], and vertices are joined by an edge if they are disjoint:

gap> petersen := PetersenGraph();;
gap> D := Digraph(Combinations([1 .. 5], 2), {x, y} -> IsEmpty(Intersection(x, y)));;
gap> IsIsomorphicDigraph(petersen, D);
true

Russ wanted to think of an edge as a pair of these 2-element subsets, and define the graph to the Digraphs package by giving a list of such pairs. Currently, this is not supported because DigraphByEdges just considers an edge as a pair of integers, so a pair of pairs is not allowed.

But we could allow this: let the dear user specify a list of vertex labels, and then define adjacency via an edge list given in terms of those vertex labels.

Behind the scenes, we could implement:

Digraph(vertex_labels, edges);

where edges is a list of pairs in vertex_labels, as:

D := DigraphByEdges(List(edges, x -> [Position(vertex_labels, x[1]), Position(vertex_labels, x[2])]));;
SetDigraphVertexLabels(D, vertex_labels);

wilfwilson avatar Aug 26 '25 14:08 wilfwilson

Would also be quite straightforward to use Digraph(vertices, source, range) for this, i.e.:

vertex_labels := Union(edges);
Digraph(vertex_labels, List(edges, x -> x[1]), List(edges, x -> x[2]));
SetDigraphVertexLabels(D, vertex_labels);

which is slightly shorter* but has no further merit over your suggestion @wilfwilson that I can see.

  • if not including the first line

james-d-mitchell avatar Aug 26 '25 15:08 james-d-mitchell