ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Mon, 26 Jul 2021 20:42:36 +0200Rooted Product Graphs on Sagemathhttps://ask.sagemath.org/question/58122/rooted-product-graphs-on-sagemath/How does one implement rooted product graphs on Sagemath? For those who haven't heard about it before, there is a Wikipedia page for it!
Any help would be highly appreciated!
Link: https://en.wikipedia.org/wiki/Rooted_product_of_graphsmorganhouseMon, 26 Jul 2021 20:42:36 +0200https://ask.sagemath.org/question/58122/Why does Sage 'stall' in this graph calculation?https://ask.sagemath.org/question/45210/why-does-sage-stall-in-this-graph-calculation/I was doing a demonstration for an intro graph theory course when it suddenly took a very long time to even look through 10,000 graphs. At home I isolated the troublesome code, which is this:
sage: for g in graphs(10):
....: x=g.edges();
Removing the x=, I found something surprising, the output stalls for >3min once it gets to the following graph:
[(0, 1, None),
(0, 2, None),
(0, 3, None),
(0, 4, None),
(0, 5, None),
(0, 6, None),
(0, 7, None),
(0, 8, None),
(1, 3, None),
(2, 3, None),
(3, 4, None),
(3, 5, None),
(3, 6, None),
(3, 7, None),
(3, 8, None),
(3, 9, None)]
Moreover on CoCalc [with a free server] this issue doesn't come up; it happily works through all of the graphs on 10 vertices with no discernable pauses. (Of course it takes a while to get through all 12 million, but I can see with debug statements that it is chugging along.)
The calculation pauses at other points but for much more reasonable lengths of time (<5sec).
Any idea what is going on here?aleph_twoSun, 27 Jan 2019 17:51:39 +0100https://ask.sagemath.org/question/45210/Find copy of subgraph and check if graph induced by neighborhood of particular vertex is bipartitehttps://ask.sagemath.org/question/46149/find-copy-of-subgraph-and-check-if-graph-induced-by-neighborhood-of-particular-vertex-is-bipartite/I asked Sage to generate all graphs on 7 vertices and 12 edges with clique number 4 using the command
g7_4=[g for g in graphs.nauty_geng('7 12') if g.clique_number()==4]
Next I defined a graph H as follows:
H=graphs.CompleteGraph(4)
H.add_edges([(4,0), (4,1), (4,5)])
For every induced isomorphic copy H' of H in each graph g in g7_4 I want Sage to find out if the subgraph induced by the neighborhood of the isomorphic copy in H' of the vertex labeled 4 in H is bipartite or not.
The issue here is that I want to target the vertex in H' that plays the role of 4 in H, but I can't figure out how to do that.
Here is my feeble attempt:
for g in g7_4:
for p in g.subgraph_search_iterator(H,induced=True): #for each induced isomorphic copy of H in g
N=p.subgraph(Set(H.neighbors(4))) #let N be subgraph induced by neighborhood of 4 (vertex from H)
if not N.is_bipartite():
print(g7_4.index(g), 'bipartite')
else:
print(g7_4.index(g), 'not bipartite')
Please help me with my code! I am still new to Sage. Thank you!merluzaSun, 14 Apr 2019 01:37:28 +0200https://ask.sagemath.org/question/46149/Building Graphs with Specific Properties Using Sagehttps://ask.sagemath.org/question/45944/building-graphs-with-specific-properties-using-sage/I would like to use Sage to build graphs with particular properties. I know how to call a program called "nauty" to ask Sage to generate, for example, all graphs on 8 vertices with 16 edges with clique number 4. However, I would like to add more properties.
Is it possible to have Sage generate all graphs with clique number 4 so that all vertices that are contained in a 4-clique satisfy a minimum degree condition? Or is it in general possible to have a particular subset of vertices satisfy a degree condition?
Thank you.merluzaFri, 29 Mar 2019 21:32:22 +0100https://ask.sagemath.org/question/45944/Latex Transition Problemhttps://ask.sagemath.org/question/45514/latex-transition-problem/ I have been getting this error UnboundLocalError: local variable 'xmin' referenced before assignment
and I have been wondering why the error is present. And how I could fix it to get the LaTex for it.
Sage: from sage.graphs.graph_plot import GraphPlot
Sage: options = {
....: 'vertex_size': 200,
....: 'vertex_labels': True,
....: 'layout': None,
....: 'edge_style': 'solid',
....: 'edge_color': 'black',
....: 'edge_colors': None,
....: 'edge_labels': False,
....: 'iterations': 50,
....: 'tree_orientation': 'down',
....: 'heights': None,
....: 'graph_border': False,
....: 'talk': False,
....: 'color_by_label': False,
....: 'partition': None,
....: 'dist': .075,
....: 'max_dist': 1.5,
....: 'loop_size': .075,
....: 'edge_labels_background': 'transparent'}
Sage:xmin = -10
xmax = 10
f = plot((x^2-2)/(x+2), (x,xmin, xmax), ymin = -20, ymax = 20)
pt1 = point((-2,2), rgbcolor='blue', pointsize=40)
z = Graph((f+pt1).show(xmin= xmin, xmax= xmax, ymin=-20, ymax=20))
GP = GraphPlot(z, options)
Sage:z.set_latex_options(
....: graphic_size=(5,5),
....: vertex_size=0.2,
....: edge_thickness=0.04,
....: edge_color='green',
....: vertex_color='green',
....: vertex_label_color='red'
....: )
Sage: latex(z)
EnlightenedFunkTue, 19 Feb 2019 19:49:01 +0100https://ask.sagemath.org/question/45514/Display graph drawings in orderhttps://ask.sagemath.org/question/43403/display-graph-drawings-in-order/Often I want to compute a graph parameter for each graph in a list of graphs. I would like to print the value of the chosen parameter along with a drawing of each graph. So I do something like this, where L is a list of graphs:
for G in L:
print G.vertex_connectivity();
show(G.plot());
The problem is that the plots don't show up until after all of the printed output, and they appear in an order different from the original list. Is there any way to force a plot to appear exactly where I want it? I am using a Sage notebook.lgmolFri, 17 Aug 2018 20:53:35 +0200https://ask.sagemath.org/question/43403/graphs.planar_graphshttps://ask.sagemath.org/question/42414/graphsplanar_graphs/So I'm a bit confused by the documentation of graphs.planar_graphs I thought it would just generate a list of planar graphs so I don't know why the following code doesn't work (and also why I need to do list(l) )
l = graphs.planar_graphs(4, dual=False)
gen=list(l) #don't know why this is necessary
k=len(gen)
ii=1
G=gen[ii]
p=G.plot()
p.show()standardtrickynessThu, 24 May 2018 00:10:38 +0200https://ask.sagemath.org/question/42414/Edge color for undirected multiedge graphshttps://ask.sagemath.org/question/39153/edge-color-for-undirected-multiedge-graphs/ It seems that there is a bug with specifying the color of undirected multiedges. Here's an example:
G=graphs.PathGraph(2)
G.allow_multiple_edges(True)
G.add_edge((0,1))
G.plot(edge_colors={"red":[(1,0)]})
The graph plotted has then four edges, two black and two red. It seems that the multiedge to be colored red is seen as a different one than the already present one, even though they are actually the same since the graph is undirected. I get the intended plot if I change the last line to:
G.plot(edge_colors={"red":[(0,1)]})AckslFri, 13 Oct 2017 16:00:23 +0200https://ask.sagemath.org/question/39153/Is there a way to draw a graph using a specific embedding?https://ask.sagemath.org/question/35533/is-there-a-way-to-draw-a-graph-using-a-specific-embedding/ It is possible to set the embedding of a graph ([set_embedding](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/generic_graph.html#sage.graphs.generic_graph.GenericGraph.set_embedding)), but `plot()` doesn't seem to respect it. Is there a way to plot the graph using the specified embedding?
Here is an example showing that `faces()` respects the embedding, although plotting each gives the same output:
sage: G = Graph({0:[1,2,3], 2:[3], 3:[4]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 2), (2, 3), (3, 4), (4, 3), (3, 0)],
[(2, 0), (0, 3), (3, 2)]]
sage: G.set_embedding({0:[2,1,3], 1:[0], 2:[0,3], 3:[0,2,4], 4:[3]})
sage: G.faces()
[[(0, 1), (1, 0), (0, 3), (3, 2), (2, 0)],
[(3, 0), (0, 2), (2, 3), (3, 4), (4, 3)]]jaebondFri, 11 Nov 2016 22:24:18 +0100https://ask.sagemath.org/question/35533/