1
$\begingroup$

Can the standard VertexContract or VertexReplace functions display a name for the collapsed node ?

Here is a minimal example:

`adg = Graph[{"U" \[DirectedEdge] "D", "D" \[DirectedEdge] "T", "T" \[DirectedEdge] "Q"}, VertexLabels -> "Name"]` VertexList @ % {"U", "D", "T", "Q"} 

VertexContract displays an anonymous node, even though the name is the list:

 adgagg2 = VertexReplace[SimpleGraph @ VertexContract[adg, {"D", "T"}], "D" -> "B"] VertexList[adgagg2] (*{"U", "B", "Q"}*) 

VertexReplace removes the labels in the display:

 adgagg = SimpleGraph@VertexReplace[adg, {"D" -> "B", "T" -> "B"}] VertexList[adgagg] (*{"U", "B", "Q"}*) 

Just wondering if I am missing a simple option somewhere. Clearly this can be addressed programmatically.

Best

Trad.

$\endgroup$
3
  • 1
    $\begingroup$ adgagg = SimpleGraph[VertexReplace[adg, {"D" -> "B", "T" -> "B"}], VertexLabels -> "Name"] ? $\endgroup$ Commented Feb 25, 2016 at 14:00
  • 1
    $\begingroup$ or SetProperty[VertexReplace[adg, "D" -> "B"], VertexLabels -> "Name"] $\endgroup$ Commented Feb 25, 2016 at 14:03
  • $\begingroup$ Indeed. Thanks. Trad. $\endgroup$ Commented Feb 25, 2016 at 14:48

1 Answer 1

2
$\begingroup$

You may use for example

SetProperty[VertexReplace[adg, "D" -> "B"], VertexLabels -> "Name"] 
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.