本文整理汇总了Python中sage.graphs.all.DiGraph.add_edges方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.add_edges方法的具体用法?Python DiGraph.add_edges怎么用?Python DiGraph.add_edges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.all.DiGraph
的用法示例。
在下文中一共展示了DiGraph.add_edges方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _is_valid_digraph_edge_set
# 需要导入模块: from sage.graphs.all import DiGraph [as 别名]
# 或者: from sage.graphs.all.DiGraph import add_edges [as 别名]
def _is_valid_digraph_edge_set( edges, frozen=0 ):
"""
Returns True if the input data is the edge set of a digraph for a quiver (no loops, no 2-cycles, edge-labels of the specified format), and returns False otherwise.
INPUT:
- ``frozen`` -- (integer; default:0) The number of frozen vertices.
EXAMPLES::
sage: from sage.combinat.cluster_algebra_quiver.mutation_class import _is_valid_digraph_edge_set
sage: _is_valid_digraph_edge_set( [[0,1,'a'],[2,3,(1,-1)]] )
The given digraph has edge labels which are not integral or integral 2-tuples.
False
sage: _is_valid_digraph_edge_set( [[0,1],[2,3,(1,-1)]] )
True
sage: _is_valid_digraph_edge_set( [[0,1,'a'],[2,3,(1,-1)],[3,2,(1,-1)]] )
The given digraph or edge list contains oriented 2-cycles.
False
"""
try:
dg = DiGraph()
dg.allow_multiple_edges(True)
dg.add_edges( edges )
# checks if the digraph contains loops
if dg.has_loops():
print "The given digraph or edge list contains loops."
return False
# checks if the digraph contains oriented 2-cycles
if _has_two_cycles( dg ):
print "The given digraph or edge list contains oriented 2-cycles."
return False
# checks if all edge labels are 'None', positive integers or tuples of positive integers
if not all( i == None or ( i in ZZ and i > 0 ) or ( type(i) == tuple and len(i) == 2 and i[0] in ZZ and i[1] in ZZ ) for i in dg.edge_labels() ):
print "The given digraph has edge labels which are not integral or integral 2-tuples."
return False
# checks if all edge labels for multiple edges are 'None' or positive integers
if dg.has_multiple_edges():
for e in set( dg.multiple_edges(labels=False) ):
if not all( i == None or ( i in ZZ and i > 0 ) for i in dg.edge_label( e[0], e[1] ) ):
print "The given digraph or edge list contains multiple edges with non-integral labels."
return False
n = dg.order() - frozen
if n < 0:
print "The number of frozen variables is larger than the number of vertices."
return False
if [ e for e in dg.edges(labels=False) if e[0] >= n] <> []:
print "The given digraph or edge list contains edges within the frozen vertices."
return False
return True
except StandardError:
print "Could not even build a digraph from the input data."
return False
示例2: NaiveCrystal
# 需要导入模块: from sage.graphs.all import DiGraph [as 别名]
# 或者: from sage.graphs.all.DiGraph import add_edges [as 别名]
class NaiveCrystal(UniqueRepresentation, Parent):
r"""
This is an example of a "crystal" which does not come from any kind of
representation, designed primarily to test the Stembridge local rules with.
The crystal has vertices labeled 0 through 5, with 0 the highest weight.
The code here could also possibly be generalized to create a class that
automatically builds a crystal from an edge-colored digraph, if someone
feels adventurous.
Currently, only the methods :meth:`highest_weight_vector`, :meth:`e`, and :meth:`f` are
guaranteed to work.
EXAMPLES::
sage: C = Crystals().example(choice='naive')
sage: C.highest_weight_vector()
0
"""
def __init__(self):
"""
EXAMPLES::
sage: C = sage.categories.examples.crystals.NaiveCrystal()
sage: C == Crystals().example(choice='naive')
True
"""
Parent.__init__(self, category = ClassicalCrystals())
self.n = 2
self._cartan_type = CartanType(['A',2])
self.G = DiGraph(5)
self.G.add_edges([ [0,1,1], [1,2,1], [2,3,1], [3,5,1], [0,4,2], [4,5,2] ])
self.module_generators = [ self(0) ]
def __repr__(self):
"""
EXAMPLES::
sage: Crystals().example(choice='naive')
A broken crystal, defined by digraph, of dimension five.
"""
return "A broken crystal, defined by digraph, of dimension five."
class Element(ElementWrapper):
def e(self, i):
r"""
Returns the action of `e_i` on ``self``.
EXAMPLES::
sage: C = Crystals().example(choice='naive')
sage: [[c,i,c.e(i)] for i in C.index_set() for c in [C(j) for j in [0..5]] if c.e(i) is not None]
[[1, 1, 0], [2, 1, 1], [3, 1, 2], [5, 1, 3], [4, 2, 0], [5, 2, 4]]
"""
assert i in self.index_set()
for edge in self.parent().G.edges():
if edge[1]==int(str(self)) and edge[2]==i:
return self.parent()(edge[0])
return None
def f(self, i):
r"""
Returns the action of `f_i` on ``self``.
EXAMPLES::
sage: C = Crystals().example(choice='naive')
sage: [[c,i,c.f(i)] for i in C.index_set() for c in [C(j) for j in [0..5]] if c.f(i) is not None]
[[0, 1, 1], [1, 1, 2], [2, 1, 3], [3, 1, 5], [0, 2, 4], [4, 2, 5]]
"""
assert i in self.index_set()
for edge in self.parent().G.edges_incident(int(str(self))):
if edge[2] == i:
return self.parent()(edge[1])
return None