Get complete graph from set of vertices?
RelationGraph[UnsameQ, vertices, VertexLabels -> "Name"]
Alternatively, you can use any of the following to get the same result:
Graph[UndirectedEdge @@@ Subsets[vertices, {2}], VertexLabels -> "Name"]
AdjacencyGraph[vertices, ConstantArray[1, {5,5}]-IdentityMatrix[5], VertexLabels -> "Name"]
SetProperty[VertexReplace[#, Thread[VertexList@# -> vertices]] &@ CompleteGraph[5],
VertexLabels -> "Name"]
To change just the labels you can use:
CompleteGraph[5, VertexLabels -> {k_ :> vertices[[k]]}]
same picture
Using AdjacencyGraph:
AdjacencyGraph[vertices,
AdjacencyMatrix[CompleteGraph[Length[vertices]]]]
Another way is with AdjacencyGraph
.
SimpleGraph[
AdjacencyGraph[vertices, ConstantArray[1, Length[vertices] {1, 1}]],
VertexLabels -> Automatic
]
With IGraph/M, you can zero out the matrix diagonal directly:
AdjacencyGraph[vertices,
IGZeroDiagonal@ConstantArray[1, Length[vertices] {1, 1}],
VertexLabels -> Automatic]