本文整理汇总了Python中sage.graphs.graph.Graph.add_path方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.add_path方法的具体用法?Python Graph.add_path怎么用?Python Graph.add_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.add_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LadderGraph
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import add_path [as 别名]
def LadderGraph(n):
"""
Returns a ladder graph with 2\*n nodes.
A ladder graph is a basic structure that is typically displayed as
a ladder, i.e.: two parallel path graphs connected at each
corresponding node pair.
This constructor depends on NetworkX numeric labels.
PLOTTING: Upon construction, the position dictionary is filled to
override the spring-layout algorithm. By convention, each ladder
graph will be displayed horizontally, with the first n nodes
displayed left to right on the top horizontal line.
EXAMPLES: Construct and show a ladder graph with 14 nodes
::
sage: g = graphs.LadderGraph(7)
sage: g.show() # long time
Create several ladder graphs in a Sage graphics array
::
sage: g = []
sage: j = []
sage: for i in range(9):
....: k = graphs.LadderGraph(i+2)
....: g.append(k)
sage: for i in range(3):
....: n = []
....: for m in range(3):
....: n.append(g[3*i + m].plot(vertex_size=50, vertex_labels=False))
....: j.append(n)
sage: G = sage.plot.graphics.GraphicsArray(j)
sage: G.show() # long time
"""
pos_dict = {}
for i in range(n):
pos_dict[i] = (i,1)
for i in range(n,2*n):
x = i - n
pos_dict[i] = (x,0)
G = Graph(pos=pos_dict, name="Ladder graph")
G.add_vertices( range(2*n) )
G.add_path( range(n) )
G.add_path( range(n,2*n) )
G.add_edges( (i,i+n) for i in range(n) )
return G