Exemplo n.º 1
0
def checkConnected(d, g):

	totalFaceCount = getNumFaces(g)
	queue = []

	#make faceGraph
	faceGraph = []
	y = 0
	while y < len(g):
		row = g[y]		
		for x in row:
			faceGraph.append((Face(int(x), y)))
		y += 1

	vg = makeVertexGraph(faceGraph)
	graph = Graph(faceGraph, vg)
		
	queue.append(graph.getFaceGraph()[0])
	visited = set()

	while len(visited) < len(graph.getFaceGraph()):
		face = queue.pop(0)
		while face in visited:
			#print "in while"
			if len(queue) > 0:
				face = queue.pop(0)
			else:
				break
		#this means that the face is visited and grpah is disconnected	
		if face in visited:
			break

		nextGroup = face.getNeighbors()
		if len(nextGroup) == 0:
			break
		else:
			queue.extend(nextGroup)

		#print "stats"
		#print len(graph.getFaceGraph()), len(queue), len(visited)
		visited.add(face)

		#print "graph"
		#print graph
		#print "-------------------"
	return len(graph.getFaceGraph()) == len(visited)
Exemplo n.º 2
0
def testConjectureDifferentFaces(hours=0):
	graphList = []
	results = open("results.txt", "w")
	results.write("The program actually run!")

	if hours == 0:
		interval = float(raw_input("How many hours would you like to run the program? "))
	else:
		interval = hours

	timeLimit = 3600 * interval
	print "limit:", timeLimit

	t1 = time.time()
	t2 = time.time()

	counter = 0
	while t2 - t1 < timeLimit:
		print "graph #" + str(counter)

		#creates a face graphs
		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)

			for f in randomGraph.getFaceGraph():
				pairs = randomGraph.getBondedVertices(f)
				print str(pairs)
			
			#must be 'fries' or 'clars'
			Graph.comparison = 'clars'
			structures.sort()

			h = structures[-1]
			h.setNumStructures(len(structures))
			#h.setString(structures[0].simpleToString())

			#is the data right?
			#print "Verts:", h.getNumVertices()
			#print "Structures:", h.getNumStructures()
			#print "Clar:", h.getFriesNumber()

			for g in graphList:
				if h.getNumVertices() == g.getNumVertices() :#and h.getNumVertices() <= 26:
					if h.getNumStructures() < g.getNumStructures():

#first part
						if h.getClarsNumber() > g.getClarsNumber():
							print 'Conjecture is false:'
								
							results.write('\ngraph H: Clars: ' + str(h.getClarsNumber()) + " Number of Structures: " + str(h.getNumStructures()) + " Number of vertices: " + str(h.getNumVertices()) + "\n") 
							results.write(str(h))
							results.write('\ngraph G: Clars: ' + str(g.getClarsNumber()) + " Number of Structures: " + str(g.getNumStructures()) + " Number of vertices: " + str(g.getNumVertices()) + "\n") 
							results.write(str(g))
							results.write("\n\n")

							drawConflictsCC(g, h)
#second part

						if h.getFriesNumber() > g.getFriesNumber():
							print 'Conjecture is false:'
							results.write('\ngraph H: Fries: ' + str(h.getFriesNumber()) + " Number of Structures: " + str(h.getNumStructures()) + " Number of vertices: " + str(h.getNumVertices()) + "\n") 
							results.write(str(h))
							results.write('\ngraph G: Fries: ' + str(g.getFriesNumber()) + " Number of Structures: " + str(g.getNumStructures()) + " Number of vertices: " + str(g.getNumVertices()) + "\n") 
							results.write(str(g))
							results.write("\n\n")
	
							drawConflictsKKFF(g, h)
#third part
						if h.getClarsNumber() > g.getClarsNumber():  
							if h.getFriesNumber() < g.getFriesNumber():
								print 'Conjecture is false:'
								results.write('\ngraph H: Clars: ' + str(h.getClarsNumber()) + "graph H: Fries: " + str(h.getFriesNumber()) + " Number of Structures: " + str(h.getNumStructures()) + " Number of vertices: " + str(h.getNumVertices()) + "\n") 
								results.write(str(h))
								results.write('\ngraph G: Clars: ' + str(g.getClarsNumber()) + "graph G: Fries: " + str(g.getFriesNumber()) +" Number of Structures: " + str(g.getNumStructures()) + " Number of vertices: " + str(g.getNumVertices()) + "\n") 
								results.write(str(g))
								results.write("\n\n")

								drawConflictsFFCC(g, h)

			#only adds graphs to list if it under some number of vertices
			graphList.append(h)

		t2 = time.time()
		counter += 1