2
$\begingroup$

In the following code, I expected that only the edge between vertices 0 and 1 would be removed.

EdgeContract[
 Graph[{0, 2, 
   1}, {Null, {{1, 3}, {1, 2}, {1, 2}, {1, 2}, {1, 2}}, {Null, 1, 2, 
    3, 4}}, 
     {FormatType -> TraditionalForm, 
   ImageSize -> {407.25, Automatic}, EdgeLabels -> {"EdgeTag"}, 
   GraphLayout -> {"Dimension" -> 2}, 
       ImageSize -> {396., Automatic}, VertexLabels -> {"Name"}}], 
 UndirectedEdge[0, 1]]

enter image description here

Is this a bug? Is there a workaround on this?

(13.3.0 for Linux x86 (64-bit))

$\endgroup$
5
  • $\begingroup$ Yes, most likely a bug. It seems that SimpleGraph is applied first. $\endgroup$ Commented May 1 at 12:04
  • $\begingroup$ Please do report it. $\endgroup$ Commented May 1 at 14:51
  • 1
    $\begingroup$ @Szabolcs Okay, I just filled the form. $\endgroup$ Commented May 1 at 22:39
  • $\begingroup$ On version 13.0.1 the bug is not present. $\endgroup$ Commented May 4 at 9:35
  • $\begingroup$ This phenomenon also occurs in version 14.0.0 $\endgroup$ Commented May 4 at 10:27

1 Answer 1

0
$\begingroup$

Here is a workaround, assuming all edges are undirected:

g = Graph[{0, 2, 1}, {Null, {{1, 3}, {1, 2}, {1, 2}, {1, 2}, {1, 2}}, {Null, 1, 2, 3, 4}}, {FormatType -> TraditionalForm, 
   ImageSize -> {407.25, Automatic}, EdgeLabels -> {"EdgeTag"}, 
   GraphLayout -> {"Dimension" -> 2}, ImageSize -> {396., Automatic}, 
   VertexLabels -> {"Name"}}]

0

ClearAll[myEdgeContract];
myEdgeContract[g_Graph, UndirectedEdge[v1_, v2_]] := 
  Module[{newvertices, newedges, options},
   newvertices = Union[VertexList[g] /. v1 -> v2]; 
   newedges = 
    DeleteCases[EdgeList[g], 
      UndirectedEdge[v1, v2, ___] | UndirectedEdge[v2, v1, ___]] /. 
     UndirectedEdge[u_, v_, t___] :> 
      UndirectedEdge[u /. v1 -> v2, v /. v1 -> v2, t];
   options = Options[g];
   Graph[newvertices, newedges, options]];

myEdgeContract[g, UndirectedEdge[0, 1]]

1

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.