本文整理汇总了Python中sage.graphs.digraph.DiGraph.delete_edge方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.delete_edge方法的具体用法?Python DiGraph.delete_edge怎么用?Python DiGraph.delete_edge使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph.delete_edge方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plot
# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import delete_edge [as 别名]
def plot(self, **kwargs):
"""
Return a graphics object representing the Kontsevich graph.
INPUT:
- ``edge_labels`` (boolean, default True) -- if True, show edge labels.
- ``indices`` (boolean, default False) -- if True, show indices as
edge labels instead of L and R; see :meth:`._latex_`.
- ``upright`` (boolean, default False) -- if True, try to plot the
graph with the ground vertices on the bottom and the rest on top.
"""
if not 'edge_labels' in kwargs:
kwargs['edge_labels'] = True # show edge labels by default
if 'indices' in kwargs:
del kwargs['indices']
KG = DiGraph(self)
for (k,e) in enumerate(self.edges()):
KG.delete_edge(e)
KG.add_edge((e[0], e[1], chr(97 + k)))
return KG.plot(**kwargs)
if len(self.ground_vertices()) == 2 and 'upright' in kwargs:
del kwargs['upright']
kwargs['save_pos'] = True
DiGraph.plot(self, **kwargs)
positions = self.get_pos()
# translate F to origin:
F_pos = vector(positions[self.ground_vertices()[0]])
for p in positions:
positions[p] = list(vector(positions[p]) - F_pos)
# scale F - G distance to 1:
G_len = abs(vector(positions[self.ground_vertices()[1]]))
for p in positions:
positions[p] = list(vector(positions[p])/G_len)
# rotate the vector F - G to (1,0)
from math import atan2
theta = -atan2(positions[self.ground_vertices()[1]][1], positions[self.ground_vertices()[1]][0])
for p in positions:
positions[p] = list(matrix([[cos(theta),-(sin(theta))],[sin(theta),cos(theta)]]) * vector(positions[p]))
# flip if most things are below the x-axis:
if len([(x,y) for (x,y) in positions.values() if y < 0])/len(self.internal_vertices()) > 0.5:
for p in positions:
positions[p] = [positions[p][0], -positions[p][1]]
return DiGraph.plot(self, **kwargs)
示例2: RandomPoset
# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import delete_edge [as 别名]
def RandomPoset(n,p):
r"""
Generate a random poset on ``n`` vertices according to a
probability ``p``.
INPUT:
- ``n`` - number of vertices, a non-negative integer
- ``p`` - a probability, a real number between 0 and 1 (inclusive)
OUTPUT:
A poset on ``n`` vertices. The construction decides to make an
ordered pair of vertices comparable in the poset with probability
``p``, however a pair is not made comparable if it would violate
the defining properties of a poset, such as transitivity.
So in practice, once the probability exceeds a small number the
generated posets may be very similar to a chain. So to create
interesting examples, keep the probability small, perhaps on the
order of `1/n`.
EXAMPLES::
sage: Posets.RandomPoset(17,.15)
Finite poset containing 17 elements
TESTS::
sage: Posets.RandomPoset('junk', 0.5)
Traceback (most recent call last):
...
TypeError: number of elements must be an integer, not junk
sage: Posets.RandomPoset(-6, 0.5)
Traceback (most recent call last):
...
ValueError: number of elements must be non-negative, not -6
sage: Posets.RandomPoset(6, 'garbage')
Traceback (most recent call last):
...
TypeError: probability must be a real number, not garbage
sage: Posets.RandomPoset(6, -0.5)
Traceback (most recent call last):
...
ValueError: probability must be between 0 and 1, not -0.5
"""
from sage.misc.prandom import random
try:
n = Integer(n)
except TypeError:
raise TypeError("number of elements must be an integer, not {0}".format(n))
if n < 0:
raise ValueError("number of elements must be non-negative, not {0}".format(n))
try:
p = float(p)
except Exception:
raise TypeError("probability must be a real number, not {0}".format(p))
if p < 0 or p> 1:
raise ValueError("probability must be between 0 and 1, not {0}".format(p))
D = DiGraph(loops=False,multiedges=False)
D.add_vertices(range(n))
for i in range(n):
for j in range(n):
if random() < p:
D.add_edge(i,j)
if not D.is_directed_acyclic():
D.delete_edge(i,j)
return Poset(D,cover_relations=False)