@@ -198,16 +198,17 @@ class BipartiteGraph(Graph):
198
198
199
199
#. From a reduced adjacency matrix::
200
200
201
- sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0), # needs sage.modules
201
+ sage: # needs sage.modules
202
+ sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0),
202
203
....: (0,1,0,1,0,1,0), (1,1,0,1,0,0,1)])
203
- sage: M # needs sage.modules
204
+ sage: M
204
205
[1 1 1 0 0 0 0]
205
206
[1 0 0 1 1 0 0]
206
207
[0 1 0 1 0 1 0]
207
208
[1 1 0 1 0 0 1]
208
- sage: H = BipartiteGraph(M); H # needs sage.modules
209
+ sage: H = BipartiteGraph(M); H
209
210
Bipartite graph on 11 vertices
210
- sage: H.edges(sort=True) # needs sage.modules
211
+ sage: H.edges(sort=True)
211
212
[(0, 7, None),
212
213
(0, 8, None),
213
214
(0, 10, None),
@@ -244,13 +245,14 @@ class BipartiteGraph(Graph):
244
245
245
246
::
246
247
247
- sage: F.<a> = GF(4) # needs sage.modules sage.rings.finite_rings
248
- sage: MS = MatrixSpace(F, 2, 3) # needs sage.modules sage.rings.finite_rings
249
- sage: M = MS.matrix([[0, 1, a + 1], [a, 1, 1]]) # needs sage.modules sage.rings.finite_rings
250
- sage: B = BipartiteGraph(M, weighted=True, sparse=True) # needs sage.modules sage.rings.finite_rings
251
- sage: B.edges(sort=True) # needs sage.modules sage.rings.finite_rings
248
+ sage: # needs sage.modules sage.rings.finite_rings
249
+ sage: F.<a> = GF(4)
250
+ sage: MS = MatrixSpace(F, 2, 3)
251
+ sage: M = MS.matrix([[0, 1, a + 1], [a, 1, 1]])
252
+ sage: B = BipartiteGraph(M, weighted=True, sparse=True)
253
+ sage: B.edges(sort=True)
252
254
[(0, 4, a), (1, 3, 1), (1, 4, 1), (2, 3, a + 1), (2, 4, 1)]
253
- sage: B.weighted() # needs sage.modules sage.rings.finite_rings
255
+ sage: B.weighted()
254
256
True
255
257
256
258
#. From an alist file::
@@ -311,10 +313,11 @@ class BipartiteGraph(Graph):
311
313
312
314
#. From a NetworkX bipartite graph::
313
315
314
- sage: import networkx # needs networkx
315
- sage: G = graphs.OctahedralGraph() # needs networkx
316
- sage: N = networkx.make_clique_bipartite(G.networkx_graph()) # needs networkx
317
- sage: B = BipartiteGraph(N) # needs networkx
316
+ sage: # needs networkx
317
+ sage: import networkx
318
+ sage: G = graphs.OctahedralGraph()
319
+ sage: N = networkx.make_clique_bipartite(G.networkx_graph())
320
+ sage: B = BipartiteGraph(N)
318
321
319
322
TESTS:
320
323
@@ -328,15 +331,16 @@ class BipartiteGraph(Graph):
328
331
Ensure that we can construct a ``BipartiteGraph`` with isolated vertices via
329
332
the reduced adjacency matrix (:trac:`10356`)::
330
333
331
- sage: a = BipartiteGraph(matrix(2, 2, [1, 0, 1, 0])) # needs sage.modules
332
- sage: a # needs sage.modules
334
+ sage: # needs sage.modules
335
+ sage: a = BipartiteGraph(matrix(2, 2, [1, 0, 1, 0]))
336
+ sage: a
333
337
Bipartite graph on 4 vertices
334
- sage: a.vertices(sort=True) # needs sage.modules
338
+ sage: a.vertices(sort=True)
335
339
[0, 1, 2, 3]
336
- sage: g = BipartiteGraph(matrix(4, 4, [1] * 4 + [0] * 12)) # needs sage.modules
337
- sage: g.vertices(sort=True) # needs sage.modules
340
+ sage: g = BipartiteGraph(matrix(4, 4, [1] * 4 + [0] * 12))
341
+ sage: g.vertices(sort=True)
338
342
[0, 1, 2, 3, 4, 5, 6, 7]
339
- sage: sorted(g.left.union(g.right)) # needs sage.modules
343
+ sage: sorted(g.left.union(g.right))
340
344
[0, 1, 2, 3, 4, 5, 6, 7]
341
345
342
346
Make sure that loops are not allowed (:trac:`23275`)::
@@ -1806,19 +1810,20 @@ def save_afile(self, fname):
1806
1810
1807
1811
EXAMPLES::
1808
1812
1809
- sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0), # needs sage.modules
1813
+ sage: # needs sage.modules
1814
+ sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0),
1810
1815
....: (0,1,0,1,0,1,0), (1,1,0,1,0,0,1)])
1811
- sage: M # needs sage.modules
1816
+ sage: M
1812
1817
[1 1 1 0 0 0 0]
1813
1818
[1 0 0 1 1 0 0]
1814
1819
[0 1 0 1 0 1 0]
1815
1820
[1 1 0 1 0 0 1]
1816
- sage: b = BipartiteGraph(M) # needs sage.modules
1817
- sage: import tempfile # needs sage.modules
1818
- sage: with tempfile.NamedTemporaryFile() as f: # needs sage.modules
1821
+ sage: b = BipartiteGraph(M)
1822
+ sage: import tempfile
1823
+ sage: with tempfile.NamedTemporaryFile() as f:
1819
1824
....: b.save_afile(f.name)
1820
1825
....: b2 = BipartiteGraph(f.name)
1821
- sage: b.is_isomorphic(b2) # needs sage.modules
1826
+ sage: b.is_isomorphic(b2)
1822
1827
True
1823
1828
1824
1829
TESTS::
@@ -1923,54 +1928,57 @@ def reduced_adjacency_matrix(self, sparse=True, *, base_ring=None, **kwds):
1923
1928
Bipartite graphs that are not weighted will return a matrix over ZZ,
1924
1929
unless a base ring is specified::
1925
1930
1926
- sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0), # needs sage.modules
1931
+ sage: # needs sage.modules
1932
+ sage: M = Matrix([(1,1,1,0,0,0,0), (1,0,0,1,1,0,0),
1927
1933
....: (0,1,0,1,0,1,0), (1,1,0,1,0,0,1)])
1928
- sage: B = BipartiteGraph(M) # needs sage.modules
1929
- sage: N = B.reduced_adjacency_matrix(); N # needs sage.modules
1934
+ sage: B = BipartiteGraph(M)
1935
+ sage: N = B.reduced_adjacency_matrix(); N
1930
1936
[1 1 1 0 0 0 0]
1931
1937
[1 0 0 1 1 0 0]
1932
1938
[0 1 0 1 0 1 0]
1933
1939
[1 1 0 1 0 0 1]
1934
- sage: N == M # needs sage.modules
1940
+ sage: N == M
1935
1941
True
1936
- sage: N[0,0].parent() # needs sage.modules
1942
+ sage: N[0,0].parent()
1937
1943
Integer Ring
1938
- sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF); N2 # needs sage.modules
1944
+ sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF); N2
1939
1945
[1.0 1.0 1.0 0.0 0.0 0.0 0.0]
1940
1946
[1.0 0.0 0.0 1.0 1.0 0.0 0.0]
1941
1947
[0.0 1.0 0.0 1.0 0.0 1.0 0.0]
1942
1948
[1.0 1.0 0.0 1.0 0.0 0.0 1.0]
1943
- sage: N2[0, 0].parent() # needs sage.modules
1949
+ sage: N2[0, 0].parent()
1944
1950
Real Double Field
1945
1951
1946
1952
Multi-edge graphs also return a matrix over ZZ,
1947
1953
unless a base ring is specified::
1948
1954
1949
- sage: M = Matrix([(1,1,2,0,0), (0,2,1,1,1), (0,1,2,1,1)]) # needs sage.modules
1950
- sage: B = BipartiteGraph(M, multiedges=True, sparse=True) # needs sage.modules
1951
- sage: N = B.reduced_adjacency_matrix() # needs sage.modules
1952
- sage: N == M # needs sage.modules
1955
+ sage: # needs sage.modules
1956
+ sage: M = Matrix([(1,1,2,0,0), (0,2,1,1,1), (0,1,2,1,1)])
1957
+ sage: B = BipartiteGraph(M, multiedges=True, sparse=True)
1958
+ sage: N = B.reduced_adjacency_matrix()
1959
+ sage: N == M
1953
1960
True
1954
- sage: N[0,0].parent() # needs sage.modules
1961
+ sage: N[0,0].parent()
1955
1962
Integer Ring
1956
- sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF) # needs sage.modules
1957
- sage: N2[0, 0].parent() # needs sage.modules
1963
+ sage: N2 = B.reduced_adjacency_matrix(base_ring=RDF)
1964
+ sage: N2[0, 0].parent()
1958
1965
Real Double Field
1959
1966
1960
1967
Weighted graphs will return a matrix over the ring given by their
1961
1968
(first) weights, unless a base ring is specified::
1962
1969
1963
- sage: F.<a> = GF(4) # needs sage.modules sage.rings.finite_rings
1964
- sage: MS = MatrixSpace(F, 2, 3) # needs sage.modules sage.rings.finite_rings
1965
- sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]]) # needs sage.modules sage.rings.finite_rings
1966
- sage: B = BipartiteGraph(M, weighted=True, sparse=True) # needs sage.modules sage.rings.finite_rings
1967
- sage: N = B.reduced_adjacency_matrix(sparse=False) # needs sage.modules sage.rings.finite_rings
1968
- sage: N == M # needs sage.modules sage.rings.finite_rings
1970
+ sage: # needs sage.modules sage.rings.finite_rings
1971
+ sage: F.<a> = GF(4)
1972
+ sage: MS = MatrixSpace(F, 2, 3)
1973
+ sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]])
1974
+ sage: B = BipartiteGraph(M, weighted=True, sparse=True)
1975
+ sage: N = B.reduced_adjacency_matrix(sparse=False)
1976
+ sage: N == M
1969
1977
True
1970
- sage: N[0,0].parent() # needs sage.modules sage.rings.finite_rings
1978
+ sage: N[0,0].parent()
1971
1979
Finite Field in a of size 2^2
1972
- sage: N2 = B.reduced_adjacency_matrix(base_ring=F) # needs sage.modules sage.rings.finite_rings
1973
- sage: N2[0, 0].parent() # needs sage.modules sage.rings.finite_rings
1980
+ sage: N2 = B.reduced_adjacency_matrix(base_ring=F)
1981
+ sage: N2[0, 0].parent()
1974
1982
Finite Field in a of size 2^2
1975
1983
1976
1984
TESTS::
@@ -1989,11 +1997,12 @@ def reduced_adjacency_matrix(self, sparse=True, *, base_ring=None, **kwds):
1989
1997
An error is raised if the specified base ring is not compatible with the
1990
1998
type of the weights of the bipartite graph::
1991
1999
1992
- sage: F.<a> = GF(4) # needs sage.modules sage.rings.finite_rings
1993
- sage: MS = MatrixSpace(F, 2, 3) # needs sage.modules sage.rings.finite_rings
1994
- sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]]) # needs sage.modules sage.rings.finite_rings
1995
- sage: B = BipartiteGraph(M, weighted=True, sparse=True) # needs sage.modules sage.rings.finite_rings
1996
- sage: B.reduced_adjacency_matrix(base_ring=RDF) # needs sage.modules sage.rings.finite_rings
2000
+ sage: # needs sage.modules sage.rings.finite_rings
2001
+ sage: F.<a> = GF(4)
2002
+ sage: MS = MatrixSpace(F, 2, 3)
2003
+ sage: M = MS.matrix([[0, 1, a+1], [a, 1, 1]])
2004
+ sage: B = BipartiteGraph(M, weighted=True, sparse=True)
2005
+ sage: B.reduced_adjacency_matrix(base_ring=RDF)
1997
2006
Traceback (most recent call last):
1998
2007
...
1999
2008
TypeError: float() argument must be a string or a ...number, not 'sage.rings.finite_rings.element_givaro.FiniteField_givaroElement'
@@ -2295,10 +2304,11 @@ def vertex_cover(self, algorithm="Konig", value_only=False,
2295
2304
2296
2305
The two algorithms should return the same result::
2297
2306
2298
- sage: g = BipartiteGraph(graphs.RandomBipartite(10, 10, .5)) # needs numpy
2299
- sage: vc1 = g.vertex_cover(algorithm="Konig") # needs numpy
2300
- sage: vc2 = g.vertex_cover(algorithm="Cliquer") # needs numpy
2301
- sage: len(vc1) == len(vc2) # needs numpy
2307
+ sage: # needs numpy
2308
+ sage: g = BipartiteGraph(graphs.RandomBipartite(10, 10, .5))
2309
+ sage: vc1 = g.vertex_cover(algorithm="Konig")
2310
+ sage: vc2 = g.vertex_cover(algorithm="Cliquer")
2311
+ sage: len(vc1) == len(vc2)
2302
2312
True
2303
2313
2304
2314
TESTS:
0 commit comments