Esempio n. 1
0
def printRes(G, resG, expectedG, layers=[]):

    fig = plt.figure()
    n = len(G)

    ### Parameters
    if (n < 50):
        withLabel = True
        nodeSize = 300
    else:
        withLabel = False
        nodeSize = 0

    if expectedG is None:
        resFig = fig.add_subplot(111, aspect='equal')
    else:
        resFig = fig.add_subplot(121, aspect='equal')

    if nx.is_connected(resG):
        resEPL = ev.getEPL(G, resG)
        resMax = ev.getMaxDegree(resG)
        resFig.title.set_text("result (EPL = " + str(resEPL) +
                              ", max degree = " + str(resMax) + ")")

    # nx.draw_circular(resG, with_labels=withLabel, node_size=nodeSize)
    pos = nx.circular_layout(resG)
    nx.draw_networkx_nodes(resG, pos)
    nx.draw_networkx_labels(resG, pos)
    nx.draw_networkx_edges(resG, pos, edge_color='k')
    for layer in layers:
        subG = nx.from_numpy_matrix(layer)
        elist = nx.to_edgelist(subG)
        nx.draw_networkx_edges(resG,
                               pos,
                               edgelist=elist,
                               edge_color=(rd.random(), rd.random(),
                                           rd.random()),
                               width=5 * rd.random())

    if expectedG is None:
        resDegrees = ev.getDegrees(resG)
        print("final degrees : " + str(resDegrees))
    else:
        expectedEPL = ev.getEPL(G, expectedG)
        expectedFig = fig.add_subplot(122, aspect='equal')
        expectedFig.title.set_text("expected (EPL = " + str(expectedEPL) + ")")
        nx.draw_circular(expectedG, with_labels=withLabel, node_size=nodeSize)

    plt.plot()
    plt.show()
Esempio n. 2
0
    def launch(nodes, highOutSubsets, highInSubsets, i, j):
        G = severalWheels(nodes, highOutSubsets, highInSubsets)

        res = sp.sparseToBND(G)
        N, _ = res[0], res[1]
        EPL = ev.getEPL(G, N)
        _max = ev.getMaxDegree(N)
        results.append([i, j, EPL, _max])

        if index[0] > checkpoint[0]:
            print(str(checkpointIndex[0]) + '%')
            checkpointIndex[0] += 1
            checkpoint[0] += step

        index[0] += 1
Esempio n. 3
0
    def launch(nodes, highSubsets, i):

        G = superStars(k, m, highSubsets, kernelSubsets)

        res = sp.sparseToBND(G)
        N, layers = res[0], res[1]

        if not nx.is_connected(N):
            subgraphs = list(nx.connected_component_subgraphs(N))
            for H in subgraphs:
                nx.draw_networkx(H)
                plt.show()
            raise NameError('The result graph is not connected')

        EPL = ev.getEPL(G, N)
        _max = ev.getMaxDegree(N)
        results.append([i, EPL, _max])

        if index[0] > checkpoint[0]:
            print(str(checkpointIndex[0]) + '%')
            checkpointIndex[0] += 1
            checkpoint[0] += step

        index[0]+=1
    dr.printInput(G)
    res = sp.sparseToBND(G)
    N, layers = res[0], res[1]

    dr.printRes(G, N, None, layers)

### Several test on random graphs
if choice == 1:
    N, n = 100000, 20

    results = []

    inputs = []
    for i in tqdm(range(N)):
        G = randomGraph(n)
        edges = str(G.edges)
        avgDegree = ev.getAverageDegree(G)
        n = len(G)

        res = sp.sparseToBND(G)
        N, layers = res[0], res[1]

        if nx.is_connected(N):
            EPL = ev.getEPL(G, N)
            _max = ev.getMaxDegree(N)
            results.append([EPL, _max, 12 * avgDegree, edges])

    headers = ['EPL', 'max degree', 'theorical max degree', 'edges']
    file = 'results/' + 'random_graphs.csv'
    ex.exportToCSV(file, headers, results)
Esempio n. 5
0
def update(num):

  if num < 3*m:
    if num % 3 == 0:
      left.clear()
      index = num//3
      edge = edges[index]
      rerouter = rerouters[index]
      left.set_title(f"I - Rerouting of the edge : ({edge[0]}, {edge[1]}) -> helper : {rerouter}")
      DrawInput.remove_edge(edge[0], edge[1])
      nx.draw_circular(DrawInput, ax=left, arrowstyle='->', arrowsize=10, with_labels=True, node_color=colors)
      for i in range(len(middles)):
        middle = middles[i]
        middle.clear()
        subGraph = subGraphs[i]
        if i == edge[0] or i == edge[1]:
          nx.draw_circular(subGraph, ax=middle, edge_color=colors[i], with_labels=True, node_color=colors)
        else:
          nx.draw_circular(subGraph, ax=middle, edge_color="#d3d3d3", with_labels=True, node_color="#d3d3d3")
    elif num % 3 == 1:
      index = num//3
      edge = edges[index]
      node = edge[0]
      middle = middles[node]
      middle.clear()
      rerouter = rerouters[index]
      subGraph = subGraphs[node]
      subGraph.add_edge(node, rerouter)
      
      nx.draw_circular(subGraph, ax=middle, edge_color=colors[node], with_labels=True, node_color=colors)

    elif num % 3 == 2:
      index = num//3
      edge = edges[index]
      node = edge[1]
      middle = middles[node]
      middle.clear()
      rerouter = rerouters[index]
      subGraph = subGraphs[node]
      subGraph.add_edge(rerouter, node)
      nx.draw_circular(subGraph, ax=middle, edge_color=colors[node], with_labels=True, node_color=colors)

  if num == 3*m:
    for i in range(len(middles)):
      middle = middles[i]
      middle.clear()
      subGraph = subGraphs[i]
      nx.draw_circular(subGraph, ax=middle, edge_color="#d3d3d3", with_labels=True, node_color="#d3d3d3")
  
  if num >= 3*m and num < 3*m + n:
    index = num - 3*m
    left.set_title(f"II - Formation of the MTs from the node {index}")
    
    middle = middles[index]
    middle.clear()
    nx.draw_circular(finalSubGraphs[index], ax=middle, edge_color=colors[index], with_labels=True, node_color=colors)

  if num == 3*m + n:
    EPL = ev.getEPL(_input, result)
    maxDegree = ev.getMaxDegree(result)
    left.clear()
    left.set_title(f"III - Combination of all the MTs (EPL: {EPL}, max degree: {maxDegree}), avg degree: {avgDegree}")
    nx.draw_circular(result, ax=left, with_labels=True, node_color=colors)
Esempio n. 6
0
inDegrees = [7 for i in range(75)] + [99 for i in range(25)]
outDegrees = [7 for i in range(60)] + [99 for i in range(25)
                                       ] + [7 for i in range(15)]

results = []

i = 0
for i in tqdm(range(N)):
    input = randomGraph2(inDegrees, outDegrees)
    res = sp.sparseToBND2(input)
    result = res[0]

    avgDegree = ev.getAverageDegree(input)
    initialMaxDegree = ev.getMaxDegree(input)
    maxDegree = ev.getMaxDegree(result) / 2  #because undirected
    EPL = ev.getEPL(input, result)
    firstDegreeBound = 3 * avgDegree
    secondDegreeBound = firstDegreeBound + 6

    line = [
        str(n),
        str(m),
        str(avgDegree),
        str(initialMaxDegree),
        str(maxDegree),
        str(EPL),
        str(firstDegreeBound),
        str(secondDegreeBound)
    ]
    results.append(line)