6
$\begingroup$

In the examples I have seen, graph vertices in Mathematica are usually explicit small integers. However, Wolfram documentation says that vertices can be any arbitrary expression (eg., george, x^2, London, 5).

Nevertheless, it seems that vertices are always referred to by number, that is, by the position of the vertex expression in VertexList[gr]. This can be confusing. For example, if I build a graph like this, using nonconsecutive vertex numbers,

Graph[1<->2, 2<->10, 10<->3, 3<->4]

then I still have to refer to the vertices as if I had made each vertex number equal to its creation order, as if I had built the graph with strictly consecutive vertex numbers:

Graph[1<->2, 2<-3 ,3<->4, 4<->1] 

Am I understanding this correctly?

$\endgroup$
3
$\begingroup$

No, you can refer to the vertices in any order and it will pair it accordingly. Compare the following:

g1 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, VertexLabels -> "Name"]

enter image description here

g2 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, 
    VertexLabels -> {1 -> "a", 10 -> "b", 2 -> "c", 4 -> "d", 3 -> "e"}]

enter image description here

Note that in the second case, I named the vertices in a different order than what was entered and did not use sequential numbers.

| improve this answer | |
$\endgroup$
  • $\begingroup$ But if I write: codeg1 = Graph[{1 <-> 2, 2 <-> 10, 10 <-> 3, 3 <-> 4}, VertexLabels -> "Name"]; GraphPlot[g1,VertexLabeling->True] then the result uses only the digits 1 through 8. That is, at the very least, confusing, don't you think? $\endgroup$ – Ralph Dratman Jul 12 '12 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.