当前位置: 首页>>代码示例>>Python>>正文


Python Graph.connect方法代码示例

本文整理汇总了Python中Graph.connect方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.connect方法的具体用法?Python Graph.connect怎么用?Python Graph.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Graph的用法示例。


在下文中一共展示了Graph.connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: json

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import connect [as 别名]
 def json(self, f):
     data = json.load(open(f))
     directed = data["direct"]
     g = Graph()
     if directed == 1:
         g = DGraph()
     for v in data["vertices"]:
         g.add_vertex(v)
     for e in data["edges"]:
         g.connect(e[2], e[0], e[1]) 
     return g
开发者ID:Pernath,项目名称:lenguajes20161_ReyVenado,代码行数:13,代码来源:GraphReader.py

示例2: csv

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import connect [as 别名]
 def csv(self, f):
     reader = csv.reader(open(f), delimiter=",")
     directed = next(reader)[0]
     directed = int(directed[7:])        
     g = Graph()
     if directed == 1:
         g = DGraph()
     for u,v,w in reader:
         g.add_vertex(u)
         g.add_vertex(v[2:3])
         g.connect(w,u,v[2:3])
     return g
开发者ID:Pernath,项目名称:lenguajes20161_ReyVenado,代码行数:14,代码来源:GraphReader.py

示例3: xml

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import connect [as 别名]
 def xml(self, f):
     tree = ET.parse(f)
     root = tree.getroot()
     directed = int(root.attrib.get('direct'))
     g = Graph()
     if directed == 1:
         g = DGraph()
     for vertex in root.findall('vertex'):
         g.add_vertex(vertex.get('label'))        
     for edge in root.findall('edge'):
         g.connect(edge.get('weight'), edge.get('source'), edge.get('target'))
     return g
开发者ID:Pernath,项目名称:lenguajes20161_ReyVenado,代码行数:14,代码来源:GraphReader.py

示例4: input

# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import connect [as 别名]
import sys
sys.path.append("../ds")
from Graph import *

if __name__ == '__main__':
    t = input()
    for i in range(t):
        n,m = [int(x) for x in raw_input().split()]
        graph = Graph(n)
        for i in xrange(m):
            x,y = [int(x) for x in raw_input().split()]
            graph.connect(x-1,y-1)
        s = input()
        graph.find_all_distances(s-1)
开发者ID:agankur21,项目名称:Algorithm,代码行数:16,代码来源:shortest_path.py


注:本文中的Graph.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。