22 lines
574 B
Python
22 lines
574 B
Python
def edgelistToDot(name, inp):
|
|
output = "strict graph \"" + name + "\" {\n"
|
|
for (x,y) in inp:
|
|
output += f" {x} -- {y};\n"
|
|
|
|
output += "}"
|
|
return output
|
|
|
|
def dotToEdgelist(graph):
|
|
outStr = []
|
|
graph = graph.split("\n")
|
|
name = graph[0].split(" ")[2]
|
|
name = name[1:len(name) - 1]
|
|
for i in range(len(graph) - 1):
|
|
if(i == 0):
|
|
continue
|
|
nodes = graph[i].split("--")
|
|
node1 = int(nodes[0])
|
|
node2 = int(nodes[1][0:len(nodes[1]) - 1])
|
|
outStr.append((node1, node2,))
|
|
return (name, outStr)
|