本文整理汇总了Python中sage.graphs.graph.Graph.relabel方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.relabel方法的具体用法?Python Graph.relabel怎么用?Python Graph.relabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.relabel方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def __init__(self, G):
"""
Initialize ``self``.
INPUT:
- ``G`` -- a graph
TESTS::
sage: G = RightAngledArtinGroup(graphs.CycleGraph(5))
sage: TestSuite(G).run()
"""
self._graph = G
F = FreeGroup(names=['v{}'.format(v) for v in self._graph.vertices()])
CG = Graph(G).complement() # Make sure it's mutable
CG.relabel() # Standardize the labels
rels = tuple(F([i+1, j+1, -i-1, -j-1]) for i,j in CG.edges(False)) #+/- 1 for indexing
FinitelyPresentedGroup.__init__(self, F, rels)
示例2: __init__
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def __init__(self, G, names):
"""
Initialize ``self``.
TESTS::
sage: G = RightAngledArtinGroup(graphs.CycleGraph(5))
sage: TestSuite(G).run()
"""
self._graph = G
F = FreeGroup(names=names)
CG = Graph(G).complement() # Make sure it's mutable
CG.relabel() # Standardize the labels
cm = [[-1]*CG.num_verts() for _ in range(CG.num_verts())]
for i in range(CG.num_verts()):
cm[i][i] = 1
for u,v in CG.edge_iterator(labels=False):
cm[u][v] = 2
cm[v][u] = 2
self._coxeter_group = CoxeterGroup(CoxeterMatrix(cm, index_set=G.vertices()))
rels = tuple(F([i + 1, j + 1, -i - 1, -j - 1])
for i, j in CG.edge_iterator(labels=False)) # +/- 1 for indexing
FinitelyPresentedGroup.__init__(self, F, rels)
示例3: relabel
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def relabel(self, perm = None, inplace = True, return_map = False,
check_input = True, complete_partial_function = True,
immutable = True):
r"""
This method has been overridden by DiscreteZOO to ensure that a mutable
copy will have type ``Graph``.
"""
if inplace:
raise ValueError("To relabel an immutable graph use inplace=False")
G = Graph(self, immutable = False)
perm = G.relabel(perm, return_map = True, check_input = check_input,
complete_partial_function = complete_partial_function)
if immutable is not False:
G = self.__class__(self, vertex_labels = perm)
if return_map:
return G, perm
else:
return G
示例4: relabel
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def relabel(
self,
perm=None,
inplace=True,
return_map=False,
check_input=True,
complete_partial_function=True,
immutable=True,
):
if inplace:
raise ValueError("To relabel an immutable graph use inplace=False")
G = Graph(self, immutable=False)
perm = G.relabel(
perm, return_map=True, check_input=check_input, complete_partial_function=complete_partial_function
)
if immutable is not False:
G = self.__class__(self, vertex_labels=perm)
if return_map:
return G, perm
else:
return G
示例5: make_graph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def make_graph(M):
"""
Code extracted from Sage's elliptic curve isogeny class (reshaped
in the case maxdegree==12)
"""
from sage.schemes.elliptic_curves.ell_curve_isogeny import fill_isogeny_matrix, unfill_isogeny_matrix
from sage.graphs.graph import Graph
n = M.nrows() # = M.ncols()
G = Graph(unfill_isogeny_matrix(M), format='weighted_adjacency_matrix')
MM = fill_isogeny_matrix(M)
# The maximum degree classifies the shape of the isogeny
# graph, though the number of vertices is often enough.
# This only holds over Q, so this code will need to change
# once other isogeny classes are implemented.
if n == 1:
# one vertex
pass
elif n == 2:
# one edge, two vertices. We align horizontally and put
# the lower number on the left vertex.
G.set_pos(pos={0:[-0.5,0],1:[0.5,0]})
else:
maxdegree = max(max(MM))
if n == 3:
# o--o--o
centervert = [i for i in range(3) if max(MM.row(i)) < maxdegree][0]
other = [i for i in range(3) if i != centervert]
G.set_pos(pos={centervert:[0,0],other[0]:[-1,0],other[1]:[1,0]})
elif maxdegree == 4:
# o--o<8
centervert = [i for i in range(4) if max(MM.row(i)) < maxdegree][0]
other = [i for i in range(4) if i != centervert]
G.set_pos(pos={centervert:[0,0],other[0]:[0,1],other[1]:[-0.8660254,-0.5],other[2]:[0.8660254,-0.5]})
elif maxdegree == 27:
# o--o--o--o
centers = [i for i in range(4) if list(MM.row(i)).count(3) == 2]
left = [j for j in range(4) if MM[centers[0],j] == 3 and j not in centers][0]
right = [j for j in range(4) if MM[centers[1],j] == 3 and j not in centers][0]
G.set_pos(pos={left:[-1.5,0],centers[0]:[-0.5,0],centers[1]:[0.5,0],right:[1.5,0]})
elif n == 4:
# square
opp = [i for i in range(1,4) if not MM[0,i].is_prime()][0]
other = [i for i in range(1,4) if i != opp]
G.set_pos(pos={0:[1,1],other[0]:[-1,1],opp:[-1,-1],other[1]:[1,-1]})
elif maxdegree == 8:
# 8>o--o<8
centers = [i for i in range(6) if list(MM.row(i)).count(2) == 3]
left = [j for j in range(6) if MM[centers[0],j] == 2 and j not in centers]
right = [j for j in range(6) if MM[centers[1],j] == 2 and j not in centers]
G.set_pos(pos={centers[0]:[-0.5,0],left[0]:[-1,0.8660254],left[1]:[-1,-0.8660254],centers[1]:[0.5,0],right[0]:[1,0.8660254],right[1]:[1,-0.8660254]})
elif maxdegree == 18:
# two squares joined on an edge
centers = [i for i in range(6) if list(MM.row(i)).count(3) == 2]
top = [j for j in range(6) if MM[centers[0],j] == 3]
bl = [j for j in range(6) if MM[top[0],j] == 2][0]
br = [j for j in range(6) if MM[top[1],j] == 2][0]
G.set_pos(pos={centers[0]:[0,0.5],centers[1]:[0,-0.5],top[0]:[-1,0.5],top[1]:[1,0.5],bl:[-1,-0.5],br:[1,-0.5]})
elif maxdegree == 16:
# tree from bottom, 3 regular except for the leaves.
centers = [i for i in range(8) if list(MM.row(i)).count(2) == 3]
center = [i for i in centers if len([j for j in centers if MM[i,j] == 2]) == 2][0]
centers.remove(center)
bottom = [j for j in range(8) if MM[center,j] == 2 and j not in centers][0]
left = [j for j in range(8) if MM[centers[0],j] == 2 and j != center]
right = [j for j in range(8) if MM[centers[1],j] == 2 and j != center]
G.set_pos(pos={center:[0,0],bottom:[0,-1],centers[0]:[-0.8660254,0.5],centers[1]:[0.8660254,0.5],left[0]:[-0.8660254,1.5],right[0]:[0.8660254,1.5],left[1]:[-1.7320508,0],right[1]:[1.7320508,0]})
elif maxdegree == 12:
# tent
centers = [i for i in range(8) if list(MM.row(i)).count(2) == 3]
left = [j for j in range(8) if MM[centers[0],j] == 2]
right = []
for i in range(3):
right.append([j for j in range(8) if MM[centers[1],j] == 2 and MM[left[i],j] == 3][0])
G.set_pos(pos={centers[0]:[-0.3,0],centers[1]:[0.3,0],
left[0]:[-0.14,0.15], right[0]:[0.14,0.15],
left[1]:[-0.14,-0.15],right[1]:[0.14,-0.15],
left[2]:[-0.14,-0.3],right[2]:[0.14,-0.3]})
G.relabel(range(1,n+1))
return G
示例6: NonisotropicUnitaryPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def NonisotropicUnitaryPolarGraph(m, q):
r"""
Returns the Graph `NU(m,q)`.
Returns the graph on nonisotropic, with respect to a nondegenerate
Hermitean form, points of the `(m-1)`-dimensional projective space over `F_q`,
with points adjacent whenever they lie on a tangent (to the set of isotropic points)
line.
For more information, see Sect. 9.9 of [BH12]_ and series C14 in [Hu75]_.
INPUT:
- ``m,q`` (integers) -- `q` must be a prime power.
EXAMPLES::
sage: g=graphs.NonisotropicUnitaryPolarGraph(5,2); g
NU(5, 2): Graph on 176 vertices
sage: g.is_strongly_regular(parameters=True)
(176, 135, 102, 108)
TESTS::
sage: graphs.NonisotropicUnitaryPolarGraph(4,2).is_strongly_regular(parameters=True)
(40, 27, 18, 18)
sage: graphs.NonisotropicUnitaryPolarGraph(4,3).is_strongly_regular(parameters=True) # long time
(540, 224, 88, 96)
sage: graphs.NonisotropicUnitaryPolarGraph(6,6)
Traceback (most recent call last):
...
ValueError: q must be a prime power
REFERENCE:
.. [Hu75] \X. L. Hubaut.
Strongly regular graphs.
Disc. Math. 13(1975), pp 357--381.
http://dx.doi.org/10.1016/0012-365X(75)90057-6
"""
p, k = is_prime_power(q,get_data=True)
if k==0:
raise ValueError('q must be a prime power')
from sage.libs.gap.libgap import libgap
from itertools import combinations
F=libgap.GF(q**2) # F_{q^2}
W=libgap.FullRowSpace(F, m) # F_{q^2}^m
B=libgap.Elements(libgap.Basis(W)) # the standard basis of W
if m % 2 != 0:
point = B[(m-1)/2]
else:
if p==2:
point = B[m/2] + F.PrimitiveRoot()*B[(m-2)/2]
else:
point = B[(m-2)/2] + B[m/2]
g = libgap.GeneralUnitaryGroup(m,q)
V = libgap.Orbit(g,point,libgap.OnLines) # orbit on nonisotropic points
gp = libgap.Action(g,V,libgap.OnLines) # make a permutation group
s = libgap.Subspace(W,[point, point+B[0]]) # a tangent line on point
# and the points there
sp = [libgap.Elements(libgap.Basis(x))[0] for x in libgap.Elements(s.Subspaces(1))]
h = libgap.Set(map(lambda x: libgap.Position(V, x), libgap.Intersection(V,sp))) # indices
L = libgap.Orbit(gp, h, libgap.OnSets) # orbit on the tangent lines
G = Graph()
for x in L: # every pair of points in the subspace is adjacent to each other in G
G.add_edges(combinations(x, 2))
G.relabel()
G.name("NU" + str((m, q)))
return G
示例7: UnitaryPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def UnitaryPolarGraph(m, q, algorithm="gap"):
r"""
Returns the Unitary Polar Graph `U(m,q)`.
For more information on Unitary Polar graphs, see the `page of
Andries Brouwer's website <http://www.win.tue.nl/~aeb/graphs/srghub.html>`_.
INPUT:
- ``m,q`` (integers) -- `q` must be a prime power.
- ``algorithm`` -- if set to 'gap' then the computation is carried via GAP
library interface, computing totally singular subspaces, which is faster for
large examples (especially with `q>2`). Otherwise it is done directly.
EXAMPLES::
sage: G = graphs.UnitaryPolarGraph(4,2); G
Unitary Polar Graph U(4, 2); GQ(4, 2): Graph on 45 vertices
sage: G.is_strongly_regular(parameters=True)
(45, 12, 3, 3)
sage: graphs.UnitaryPolarGraph(5,2).is_strongly_regular(parameters=True)
(165, 36, 3, 9)
sage: graphs.UnitaryPolarGraph(6,2) # not tested (long time)
Unitary Polar Graph U(6, 2): Graph on 693 vertices
TESTS::
sage: graphs.UnitaryPolarGraph(4,3, algorithm="gap").is_strongly_regular(parameters=True)
(280, 36, 8, 4)
sage: graphs.UnitaryPolarGraph(4,3).is_strongly_regular(parameters=True)
(280, 36, 8, 4)
sage: graphs.UnitaryPolarGraph(4,3, algorithm="foo")
Traceback (most recent call last):
...
ValueError: unknown algorithm!
"""
if algorithm == "gap":
from sage.libs.gap.libgap import libgap
G = _polar_graph(m, q**2, libgap.GeneralUnitaryGroup(m, q))
elif algorithm == None: # slow on large examples
from sage.schemes.projective.projective_space import ProjectiveSpace
from sage.modules.free_module_element import free_module_element as vector
Fq = FiniteField(q**2, 'a')
PG = map(vector, ProjectiveSpace(m - 1, Fq))
map(lambda x: x.set_immutable(), PG)
def P(x,y):
return sum(map(lambda j: x[j]*y[m-1-j]**q, xrange(m)))==0
V = filter(lambda x: P(x,x), PG)
G = Graph([V,lambda x,y: # bottleneck is here, of course:
P(x,y)], loops=False)
else:
raise ValueError("unknown algorithm!")
G.relabel()
G.name("Unitary Polar Graph U" + str((m, q)))
if m==4:
G.name(G.name()+'; GQ'+str((q**2,q)))
if m==5:
G.name(G.name()+'; GQ'+str((q**2,q**3)))
return G
示例8: SymplecticPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def SymplecticPolarGraph(d, q, algorithm=None):
r"""
Returns the Symplectic Polar Graph `Sp(d,q)`.
The Symplectic Polar Graph `Sp(d,q)` is built from a projective space of dimension
`d-1` over a field `F_q`, and a symplectic form `f`. Two vertices `u,v` are
made adjacent if `f(u,v)=0`.
See the page `on symplectic graphs on Andries Brouwer's website
<http://www.win.tue.nl/~aeb/graphs/Sp.html>`_.
INPUT:
- ``d,q`` (integers) -- note that only even values of `d` are accepted by
the function.
- ``algorithm`` -- if set to 'gap' then the computation is carried via GAP
library interface, computing totally singular subspaces, which is faster for `q>3`.
Otherwise it is done directly.
EXAMPLES:
Computation of the spectrum of `Sp(6,2)`::
sage: g = graphs.SymplecticGraph(6,2)
doctest:...: DeprecationWarning: SymplecticGraph is deprecated. Please use sage.graphs.generators.classical_geometries.SymplecticPolarGraph instead.
See http://trac.sagemath.org/19136 for details.
sage: g.is_strongly_regular(parameters=True)
(63, 30, 13, 15)
sage: set(g.spectrum()) == {-5, 3, 30}
True
The parameters of `Sp(4,q)` are the same as of `O(5,q)`, but they are
not isomorphic if `q` is odd::
sage: G = graphs.SymplecticPolarGraph(4,3)
sage: G.is_strongly_regular(parameters=True)
(40, 12, 2, 4)
sage: O=graphs.OrthogonalPolarGraph(5,3)
sage: O.is_strongly_regular(parameters=True)
(40, 12, 2, 4)
sage: O.is_isomorphic(G)
False
sage: graphs.SymplecticPolarGraph(6,4,algorithm="gap").is_strongly_regular(parameters=True) # not tested (long time)
(1365, 340, 83, 85)
TESTS::
sage: graphs.SymplecticPolarGraph(4,4,algorithm="gap").is_strongly_regular(parameters=True)
(85, 20, 3, 5)
sage: graphs.SymplecticPolarGraph(4,4).is_strongly_regular(parameters=True)
(85, 20, 3, 5)
sage: graphs.SymplecticPolarGraph(4,4,algorithm="blah")
Traceback (most recent call last):
...
ValueError: unknown algorithm!
"""
if d < 1 or d%2 != 0:
raise ValueError("d must be even and greater than 2")
if algorithm == "gap": # faster for larger (q>3) fields
from sage.libs.gap.libgap import libgap
G = _polar_graph(d, q, libgap.SymplecticGroup(d, q))
elif algorithm == None: # faster for small (q<4) fields
from sage.modules.free_module import VectorSpace
from sage.schemes.projective.projective_space import ProjectiveSpace
from sage.matrix.constructor import identity_matrix, block_matrix, zero_matrix
F = FiniteField(q,"x")
M = block_matrix(F, 2, 2,
[zero_matrix(F,d/2),
identity_matrix(F,d/2),
-identity_matrix(F,d/2),
zero_matrix(F,d/2)])
V = VectorSpace(F,d)
PV = list(ProjectiveSpace(d-1,F))
G = Graph([[tuple(_) for _ in PV], lambda x,y:V(x)*(M*V(y)) == 0], loops = False)
else:
raise ValueError("unknown algorithm!")
G.name("Symplectic Polar Graph Sp("+str(d)+","+str(q)+")")
G.relabel()
return G
示例9: _orthogonal_polar_graph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
#.........这里部分代码省略.........
sage: from sage.graphs.generators.classical_geometries import _orthogonal_polar_graph
sage: g=_orthogonal_polar_graph(3,5,point_type=[2,3])
sage: g.is_strongly_regular(parameters=True)
(10, 3, 0, 1)
A locally Petersen graph (a.k.a. Doro graph, a.k.a. Hall graph)::
sage: g=_orthogonal_polar_graph(4,5,'-',point_type=[2,3])
sage: g.is_distance_regular(parameters=True)
([10, 6, 4, None], [None, 1, 2, 5])
Various big and slow to build graphs:
`NO^+(7,3)`::
sage: g=_orthogonal_polar_graph(7,3,point_type=[1]) # not tested (long time)
sage: g.is_strongly_regular(parameters=True) # not tested (long time)
(378, 117, 36, 36)
`NO^-(7,3)`::
sage: g=_orthogonal_polar_graph(7,3,point_type=[-1]) # not tested (long time)
sage: g.is_strongly_regular(parameters=True) # not tested (long time)
(351, 126, 45, 45)
`NO^+(6,3)`::
sage: g=_orthogonal_polar_graph(6,3,point_type=[1])
sage: g.is_strongly_regular(parameters=True)
(117, 36, 15, 9)
`NO^-(6,3)`::
sage: g=_orthogonal_polar_graph(6,3,'-',point_type=[1])
sage: g.is_strongly_regular(parameters=True)
(126, 45, 12, 18)
`NO^{-,\perp}(5,5)`::
sage: g=_orthogonal_polar_graph(5,5,point_type=[2,3]) # long time
sage: g.is_strongly_regular(parameters=True) # long time
(300, 65, 10, 15)
`NO^{+,\perp}(5,5)`::
sage: g=_orthogonal_polar_graph(5,5,point_type=[1,-1]) # not tested (long time)
sage: g.is_strongly_regular(parameters=True) # not tested (long time)
(325, 60, 15, 10)
TESTS::
sage: g=_orthogonal_polar_graph(5,3,point_type=[-1])
sage: g.is_strongly_regular(parameters=True)
(45, 12, 3, 3)
sage: g=_orthogonal_polar_graph(5,3,point_type=[1])
sage: g.is_strongly_regular(parameters=True)
(36, 15, 6, 6)
"""
from sage.schemes.projective.projective_space import ProjectiveSpace
from sage.modules.free_module_element import free_module_element as vector
from sage.matrix.constructor import Matrix
from sage.libs.gap.libgap import libgap
from itertools import combinations
if m % 2 == 0:
if sign != "+" and sign != "-":
raise ValueError("sign must be equal to either '-' or '+' when "
"m is even")
else:
if sign != "" and sign != "+":
raise ValueError("sign must be equal to either '' or '+' when "
"m is odd")
sign = ""
e = {'+': 1,
'-': -1,
'' : 0}[sign]
M = Matrix(libgap.InvariantQuadraticForm(libgap.GeneralOrthogonalGroup(e,m,q))['matrix'])
Fq = libgap.GF(q).sage()
PG = map(vector, ProjectiveSpace(m - 1, Fq))
map(lambda x: x.set_immutable(), PG)
def F(x):
return x*M*x
if q % 2 == 0:
def P(x,y):
return F(x-y)
else:
def P(x,y):
return x*M*y+y*M*x
V = [x for x in PG if F(x) in point_type]
G = Graph([V,lambda x,y:P(x,y)==0],loops=False)
G.relabel()
return G
示例10: AffineOrthogonalPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def AffineOrthogonalPolarGraph(d,q,sign="+"):
r"""
Returns the affine polar graph `VO^+(d,q),VO^-(d,q)` or `VO(d,q)`.
Affine Polar graphs are built from a `d`-dimensional vector space over
`F_q`, and a quadratic form which is hyperbolic, elliptic or parabolic
according to the value of ``sign``.
Note that `VO^+(d,q),VO^-(d,q)` are strongly regular graphs, while `VO(d,q)`
is not.
For more information on Affine Polar graphs, see `Affine Polar
Graphs page of Andries Brouwer's website
<http://www.win.tue.nl/~aeb/graphs/VO.html>`_.
INPUT:
- ``d`` (integer) -- ``d`` must be even if ``sign != None``, and odd
otherwise.
- ``q`` (integer) -- a power of a prime number, as `F_q` must exist.
- ``sign`` -- must be equal to ``"+"``, ``"-"``, or ``None`` to compute
(respectively) `VO^+(d,q),VO^-(d,q)` or `VO(d,q)`. By default
``sign="+"``.
.. NOTE::
The graph `VO^\epsilon(d,q)` is the graph induced by the
non-neighbors of a vertex in an :meth:`Orthogonal Polar Graph
<OrthogonalPolarGraph>` `O^\epsilon(d+2,q)`.
EXAMPLES:
The :meth:`Brouwer-Haemers graph <BrouwerHaemersGraph>` is isomorphic to
`VO^-(4,3)`::
sage: g = graphs.AffineOrthogonalPolarGraph(4,3,"-")
sage: g.is_isomorphic(graphs.BrouwerHaemersGraph())
True
Some examples from `Brouwer's table or strongly regular graphs
<http://www.win.tue.nl/~aeb/graphs/srg/srgtab.html>`_::
sage: g = graphs.AffineOrthogonalPolarGraph(6,2,"-"); g
Affine Polar Graph VO^-(6,2): Graph on 64 vertices
sage: g.is_strongly_regular(parameters=True)
(64, 27, 10, 12)
sage: g = graphs.AffineOrthogonalPolarGraph(6,2,"+"); g
Affine Polar Graph VO^+(6,2): Graph on 64 vertices
sage: g.is_strongly_regular(parameters=True)
(64, 35, 18, 20)
When ``sign is None``::
sage: g = graphs.AffineOrthogonalPolarGraph(5,2,None); g
Affine Polar Graph VO^-(5,2): Graph on 32 vertices
sage: g.is_strongly_regular(parameters=True)
False
sage: g.is_regular()
True
sage: g.is_vertex_transitive()
True
"""
if sign in ["+","-"]:
s = 1 if sign == "+" else -1
if d%2 == 1:
raise ValueError("d must be even when sign!=None")
else:
if d%2 == 0:
raise ValueError("d must be odd when sign==None")
s = 0
from sage.interfaces.gap import gap
from sage.modules.free_module import VectorSpace
from sage.matrix.constructor import Matrix
from sage.libs.gap.libgap import libgap
from itertools import combinations
M = Matrix(libgap.InvariantQuadraticForm(libgap.GeneralOrthogonalGroup(s,d,q))['matrix'])
F = libgap.GF(q).sage()
V = list(VectorSpace(F,d))
G = Graph()
G.add_vertices([tuple(_) for _ in V])
for x,y in combinations(V,2):
if not (x-y)*M*(x-y):
G.add_edge(tuple(x),tuple(y))
G.name("Affine Polar Graph VO^"+str('+' if s == 1 else '-')+"("+str(d)+","+str(q)+")")
G.relabel()
return G
示例11: graph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def graph(self):
"""
Returns a graph whose vertices correspond to curves in this class, and whose edges correspond to prime degree isogenies.
.. note:
There are only finitely many possible isogeny graphs for
curves over Q [M78]. This function tries to lay out the graph
nicely by special casing each isogeny graph.
.. note:
The vertices are labeled 1 to n rather than 0 to n-1 to
correspond to LMFDB and Cremona labels.
EXAMPLES::
sage: isocls = EllipticCurve('15a3').isogeny_class(use_tuple=False)
sage: G = isocls.graph()
sage: sorted(G._pos.items())
[(1, [-0.8660254, 0.5]), (2, [-0.8660254, 1.5]), (3, [-1.7320508, 0]), (4, [0, 0]), (5, [0, -1]), (6, [0.8660254, 0.5]), (7, [0.8660254, 1.5]), (8, [1.7320508, 0])]
REFERENCES:
.. [M78] B. Mazur. Rational Isogenies of Prime Degree.
*Inventiones mathematicae* 44,129-162 (1978).
"""
from sage.graphs.graph import Graph
M = self.matrix(fill = False)
n = M.nrows() # = M.ncols()
G = Graph(M, format='weighted_adjacency_matrix')
N = self.matrix(fill = True)
D = dict([(v,self.curves[v]) for v in G.vertices()])
# The maximum degree classifies the shape of the isogeny
# graph, though the number of vertices is often enough.
# This only holds over Q, so this code will need to change
# once other isogeny classes are implemented.
if n == 1:
# one vertex
pass
elif n == 2:
# one edge, two vertices. We align horizontally and put
# the lower number on the left vertex.
G.set_pos(pos={0:[-0.5,0],1:[0.5,0]})
else:
maxdegree = max(max(N))
if n == 3:
# o--o--o
centervert = [i for i in range(3) if max(N.row(i)) < maxdegree][0]
other = [i for i in range(3) if i != centervert]
G.set_pos(pos={centervert:[0,0],other[0]:[-1,0],other[1]:[1,0]})
elif maxdegree == 4:
# o--o<8
centervert = [i for i in range(4) if max(N.row(i)) < maxdegree][0]
other = [i for i in range(4) if i != centervert]
G.set_pos(pos={centervert:[0,0],other[0]:[0,1],other[1]:[-0.8660254,-0.5],other[2]:[0.8660254,-0.5]})
elif maxdegree == 27:
# o--o--o--o
centers = [i for i in range(4) if list(N.row(i)).count(3) == 2]
left = [j for j in range(4) if N[centers[0],j] == 3 and j not in centers][0]
right = [j for j in range(4) if N[centers[1],j] == 3 and j not in centers][0]
G.set_pos(pos={left:[-1.5,0],centers[0]:[-0.5,0],centers[1]:[0.5,0],right:[1.5,0]})
elif n == 4:
# square
opp = [i for i in range(1,4) if not N[0,i].is_prime()][0]
other = [i for i in range(1,4) if i != opp]
G.set_pos(pos={0:[1,1],other[0]:[-1,1],opp:[-1,-1],other[1]:[1,-1]})
elif maxdegree == 8:
# 8>o--o<8
centers = [i for i in range(6) if list(N.row(i)).count(2) == 3]
left = [j for j in range(6) if N[centers[0],j] == 2 and j not in centers]
right = [j for j in range(6) if N[centers[1],j] == 2 and j not in centers]
G.set_pos(pos={centers[0]:[-0.5,0],left[0]:[-1,0.8660254],left[1]:[-1,-0.8660254],centers[1]:[0.5,0],right[0]:[1,0.8660254],right[1]:[1,-0.8660254]})
elif maxdegree == 18:
# two squares joined on an edge
centers = [i for i in range(6) if list(N.row(i)).count(3) == 2]
top = [j for j in range(6) if N[centers[0],j] == 3]
bl = [j for j in range(6) if N[top[0],j] == 2][0]
br = [j for j in range(6) if N[top[1],j] == 2][0]
G.set_pos(pos={centers[0]:[0,0.5],centers[1]:[0,-0.5],top[0]:[-1,0.5],top[1]:[1,0.5],bl:[-1,-0.5],br:[1,-0.5]})
elif maxdegree == 16:
# tree from bottom, 3 regular except for the leaves.
centers = [i for i in range(8) if list(N.row(i)).count(2) == 3]
center = [i for i in centers if len([j for j in centers if N[i,j] == 2]) == 2][0]
centers.remove(center)
bottom = [j for j in range(8) if N[center,j] == 2 and j not in centers][0]
left = [j for j in range(8) if N[centers[0],j] == 2 and j != center]
right = [j for j in range(8) if N[centers[1],j] == 2 and j != center]
G.set_pos(pos={center:[0,0],bottom:[0,-1],centers[0]:[-0.8660254,0.5],centers[1]:[0.8660254,0.5],left[0]:[-0.8660254,1.5],right[0]:[0.8660254,1.5],left[1]:[-1.7320508,0],right[1]:[1.7320508,0]})
elif maxdegree == 12:
# tent
centers = [i for i in range(8) if list(N.row(i)).count(2) == 3]
left = [j for j in range(8) if N[centers[0],j] == 2]
right = []
for i in range(3):
right.append([j for j in range(8) if N[centers[1],j] == 2 and N[left[i],j] == 3][0])
G.set_pos(pos={centers[0]:[-0.75,0],centers[1]:[0.75,0],left[0]:[-0.75,1],right[0]:[0.75,1],left[1]:[-1.25,-0.75],right[1]:[0.25,-0.75],left[2]:[-0.25,-0.25],right[2]:[1.25,-0.25]})
G.set_vertices(D)
G.relabel(range(1,n+1))
return G
示例12: ChessboardGraphGenerator
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import relabel [as 别名]
def ChessboardGraphGenerator(dim_list,
rook = True, rook_radius = None,
bishop = True, bishop_radius = None,
knight = True, knight_x = 1, knight_y = 2,
relabel = False):
r"""
Returns a Graph built on a `d`-dimensional chessboard with prescribed
dimensions and interconnections.
This function allows to generate many kinds of graphs corresponding to legal
movements on a `d`-dimensional chessboard: Queen Graph, King Graph, Knight
Graphs, Bishop Graph, and many generalizations. It also allows to avoid
redondant code.
INPUT:
- ``dim_list`` -- an iterable object (list, set, dict) providing the
dimensions `n_1, n_2, \ldots, n_d`, with `n_i \geq 1`, of the chessboard.
- ``rook`` -- (default: ``True``) boolean value indicating if the chess
piece is able to move as a rook, that is at any distance along a
dimension.
- ``rook_radius`` -- (default: None) integer value restricting the rook-like
movements to distance at most `rook_radius`.
- ``bishop`` -- (default: ``True``) boolean value indicating if the chess
piece is able to move like a bishop, that is along diagonals.
- ``bishop_radius`` -- (default: None) integer value restricting the
bishop-like movements to distance at most `bishop_radius`.
- ``knight`` -- (default: ``True``) boolean value indicating if the chess
piece is able to move like a knight.
- ``knight_x`` -- (default: 1) integer indicating the number on steps the
chess piece moves in one dimension when moving like a knight.
- ``knight_y`` -- (default: 2) integer indicating the number on steps the
chess piece moves in the second dimension when moving like a knight.
- ``relabel`` -- (default: ``False``) a boolean set to ``True`` if vertices
must be relabeled as integers.
OUTPUT:
- A Graph build on a `d`-dimensional chessboard with prescribed dimensions,
and with edges according given parameters.
- A string encoding the dimensions. This is mainly useful for providing
names to graphs.
EXAMPLES:
A `(2,2)`-King Graph is isomorphic to the complete graph on 4 vertices::
sage: G, _ = graphs.ChessboardGraphGenerator( [2,2] )
sage: G.is_isomorphic( graphs.CompleteGraph(4) )
True
A Rook's Graph in 2 dimensions is isomporphic to the Cartesian product of 2
complete graphs::
sage: G, _ = graphs.ChessboardGraphGenerator( [3,4], rook=True, rook_radius=None, bishop=False, knight=False )
sage: H = ( graphs.CompleteGraph(3) ).cartesian_product( graphs.CompleteGraph(4) )
sage: G.is_isomorphic(H)
True
TESTS:
Giving dimensions less than 2::
sage: graphs.ChessboardGraphGenerator( [0, 2] )
Traceback (most recent call last):
...
ValueError: The dimensions must be positive integers larger than 1.
Giving non integer dimensions::
sage: graphs.ChessboardGraphGenerator( [4.5, 2] )
Traceback (most recent call last):
...
ValueError: The dimensions must be positive integers larger than 1.
Giving too few dimensions::
sage: graphs.ChessboardGraphGenerator( [2] )
Traceback (most recent call last):
...
ValueError: The chessboard must have at least 2 dimensions.
Giving a non-iterable object as first parameter::
sage: graphs.ChessboardGraphGenerator( 2, 3 )
Traceback (most recent call last):
...
TypeError: The first parameter must be an iterable object.
Giving too small rook radius::
#.........这里部分代码省略.........