Exemplo n.º 1
0
def randomGraphWithCNum(nodes, number, step=50):
    edges = []
    while True:
        print("Number of edges:", len(edges))
        newEdges = []
        for i in range(step):
            newEdge = (random.randrange(nodes), random.randrange(nodes))
            flippedEdge = (newEdge[1], newEdge[0])
            if newEdge not in edges and newEdge not in newEdges and flippedEdge not in edges and flippedEdge not in newEdges:
                newEdges.append(newEdge)

        c = max(cnum.getColoringHEA(nodes, edges + newEdges))
        print("c: ", c)
        while c > number:
            newEdges = newEdges[:len(newEdges)//2]
            c = max(cnum.getColoringHEA(nodes, edges + newEdges))

        edges += newEdges

        if c == number:
            break

    g = nx.Graph()
    for n in range(nodes):
        g.add_node(n)
    for (a, b) in edges:
        g.add_edge(a, b)

    return g
Exemplo n.º 2
0
def getTime(numberOfNodes, listOfEdges):
    suma = 0
    for i in range(repetitions):
        start_time = time.time()
        cnum.getColoringHEA(numberOfNodes, listOfEdges)
        end_time = time.time() - start_time
        suma += end_time
    average = suma / repetitions
    return average
Exemplo n.º 3
0
def getChromaticNumber(numberOfNodes, listOfEdges):
    coloring = cnum.getColoringHEA(numberOfNodes, listOfEdges)
    c = max(coloring)
    return c
Exemplo n.º 4
0
        print("Number of edges:", len(edges))
        newEdges = []
        for i in range(step):
            newEdge = (random.randrange(nodes), random.randrange(nodes))
            flippedEdge = (newEdge[1], newEdge[0])
            if newEdge not in edges and newEdge not in newEdges and flippedEdge not in edges and flippedEdge not in newEdges:
                newEdges.append(newEdge)

        c = max(cnum.getColoringHEA(nodes, edges + newEdges))
        print("c: ", c)
        while c > number:
            newEdges = newEdges[:len(newEdges)//2]
            c = max(cnum.getColoringHEA(nodes, edges + newEdges))

        edges += newEdges

        if c == number:
            break

    g = nx.Graph()
    for n in range(nodes):
        g.add_node(n)
    for (a, b) in edges:
        g.add_edge(a, b)

    return g


g = randomGraphWithCNum(40, 40, 500)
print(max(cnum.getColoringHEA(len(g.nodes()), g.edges())))