本文整理汇总了Python中Graph.Graph.addDirect方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.addDirect方法的具体用法?Python Graph.addDirect怎么用?Python Graph.addDirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.addDirect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: leeCSV
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import addDirect [as 别名]
def leeCSV(self):
grafica = Graph(0,[],[])
with open(self.archivo) as csv_file:
csv_data=csv.reader(csv_file, delimiter=',')
if( next(csv_data)[0]== 'direct=1'):
grafica.addDirect(1)
for l in csv_data:
grafica.addVx(l[0])
grafica.addEd(l[0],l[1],l[2])
return grafica
示例2: leeJSON
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import addDirect [as 别名]
def leeJSON(self):
gr=Graph(0,[],[])
with open(self.archivo) as json_file:
json_data = json.load(json_file)
dir1=json_data["direct"]
vert1=json_data["vertices"]
edge1=json_data["edges"]
gr.addDirect(dir1)
for v in vert1:
gr.addVx(v)
for e in edge1:
gr.addEd(e[0],e[1],e[2])
return gr
示例3: leeXML
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import addDirect [as 别名]
def leeXML (self):
graficax=Graph(0,[],[])
line = parse(self.archivo)
dirc = line.getElementsByTagName('graph')
if dirc[0].attributes['direct'] == 1:
graficax.addDirect(1)
vert = line.getElementsByTagName('vertex')
for v in vert:
graficax.addVx(v.attributes['label'].value)
ari = line.getElementsByTagName('edge')
for a in ari:
ori = a.attributes['source'].value
des = a.attributes['target'].value
peso = a.attributes['weight'].value
graficax.addEd(ori,des,peso)
return graficax