def GenerateAllGraphsWithManyXNoY(xCardinalityUpperBound): t = range(1, xCardinalityUpperBound) graphConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) for thisGraphConfiguration in graphConfigSet: myGraph = ConstructBaseGraph() for thisSetIndex in range(0,CYCLE_LENGTH): if thisGraphConfiguration[thisSetIndex] >= 2: myGraph = AddXSet(myGraph, thisGraphConfiguration[thisSetIndex] - 1, False, thisSetIndex) if not (GIsHFree(myGraph, FORBIDDEN_SUBGRAPHS)): print("ERROR!") f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() exit() result = TheAlgorithm(myGraph) if(result == True): print("Conjecture Holds.") else: print("Conjecture Fails!") G = convert_node_labels_to_integers(G, 0, ordering='default', label_attribute = None) f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() myGraph.clear() return
def DifferentSizeXSetsNoYSetsTest(xCardinalityUpperBound): t = range(1,xCardinalityUpperBound) graphConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) for thisGraphConfiguration in graphConfigSet: myGraph = ConstructOnion(1) for thisSetIndex in range(0,CYCLE_LENGTH): if thisGraphConfiguration[thisSetIndex] >= 2: myGraph = AddXSet(myGraph, thisGraphConfiguration[thisSetIndex] - 1, False, thisSetIndex) thisStrongStableSet = FindStrongStableSet(myGraph) if not (GIsHFree(myGraph, FORBIDDEN_SUBGRAPHS)): print("ERROR!") f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() exit() if thisStrongStableSet == None: print("G does not contain a strong stable set") WriteToLogFile("X Config: {0}".format(thisGraphConfiguration)) f = File(DIRECTORY + "_X_only", G = myGraph, logger = MY_LOGGER, base="C5-") f.save() else: print("G does contain a strong stable set: {0}".format(thisStrongStableSet)) myGraph.clear() return
def GenerateAllGraphsWithManyXNoY(xCardinalityUpperBound): t = range(1, xCardinalityUpperBound) graphConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) for thisGraphConfiguration in graphConfigSet: myGraph = ConstructBaseGraph() for thisSetIndex in range(0,CYCLE_LENGTH): if thisGraphConfiguration[thisSetIndex] >= 2: myGraph = AddXSet(myGraph, thisGraphConfiguration[thisSetIndex] - 1, False, thisSetIndex) if not (GIsHFree(myGraph, FORBIDDEN_SUBGRAPHS)): print("ERROR!") print(myGraph.edges()) f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() exit() coloring = GreedyColoring(myGraph) if(valid_coloring(coloring, myGraph)): print("Valid coloring") else: print("INVALID coloring!") f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() myGraph.clear() return
def DifferentSizeXAndDifferentSizeY(xyCardinalityUpperBound): #ALWAYS ADD X'S ***BEFORE*** adding your Y's! t = range(1,xyCardinalityUpperBound) xConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) yConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) badYConfigurations = set() #Now we need to sift through our Y sets and remove illegal ones #No more than 3 Y's for thisYConfig in yConfigSet: numberYSets = 0 for i in range(0,CYCLE_LENGTH): if thisYConfig[i] == 2: numberYSets += 1; if thisYConfig[(i + 3) % CYCLE_LENGTH] == 2 or thisYConfig[(i + 4) % CYCLE_LENGTH] == 2: badYConfigurations = badYConfigurations.union({thisYConfig}) break if numberYSets > 3: badYConfigurations = badYConfigurations.union(set(thisYConfig)) break yConfigSet.difference_update(badYConfigurations) # now we may construct our graphs! for thisXConfig in xConfigSet: for thisYConfig in yConfigSet: myGraph = ConstructOnion(1) for i in range(0,CYCLE_LENGTH): if thisXConfig[i] >= 2: myGraph = AddXSet(myGraph, thisXConfig[i] - 1, False, i) for i in range(0,CYCLE_LENGTH): if thisYConfig[i] >= 2: myGraph = AddYSet(myGraph, thisXConfig[i] - 1, False, i) #Since the strong stable set is probabilistic, run it a few times just in case #it returns None when in fact a strong stable set exists! for i in range(0,STABLE_SET_SEARCH_ITERATIONS): thisStrongStableSet = FindStrongStableSet(myGraph) if thisStrongStableSet != None: break if not (GIsHFree(myGraph, FORBIDDEN_SUBGRAPHS)): print("ERROR!") f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() exit() if thisStrongStableSet == None: print("G does not contain a strong stable set") WriteToLogFile("X Config: {0} Y Config: {1}".format(thisXConfig, thisYConfig)) f = File(DIRECTORY + "X_and_Y", G = myGraph, logger = MY_LOGGER, base="C5-") f.save() else: print("G does contain a strong stable set: {0}".format(thisStrongStableSet)) myGraph.clear() return
def GenerateAllGraphsWithManyXManyY(xyCardinalityUpperBound): #ALWAYS ADD X'S ***BEFORE*** adding your Y's! t = range(1,xyCardinalityUpperBound) xConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) yConfigSet = set(set(product(set(t),repeat = CYCLE_LENGTH))) badYConfigurations = set() #Now we need to sift through our Y sets and remove illegal ones #No more than 3 Y's for thisYConfig in yConfigSet: numberYSets = 0 for i in range(0,CYCLE_LENGTH): if thisYConfig[i] >= 2: numberYSets += 1; if thisYConfig[(i + 3) % CYCLE_LENGTH] == 2 or thisYConfig[(i + 4) % CYCLE_LENGTH] >= 2: badYConfigurations = badYConfigurations.union({thisYConfig}) break if numberYSets > 3: badYConfigurations = badYConfigurations.union(set(thisYConfig)) break yConfigSet.difference_update(badYConfigurations) graphsAnalyzedSoFar = 0 # now we may construct our graphs! for thisXConfig in xConfigSet: for thisYConfig in yConfigSet: myGraph = ConstructBaseGraph() for i in range(0,CYCLE_LENGTH): if thisXConfig[i] >= 2: myGraph = AddXSet(myGraph, thisXConfig[i] - 1, False, i) for i in range(0,CYCLE_LENGTH): if thisYConfig[i] >= 2: myGraph = AddYSet(myGraph, thisXConfig[i] - 1, False, i) if not (GIsHFree(myGraph, FORBIDDEN_SUBGRAPHS)): print("ERROR!") f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() exit() coloring = GreedyColoring(myGraph) if valid_coloring(coloring, myGraph): print("Valid Coloring") else: print("INVALID coloring!") f = File(DIRECTORY, G = myGraph, logger = MY_LOGGER, base="C5-") f.save() myGraph.clear() graphsAnalyzedSoFar += 1 print("Graphs Analyzed: {0}:" .format(graphsAnalyzedSoFar)) return
def Process(): count = 1 allZSetPossibilities = GenerateZSetPossibilities() thisGraph = ConstructBaseGraph() for thisZConfig in allZSetPossibilities: WriteToLogFile("Current Z Configuration {0}".format(count)) #add the extra Z's (and appropriate edges) if needed for thisZ in enumerate(thisZConfig): if thisZ[1] != 1: #add the extra node nodeIndex = thisGraph.number_of_nodes() thisGraph.add_node(nodeIndex) Z_SETS[thisZ[0]].append(nodeIndex) #Z forms a clique for thisExistingZ in Z_SETS[thisZ[0]]: if nodeIndex != thisExistingZ: thisGraph.add_edge(nodeIndex, thisExistingZ) #add the edges for C5 thisGraph.add_edge((thisZ[0] - 1) % NUMBER_OF_Z_SETS, nodeIndex) thisGraph.add_edge(thisZ[0] % NUMBER_OF_Z_SETS, nodeIndex) thisGraph.add_edge((thisZ[0] + 1) % NUMBER_OF_Z_SETS, nodeIndex) #generate all possible edge permutations allZVertices = [] for thisZSet in Z_SETS: for thisZ in thisZSet: allZVertices.append(thisZ) graphToTest = deepcopy(thisGraph) for thisEdgePosssibility in product(range(2),repeat = len(allZVertices)): #add each of these edge sets to the graph we will test AddEdges(graphToTest, thisEdgePosssibility, allZVertices) #Check to ensure it does not contain a forbidden induced subgraph if GIsHFree(graphToTest, FORBIDDEN_INDUCED_SUBGRAPHS): #Check that the clique number is equal to the chromatic number if CliqueNumEqualsChromaticNum(graphToTest): WriteToLogFile("Graph Passed.") else: WriteToLogFile("Graph Failed!") f = File(DIRECTORY, G = graphToTest, logger = MY_LOGGER, base="C5-") f.save() graphToTest.clear() graphToTest = deepcopy(thisGraph) WriteToLogFile("Proceeding to analyze new Z configuration!") count += 1 return
def process(): index = 0 #Generate an array corresponding to the k-vertices we want to add to c7 for add in combinations_with_replacement(range(4), 7): print(add) #We can have at most 3 Z's and 2 Y's, making 5 possible vertices we can add if count(add) > 5: break for thisPermutation in permutations(add): #copy initial graph (c7) and add vertices #self.g = BASE.copy() g = make_cycle(7) add_vertices(g, thisPermutation) check = True #we want our graph to remain {4k1,c4,c6}-free for H in FORBIDDEN: if induced_subgraph(g, H): check = False break if check: #log it f = File(DIRECTORY, G=g, logger=LOGGER, base="C5-") fp = f.save() if fp is not None: index += 1 print("Created Graph: %d" % index)
def go(): for g in Generator(GRAPH, DROPS, FORBIDDEN, logger=LOGGER).iterate(): if not check_condition_holds(g): f = File(MYPATH, G=g, logger=LOGGER, base="") fp = f.save() LOGGER.info("Found the special graph") print("Found the special graph")
def check_graph(drops, graph, forbidden): for g in Generator(graph, drops, forbidden, logger=LOGGER).iterate(): if special_graph(g): f = File(MYPATH, G=g, logger=LOGGER, base="") fp = f.save() LOGGER.info("Found the special graph") print("Found the special graph")
def FinalProcessGraph(G): result = "" if(GIsHFree(G, FORBIDDEN_SUBGRAPHS)): #check that the clique number equals the chromatic number if CliqueNumEqualsChromaticNum(G): result = "Graph Passed" else: result = "Graph Failed!!" #save em' f = File(DIRECTORY, G = G, logger = MY_LOGGER, base="C5-") f.save() else: #Mainly for my own interest. This should never happen since we are following the rules! result = "CONAINS FORBIDDEN INDUCED SUBGRAPH!!" return result
def go(): count = 0 for g in Generator(GRAPH, DROPS, FORBIDDEN, logger=LOGGER).iterate(): count += 1 if not conjecture_holds(g): f = File(MYPATH, G=g, logger=LOGGER, base="") fp = f.save() LOGGER.info("Found the special graph") print("Found the special graph") if count % 1000 == 0: print("Checked {} graphs".format(count)) print("Done")
def Process(): currentZSize = 1 #construct each graph while currentZSize <= MAX_Z_SIZE: LogGraphInfo("Checking graphs with |Zi| = |Zi+1| = " + str(currentZSize)) thisGraph, firstZVertices, secondZVertices = ConstructGraph(currentZSize) baseGraph = copy.deepcopy(thisGraph) #Look at all possible edge configurations between the two Z sets #Create a set of all edges allPossibleEdges = set() for i in product(firstZVertices, secondZVertices): allPossibleEdges.add(i) #Now, we need to look at/create all possible graphs we can create from Zi and Zi+1 for i in range(0, 2 * currentZSize + 1): for thisCombination in combinations(allPossibleEdges,i): for edge in thisCombination: thisGraph.add_edge(edge[0], edge[1]) #create the graph for each config #Now we need to make sure the graph we created is (4k1, C4, C6)-free if IsHFreeGraph(FORBIDDEN, thisGraph): if ChromaticNumberEqualsCLiqueNumber(thisGraph): LogGraphInfo("Graph Passed.") else: LogGraphInfo("Graph Failed.") f = File(DIRECTORY, G = thisGraph, logger = LOGGER, base = "C5-") fp = f.save() thisGraph.clear() thisGraph = copy.deepcopy(baseGraph) currentZSize += 1 thisGraph.clear() baseGraph.clear() return
sys.path.append("..") #Adds higher directory modules to python path from graph.helper import make_cycle, make_cok4 from os import getcwd from os.path import join from utility.generator import Generator2 from utility.file import File import logging FORBIDDEN_SUBGRAPHS = [make_cycle(4), make_cycle(5), make_cycle(7), make_cok4()] FAMILY = "C7-free" DIRECTORY = join(getcwd(), 'GraphFamilies', FAMILY) BASE_CYCLE = make_cycle(6) BASE = "C7-free" logging.basicConfig(filename=BASE+FAMILY+".log", level=logging.INFO, format='%(asctime)s %(message)s') LOGGER = logging.getLogger(__name__) generator = Generator2(BASE_CYCLE, 4, FORBIDDEN_SUBGRAPHS) index = 0 for graph in generator.iterate(): print("t") f = File(DIRECTORY, G=graph, logger=LOGGER, base=BASE) fp = f.save() if fp is not None: index += 1 LOGGER.info("Unique graph found %s" % fp) print("Total Graphs Produced: %d" % index) print("Complete") LOGGER.info("Total Graphs Produced %d" % index) LOGGER.info("Complete")
#add the new node vertexToAddNum = resultGraph.number_of_nodes() resultGraph.add_node(vertexToAddNum) x_sets[vertexIndex % CYCLE_LENGTH].append(vertexToAddNum) #add its edges resultGraph.add_edge( (vertexToAddNum - 1) % CYCLE_LENGTH, vertexToAddNum ) resultGraph.add_edge( vertexToAddNum % CYCLE_LENGTH, vertexToAddNum) resultGraph.add_edge( (vertexToAddNum + 1) % CYCLE_LENGTH, vertexToAddNum) #x_i forms a clique for thisXSet in x_sets: if(len(thisXSet) > 1): for thisCliqueEdge in product(thisXSet, thisXSet): if(thisCliqueEdge[0] != thisCliqueEdge[1]): resultGraph.add_edge(thisCliqueEdge[0], thisCliqueEdge[1]) #X_i joins its neighbours for thisXSetIndex in range(0,CYCLE_LENGTH): x1 = x_sets[thisXSetIndex] x2 = x_sets[(thisXSetIndex+1) % CYCLE_LENGTH] for vertexI in x1: for vertexJ in x2: resultGraph.add_edge(vertexI,vertexJ) return resultGraph result = Construct() print("Clique number: {0}".format(graph_clique_number(result))) f = File(DIRECTORY, G = result, logger = MY_LOGGER, base="C5-") f.save()