€csage.server.notebook.notebook Notebook q)q}q(U_Notebook__worksheetsq}q(U (csage.server.notebook.worksheet Worksheet qoq}q(U_Worksheet__filenameq U_U_Worksheet__cellsq ]q((csage.server.notebook.cell Cell qoq }q(U _Cell__inqU2+3qU_Cell__introspect_htmlqU!
qU_Cell__worksheetqhU_Cell__completionsq‰U_Cell__introspectq‰U_Cell__out_htmlqU U _Cell__idqM U_Cell__is_htmlq‰U_before_preparseqURos.chdir("/Users/was/talks/2007-01-05-msr/sage_notebook/worksheets/_/cells/0") 2+3qU _Cell__dirqU"sage_notebook/worksheets/_/cells/0qU _Cell__outqU 5 qUhas_new_outputq‰U_Cell__versionq KU_Cell__sageq!csage.interfaces.sage0 reduce_load_Sage q")Rq#U_Cell__typeq$Uwrapq%U_Cell__timeq&‰U_Cell__interruptedq'‰ub(hoq(}q)(U _Cell__inq*U2+5q+hU!q,U_Cell__worksheetq-hU_Cell__completionsq.‰h‰U_Cell__out_htmlq/U U _Cell__idq0Mh‰hURos.chdir("/Users/was/talks/2007-01-05-msr/sage_notebook/worksheets/_/cells/1") 2+5q1U _Cell__dirq2U"sage_notebook/worksheets/_/cells/1q3U _Cell__outq4U 7 q5Uhas_new_outputq6‰U_Cell__versionq7Kh!h#U_Cell__typeq8h%h&‰U_Cell__interruptedq9‰ub(hoq:}q;(h*U$E = magma.EllipticCurve([1,2,3,4,5])q
rR hM0jD ‰jE Udos.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/1")
show(g)rS hU&sage_notebook/worksheets/graph/cells/1rT hU
rU h‰h KjJ h#h$jK jL ‰h'‰ub(horV }rW (hU(g = graphs.CompleteBipartiteGraph(5,100)rX hU!rY hj h‰h‰hU h‰hM0huUgraphs.CompleteBirZ hU…os.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/2")
g = graphs.CompleteBipartiteGraph(5,100)r[ hU&sage_notebook/worksheets/graph/cells/2r\ hU
r] h‰h Kh!h#h$j h&‰h'‰ub(hor^ }r_ (h*Ugraphs.CompleteBipartiteGraphr` hT? File: /Volumes/HOME/s/local/lib/python2.5/site-packages/sage/graphs/graph_database.py
Source Code (starting at line 566):
def CompleteBipartiteGraph(self, n1, n2):
"""
Returns a Complete Bipartite Graph sized n1+n2, with each of the
nodes [0,(n1-1)] connected to each of the nodes [n1,(n2-1)] and
vice versa.
A Complete Bipartite Graph is a graph with its vertices partitioned
into two groups, V1 and V2. Each v in V1 is connected to every v
in V2, and vice versa.
PLOTTING:
Upon construction, the position dictionary is filled to override
the spring-layout algorithm. By convention, each complete bipartite
graph will be displayed with the first n1 nodes on the top row (at
y=1) from left to right. The remaining n2 nodes appear at y=0,
also from left to right. The shorter row (partition with fewer
nodes) is stretched to the same length as the longer row, unless
the shorter row has 1 node; in which case it is centered. The x
values in the plot are in domain [0,max{n1,n2}].
In the Complete Bipartite graph, there is a visual difference in
using the spring-layout algorithm vs. the position dictionary used
in this constructor. The position dictionary flattens the graph
and separates the partitioned nodes, making it clear which nodes
an edge is connected to. The Complete Bipartite graph plotted with
the spring-layout algorithm tends to center the nodes in n1 (see
spring_med in examples below), thus overlapping its nodes and edges,
making it typically hard to decipher.
Filling the position dictionary in advance adds O(n) to the
constructor. Feel free to race the constructors below in the
examples section. The much larger difference is the time added by
the spring-layout algorithm when plotting. (Also shown in the
example below). The spring model is typically described as O(n^3),
as appears to be the case in the NetworkX source code.
EXAMPLES:
# The following examples require NetworkX (to use default)
sage: import networkx as NX
# Compare the constructors (results will vary)
sage.: time n = NX.complete_bipartite_graph(389,157); spring_big = Graph(n)
# CPU time: 9.28 s, Wall time: 11.02 s
sage.: time posdict_big = graphs.CompleteBipartiteGraph(389,157)
# CPU time: 10.72 s, Wall time: 13.84 s
# Compare the plotting speeds (results will vary)
sage: n = NX.complete_bipartite_graph(11,17)
sage: spring_med = Graph(n)
sage: posdict_med = graphs.CompleteBipartiteGraph(11,17)
# Notice here how the spring-layout tends to center the nodes of n1
sage.: time spring_med.show()
# CPU time: 3.84 s, Wall time: 4.49 s
sage.: time posdict_med.show()
# CPU time: 0.96 s, Wall time: 1.14 s
# View many Complete Bipartite graphs with a SAGE Graphics Array
# With this constructor (i.e., the position dictionary filled)
sage: g = []
sage: j = []
sage: for i in range(9):
... k = graphs.CompleteBipartiteGraph(i+1,4)
... g.append(k)
...
sage: for i in range(3):
... n = []
... for m in range(3):
... n.append(g[3*i + m].plot(node_size=50, with_labels=False))
... j.append(n)
...
sage: G = sage.plot.plot.GraphicsArray(j)
sage.: G.show()
# Compared to plotting with the spring-layout algorithm
sage: g = []
sage: j = []
sage: for i in range(9):
... spr = NX.complete_bipartite_graph(i+1,4)
... k = Graph(spr)
... g.append(k)
...
sage: for i in range(3):
... n = []
... for m in range(3):
... n.append(g[3*i + m].plot(node_size=50, with_labels=False))
... j.append(n)
...
sage: G = sage.plot.plot.GraphicsArray(j)
sage.: G.show()
"""
pos_dict = {}
c1 = 1 # scaling factor for top row
c2 = 1 # scaling factor for bottom row
c3 = 0 # pad to center if top row has 1 node
c4 = 0 # pad to center if bottom row has 1 node
if n1 > n2:
if n2 == 1:
c4 = (n1-1)/2
else:
c2 = ((n1-1)/(n2-1))
elif n2 > n1:
if n1 == 1:
c3 = (n2-1)/2
else:
c1 = ((n2-1)/(n1-1))
for i in range(n1):
x = c1*i + c3
y = 1
pos_dict[i] = [x,y]
for i in range(n1+n2)[n1:]:
x = c2*(i-n1) + c4
y = 0
pos_dict[i] = [x,y]
G = NX.complete_bipartite_graph(n1,n2)
return graph.Graph(G, pos=pos_dict, name="Complete bipartite graph on %d vertices"%(n1+n2))ra h-j h.‰h]rb (Ugraphs.CompleteBipartiteGraph??rc U eh/U>
rd h‰h0M0huUgraphs.CompleteBire hU|os.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/3")
graphs.CompleteBipartiteGraph??rf h2U&sage_notebook/worksheets/graph/cells/3rg h4U
rh h6‰h7Kh!h#h8hAh&‰h9‰ub(hori }rj (j Ugj U!rk j
j j ‰j ‰j U j M0j ‰j U^os.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/5")
grl j U&sage_notebook/worksheets/graph/cells/5rm j UK
Complete bipartite graph on 105 vertices: a simple graph on 105 vertices
rn j ‰j Kj h#j j j ‰j ‰ub(horo }rp (h*Ug.save('mygraph')rq j U!rr h-j h.‰j ‰h/U h0M0j ‰j Unos.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/4")
g.save('mygraph')rs h2U&sage_notebook/worksheets/graph/cells/4rt h4U
ru h6‰h7Kj h#h8j j ‰h9‰ub(horv }rw (j U5P = plot(sin, 0, 10, rgbcolor=(0,0.5,0), thickness=5)rx j U!ry j
j j ‰j ‰j U j M0j ‰j U’os.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/6")
P = plot(sin, 0, 10, rgbcolor=(0,0.5,0), thickness=5)rz j U&sage_notebook/worksheets/graph/cells/6r{ j U
r| j ‰j Kj h#j j j ‰j ‰ub(hor} }r~ (j UPj U!r j
j j ‰j ‰j U j M0j ‰j U^os.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/7")
Pr€ j U&sage_notebook/worksheets/graph/cells/7r j U5
Graphics object consisting of 1 graphics primitive
r‚ j ‰j Kj h#j j j ‰j ‰ub(horƒ }r„ (j UP.show()r… j U!r† j
j j ‰j ‰j U>
r‡ j M0j ‰j Ueos.chdir("/Volumes/HOME/talks/2006-12-waterloo/sage/sage_notebook/worksheets/graph/cells/8")
P.show()rˆ j U&sage_notebook/worksheets/graph/cells/8r‰ j U
rŠ j ‰j Kj h#j j j ‰j ‰ub(hor‹ }rŒ (j U j
j j ‰j U j M 0j U&sage_notebook/worksheets/graph/cells/9r j U j ‰j K j j j ‰ubeU_Worksheet__synchrorŽ K