本文整理汇总了Python中sage.graphs.graph.Graph.name方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.name方法的具体用法?Python Graph.name怎么用?Python Graph.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CompleteMultipartiteGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def CompleteMultipartiteGraph(l):
r"""
Returns a complete multipartite graph.
INPUT:
- ``l`` -- a list of integers : the respective sizes
of the components.
EXAMPLE:
A complete tripartite graph with sets of sizes
`5, 6, 8`::
sage: g = graphs.CompleteMultipartiteGraph([5, 6, 8]); g
Multipartite Graph with set sizes [5, 6, 8]: Graph on 19 vertices
It clearly has a chromatic number of 3::
sage: g.chromatic_number()
3
"""
g = Graph()
for i in l:
g = g + CompleteGraph(i)
g = g.complement()
g.name("Multipartite Graph with set sizes "+str(l))
return g
示例2: name
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def name(self, new = None, *largs, **kargs):
store = lookup(kargs, "store",
default = self._initialized and discretezoo.WRITE_TO_DB,
destroy = True)
cur = lookup(kargs, "cur", default = None, destroy = True)
default = len(largs) + len(kargs) == 0
if default:
old = lookup(self._graphprops, "name", default = "")
if new is None:
return old
elif new != old:
if new == "":
new = None
if store:
self._update_rows(ZooGraph, {"name": new},
{self._spec["primary_key"]: self._zooid},
cur = cur)
update(self._graphprops, "name", new)
else:
return Graph.name(self, new, *largs, **kargs)
示例3: NonisotropicUnitaryPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [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
示例4: TaylorTwographDescendantSRG
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def TaylorTwographDescendantSRG(q, clique_partition=None):
r"""
constructing the descendant graph of the Taylor's two-graph for `U_3(q)`, `q` odd
This is a strongly regular graph with parameters
`(v,k,\lambda,\mu)=(q^3, (q^2+1)(q-1)/2, (q-1)^3/4-1, (q^2+1)(q-1)/4)`
obtained as a two-graph descendant of the
:func:`Taylor's two-graph <sage.combinat.designs.twographs.taylor_twograph>` `T`.
This graph admits a partition into cliques of size `q`, which are useful in
:func:`~sage.graphs.graph_generators.GraphGenerators.TaylorTwographSRG`,
a strongly regular graph on `q^3+1` vertices in the
Seidel switching class of `T`, for which we need `(q^2+1)/2` cliques.
The cliques are the `q^2` lines on `v_0` of the projective plane containing the unital
for `U_3(q)`, and intersecting the unital (i.e. the vertices of the graph and the point
we remove) in `q+1` points. This is all taken from §7E of [BvL84]_.
INPUT:
- ``q`` -- a power of an odd prime number
- ``clique_partition`` -- if ``True``, return `q^2-1` cliques of size `q`
with empty pairwise intersection. (Removing all of them leaves a clique, too),
and the point removed from the unital.
EXAMPLES::
sage: g=graphs.TaylorTwographDescendantSRG(3); g
Taylor two-graph descendant SRG: Graph on 27 vertices
sage: g.is_strongly_regular(parameters=True)
(27, 10, 1, 5)
sage: from sage.combinat.designs.twographs import taylor_twograph
sage: T = taylor_twograph(3) # long time
sage: g.is_isomorphic(T.descendant(T.ground_set()[1])) # long time
True
sage: g=graphs.TaylorTwographDescendantSRG(5) # not tested (long time)
sage: g.is_strongly_regular(parameters=True) # not tested (long time)
(125, 52, 15, 26)
TESTS::
sage: g,l,_=graphs.TaylorTwographDescendantSRG(3,clique_partition=True)
sage: all(map(lambda x: g.is_clique(x), l))
True
sage: graphs.TaylorTwographDescendantSRG(4)
Traceback (most recent call last):
...
ValueError: q must be an odd prime power
sage: graphs.TaylorTwographDescendantSRG(6)
Traceback (most recent call last):
...
ValueError: q must be an odd prime power
"""
p, k = is_prime_power(q,get_data=True)
if k==0 or p==2:
raise ValueError('q must be an odd prime power')
from sage.schemes.projective.projective_space import ProjectiveSpace
from sage.modules.free_module_element import free_module_element as vector
from sage.rings.finite_rings.integer_mod import mod
from __builtin__ import sum
Fq = FiniteField(q**2, 'a')
PG = map(tuple,ProjectiveSpace(2, Fq))
def S(x,y):
return sum(map(lambda j: x[j]*y[2-j]**q, xrange(3)))
V = filter(lambda x: S(x,x)==0, PG) # the points of the unital
v0 = V[0]
V.remove(v0)
if mod(q,4)==1:
G = Graph([V,lambda y,z: not (S(v0,y)*S(y,z)*S(z,v0)).is_square()], loops=False)
else:
G = Graph([V,lambda y,z: (S(v0,y)*S(y,z)*S(z,v0)).is_square()], loops=False)
G.name("Taylor two-graph descendant SRG")
if clique_partition:
lines = map(lambda x: filter(lambda t: t[0]+x*t[1]==0, V),
filter(lambda z: z != 0, Fq))
return (G, lines, v0)
else:
return G
示例5: NonisotropicOrthogonalPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
#.........这里部分代码省略.........
sage: g=graphs.NonisotropicOrthogonalPolarGraph(8,2,'+')
sage: g.is_strongly_regular(parameters=True)
(120, 63, 30, 36)
Wilbrink's graphs for `q=5`::
sage: graphs.NonisotropicOrthogonalPolarGraph(5,5,perp=1).is_strongly_regular(parameters=True) # long time
(325, 60, 15, 10)
sage: graphs.NonisotropicOrthogonalPolarGraph(5,5,'-',perp=1).is_strongly_regular(parameters=True) # long time
(300, 65, 10, 15)
Wilbrink's graphs::
sage: g=graphs.NonisotropicOrthogonalPolarGraph(5,4,'+')
sage: g.is_strongly_regular(parameters=True)
(136, 75, 42, 40)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(5,4,'-')
sage: g.is_strongly_regular(parameters=True)
(120, 51, 18, 24)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(7,4,'+'); g # not tested (long time)
NO^+(7, 4): Graph on 2080 vertices
sage: g.is_strongly_regular(parameters=True) # not tested (long time)
(2080, 1071, 558, 544)
TESTS::
sage: g=graphs.NonisotropicOrthogonalPolarGraph(4,2); g
NO^+(4, 2): Graph on 6 vertices
sage: graphs.NonisotropicOrthogonalPolarGraph(4,3,'-').is_strongly_regular(parameters=True)
(15, 6, 1, 3)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(3,5,'-',perp=1); g
NO^-,perp(3, 5): Graph on 10 vertices
sage: g.is_strongly_regular(parameters=True)
(10, 3, 0, 1)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(6,3,'+') # long time
sage: g.is_strongly_regular(parameters=True) # long time
(117, 36, 15, 9)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(6,3,'-'); g # long time
NO^-(6, 3): Graph on 126 vertices
sage: g.is_strongly_regular(parameters=True) # long time
(126, 45, 12, 18)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(5,5,'-') # long time
sage: g.is_strongly_regular(parameters=True) # long time
(300, 104, 28, 40)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(5,5,'+') # long time
sage: g.is_strongly_regular(parameters=True) # long time
(325, 144, 68, 60)
sage: g=graphs.NonisotropicOrthogonalPolarGraph(6,4,'+')
Traceback (most recent call last):
...
ValueError: for m even q must be 2 or 3
"""
from sage.graphs.generators.classical_geometries import _orthogonal_polar_graph
p, k = is_prime_power(q,get_data=True)
if k==0:
raise ValueError('q must be a prime power')
dec = ''
if m % 2 == 0:
if q in [2,3]:
G = _orthogonal_polar_graph(m, q, sign=sign, point_type=[1])
else:
raise ValueError("for m even q must be 2 or 3")
elif not perp is None:
if q == 5:
G = _orthogonal_polar_graph(m, q, point_type=\
[-1,1] if sign=='+' else [2,3] if sign=='-' else [])
dec = ",perp"
else:
raise ValueError("for perp not None q must be 5")
else:
if not sign in ['+','-']:
raise ValueError("sign must be '+' or '-'")
from sage.libs.gap.libgap import libgap
g0 = libgap.GeneralOrthogonalGroup(m,q)
g = libgap.Group(libgap.List(g0.GeneratorsOfGroup(),libgap.TransposedMat))
F=libgap.GF(q) # F_q
W=libgap.FullRowSpace(F, m) # F_q^m
e = 1 if sign=='+' else -1
n = (m-1)/2
# we build (q^n(q^n+e)/2, (q^n-e)(q^(n-1)+e), 2(q^(2n-2)-1)+eq^(n-1)(q-1),
# 2q^(n-1)(q^(n-1)+e))-srg
# **use** v and k to select appropriate orbit and orbital
nvert = (q**n)*(q**n+e)/2 # v
deg = (q**n-e)*(q**(n-1)+e) # k
S=map(lambda x: libgap.Elements(libgap.Basis(x))[0], \
libgap.Elements(libgap.Subspaces(W,1)))
V = filter(lambda x: len(x)==nvert, libgap.Orbits(g,S,libgap.OnLines))
assert len(V)==1
V = V[0]
gp = libgap.Action(g,V,libgap.OnLines) # make a permutation group
h = libgap.Stabilizer(gp,1)
Vh = filter(lambda x: len(x)==deg, libgap.Orbits(h,libgap.Orbit(gp,1)))
assert len(Vh)==1
Vh = Vh[0][0]
L = libgap.Orbit(gp, [1, Vh], libgap.OnSets)
G = Graph()
G.add_edges(L)
G.name("NO^" + sign + dec + str((m, q)))
return G
示例6: UnitaryPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [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
示例7: CossidentePenttilaGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
#.........这里部分代码省略.........
Cossidente-Penttila `((q^3+1)(q+1)/2,(q^2+1)(q-1)/2,(q-3)/2,(q-1)^2/2)`-strongly regular graph
For each odd prime power `q`, one can partition the points of the `O_6^-(q)`-generalized
quadrange `GQ(q,q^2)` into two parts, so that on any of them the induced subgraph of
the point graph of the GQ has parameters as above [CP05]_.
Directly follwing the construction in [CP05]_ is not efficient,
as one then needs to construct the dual `GQ(q^2,q)`. Thus we
describe here a more efficient approach that we came up with, following a suggestion by
T.Penttila. Namely, this partition is invariant
under the subgroup `H=\Omega_3(q^2)<O_6^-(q)`. We build the appropriate `H`, which
leaves the form `B(X,Y,Z)=XY+Z^2` invariant, and
pick up two orbits of `H` on the `F_q`-points. One them is `B`-isotropic, and we
take the representative `(1:0:0)`. The other one corresponds to the points of
`PG(2,q^2)` that have all the lines on them either missing the conic specified by `B`, or
intersecting the conic in two points. We take `(1:1:e)` as the representative. It suffices
to pick `e` so that `e^2+1` is not a square in `F_{q^2}`. Indeed,
The conic can be viewed as the union of `\{(0:1:0)\}` and `\{(1:-t^2:t) | t \in F_{q^2}\}`.
The coefficients of a generic line on `(1:1:e)` are `[1:-1-eb:b]`, for `-1\neq eb`.
Thus, to make sure the intersection with the conic is always even, we need that the
discriminant of `1+(1+eb)t^2+tb=0` never vanishes, and this is if and only if
`e^2+1` is not a square. Further, we need to adjust `B`, by multiplying it by appropriately
chosen `\nu`, so that `(1:1:e)` becomes isotropic under the relative trace norm
`\nu B(X,Y,Z)+(\nu B(X,Y,Z))^q`. The latter is used then to define the graph.
INPUT:
- ``q`` -- an odd prime power.
EXAMPLES:
For `q=3` one gets Sims-Gewirtz graph. ::
sage: G=graphs.CossidentePenttilaGraph(3) # optional - gap_packages (grape)
sage: G.is_strongly_regular(parameters=True) # optional - gap_packages (grape)
(56, 10, 0, 2)
For `q>3` one gets new graphs. ::
sage: G=graphs.CossidentePenttilaGraph(5) # optional - gap_packages (grape)
sage: G.is_strongly_regular(parameters=True) # optional - gap_packages (grape)
(378, 52, 1, 8)
TESTS::
sage: G=graphs.CossidentePenttilaGraph(7) # optional - gap_packages (grape) # long time
sage: G.is_strongly_regular(parameters=True) # optional - gap_packages (grape) # long time
(1376, 150, 2, 18)
sage: graphs.CossidentePenttilaGraph(2)
Traceback (most recent call last):
...
ValueError: q(=2) must be an odd prime power
REFERENCES:
.. [CP05] \A.Cossidente and T.Penttila
Hemisystems on the Hermitian surface
Journal of London Math. Soc. 72(2005), 731-741
"""
p, k = is_prime_power(q,get_data=True)
if k==0 or p==2:
raise ValueError('q(={}) must be an odd prime power'.format(q))
from sage.libs.gap.libgap import libgap
from sage.misc.package import is_package_installed, PackageNotFoundError
if not is_package_installed('gap_packages'):
raise PackageNotFoundError('gap_packages')
adj_list=libgap.function_factory("""function(q)
local z, e, so, G, nu, G1, G0, B, T, s, O1, O2, x;
LoadPackage("grape");
G0:=SO(3,q^2);
so:=GeneratorsOfGroup(G0);
G1:=Group(Comm(so[1],so[2]),Comm(so[1],so[3]),Comm(so[2],so[3]));
B:=InvariantBilinearForm(G0).matrix;
z:=Z(q^2); e:=z; sqo:=(q^2-1)/2;
if IsInt(sqo/Order(e^2+z^0)) then
e:=z^First([2..q^2-2], x-> not IsInt(sqo/Order(z^(2*x)+z^0)));
fi;
nu:=z^First([0..q^2-2], x->z^x*(e^2+z^0)+(z^x*(e^2+z^0))^q=0*z);
T:=function(x)
local r;
r:=nu*x*B*x;
return r+r^q;
end;
s:=Group([Z(q)*IdentityMat(3,GF(q))]);
O1:=Orbit(G1, Set(Orbit(s,z^0*[1,0,0])), OnSets);
O2:=Orbit(G1, Set(Orbit(s,z^0*[1,1,e])), OnSets);
G:=Graph(G1,Concatenation(O1,O2),OnSets,
function(x,y) return x<>y and 0*z=T(x[1]+y[1]); end);
return List([1..OrderGraph(G)],x->Adjacency(G,x));
end;""")
adj = adj_list(q) # for each vertex, we get the list of vertices it is adjacent to
G = Graph(((i,int(j-1))
for i,ni in enumerate(adj) for j in ni),
format='list_of_edges', multiedges=False)
G.name('CossidentePenttila('+str(q)+')')
return G
示例8: SymplecticPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [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: OrthogonalArrayBlockGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
#.........这里部分代码省略.........
- ``OA`` -- An orthogonal array. If set to ``None`` (default) then
:func:`~sage.combinat.designs.orthogonal_arrays.orthogonal_array` is
called to compute an `OA(k,n)`.
EXAMPLES::
sage: G = graphs.OrthogonalArrayBlockGraph(5,5); G
OA(5,5): Graph on 25 vertices
sage: G.is_strongly_regular(parameters=True)
(25, 20, 15, 20)
sage: G = graphs.OrthogonalArrayBlockGraph(4,10); G
OA(4,10): Graph on 100 vertices
sage: G.is_strongly_regular(parameters=True)
(100, 36, 14, 12)
Two graphs built from different orthogonal arrays are also different::
sage: k=4;n=10
sage: OAa = designs.orthogonal_arrays.build(k,n)
sage: OAb = [[(x+1)%n for x in R] for R in OAa]
sage: set(map(tuple,OAa)) == set(map(tuple,OAb))
False
sage: Ga = graphs.OrthogonalArrayBlockGraph(k,n,OAa)
sage: Gb = graphs.OrthogonalArrayBlockGraph(k,n,OAb)
sage: Ga == Gb
False
As ``OAb`` was obtained from ``OAa`` by a relabelling the two graphs are
isomorphic::
sage: Ga.is_isomorphic(Gb)
True
But there are examples of `OA(k,n)` for which the resulting graphs are not
isomorphic::
sage: oa0 = [[0, 0, 1], [0, 1, 3], [0, 2, 0], [0, 3, 2],
....: [1, 0, 3], [1, 1, 1], [1, 2, 2], [1, 3, 0],
....: [2, 0, 0], [2, 1, 2], [2, 2, 1], [2, 3, 3],
....: [3, 0, 2], [3, 1, 0], [3, 2, 3], [3, 3, 1]]
sage: oa1 = [[0, 0, 1], [0, 1, 0], [0, 2, 3], [0, 3, 2],
....: [1, 0, 3], [1, 1, 2], [1, 2, 0], [1, 3, 1],
....: [2, 0, 0], [2, 1, 1], [2, 2, 2], [2, 3, 3],
....: [3, 0, 2], [3, 1, 3], [3, 2, 1], [3, 3, 0]]
sage: g0 = graphs.OrthogonalArrayBlockGraph(3,4,oa0)
sage: g1 = graphs.OrthogonalArrayBlockGraph(3,4,oa1)
sage: g0.is_isomorphic(g1)
False
But nevertheless isospectral::
sage: g0.spectrum()
[9, 1, 1, 1, 1, 1, 1, 1, 1, 1, -3, -3, -3, -3, -3, -3]
sage: g1.spectrum()
[9, 1, 1, 1, 1, 1, 1, 1, 1, 1, -3, -3, -3, -3, -3, -3]
Note that the graph ``g0`` is actually isomorphic to the affine polar graph
`VO^+(4,2)`::
sage: graphs.AffineOrthogonalPolarGraph(4,2,'+').is_isomorphic(g0)
True
TESTS::
sage: G = graphs.OrthogonalArrayBlockGraph(4,6)
Traceback (most recent call last):
...
NotImplementedError: I don't know how to build an OA(4,6)!
sage: G = graphs.OrthogonalArrayBlockGraph(8,2)
Traceback (most recent call last):
...
ValueError: There is no OA(8,2). Beware, Brouwer's website uses OA(n,k) instead of OA(k,n) !
"""
if n>1 and k>=n+2:
raise ValueError("There is no OA({},{}). Beware, Brouwer's website uses OA(n,k) instead of OA(k,n) !".format(k,n))
from itertools import combinations
if OA is None:
from sage.combinat.designs.orthogonal_arrays import orthogonal_array
OA = orthogonal_array(k,n)
else:
assert len(OA) == n**2
assert n == 0 or k == len(OA[0])
OA = map(tuple,OA)
d = [[[] for j in range(n)] for i in range(k)]
for R in OA:
for i,x in enumerate(R):
d[i][x].append(R)
g = Graph()
for l in d:
for ll in l:
g.add_edges(combinations(ll,2))
g.name("OA({},{})".format(k,n))
return g
示例10: AffineOrthogonalPolarGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [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: WorldMap
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def WorldMap():
"""
Returns the Graph of all the countries, in which two countries are adjacent
in the graph if they have a common boundary.
This graph has been built from the data available
in The CIA World Factbook [CIA]_ (2009-08-21).
The returned graph ``G`` has a member ``G.gps_coordinates``
equal to a dictionary containing the GPS coordinates
of each country's capital city.
EXAMPLES::
sage: g=graphs.WorldMap()
sage: g.has_edge("France","Italy")
True
sage: g.gps_coordinates["Bolivia"]
[[17, 'S'], [65, 'W']]
sage: sorted(g.connected_component_containing_vertex('Ireland'))
['Ireland', 'United Kingdom']
REFERENCE:
.. [CIA] CIA Factbook 09 https://www.cia.gov/library/publications/the-world-factbook/
"""
edges = [
('Afghanistan', 'China', None), ('Afghanistan', 'Iran', None),
('Afghanistan', 'Uzbekistan', None), ('Albania', 'Greece', None),
('Albania', 'Kosovo', None), ('Albania', 'Macedonia', None),
('Albania', 'Montenegro', None), ('Algeria', 'Morocco', None),
('Algeria', 'Tunisia', None), ('Andorra', 'Spain', None),
('Angola', 'Democratic Republic of the Congo', None), ('Angola', 'Namibia', None),
('Angola', 'Zambia', None), ('Argentina', 'Bolivia', None),
('Argentina', 'Brazil', None), ('Argentina', 'Chile', None),
('Argentina', 'Paraguay', None), ('Argentina', 'Uruguay', None),
('Armenia', 'Georgia', None), ('Armenia', 'Iran', None),
('Austria', 'Germany', None), ('Azerbaijan', 'Armenia', None),
('Azerbaijan', 'Georgia', None), ('Azerbaijan', 'Iran', None),
('Azerbaijan', 'Russia', None), ('Azerbaijan', 'Turkey', None),
('Bangladesh', 'Burma', None), ('Belgium', 'Germany', None),
('Belgium', 'Netherlands', None), ('Belize', 'Mexico', None),
('Benin', 'Burkina Faso', None), ('Benin', 'Niger', None),
('Benin', 'Nigeria', None), ('Benin', 'Togo', None),
('Bolivia', 'Brazil', None), ('Bolivia', 'Chile', None),
('Bolivia', 'Paraguay', None), ('Bolivia', 'Peru', None),
('Bosnia and Herzegovina', 'Croatia', None), ('Bosnia and Herzegovina', 'Montenegro', None),
('Bosnia and Herzegovina', 'Serbia', None), ('Brazil', 'Colombia', None),
('Brazil', 'Guyana', None), ('Brazil', 'Suriname', None),
('Brazil', 'Venezuela', None), ('Bulgaria', 'Greece', None),
('Bulgaria', 'Macedonia', None), ('Bulgaria', 'Romania', None),
('Bulgaria', 'Serbia', None), ('Burkina Faso', 'Mali', None),
('Burkina Faso', 'Niger', None), ('Burkina Faso', 'Togo', None),
('Burundi', 'Democratic Republic of the Congo', None), ('Cambodia', 'Laos', None),
('Cambodia', 'Thailand', None), ('Cambodia', 'Vietnam', None),
('Cameroon', 'Central African Republic', None), ('Cameroon', 'Chad', None),
('Cameroon', 'Equatorial Guinea', None), ('Cameroon', 'Nigeria', None),
('Cameroon', 'Republic of the Congo', None), ('Canada', 'United States', None),
('Central African Republic', 'Chad', None), ('Central African Republic', 'Democratic Republic of the Congo', None),
('Central African Republic', 'Sudan', None), ('Chad', 'Niger', None),
('Chad', 'Nigeria', None), ('Chad', 'Sudan', None),
('China', 'Bhutan', None), ('China', 'Burma', None),
('China', 'Hong Kong', None), ('China', 'Kazakhstan', None),
('China', 'Kyrgyzstan', None), ('China', 'Mongolia', None),
('China', 'Nepal', None), ('China', 'North Korea', None),
('China', 'Russia', None), ('China', 'Vietnam', None),
('Colombia', 'Venezuela', None), ('Costa Rica', 'Nicaragua', None),
("Cote d'Ivoire", 'Burkina Faso', None), ("Cote d'Ivoire", 'Guinea', None),
("Cote d'Ivoire", 'Mali', None), ('Cyprus', 'Akrotiri', None),
('Cyprus', 'Dhekelia', None), ('Czech Republic', 'Austria', None),
('Czech Republic', 'Germany', None), ('Czech Republic', 'Poland', None),
('Democratic Republic of the Congo', 'Zambia', None), ('Denmark', 'Germany', None),
('Djibouti', 'Eritrea', None), ('Dominican Republic', 'Haiti', None),
('Ecuador', 'Colombia', None), ('El Salvador', 'Honduras', None),
('Ethiopia', 'Djibouti', None), ('Ethiopia', 'Eritrea', None),
('Ethiopia', 'Kenya', None), ('Ethiopia', 'Somalia', None),
('Ethiopia', 'Sudan', None), ('Finland', 'Russia', None),
('Finland', 'Sweden', None), ('France', 'Andorra', None),
('France', 'Belgium', None), ('France', 'Brazil', None),
('France', 'Germany', None), ('France', 'Italy', None),
('France', 'Luxembourg', None), ('France', 'Spain', None),
('France', 'Suriname', None), ('France', 'Switzerland', None),
('Gabon', 'Cameroon', None), ('Gabon', 'Equatorial Guinea', None),
('Gabon', 'Republic of the Congo', None), ('Gaza Strip', 'Egypt', None),
('Gaza Strip', 'Israel', None), ('Ghana', 'Burkina Faso', None),
('Ghana', "Cote d'Ivoire", None), ('Ghana', 'Togo', None),
('Gibraltar', 'Spain', None), ('Guatemala', 'Belize', None),
('Guatemala', 'El Salvador', None), ('Guatemala', 'Honduras', None),
('Guatemala', 'Mexico', None), ('Guinea', 'Sierra Leone', None),
('Guinea-Bissau', 'Guinea', None), ('Guinea-Bissau', 'Senegal', None),
('Honduras', 'Nicaragua', None), ('Hungary', 'Austria', None),
('Hungary', 'Croatia', None), ('Hungary', 'Serbia', None),
('India', 'Bangladesh', None), ('India', 'Bhutan', None),
('India', 'Burma', None), ('India', 'China', None),
('India', 'Nepal', None), ('Indonesia', 'Papua New Guinea', None),
('Iran', 'Iraq', None), ('Ireland', 'United Kingdom', None),
('Israel', 'Egypt', None), ('Italy', 'Austria', None),
('Jordan', 'Iraq', None), ('Jordan', 'Israel', None),
('Jordan', 'Syria', None), ('Jordan', 'West Bank', None),
('Kazakhstan', 'Kyrgyzstan', None), ('Kenya', 'Somalia', None),
#.........这里部分代码省略.........
示例12: WorldMap
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def WorldMap():
"""
Returns the Graph of all the countries, in which two countries are adjacent
in the graph if they have a common boundary.
This graph has been built from the data available
in The CIA World Factbook [CIA]_ (2009-08-21).
The returned graph ``G`` has a member ``G.gps_coordinates``
equal to a dictionary containing the GPS coordinates
of each country's capital city.
EXAMPLE::
sage: g=graphs.WorldMap()
sage: g.has_edge("France","Italy")
True
sage: g.gps_coordinates["Bolivia"]
[[17, 'S'], [65, 'W']]
sage: sorted(g.connected_component_containing_vertex('Ireland'))
['Ireland', 'United Kingdom']
REFERENCE:
.. [CIA] CIA Factbook 09 https://www.cia.gov/library/publications/the-world-factbook/
"""
edges = [
("Afghanistan", "China", None),
("Afghanistan", "Iran", None),
("Afghanistan", "Uzbekistan", None),
("Albania", "Greece", None),
("Albania", "Kosovo", None),
("Albania", "Macedonia", None),
("Albania", "Montenegro", None),
("Algeria", "Morocco", None),
("Algeria", "Tunisia", None),
("Andorra", "Spain", None),
("Angola", "Democratic Republic of the Congo", None),
("Angola", "Namibia", None),
("Angola", "Zambia", None),
("Argentina", "Bolivia", None),
("Argentina", "Brazil", None),
("Argentina", "Chile", None),
("Argentina", "Paraguay", None),
("Argentina", "Uruguay", None),
("Armenia", "Georgia", None),
("Armenia", "Iran", None),
("Austria", "Germany", None),
("Azerbaijan", "Armenia", None),
("Azerbaijan", "Georgia", None),
("Azerbaijan", "Iran", None),
("Azerbaijan", "Russia", None),
("Azerbaijan", "Turkey", None),
("Bangladesh", "Burma", None),
("Belgium", "Germany", None),
("Belgium", "Netherlands", None),
("Belize", "Mexico", None),
("Benin", "Burkina Faso", None),
("Benin", "Niger", None),
("Benin", "Nigeria", None),
("Benin", "Togo", None),
("Bolivia", "Brazil", None),
("Bolivia", "Chile", None),
("Bolivia", "Paraguay", None),
("Bolivia", "Peru", None),
("Bosnia and Herzegovina", "Croatia", None),
("Bosnia and Herzegovina", "Montenegro", None),
("Bosnia and Herzegovina", "Serbia", None),
("Brazil", "Colombia", None),
("Brazil", "Guyana", None),
("Brazil", "Suriname", None),
("Brazil", "Venezuela", None),
("Bulgaria", "Greece", None),
("Bulgaria", "Macedonia", None),
("Bulgaria", "Romania", None),
("Bulgaria", "Serbia", None),
("Burkina Faso", "Mali", None),
("Burkina Faso", "Niger", None),
("Burkina Faso", "Togo", None),
("Burundi", "Democratic Republic of the Congo", None),
("Cambodia", "Laos", None),
("Cambodia", "Thailand", None),
("Cambodia", "Vietnam", None),
("Cameroon", "Central African Republic", None),
("Cameroon", "Chad", None),
("Cameroon", "Equatorial Guinea", None),
("Cameroon", "Nigeria", None),
("Cameroon", "Republic of the Congo", None),
("Canada", "United States", None),
("Central African Republic", "Chad", None),
("Central African Republic", "Democratic Republic of the Congo", None),
("Central African Republic", "Sudan", None),
("Chad", "Niger", None),
("Chad", "Nigeria", None),
("Chad", "Sudan", None),
("China", "Bhutan", None),
("China", "Burma", None),
("China", "Hong Kong", None),
("China", "Kazakhstan", None),
("China", "Kyrgyzstan", None),
#.........这里部分代码省略.........
示例13: GridGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def GridGraph(dim_list):
"""
Returns an n-dimensional grid graph.
INPUT:
- ``dim_list`` - a list of integers representing the
number of nodes to extend in each dimension.
PLOTTING: When plotting, this graph will use the default
spring-layout algorithm, unless a position dictionary is
specified.
EXAMPLES::
sage: G = graphs.GridGraph([2,3,4])
sage: G.show() # long time
::
sage: C = graphs.CubeGraph(4)
sage: G = graphs.GridGraph([2,2,2,2])
sage: C.show() # long time
sage: G.show() # long time
TESTS:
The graph name contains the dimension::
sage: g = graphs.GridGraph([5, 7])
sage: g.name()
'Grid Graph for [5, 7]'
sage: g = graphs.GridGraph([2, 3, 4])
sage: g.name()
'Grid Graph for [2, 3, 4]'
sage: g = graphs.GridGraph([2, 4, 3])
sage: g.name()
'Grid Graph for [2, 4, 3]'
One dimensional grids (i.e., path) have simple vertex labels::
sage: g = graphs.GridGraph([5])
sage: g.vertices()
[0, 1, 2, 3, 4]
The graph is correct::
sage: dim = [randint(1,4) for i in range(4)]
sage: g = graphs.GridGraph(dim)
sage: import networkx
sage: h = Graph( networkx.grid_graph(list(dim)) )
sage: g.is_isomorphic(h)
True
Trivial cases::
sage: g = graphs.GridGraph([]); g; g.vertices()
Grid Graph for []: Graph on 0 vertices
[]
sage: g = graphs.GridGraph([1]); g; g.vertices()
Grid Graph for [1]: Graph on 1 vertex
[0]
sage: g = graphs.GridGraph([2]); g; g.vertices()
Grid Graph for [2]: Graph on 2 vertices
[0, 1]
sage: g = graphs.GridGraph([1,1]); g; g.vertices()
Grid Graph for [1, 1]: Graph on 1 vertex
[(0, 0)]
sage: g = graphs.GridGraph([1, 1, 1]); g; g.vertices()
Grid Graph for [1, 1, 1]: Graph on 1 vertex
[(0, 0, 0)]
sage: g = graphs.GridGraph([1,1,2]); g; g.vertices()
Grid Graph for [1, 1, 2]: Graph on 2 vertices
[(0, 0, 0), (0, 0, 1)]
All dimensions must be positive integers::
sage: g = graphs.GridGraph([2,-1,3])
Traceback (most recent call last):
...
ValueError: All dimensions must be positive integers !
"""
dim = [int(a) for a in dim_list]
if any(a <= 0 for a in dim):
raise ValueError("All dimensions must be positive integers !")
g = Graph()
n_dim = len(dim)
if n_dim==1:
# Vertices are labeled from 0 to dim[0]-1
g = PathGraph(dim[0])
elif n_dim==2:
# We use the Grid2dGraph generator to also get the positions
g = Grid2dGraph(*dim)
elif n_dim>2:
# Vertices are tuples of dimension n_dim, and the graph contains at
# least vertex (0, 0, ..., 0)
g.add_vertex(tuple([0]*n_dim))
#.........这里部分代码省略.........
示例14: CompleteMultipartiteGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def CompleteMultipartiteGraph(l):
r"""
Returns a complete multipartite graph.
INPUT:
- ``l`` -- a list of integers : the respective sizes
of the components.
EXAMPLE:
A complete tripartite graph with sets of sizes
`5, 6, 8`::
sage: g = graphs.CompleteMultipartiteGraph([5, 6, 8]); g
Multipartite Graph with set sizes [5, 6, 8]: Graph on 19 vertices
It clearly has a chromatic number of 3::
sage: g.chromatic_number()
3
"""
n = sum(l) #getting the number of vertices
r = len(l) #getting the number of partitions
positions = {}
if r > 2: #position code gives bad results on bipartite or isolated graphs
'''
Produce a layout of the vertices so that vertices in the same
vertex set are adjecent and clearly separated from vertices in other
vertex sets.
This is done by calculating the vertices of an r-gon then
calculating the slope between adjacent vertices. We then 'walk'
around the r-gon placing graph vertices in regular intervals between
adjacent vertices of the r-gon.
Makes a nicely organized graph like in this picture:
https://commons.wikimedia.org/wiki/File:Turan_13-4.svg
'''
points = [[cos(2*pi*i/r),sin(2*pi*i/r)] for i in range(r)]
slopes = [[(points[(i+1)%r][0]-points[i%r][0]),
(points[(i+1)%r][1]-points[i%r][1])] for i in range(r)]
counter = 0
for i in range(len(l)):
vertex_set_size = l[i]+1
for j in range(1,vertex_set_size):
x = points[i][0]+slopes[i][0]*j/(vertex_set_size)
y = points[i][1]+slopes[i][1]*j/(vertex_set_size)
positions[counter] = (x,y)
counter += 1
g = Graph()
for i in l:
g = g + CompleteGraph(i)
g = g.complement()
g.set_pos(positions)
g.name("Multipartite Graph with set sizes "+str(l))
return g
示例15: AfricaMap
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import name [as 别名]
def AfricaMap(continental=False, year=2018):
"""
Return African states as a graph of common border.
"African state" here is defined as an independent
state having the capital city in Africa. The graph
has an edge between those countries that have common
*land* border.
INPUT:
- ``continental``, a Boolean -- if set, only return states in
the continental Africa
- ``year`` -- reserved for future use
EXAMPLES::
sage: Africa = graphs.AfricaMap(); Africa
Africa Map: Graph on 54 vertices
sage: sorted(Africa.neighbors('Libya'))
['Algeria', 'Chad', 'Egypt', 'Niger', 'Sudan', 'Tunisia']
sage: cont_Africa = graphs.AfricaMap(continental=True)
sage: cont_Africa.order()
48
sage: 'Madagaskar' in cont_Africa
False
TESTS::
sage: Africa.plot()
Graphics object consisting of 159 graphics primitives
"""
if year != 2018:
raise ValueError("currently only year 2018 is implemented")
common_border = {
'Algeria': ['Libya', 'Mali', 'Mauritania', 'Morocco', 'Niger', 'Tunisia'],
'Angola': ['Namibia', 'Zambia'],
'Benin': ['Burkina Faso', 'Niger', 'Nigeria', 'Togo'],
'Botswana': ['Namibia', 'South Africa', 'Zimbabwe'],
'Burkina Faso': ['Ghana', 'Ivory Coast', 'Mali', 'Niger', 'Togo'],
'Cameroon': ['Central Africa', 'Chad', 'Equatorial Guinea', 'Gabon', 'Nigeria'],
'Central Africa': ['Chad', 'South Sudan', 'Sudan'],
'Chad': ['Libya', 'Niger', 'Nigeria', 'Sudan'],
'Republic of the Congo': ['Gabon', 'Cameroon', 'Central Africa', 'Angola',
'Democratic Republic of the Congo'],
'Democratic Republic of the Congo': ['Zambia', 'South Sudan', 'Tanzania', 'Burundi',
'Rwanda', 'Uganda', 'Central Africa', 'Angola'],
'Djibouti': ['Eritrea', 'Ethiopia', 'Somalia'],
'Ethiopia': ['Eritrea', 'Kenya', 'Somalia', 'South Sudan', 'Sudan'],
'Gabon': ['Equatorial Guinea'],
'Ghana': ['Ivory Coast', 'Togo'],
'Guinea': ['Guinea-Bissau', 'Ivory Coast', 'Liberia', 'Sierra Leone'],
'Kenya': ['Somalia', 'South Sudan', 'Tanzania', 'Uganda'],
'Liberia': ['Ivory Coast', 'Sierra Leone'],
'Libya': ['Egypt', 'Niger', 'Sudan', 'Tunisia'],
'Mali': ['Guinea', 'Ivory Coast', 'Mauritania', 'Niger', 'Senegal'],
'Mozambique': ['Malawi', 'South Africa', 'Swaziland', 'Zimbabwe'],
'Niger': ['Nigeria'],
'Rwanda': ['Burundi', 'Tanzania', 'Uganda'],
'Senegal': ['Guinea', 'Guinea-Bissau', 'Mauritania', 'Gambia'],
'South Africa': ['Lesotho', 'Namibia', 'Swaziland', 'Zimbabwe'],
'South Sudan': ['Uganda', 'Sudan', 'Democratic Republic of the Congo'],
'Sudan': ['Egypt', 'Eritrea'],
'Tanzania': ['Burundi', 'Malawi', 'Mozambique', 'Uganda', 'Zambia'],
'Zambia': ['Malawi', 'Mozambique', 'Namibia', 'Zimbabwe']
}
no_land_border = ['Cape Verde', 'Seychelles', 'Mauritius', u'São Tomé and Príncipe', 'Madagascar', 'Comoros']
G = Graph(common_border, format='dict_of_lists')
if continental:
G = G.subgraph(G.connected_component_containing_vertex('Central Africa'))
G.name(new="Continental Africa Map")
else:
G.add_vertices(no_land_border)
G.name(new="Africa Map")
return G