def effect(self):
totalTimerStart = timeit.default_timer()
(vertices, edges) = self.parseSVG()
G = self.buildGraph(vertices, edges)
timerStart = timeit.default_timer()
self.mergeWithTolerance(G, self.options.tolerance)
timerStop = timeit.default_timer()
mergeDuration = timerStop-timerStart
"""for e in G.edges():
self.log("E "+str(e[0]) + " " + str(e[1]))
for n in G.nodes():
self.log("Degree of "+str(n) + ": " + str(G.degree(n)))"""
#Split disjoint graphs
connectedGraphs = list(nx.connected_component_subgraphs(G))
self.log("Number of disconnected graphs: " + str(len(connectedGraphs)))
paths = []
makeEulerianDuration = 0
for connectedGraph in connectedGraphs:
timerStart = timeit.default_timer()
if self.options.overwriteRule == OVERWRITE_ALLOW_NONE:
connectedGraph = self.makeEulerianGraphExtraNode(connectedGraph)
else:
connectedGraph = self.makeEulerianGraph(connectedGraph)
timerStop = timeit.default_timer()
makeEulerianDuration += timerStop-timerStart
#connectedGraph is now likely a multigraph
pathEdges = self.eulerian_circuit_hierholzer(connectedGraph)
pathEdges = self.removeSomeEdges(connectedGraph, pathEdges)
pathEdges = self.shiftEdgesToBreak(pathEdges)
paths.extend(self.edgesToPaths(pathEdges))
self.log("Path number: " + str(len(paths)))
self.log("Total path length: " + str(sum(self.pathLength(G, x) for x in paths)))
self.pathsToSVG(G, paths)
totalTimerStop = timeit.default_timer()
totalDuration = totalTimerStop-totalTimerStart
self.log("Merge duration: {:f} sec ({:f} min)".format(mergeDuration, mergeDuration/60))
self.log("Make Eulerian duration: {:f} sec ({:f} min)".format(makeEulerianDuration, makeEulerianDuration/60))
self.log("Total duration: {:f} sec ({:f} min)".format(totalDuration, totalDuration/60))
评论列表
文章目录