VertexLabels not inherited by edges?

I'd like to custom name the vertices of a (complete) graph and have those names reflected in the edges.

shiftGraph produces a complete graph with vertices labels from imin to imax.

             CompleteGraph[imax - imin + 1, DirectedEdges -> True,
VertexLabels -> Thread[Rule[Range[1, imax - imin + 1],Range[imin, imax]]]];


shiftGraph[2,4] yields:

But those vertex labels are not inherited by the edges:

EdgeList[shiftGraph[2, 4]]


yields

{1 [DirectedEdge] 2, 1 [DirectedEdge] 3, 2 [DirectedEdge] 1, 2 [DirectedEdge] 3, 3 [DirectedEdge] 1, 3 [DirectedEdge] 2}

Is that expected or desirable? I suppose the fix is to apply the VertexLabels rules to the edges. Cleaner methods?

• VertexLabels only affects the display of the vertices - the underlying vertex names are still 1 to n (compare also with Graph). Unfortunately, you can't specify the vertex names for CompleteGraph upon construction, so you'll have to rename them after the fact using VertexReplace Mar 13 at 18:52

You can use IndexGraph to get the desired result:

ClearAll[shiftGraph]
shiftGraph[imin_, imax_, o : OptionsPattern[Graph]] :=
Graph[IndexGraph[CompleteGraph[imax - imin + 1, DirectedEdges -> True], imin], o]

shiftGraph[2, 4, VertexLabels -> "Name", EdgeLabels -> "Name"]


EdgeList[shiftGraph[2, 4]]


• Perfect! Thank you. The language is so rich, it is impossible to be familiar with all its many features.
– JV3
Mar 15 at 13:05

IGCompleteGraph from IGraph/M makes it easy to create a complete graph with the vertex names of your choice.

EdgeList@IGCompleteGraph[{"a", "b", "c", "d"}]
(* {"a" \[UndirectedEdge] "b", "a" \[UndirectedEdge] "c",
"a" \[UndirectedEdge] "d", "b" \[UndirectedEdge] "c",
"b" \[UndirectedEdge] "d", "c" \[UndirectedEdge] "d"} *)