本文整理汇总了Python中sage.graphs.digraph.DiGraph._embedding方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph._embedding方法的具体用法?Python DiGraph._embedding怎么用?Python DiGraph._embedding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph._embedding方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: random_orientation
# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import _embedding [as 别名]
def random_orientation(G):
r"""
Return a random orientation of a graph `G`.
An *orientation* of an undirected graph is a directed graph such that every
edge is assigned a direction. Hence there are `2^m` oriented digraphs for a
simple graph with `m` edges.
INPUT:
- ``G`` -- a Graph.
EXAMPLES::
sage: from sage.graphs.orientations import random_orientation
sage: G = graphs.PetersenGraph()
sage: D = random_orientation(G)
sage: D.order() == G.order(), D.size() == G.size()
(True, True)
TESTS:
Giving anything else than a Graph::
sage: random_orientation([])
Traceback (most recent call last):
...
ValueError: the input parameter must be a Graph
.. SEEALSO::
- :meth:`~Graph.orientations`
"""
from sage.graphs.graph import Graph
if not isinstance(G, Graph):
raise ValueError("the input parameter must be a Graph")
D = DiGraph(data=[G.vertices(), []],
format='vertices_and_edges',
multiedges=G.allows_multiple_edges(),
loops=G.allows_loops(),
weighted=G.weighted(),
pos=G.get_pos(),
name="Random orientation of {}".format(G.name()) )
if hasattr(G, '_embedding'):
D._embedding = copy(G._embedding)
from sage.misc.prandom import getrandbits
rbits = getrandbits(G.size())
for u,v,l in G.edge_iterator():
if rbits % 2:
D.add_edge(u, v, l)
else:
D.add_edge(v, u, l)
rbits >>= 1
return D