Skip to main content
Tweeted twitter.com/#!/StackMma/status/340605615082717184
deleted 407 characters in body
Source Link
Juho
  • 1.9k
  • 1
  • 20
  • 34

Consider the following simplecomplete graph produced byon 3 vertices.

g = CompleteGraph[3, VertexLabels -> "Name", ImagePadding -> 10]; PropertyValue[{g, 1 \[UndirectedEdge] 2}, EdgeStyle] = Red; PropertyValue[{g, 1 \[UndirectedEdge] 3}, EdgeStyle] = Green; PropertyValue[{g, 2 \[UndirectedEdge] 3}, EdgeStyle] = Blue; 

enter image description hereenter image description here

Then, a method gives me a list of interesting edges, say $\{(1,2),(2,3)\}$. I want to get a subgraph of $g$ that corresponds to precisely the given edgelist, such that the edge properties are preserved, in this case colors. How can I get a subgraph corresponding precisely to a given set of edgesdo this?

If I use Subgraph[g,e,Options[g]]e] with e = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}, I get back the original graph. This does preserve the colors, but includes an extra edge, namely $(3,1)$ that I don't want. However, Subgraph does have a pattern as an argument. That might do the trick, but perhaps there's an easier way.

Consider the following simple graph produced by

g = CompleteGraph[3, VertexLabels -> "Name", ImagePadding -> 10]; PropertyValue[{g, 1 \[UndirectedEdge] 2}, EdgeStyle] = Red; PropertyValue[{g, 1 \[UndirectedEdge] 3}, EdgeStyle] = Green; PropertyValue[{g, 2 \[UndirectedEdge] 3}, EdgeStyle] = Blue; 

enter image description here

Then, a method gives me a list of interesting edges, say $\{(1,2),(2,3)\}$. I want to get a subgraph of $g$ that corresponds to precisely the given edgelist, such that the edge properties are preserved, in this case colors. How can I get a subgraph corresponding precisely to a given set of edges?

If I use Subgraph[g,e,Options[g]] with e = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}, I get back the original graph. This does preserve the colors, but includes an extra edge, namely $(3,1)$ that I don't want. However, Subgraph does have a pattern as an argument. That might do the trick, but perhaps there's an easier way.

Consider the complete graph on 3 vertices.

enter image description here

Then, a method gives me a list of interesting edges, say $\{(1,2),(2,3)\}$. I want to get a subgraph of $g$ that corresponds to precisely the given edgelist. How can I do this?

If I use Subgraph[g,e] with e = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}, I get back the original graph. This does preserve the colors, but includes an extra edge, namely $(3,1)$ that I don't want. However, Subgraph does have a pattern as an argument. That might do the trick, but perhaps there's an easier way.

added 241 characters in body
Source Link
Juho
  • 1.9k
  • 1
  • 20
  • 34

How docan I make Subgraph outputget precisely the subgraph corresponding to a set of edges?

Consider the following simple graph that contains a cycle: enter image description here

Then, I have a list of edges that form a path in the graph, such as $\{ (4,1),(1,3),(3,2) \}$. Using Subgraph and this set of edges, I get the edge $(1,2)$ included in the output. How do I get around this? Here's an example, where the expected output is a path graph, but instead I get the original graph.produced by

eg = {4 \[UndirectedEdge] 1CompleteGraph[3, 1VertexLabels \[UndirectedEdge]-> 3"Name", 3ImagePadding \[UndirectedEdge]-> 210]; PropertyValue[{g, 21 \[UndirectedEdge] 12};,  gEdgeStyle] = Graph[eRed; PropertyValue[{g, VertexLabels1 ->\[UndirectedEdge] "Name"3}, ImagePaddingEdgeStyle] ->= 10]; Green; Subgraph[gPropertyValue[{g, Most[e]2 \[UndirectedEdge] 3}, Options[g]]EdgeStyle] = Blue; 

enter image description here

Then, a method gives me a list of interesting edges, say $\{(1,2),(2,3)\}$. I noticedwant to get a subgraph of $g$ that corresponds to precisely the given edgelist, such that the edge properties are preserved, in this case colors. How can I get a subgraph corresponding precisely to a given set of edges?

If I use Subgraph[g,e,Options[g]] with e = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}, I get back the original graph. This does preserve the colors, but includes an extra edge, namely $(3,1)$ that I don't want. However, Subgraph can takedoes have a pattern as an argument, and I'm guessing that. That might do the trick. But, but perhaps there's an easier way.

