takemaru / graphillion

Fast, lightweight graphset operation library
Other
466 stars 40 forks source link

The Question about connection with networkX #38

Open ganyariya opened 5 years ago

ganyariya commented 5 years ago

Hello. I'm a student in Japan, recently using graphillion.

I found that GraphSet.converters is strange in source code, and happens error.

import matplotlib.pyplot as plt
from graphillion import GraphSet
import graphillion.tutorial as tl
import random
import networkx as nx

CONST_H = 500
CONST_W = 500

N = int(input())
M = int(input())

# Graphの接続設定
G = [[] for i in range(N)]
for i in range(M):
    while True:
        a = random.randint(0, N - 1)
        b = random.randint(0, N - 1)
        if a != b:
            break
    G[a].append(b)
    G[b].append(a)

# 位置の設定
P = [(random.uniform(-CONST_W, CONST_W), random.uniform(-CONST_H, CONST_H))
     for i in range(N)]

GraphSet.converters['to_edges'] = nx.Graph
GraphSet.converters['to_graph'] = nx.Graph.edges()

graph = nx.Graph()

for i in range(N):
    graph.add_node(i)

for i in range(N):
    for j in range(len(G[i])):
        graph.add_edge(i, G[i][j])

# 全体図の描画
# nx.draw_networkx(graph, pos=P)
# plt.show()

GraphSet.set_universe(graph)

This code arises error in "GraphSet.set_universe(graph)", which error represents

Traceback (most recent call last):
  File "graph.py", line 30, in <module>
    GraphSet.converters['to_graph'] = nx.Graph.edges()
TypeError: 'property' object is not callable

When I saw the source code about set_converters 2101, 2102, rows

    converters = { 'to_graph': lambda edges: edges,
                   'to_edges': lambda graph: graph }

Is this correct? I think this source code made mistake about changing position in 'to_graph', 'to_edges'.

Thank you.

takemaru commented 5 years ago

Please carefully read the sample code in Working with NetworkX.

Your following code GraphSet.converters['to_graph'] = nx.Graph.edges() should be GraphSet.converters['to_graph'] = nx.Graph.edges