本文整理汇总了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
示例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
示例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
示例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)