How do I make Subgraph output precisely the subgraph corresponding to a set of edges?

Consider the following simple graph that contains a cycle: enter image description here

Then, I have a list of edges that form a path in the graph, such as $\{ (4,1),(1,3),(3,2) \}$. Using Subgraph and this set of edges, I get the edge $(1,2)$ included in the output. How do I get around this? Here's an example, where the expected output is a path graph, but instead I get the original graph.

e = {4 \[UndirectedEdge] 1, 1 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 1};  g = Graph[e, VertexLabels -> "Name", ImagePadding -> 10];  Subgraph[g, Most[e], Options[g]] 

I noticed that Subgraph can take a pattern as an argument, and I'm guessing that might do the trick. But perhaps there's an easier way.

How can I get precisely the subgraph corresponding to a set of edges?

Consider the following simple graph produced by

g = CompleteGraph[3, VertexLabels -> "Name", ImagePadding -> 10]; PropertyValue[{g, 1 \[UndirectedEdge] 2}, EdgeStyle] = Red; PropertyValue[{g, 1 \[UndirectedEdge] 3}, EdgeStyle] = Green; PropertyValue[{g, 2 \[UndirectedEdge] 3}, EdgeStyle] = Blue; 

enter image description here

Then, a method gives me a list of interesting edges, say $\{(1,2),(2,3)\}$. I want to get a subgraph of $g$ that corresponds to precisely the given edgelist, such that the edge properties are preserved, in this case colors. How can I get a subgraph corresponding precisely to a given set of edges?

If I use Subgraph[g,e,Options[g]] with e = {1 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 3}, I get back the original graph. This does preserve the colors, but includes an extra edge, namely $(3,1)$ that I don't want. However, Subgraph does have a pattern as an argument. That might do the trick, but perhaps there's an easier way.

edited title
Source Link
Juho
  • 1.9k
  • 1
  • 20
  • 34

Why doesn't How do I make Subgraph output precisely the subgraph corresponding to a set of edges?

Consider the following simple graph that contains a cycle: enter image description here

Then, I have a list of edges that form a path in the graph, such as $\{ (4,1),(1,3),(3,2) \}$. Using Subgraph and this set of edges, I get the edge $(1,2)$ included in the output. Why, and howHow do I get around this? Here's an example, where the expected output is a path graph, but instead I get the original graph.

e = {4 \[UndirectedEdge] 1, 1 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 1}; g = Graph[e, VertexLabels -> "Name", ImagePadding -> 10]; Subgraph[g, Most[e], Options[g]] 

I noticed that Subgraph can take a pattern as an argument, and I'm guessing that might do the trick. But perhaps there's an easier way.

Why doesn't Subgraph output precisely the subgraph corresponding to a set of edges?

Consider the following simple graph that contains a cycle: enter image description here

Then, I have a list of edges that form a path in the graph, such as $\{ (4,1),(1,3),(3,2) \}$. Using Subgraph and this set of edges, I get the edge $(1,2)$ included in the output. Why, and how do I get around this? Here's an example, where the expected output is a path graph, but instead I get the original graph.

e = {4 \[UndirectedEdge] 1, 1 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 1}; g = Graph[e, VertexLabels -> "Name", ImagePadding -> 10]; Subgraph[g, Most[e], Options[g]] 

I noticed that Subgraph can take a pattern as an argument, and I'm guessing that might do the trick. But perhaps there's an easier way.

How do I make Subgraph output precisely the subgraph corresponding to a set of edges?

Consider the following simple graph that contains a cycle: enter image description here

Then, I have a list of edges that form a path in the graph, such as $\{ (4,1),(1,3),(3,2) \}$. Using Subgraph and this set of edges, I get the edge $(1,2)$ included in the output. How do I get around this? Here's an example, where the expected output is a path graph, but instead I get the original graph.

e = {4 \[UndirectedEdge] 1, 1 \[UndirectedEdge] 3, 3 \[UndirectedEdge] 2, 2 \[UndirectedEdge] 1}; g = Graph[e, VertexLabels -> "Name", ImagePadding -> 10]; Subgraph[g, Most[e], Options[g]] 

I noticed that Subgraph can take a pattern as an argument, and I'm guessing that might do the trick. But perhaps there's an easier way.

Source Link
Juho
  • 1.9k
  • 1
  • 20
  • 34
Loading