本文整理汇总了Python中Graph.add_vertice方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.add_vertice方法的具体用法?Python Graph.add_vertice怎么用?Python Graph.add_vertice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.add_vertice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readJSON
# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import add_vertice [as 别名]
def readJSON(archivo):
graph = Graph()
with open(os.getcwd()+"/ejemplos/"+archivo,encoding='utf-8') as data_file:
data = json.loads(data_file.read())
if data['direct']==1:
graph.set_dirigida(True)
for vertice in data['vertices']:
graph.add_vertice(Vertex(vertice,0,[]))
for arista in data['edges']:
graph.add_arista(Edges(arista[0],arista[1],arista[2]))
for vertice in graph.vertices():
if vertice.etiqueta == arista[0]:
vertice.add_vecino(arista[1])
for vertex in graph.vertices():
if vertex.etiqueta == arista[1]:
vertex.add_vecino(arista[0])
return graph
示例2: readCSV
# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import add_vertice [as 别名]
def readCSV(archivo):
graph = Graph()
reader = csv.reader(open(os.getcwd()+"/ejemplos/"+archivo, 'r'))
tipo= next(reader, None)
if tipo ==['direct=1']:
graph.set_dirigida(True)
for row in enumerate(reader):
if row[1][0] not in graph.get_etiquetas():
graph.add_vertice(Vertex(row[1][0], 1, [row[1][1][2::3]]))
else:
for vertice in graph.vertices():
if vertice.etiqueta == row[1][0]:
vertice.add_vecino(row[1][1][2::3])
if row[1][1][2::3] not in graph.get_etiquetas():
graph.add_vertice(Vertex(row[1][1][2::3], 1, [row[1][0]]))
else:
for vertice in graph.vertices():
if vertice.etiqueta == row[1][1][2::3]:
vertice.add_vecino(row[1][0])
graph.add_arista(Edges(row[1][0],row[1][1][2::3],row[1][2][1::]))
return graph
示例3: readXML
# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import add_vertice [as 别名]
def readXML(archivo):
graph=Graph()
doc = minidom.parse(os.getcwd()+"/ejemplos/"+archivo)
vertexs = doc.getElementsByTagName("vertex")
edges = doc.getElementsByTagName("edge")
grafo = doc.getElementsByTagName("graph")
lis=[]
for g in grafo:
lis.append(g.getAttribute("direct"))
if lis[0] == '1':
graph.set_dirigida(True)
for vertex in vertexs:
graph.add_vertice(Vertex(vertex.getAttribute("label"),0,[]))
for edge in edges:
graph.add_arista(Edges(edge.getAttribute("source"),edge.getAttribute("target"),edge.getAttribute("weight")))
for vertice in graph.vertices():
if vertice.etiqueta == edge.getAttribute("source"):
vertice.add_vecino(edge.getAttribute("target"))
for vertex in graph.vertices():
if vertex.etiqueta == edge.getAttribute("target"):
vertex.add_vecino(edge.getAttribute("source"))
return graph