本文整理汇总了Python中Graph.maxClars方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.maxClars方法的具体用法?Python Graph.maxClars怎么用?Python Graph.maxClars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph.maxClars方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: combineGraphs
# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import maxClars [as 别名]
def combineGraphs(path = "CombinedTemps",extension = ".txt"):
folderName = "CombinedTemps"
if os.path.exists(folderName):
num_files = len([f for f in os.listdir(path)
if os.path.isfile(os.path.join(path, f))])
num_files -= 1
else:
num_files = 0
graphNumber = 0
superGraphNumber = num_files
deletedCount = 0
storedGraphs = {}
interval = float(raw_input("How many hours would you like to run the program? "))
timeLimit = 3600 * interval
print "limit:", timeLimit
t1 = time.time()
t2 = time.time()
while t2 - t1 < timeLimit:
print "graph " + str(graphNumber)
flag = False
#new stuff
randomFaces = createRandomGraph()
vertexGraph = []
#Finds connected graph
while len(vertexGraph) % 2 != 0 or len(vertexGraph) == 0 or countPeaksAndValleys(randomFaces) == False or isConnected(faceGraphToInts(randomFaces)) == False:
randomFaces = createRandomGraph()
vertexGraph = makeVertexGraph(randomFaces)
randomGraph = Graph(randomFaces, vertexGraph)
perfectMatchingThm = isKekulean(randomGraph)
if perfectMatchingThm == True:
structures = assignMatching(randomGraph)
#end new stuff
Graph.comparison = 'clars'
structures.sort()
randomGraph.maxClars = structures[-1].getClarsNumber()
#For testing
#fgraph = getInput("graph.txt");
#vgraph = makeVertexGraph(fgraph)
#graph = Graph(fgraph, vgraph)
req_edges = getRequiredSet(structures)
externalEdges = getExternalEdges(req_edges)
#print len(externalEdges)
#for edge in externalEdges:
# face = (edge[0].getFaces() & edge[1].getFaces()).pop()
# print face, "\t", face.getVertices().index(edge[0]), "\t", face.getVertices().index(edge[1])
if len(externalEdges) > 0:
#add graph and edges to list
storedGraphs[randomGraph] = externalEdges
for g, edges in storedGraphs.items():
complements = getComplements(externalEdges, edges)
#print "len", len(complements)
for edge, compEdge in complements:
faceA = (edge[0].getFaces() & edge[1].getFaces()).pop()
#print compEdge
faceB = (compEdge[0].getFaces() & compEdge[1].getFaces()).pop()
x = faceA.getX() - faceB.getX()
y = faceA.getY() - faceB.getY()
#print "A: x:", faceA.x, "y:", faceA.y
#print "B: x:", faceB.x, "y:", faceB.y
#print "xdiff:", x, "ydiff:", y
if edge[2] == "TOP_RIGHT" and compEdge[2] == "BOTTOM_LEFT":
newGraph = offsetFaces(g, x, y + 1);
elif edge[2] == "RIGHT" and compEdge[2] == "LEFT":
newGraph = offsetFaces(g, x + 1, y);
elif edge[2] == "TOP_LEFT" and compEdge[2] == "BOTTOM_RIGHT":
newGraph = offsetFaces(g, x + 1, y + 1);
elif edge[2] == "BOTTOM_LEFT" and compEdge[2] == "TOP_RIGHT":
newGraph = offsetFaces(g, x, y - 1);
elif edge[2] == "LEFT" and compEdge[2] == "RIGHT":
newGraph = offsetFaces(g, x - 1, y);
elif edge[2] == "BOTTOM_RIGHT" and compEdge[2] == "TOP_LEFT":
newGraph = offsetFaces(g, x - 1, y - 1);
overlap = checkFaceOverlap(randomGraph, newGraph)
#print overlap
if overlap is False:
faceGraph = combineFaces(randomGraph, newGraph)
#.........这里部分代码省略.........
示例2: combineGraphs
# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import maxClars [as 别名]
def combineGraphs(root,interval):
global Break
Break = False
quit = Button(root, text ="Quit", command = BreakModule)
quit.pack(side = LEFT)
graphNumber = 0
superGraphNumber = 0
deletedCount = 0
scrollbar = Scrollbar(root)
scrollbar.pack(side = RIGHT,fill = Y)
text = Text(root,yscrollcommand = scrollbar.set)
text.pack()
scrollbar.config(command=text.yview)
storedGraphs = {}
timeLimit = 3600 * interval
t1 = time.time()
t2 = time.time()
while t2 - t1 < timeLimit:
text.insert(CURRENT,"graph: " + str(graphNumber) + "\n")
if Break == True:
Break = False
quit.destroy()
break
flag = False
#new stuff
randomFaces = createRandomGraph()
vertexGraph = []
#Finds connected graph
while len(vertexGraph) % 2 != 0 or len(vertexGraph) == 0 or countPeaksAndValleys(randomFaces) == False or isConnected(faceGraphToInts(randomFaces)) == False:
randomFaces = createRandomGraph()
vertexGraph = makeVertexGraph(randomFaces)
randomGraph = Graph(randomFaces, vertexGraph)
perfectMatchingThm = isKekulean(randomGraph)
if perfectMatchingThm == True:
structures = assignMatching(randomGraph)
#end new stuff
Graph.comparison = 'clars'
structures.sort()
randomGraph.maxClars = structures[-1].getClarsNumber()
req_edges = getRequiredSet(structures)
externalEdges = getExternalEdges(req_edges)
if len(externalEdges) > 0:
#add graph and edges to list
storedGraphs[randomGraph] = externalEdges
for g, edges in storedGraphs.items():
complements = getComplements(externalEdges, edges)
for edge, compEdge in complements:
faceA = (edge[0].getFaces() & edge[1].getFaces()).pop()
faceB = (compEdge[0].getFaces() & compEdge[1].getFaces()).pop()
x = faceA.getX() - faceB.getX()
y = faceA.getY() - faceB.getY()
if edge[2] == "TOP_RIGHT" and compEdge[2] == "BOTTOM_LEFT":
newGraph = offsetFaces(g, x, y + 1);
elif edge[2] == "RIGHT" and compEdge[2] == "LEFT":
newGraph = offsetFaces(g, x + 1, y);
elif edge[2] == "TOP_LEFT" and compEdge[2] == "BOTTOM_RIGHT":
newGraph = offsetFaces(g, x + 1, y + 1);
elif edge[2] == "BOTTOM_LEFT" and compEdge[2] == "TOP_RIGHT":
newGraph = offsetFaces(g, x, y - 1);
elif edge[2] == "LEFT" and compEdge[2] == "RIGHT":
newGraph = offsetFaces(g, x - 1, y);
elif edge[2] == "BOTTOM_RIGHT" and compEdge[2] == "TOP_LEFT":
newGraph = offsetFaces(g, x - 1, y - 1);
overlap = checkFaceOverlap(randomGraph, newGraph)
#print overlap
if overlap is False:
faceGraph = combineFaces(randomGraph, newGraph)
faceGraph = adjustForNegatives(faceGraph)
vertexGraph = makeVertexGraph(faceGraph)
superGraph = Graph(faceGraph, vertexGraph)
structures = assignMatching(superGraph)
#.........这里部分代码省略.........
示例3: combineGraphs
# 需要导入模块: import Graph [as 别名]
# 或者: from Graph import maxClars [as 别名]
def combineGraphs():
graphNumber = 0
superGraphNumber = 0
storedGraphs = {}
interval = float(raw_input("How many hours would you like to run the program? "))
timeLimit = 3600 * interval
print "limit:", timeLimit
t1 = time.time()
t2 = time.time()
while t2 - t1 < timeLimit:
print "graph", graphNumber
flag = False
graph = _createRandomKekulean()
matchings = assignMatching(graph)
while len(matchings) == 0:
graph = _createRandomKekulean()
matchings = assignMatching(graph)
graph.numStructures = len(matchings)
Graph.comparison = 'clars'
matchings.sort()
graph.maxClars = matchings[-1].getClarsNumber()
#For testing
#fgraph = getInput("graph.txt");
#vgraph = makeVertexGraph(fgraph)
#graph = Graph(fgraph, vgraph)
req_edges = getRequiredSet(matchings)
externalEdges = getExternalEdges(req_edges)
#print len(externalEdges)
#for edge in externalEdges:
# face = (edge[0].getFaces() & edge[1].getFaces()).pop()
# print face, "\t", face.getVertices().index(edge[0]), "\t", face.getVertices().index(edge[1])
if len(externalEdges) > 0:
#add graph and edges to list
storedGraphs[graph] = externalEdges
for g, edges in storedGraphs.items():
complements = getComplements(externalEdges, edges)
#print "len", len(complements)
for edge, compEdge in complements:
faceA = (edge[0].getFaces() & edge[1].getFaces()).pop()
#print compEdge
faceB = (compEdge[0].getFaces() & compEdge[1].getFaces()).pop()
x = faceA.getX() - faceB.getX()
y = faceA.getY() - faceB.getY()
#print "A: x:", faceA.x, "y:", faceA.y
#print "B: x:", faceB.x, "y:", faceB.y
#print "xdiff:", x, "ydiff:", y
if edge[2] == "TOP_RIGHT" and compEdge[2] == "BOTTOM_LEFT":
newGraph = offsetFaces(g, x, y + 1);
elif edge[2] == "RIGHT" and compEdge[2] == "LEFT":
newGraph = offsetFaces(g, x + 1, y);
elif edge[2] == "TOP_LEFT" and compEdge[2] == "BOTTOM_RIGHT":
newGraph = offsetFaces(g, x + 1, y + 1);
elif edge[2] == "BOTTOM_LEFT" and compEdge[2] == "TOP_RIGHT":
newGraph = offsetFaces(g, x, y - 1);
elif edge[2] == "LEFT" and compEdge[2] == "RIGHT":
newGraph = offsetFaces(g, x - 1, y);
elif edge[2] == "BOTTOM_RIGHT" and compEdge[2] == "TOP_LEFT":
newGraph = offsetFaces(g, x - 1, y - 1);
overlap = checkFaceOverlap(graph, newGraph)
#print overlap
if overlap is False:
faceGraph = combineFaces(graph, newGraph)
faceGraph = adjustForNegatives(faceGraph)
vertexGraph = makeVertexGraph(faceGraph)
superGraph = Graph(faceGraph, vertexGraph)
matchings = assignMatching(superGraph)
if len(matchings) > 0:
if not os.path.exists("CombinedGraphs"):
os.mkdir("CombinedGraphs")
folderName = "CombinedGraphs/superGraph" + str(graphNumber)
#setup folder
if not os.path.exists(folderName):
os.mkdir(folderName)
superGraph.numStructures = len(matchings)
Graph.comparison = 'clars'
matchings.sort()
print "super len:", len(matchings)
superGraph.maxClars = matchings[-1].getClarsNumber()
#.........这里部分代码省略.........