本文整理汇总了Python中sage.graphs.digraph.DiGraph.order方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.order方法的具体用法?Python DiGraph.order怎么用?Python DiGraph.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph.order方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_partial_cube
# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import order [as 别名]
def is_partial_cube(G, certificate=False):
r"""
Test whether the given graph is a partial cube.
A partial cube is a graph that can be isometrically embedded into a
hypercube, i.e., its vertices can be labelled with (0,1)-vectors of some
fixed length such that the distance between any two vertices in the graph
equals the Hamming distance of their labels.
Originally written by D. Eppstein for the PADS library
(http://www.ics.uci.edu/~eppstein/PADS/), see also
[Eppstein2008]_. The algorithm runs in `O(n^2)` time, where `n`
is the number of vertices. See the documentation of
:mod:`~sage.graphs.partial_cube` for an overview of the algorithm.
INPUT:
- ``certificate`` (boolean; ``False``) -- The function returns ``True``
or ``False`` according to the graph, when ``certificate = False``. When
``certificate = True`` and the graph is a partial cube, the function
returns ``(True, mapping)``, where ``mapping`` is an isometric mapping of
the vertices of the graph to the vertices of a hypercube ((0, 1)-strings
of a fixed length). When ``certificate = True`` and the graph is not a
partial cube, ``(False, None)`` is returned.
EXAMPLES:
The Petersen graph is not a partial cube::
sage: g = graphs.PetersenGraph()
sage: g.is_partial_cube()
False
All prisms are partial cubes::
sage: g = graphs.CycleGraph(10).cartesian_product(graphs.CompleteGraph(2))
sage: g.is_partial_cube()
True
TESTS:
The returned mapping is an isometric embedding into a hypercube::
sage: g = graphs.DesarguesGraph()
sage: _, m = g.is_partial_cube(certificate = True)
sage: m # random
{0: '00000',
1: '00001',
2: '00011',
3: '01011',
4: '11011',
5: '11111',
6: '11110',
7: '11100',
8: '10100',
9: '00100',
10: '01000',
11: '10001',
12: '00111',
13: '01010',
14: '11001',
15: '10111',
16: '01110',
17: '11000',
18: '10101',
19: '00110'}
sage: all(all(g.distance(u, v) == len([i for i in range(len(m[u])) if m[u][i] != m[v][i]]) for v in m) for u in m)
True
A graph without vertices is trivially a partial cube::
sage: Graph().is_partial_cube(certificate = True)
(True, {})
"""
G._scream_if_not_simple()
if G.order() == 0:
if certificate:
return (True, {})
else:
return True
if certificate:
fail = (False, None)
else:
fail = False
if not G.is_connected():
return fail
n = G.order()
# Initial sanity check: are there few enough edges?
# Needed so that we don't try to use union-find on a dense
# graph and incur superquadratic runtimes.
if 1 << (2*G.size()//n) > n:
return fail
# Check for bipartiteness.
# This ensures also that each contraction will be bipartite.
#.........这里部分代码省略.........