ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 18 Feb 2020 21:38:26 -0600Displaying Chessboard Graphshttp://ask.sagemath.org/question/49976/displaying-chessboard-graphs/I'm looking at various graphs and their plotting methods. For the code
G = graphs.KnightGraph([3,3])
G.show()
Sage displays:
![image description](/upfiles/15820828503619033.jpg)
I'd like the vertices to be arranged in a 3 by 3 grid so that the chessboard nature of the graph is more apparent.
From the documentation [here](http://doc.sagemath.org/html/en/reference/plotting/sage/graphs/graph_plot.html) I tried specifying the position by using a dictionary:
G = graphs.KnightGraph([3,3])
pos_dict = {}
for i in range(0,2):
for j in range(0,2):
pos_dict[G.vertices()[3*i+j]] = [i*.5,j*.5]
pl = G.graphplot(pos=pos_dict)
pl.show()
This doesn't give the intended result. Even stranger, running the code multiple times shows the position of only some of the
vertices is fixed while others change position.
How can I display an n by n chessboard graph so that it's vertices form an n by n square?
dazedANDconfusedTue, 18 Feb 2020 21:38:26 -0600http://ask.sagemath.org/question/49976/Automorphism group of edge symmetryhttp://ask.sagemath.org/question/47334/automorphism-group-of-edge-symmetry/ I asked a similar question before,
https://ask.sagemath.org/question/42762/automorphism-group-of-weighted-graph/
I am curious that is there any similar function for finding "edge symmetry"?
Note: the link I provided is for "node symmetry" in a network (graph). sleeve chenThu, 01 Aug 2019 04:21:31 -0500http://ask.sagemath.org/question/47334/DiGraph, Latex, and same orientationhttp://ask.sagemath.org/question/48140/digraph-latex-and-same-orientation/Hi
1) is it possible to write in Latex in vertices and edges ?
2) depending on whether I set the value of the Population variable to 1000 or to 100000 it swaps the branches sick and not sick, so is it a possibility to keep the same orientation each time ?
p=1000 ;print "Population : "+str(p)
sr=1/1000 ;print "Sick Rate : "+str(sr)
pfr=95/100 ;print "Positive False Rate : "+str(pfr*100)+'/'+"100"
nfr=40/100 ;print "Negative False Rate : "+str(nfr*100)+'/'+"100"
PbNS=(p-p*sr)*(1-pfr);print "Positive but Not Sick : "+str(round((p-p*sr)*(1-pfr),5))
PaS=((p-(1-sr)*p))*(1-nfr); print "Positive and Sick : ",str(round(((p-(1-sr)*p))*(1-nfr),5))
print "chance to be Sick if Tested Positive : ",PaS/(PbNS+PaS)," about :",round((PaS/(PbNS+PaS)),5)," : ",\
round((PaS/(PbNS+PaS))*100,5),"%"
H0=DiGraph({0:[1,2], 1:[3,4], 2:[5,6]})
#H.set_latex_options(edge_labels=True)
H0.set_edge_label(0, 1, "Not Sick : "+str(p-sr*p)+"/" +str(p))
H0.set_edge_label(0, 2, "Sick: "+str((p-(1-sr)*p))+'/'+str(p))
# not sick branch
H0.set_edge_label(1, 3, "Not Sick \n Tested Negative: "+str(pfr*100)+'/'+"100")
H0.set_edge_label(1, 4, "\n\n\n Not Sick \n Tested Positive: "+str((1-pfr)*100)+'/'+"100")
# sick branch
H0.set_edge_label(2, 5, "Sick Tested Negative: "+str((nfr)*100)+'/'+"100")
H0.set_edge_label(2, 6, "\n\n\n\nSick Tested Positive: \n "+str((1-nfr)*100)+'/'+"100")
H0.relabel({0:str(p)+' Peoples' , 1:str(p-p*sr), 2:str(p-p*(1-sr)), \
3:str(round((p-p*sr)*pfr,5))+' \n Tested Negative and Not Sick', \
4:str(round((p-p*sr)*(1-pfr),5))+' \n Tested positive but Not Sick', \
5:str(round(((p-(1-sr)*p))*(nfr),5))+' \n Tested Negative and Sick', \
6:str(round(((p-(1-sr)*p))*(1-nfr),5))+' \n Tested Positive and Sick'})
H0.show(vertex_color='white', vertex_shape='_',edge_labels=True,figsize=[10,10],layout='tree')
[edited the 2019/10/06, below attempt to solve pb with get_pos(),see David Coudert comment]
it seems that get_pos() does not get something ?:
def ShowTreeH0(p,H0Vert,H0Pos):
sr=1/1000 ;print "Sick Rate : "+str(sr)
pfr=95/100 ;print "Positive False Rate : "+str(pfr*100)+'/'+"100"
nfr=40/100 ;print "Negative False Rate : "+str(nfr*100)+'/'+"100"
PbNS=(p-p*sr)*(1-pfr);print "Positive but Not Sick : "+str(round((p-p*sr)*(1-pfr),5))
PaS=((p-(1-sr)*p))*(1-nfr); print "Positive and Sick : ",str(round(((p-(1-sr)*p))*(1-nfr),5))
print "chance to be Sick if Tested Positive : ",PaS/(PbNS+PaS)," about :",round((PaS/(PbNS+PaS)),5)," : ",\
round((PaS/(PbNS+PaS))*100,5),"%"
H0=DiGraph({0:[1,2], 1:[3,4], 2:[5,6]})
#H.set_latex_options(edge_labels=True)
H0.set_edge_label(0, 1, "Not Sick : "+str(p-sr*p)+"/" +str(p))
H0.set_edge_label(0, 2, "Sick: "+str((p-(1-sr)*p))+'/'+str(p))
# not sick branch
H0.set_edge_label(1, 3, "Not Sick \n Tested Negative: "+str(pfr*100)+'/'+"100")
H0.set_edge_label(1, 4, "\n\n\n Not Sick \n Tested Positive: "+str((1-pfr)*100)+'/'+"100")
# sick branch
H0.set_edge_label(2, 5, "Sick Tested Negative: "+str((nfr)*100)+'/'+"100")
H0.set_edge_label(2, 6, "\n\n\n\nSick Tested Positive: \n "+str((1-nfr)*100)+'/'+"100")
H0.relabel({0:str(p)+' Peoples' , 1:str(p-p*sr), 2:str(p-p*(1-sr)), \
3:str(round((p-p*sr)*pfr,5))+' \n Tested Negative and Not Sick', \
4:str(round((p-p*sr)*(1-pfr),5))+' \n Tested positive but Not Sick', \
5:str(round(((p-(1-sr)*p))*(nfr),5))+' \n Tested Negative and Sick', \
6:str(round(((p-(1-sr)*p))*(1-nfr),5))+' \n Tested Positive and Sick'})
if H0Vert<>None and H0Vert<>None :
print " set vertice and position"
H0.set_vertices(H0Vert)
H0.set_pos(H0Pos)
H0.show(vertex_color='white', vertex_shape='_',edge_labels=True,figsize=[10,10],layout='tree')
return H0.get_vertices(),H0.get_pos()
H0Vert=None
H0Pos=None
p=1000 ;print "Population : "+str(p)
H0Vert,H0Pos=ShowTreeH0(p,H0Vert,H0Pos)
p=100000 ;print "Population : "+str(p)
H0Vert,H0Pos=ShowTreeH0(p,H0Vert,H0Pos)ortolljWed, 02 Oct 2019 05:46:03 -0500http://ask.sagemath.org/question/48140/How to count face on a bipartite graph?http://ask.sagemath.org/question/47057/how-to-count-face-on-a-bipartite-graph/I am graphing a bipartite graph but I need to rearrange the graph. The graph is generated by a list of list. One of the rearrangement guidelines is that the faces have to be surrounded by a certain amount of "white" vertices. Therefore, I wanted to create a checker function that can count the faces of the graph and count the "white" vertices around that face. If the graph doesn't have the correct amount of faces and/or the number of "white" vertices then the program will rearrange the graph. I would like some guidance on this task, what code/math I should use or if I should use a different approach. I have attached the code. If more information is needed to help, please contact me at cameron.dthomas@morehouse.edu
Thanks for your time,
Cameron Thomas
D={}
graph=Graph(D, multiedges=True)
def Dessin(S0, S1):
numVertices = len(S0)+len(S1)
G={}
#adds keys to G
for i in range(numVertices):
G[i]=(S0+S1)[i]
for i in range(len(S0)):
#print(S0[i])
for j in range(len(S0[i])):
#print(S0[i][j])
for k in range(len(S1)):
if S0[i][j] in S1[k]:
graph.add_edge(i,k + len(S0),S0[i][j])
print(G)
def color(S0, S1):
grey=[]
white=[]
for i in range(len(S0)):
grey.append(i)
for i in range(len(S1)):
white.append(i+len(S0))
return [grey,white]
Dessin(S0, S1)
color(S0, S1)
graph.graphplot(edge_labels=True, vertex_colors={'grey': color(S0,S1)[0],'white':color(S0,S1)[1]}, vertex_labels=True).show()
return(graph)
Graf([[1,5,4,3,2]],[[1],[2],[3],[4],[5]])CamDTho3Wed, 03 Jul 2019 23:18:28 -0500http://ask.sagemath.org/question/47057/Plotting Graphs with different size verticeshttp://ask.sagemath.org/question/46953/plotting-graphs-with-different-size-vertices/ Hi, I'm trying to plot a graph where all vertices have a different size, depending on a value assigned to them, so a vertex with a high value would have a larger circumference.
I don't really know where to start. Can you help me?ga38xabThu, 20 Jun 2019 05:58:49 -0500http://ask.sagemath.org/question/46953/fractional chromatic index of edge-weighted graphshttp://ask.sagemath.org/question/46900/fractional-chromatic-index-of-edge-weighted-graphs/How would you compute the fractional chromatic index of an edge-weighted graph using SAGE?
The built-in function fractional_chromatic_index seems to compute the fractional chromatic index for only unweighted graphs. For instance, if $G$ is the 5-cycle graph, its fractional chromatic index is $2.5$. But if one of the edges can be ignored, say by giving it a zero weight, then the fractional chromatic index becomes $2$.
The code and output below shows that SAGE ignores the edge-weights (notice that the edge-weights need not be integral - in the graph below, the correct value of the fractional chromatic index is 2.1, which is the maximum sum $1.1+1.0$ of weights of edges incident to a vertex):
sage: G = graphs.EmptyGraph()
sage: G.add_edges([(1,2,1.1),(2,3,1),(3,4,1),(4,5,1),(5,1,0)])
sage: G.fractional_chromatic_index()
5/2
sage:
Is there some way to get the built-in function to take edge weights into account? Or can this value be computed using some other method?Ashwin GanesanTue, 11 Jun 2019 03:52:15 -0500http://ask.sagemath.org/question/46900/Graphing Complex Functions 3D (x,y,i axes) Instead Of Color-Coded 2D (x,i)http://ask.sagemath.org/question/10368/graphing-complex-functions-3d-xyi-axes-instead-of-color-coded-2d-xi/Following [this guide to Sage][1]: and using [Sage Online][2] produced the following graphs:
![enter image description here][3]
![enter image description here][4]
It would be nice to see it in 3D instead of merely color coded. The y-axis is coming out of the picture toward us and instead of seeing the 3D surface (in x,y,i coordinates) we see a color-graph on the x-i plane.
You can do what I wish [using Maple:](http://math.stackexchange.com/questions/448397/graphing-compex-functions-3d-x-y-i-axes-instead-of-color-coded-sage/448410?noredirect=1#448410)
[1]: http://www.sagemath.org/doc/reference/plotting/sage/plot/complex_plot.html
[2]: http://www.sagenb.org/
[3]: http://i.stack.imgur.com/gw8Aj.png
[4]: http://i.stack.imgur.com/NYP76.jpgJoe HobbitSat, 20 Jul 2013 13:50:24 -0500http://ask.sagemath.org/question/10368/What are distance regular graphshttp://ask.sagemath.org/question/45960/what-are-distance-regular-graphs/ A connected graph Γ with diameter D is called distance-regular if there are constants ci,ai,bi — the so-called intersection numbers — such that for all i = 0,1,...,D, and all vertices x and y at distance i = d(x,y), among the neighbors ofy, there are ci at distance i−1 from x, ai at distance i, and bi at distance i+1. It follows that Γ is a regular graph with valency k = b0, and that ci +ai +bi = kfor all i = 0, 1, . . . , D. By these equations, the intersection numbers ai can be expressed in terms of the others, and it is standard to put these others in the so-called intersection array
{b0,b1,...,bD−1;c1,c2,...,cD}.VindieselwalkerSun, 31 Mar 2019 09:09:05 -0500http://ask.sagemath.org/question/45960/Sage Floyd algorithm in Cythonhttp://ask.sagemath.org/question/44823/sage-floyd-algorithm-in-cython/Hi
Classical Floyd algorithm computes all shortest path in a **weighted** graph and this algorithm has a $O(n^3)$ complexity (-> it can be slow). So i'm a bit surprised to see that the Cython version provided in Sage works only if `by_weight==False` meaning that all weights are 1 by default (its computes the transitive closure of the graph).
As a consequence, does it mean the only way to compute the "true" all-shortest-path in Sage is by using the pure Python implementation ?elasticaMon, 31 Dec 2018 03:53:04 -0600http://ask.sagemath.org/question/44823/Where has _circle_embedding gone?http://ask.sagemath.org/question/44467/where-has-_circle_embedding-gone/After nearly killing myself (in frustration) installing Sage 8.4 from source on OSX 10.14.1 (Mojave), I discover that a graph plotting command that I frequently use has vanished, breaking a number of my own programs.
Previously (on SageMath up to 8.2) I would do
from sage.graphs.graph_plot import _circle_embedding
in order to access this.
Now I just get
ImportError: cannot import name _circle_embedding
I can relatively easily replace this *particular* function myself, but if it were something more complicated, I would be at a loss to know how to track down the cause for its disappearance and figure out how to get it back.
So I guess the questions are: has it only vanished for me due to a botched or incomplete installation, or has it somehow been removed from Sage? In either case, how can I recover it?GordonTue, 27 Nov 2018 02:59:33 -0600http://ask.sagemath.org/question/44467/Graph with partial edge labellinghttp://ask.sagemath.org/question/43892/graph-with-partial-edge-labelling/ Hello all,
I need to draw a graph in which some edges are labelled and some edges are not.
I know how to make all the edges labelled. But I need mixed edges (some are labelled and some are not).
Kindly help me with this.
Thank youGA316Wed, 10 Oct 2018 02:04:43 -0500http://ask.sagemath.org/question/43892/creating graph with dotted edgeshttp://ask.sagemath.org/question/43872/creating-graph-with-dotted-edges/ Hello all,
I need to draw a graph in which some edges are usual and some edges are dotted. I know how to make all the edges dotted (using the option "dotted" for the parameter edge_style of plot). But I need mixed edges (some are dotted and some are usual). Kindly help me with this.
Thank you.
GA316Mon, 08 Oct 2018 11:17:43 -0500http://ask.sagemath.org/question/43872/values or names on tree branches (graph)http://ask.sagemath.org/question/43691/values-or-names-on-tree-branches-graph/ Hi
How can I make appear names (or,and) numerical values on the branches ?.
#https://ask.sagemath.org/question/43106/preserving-the-rooted-tree-layout-in-graphs/
G=Graph({1:[2,3],2:[4,5],3:[6,7]})
G.weighted(False)
G.show(layout='tree',tree_root=1)
show(G.vertices())ortolljTue, 18 Sep 2018 06:33:09 -0500http://ask.sagemath.org/question/43691/Why can't I find the spectral radius of a tree?http://ask.sagemath.org/question/43496/why-cant-i-find-the-spectral-radius-of-a-tree/ If I create some connected graphs, and ask SageMath for their spectral radius, the command never returns (well, I have only let it run for a few minutes) if the target is a tree.
Here is a simple example:
g = graphs.CompleteBipartiteGraph(1,3)
print g.spectrum()
print g.spectral_radius()
The only advertised requirement for the target is that it be strongly connected, but as it is a connected graph, this should automatically be satisfied.
Yes, I can work around by computing the spectrum and taking the biggest, but I'd still like to know why this does not work.GordonMon, 27 Aug 2018 22:23:37 -0500http://ask.sagemath.org/question/43496/class of trees or graphshttp://ask.sagemath.org/question/43454/class-of-trees-or-graphs/ [Here](http://doc.sagemath.org/html/en/reference/graphs/sage/graphs/trees.html) we can see how to generate all the trees of order $n$ and is not upto isomorphism. But I dont want all trees of order $n$.
I want to know is there class of graphs which are particular typres of trees, like class of paths.
In general where I can find how to define class of complete graph, cycles, . . .
Kindly share the link for the documentation.
Thank you.GA316Thu, 23 Aug 2018 22:10:09 -0500http://ask.sagemath.org/question/43454/How can I generate a graph from an .mtx file?http://ask.sagemath.org/question/42866/how-can-i-generate-a-graph-from-an-mtx-file/The .mtx file contains the information of an sparse matrix in matrix market format. How can I generate the underlying graph of this matrix in SAGE?
Alternatively, since I now how to generate the .mat file from .mtx file in MATLAB, how can I generate the graph from .mat file in SAGE?
The matrix in .mtx in format is the adjacency matrix of the graph. The problem is I cannot read the matrix and generate the underlying graph in SAGE 8.2 (Jupyter).ASHSun, 08 Jul 2018 23:13:44 -0500http://ask.sagemath.org/question/42866/Show3d has no partition optionhttp://ask.sagemath.org/question/42820/show3d-has-no-partition-option/ `graph.show(partition = Pi)` works but `graph.show3d(partition =Pi)` doesn't. Is this something that might be fixed in the future? Or is there a workaround? Bjørn Kjos-HanssenWed, 04 Jul 2018 02:19:18 -0500http://ask.sagemath.org/question/42820/Automorphism group of weighted graphhttp://ask.sagemath.org/question/42762/automorphism-group-of-weighted-graph/I know we can use sage to find the group of automorphisms of a graph $G$:
G.automorphism_group().list()
However, the above way can only be used to the unweighted graph. So for example:
G = matrix([[0,10,0],
[10,0,1],
[0,1,0]])
G1 = Graph(G, weighted = True)
G1.show(edge_labels=True )
G.automorphism_group().list()
The result is:
[(), (0,2)]
However, this result is not correct (correct for unweighted case). This is because $AD\neq DA$, where
$$D = \begin{bmatrix} 0 & 0 & 1 \\\ 0 & 1 & 0 \\\ 1 & 0 & 0\end{bmatrix},$$ which is a permutation matrix and
$$A = \begin{bmatrix} 0 & 10 & 0 \\\ 10 & 0 & 1 \\\ 0 & 1 & 0\end{bmatrix},$$ which is an adjacency matrix.
Can we use SAGE to find the group of automorphisms of a graph?sleeve chenWed, 27 Jun 2018 20:22:14 -0500http://ask.sagemath.org/question/42762/Problem with .stl and Graphhttp://ask.sagemath.org/question/41702/problem-with-stl-and-graph/Hi everyone!
I have a problem with SageMath, and I need your help :).
I want to save my personal Graph from a list to a .stl file
(.stl for 3d object representation, "stereolithography").
My code:
p = [[0,0,0],[1,2,3],[2,3,1],[2,1,0],[1,3,2],[3,2,1]]
points = PointConfiguration(p)
triang = points.triangulate()
triang.save('mygraph.stl')
triang.plot(axes=False)
___
When I try to save my file it's in the .sobj extension. (I research this extension
and it's just an extension SageObject, so it's not useful for me). I want to draw
a graph with a list of point and to convert them in a .stl file.
I already tried:
- save the plot:
triang.plot().save('mygraph.stl') # Fails as there is no attribute face_list
- save the all[-1]:
triang.all[-1].save('test.stl') # Fails as PointConfiguration don't have argument all.
I don't know what is the problem, so I ask for your help.
Thank you very much.haaggenWed, 21 Mar 2018 15:48:59 -0500http://ask.sagemath.org/question/41702/Flow gives error for disconnected verticeshttp://ask.sagemath.org/question/41419/flow-gives-error-for-disconnected-vertices/ When calculating the flow between to vertices which are not connected in a graph, the method returns a ValueError. I would have assumed that it would just return 0. Here's a minimal example:
G=Graph({0:[],1:[]})
G.flow(0,1) # raises the error ValueError: vertex '0' is not in the (di)graph
If on the other hand one tries the shortest_path method it just returns a empty list, since there is not path between 0 and 1.
G.shortest_path(0,1) #returns []AckslWed, 07 Mar 2018 06:21:06 -0600http://ask.sagemath.org/question/41419/How to write the given program in sagehttp://ask.sagemath.org/question/41274/how-to-write-the-given-program-in-sage/I am new to sage. I have learned the basics of sage programming from various online notes.
I am interested to apply sage in linear algebra and graph theory.
My problem is I want to draw a graph as follows:
Vertices : Subspaces of a vector space of dimension $n$.
Edges: $V_1V_2\iff V_1 \subset V_2$ or $V_2\subset V_1$.
Please don't give me the solution.
Please help me how to write it step by step or give some resources from where I can find this.
CaptchaMon, 26 Feb 2018 21:53:00 -0600http://ask.sagemath.org/question/41274/Import error with pydotplushttp://ask.sagemath.org/question/41078/import-error-with-pydotplus/ Hello,
I am running Sagemath 7.3 on Linux. I would like to export a graph using the export function of the graph, but I get the error
`
ImportError: No module named pydotplus`
The python module pydotplus was already installed with `pip install pydotplus`
I cannot find any help regarding this issue. Any suggestion?
Thank you in advance for your helpluno_TMon, 12 Feb 2018 07:55:11 -0600http://ask.sagemath.org/question/41078/shortest pathhttp://ask.sagemath.org/question/40267/shortest-path/Hi, I wanna find the best route by minimizing the cost form 4a to 1a,
I write this code in Cocalc
G = Graph({"1a": {"2a": 521916, "22a": 182390, "23a": 144448, "44a": 1199260, "101a": 73200},
"23a": {"24a": 200324,"101a": 193980},
"2a": {"3a": 193980},
"3a": {"4a": 176900},
"4a" : {"5a":78080},
"5a" : {"6a":599386},
"6a" : {"7a":633180, "30a":845582},
"7a":{"8a":293532},
"8a":{"9a":197030, "32a":562420},
"9a":{"10a":97600},
"10a":{"17a":154940},
"9a":{"16a":342820},
"16a":{"17a":354898,"18a":164578, "15a":309880,"18a":164578},
"15a":{"14a":592920},
"18a":{"19a":147559},
"19a":{"20a":338550},
"20a":{"21a":190930},
"21a":{"7a":26230},
"32a":{"31a":207400},
"11a":{"12a":498980},
"33a":{"34a":378200},
"34a":{"35a":196176},
"30a":{"28a":200080},
"28a":{"29a":390888},
"29a":{"25a":462136},
"25a":{"26a":536800},
"2a":{"25a":183000},
"26a":{"27a":694790},
"27a":{"28a":747128},
"27a":{"41a":317200},
"41a":{"42a":451400},
"42a":{"12a":85400},
"41a":{"40a":660020},
"42a":{"44a":500566},
"12a":{"64a":231800},
"64a":{"65a":505568},
"45a":{"46a":581696},
"46a":{"47a":819352},
"47a":{"48a":486292},
"48a":{"49a":466406},
"49a":{"50a":292800},
"50a":{"51a":744200},
"51a":{"52a":256200},
"52a":{"53a":573400},
"52a":{"54a":744200},
"54a":{"55a":195200},
"55a":{"56a":689300},
"55a":{"62a":366000},
"62a":{"63a":793000},
"56a":{"57a":183000},
"57a":{"58a":149084},
"58a":{"59a":390400},
"59a":{"60a":265960},
"60a":{"61a":378810},
"66a":{"67a":504470},
"67a":{"68a":245830},
"68a":{"69a":213500},
"69a":{"70a":256200},
"67a":{"71a":833138},
"71a":{"72a":686860},
"72a":{"73a":732000},
"73a":{"74a":305000},
"74a":{"75a":207400},
"72a":{"76a":479460},
"76a":{"77a":183000},
"77a":{"78a":512400},
"71a":{"84a":131760},
"84a":{"83a":466040},
"83a":{"85a":187880},
"83a":{"82a":453840},
"82a":{"81a":376980},
"81a":{"80a":451400},
"80a":{"79a":368074},
"85a":{"86a":543266},
"86a":{"87a":513742},
"87a":{"88a":699426},
"88a":{"89a":685030},
"89a":{"90a":386130},
"89a":{"91a":451400},
"91a":{"92a":669170},
"92a":{"93a":313784},
"93a":{"94a":12.2},
"93a":{"95a":548024},
"95a":{"96a":45140},
"86a":{"97a":319640},
"36a":{"37a":31720},
"98a":{"99a":488000},
"98a":{"39a":644770},
"39a":{"43a":435906},
"49a":{"57a":399916},
"23a":{"101a":193980},
"101a":{"1a":73200},
"2a":{"25a":183000},
"23b":{"101b":82200},
"101b":{"25b":373800},
"25b":{"3b":63000},
"3b":{"4b":245400},
"4b":{"6b":202800},
"6b":{"7b":180000},
"7b":{"8b":220800},
"8b":{"13b":246000},
"23a":{"23b":250000},
"101b":{"101a":250000},
"25b":{"25a":250000},
"3b":{"3a":250000},
"4b":{"4a":250000},
"6b":{"6a":250000},
"7b":{"7a":250000},
"8b":{"8a":250000},
"13b":{"13a":250000}})
G.plot(edge_labels=True).show() # long time
G.shortest_path("4a", "1a", by_weight=True)
<change> I mean I wrote G.shortest_path("4a", "1a", by_weight=True) instead of G.shortest_path("3a", "2a", by_weight=True)
but it gives me 4a,5a,6a,30a, 28a, 29a, 25a, 2a,1a (which is not the best route)
because i try to manually calculate and there's a better route which is 4a, 3a, 2a, 1a
so, why this g.shortest_path doesn't give me the shortest one?
n btw what's the command to print/show the total cost of the chosen shortest path?
Thanks, Astra
Ps. I'm new to sagemathAstra BeThu, 21 Dec 2017 03:01:47 -0600http://ask.sagemath.org/question/40267/find embedded subgraphshttp://ask.sagemath.org/question/40140/find-embedded-subgraphs/Hi there,
is there a method to find all embedded copies of a graph in another graph, e.g. given two graphs H and G I want something like:
G = graphs.RandomGNP(10,.3) #some graph
H = Graph({1:[1,2], 2:[1,2]}) #some other graph
list = G.find_subgraphs(H, homeomorphic=False/True)
Where the elements list are all the subgraphs in G which are isomorphic/homeomorphic to H.
If this is too much to ask for, there should be at least a method to return all cycles in G (i.e. closed paths in G with each vertex at most once). Since there exists the Hamiltonian cycle method this one should exist too.
PS: In my case the graph has multiedges (and loops, but we can ignore this here).ctstWed, 13 Dec 2017 09:13:56 -0600http://ask.sagemath.org/question/40140/Plotting a frequency chart from a set of valueshttp://ask.sagemath.org/question/39677/plotting-a-frequency-chart-from-a-set-of-values/Hello,
I have got a list of results from my function already. And now, I need to visualise this information and plot a chart of how many times each particular value is repeated in a list. I know how to do a histogram, but it shows intervals of values, but not specific values. I need to access all the values afterwards as well and be able to work with them.
----------
I have found also that I can count values using a command "count"
`list.count()` if it is necessary to do it like this in my problem.
I'd like to ask what is the code for such frequency chart (or plot of points)? And how do I need to define my variables?
Would be much appreciated if someone could help in any way. Thank you very much.
XeniaXeniaMon, 20 Nov 2017 12:12:52 -0600http://ask.sagemath.org/question/39677/Graphing ineqalitieshttp://ask.sagemath.org/question/39216/graphing-ineqalities/ So I'm trying to graph the inequality x+y+3u>=0
I want to keep the u fixed, but I'm having issues finding out how to do that.
Also, I was wondering if it would be possible to have some type of dynamic slider for u, so that this way I can change the value of u.kaylavb23Thu, 19 Oct 2017 09:37:54 -0500http://ask.sagemath.org/question/39216/Edge color for undirected multiedge graphshttp://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 09:00:23 -0500http://ask.sagemath.org/question/39153/Stochastic block modelhttp://ask.sagemath.org/question/38929/stochastic-block-model/Hi all,
I would like to draw a random graph by Sage. The general stochastic model is the following: The graph contains $n$ vertices and the n vertices are divided into $r$ communities $C_1\cdots,C_r$. For two vertices within the same community, there is a probability $P_r$ that they are connected directly by an edge. How do I plot such a graph in Sage? References appreciated.Dianbin BaoThu, 21 Sep 2017 13:19:26 -0500http://ask.sagemath.org/question/38929/Paths beginning with a certain vertexhttp://ask.sagemath.org/question/38452/paths-beginning-with-a-certain-vertex/So I have a graph $G$ and a distinguished vertex, labeled with $0$ say. I would like to create a list of all paths of length $k$ that start with $0$.
One way I see how to do this with subgraph_search is to change $0$ into a large clique (larger than the clique number of $G$) and then use subgraph_search_iterator to find all subgraphs with a large clique connected to a path of length $k-1$. However, this seems pretty inefficient. Is there a better way?
vukovMon, 31 Jul 2017 17:09:40 -0500http://ask.sagemath.org/question/38452/Random block graphhttp://ask.sagemath.org/question/37433/random-block-graph/ How can I get a random connected graph with m blocks so that each block is a k-clique (complete graph with k vertices). Deepak SarmaWed, 26 Apr 2017 06:35:00 -0500http://ask.sagemath.org/question/37433/