pythonã®ãã¬ã¼ã ã¯ã¼ã¯NetworkXã§ã°ã©ãçè«
ã°ã©ãçè«~ç¹ã¨ç·~
ãæ°å¦ã®ä¸åéã§ãããªãããæ å ±ç³»ã®ç¹ã«ã¢ã«ã´ãªãºã åéã§çºå±ãã¦ããã°ã©ãçè«ã
åºæ¬çãªé¨åã¯ã¨ã£ã¦ãç°¡åã§ãã¨ã«ããç¹(node)ã¨ç·(edge)ã«ã¤ãã¦èããå¦åã
ãå®è£ ã«ä½¿ãè¨èªã¯ãboostã«graphã¢ã«ã´ãªãºã ããããããªã®ã§c++ã¨ãèãããã©ã軽éè¨èªã§ãµã¯ãµã¯ä½ãããã£ãããããã¥ã¡ã³ããå å®ãã¦ãããªNetworkXã¨ãããã¬ã¼ã ã¯ã¼ã¯ã使ããã¨ã«ã
ã¤ã³ã¹ãã¼ã«
å ¬å¼ãµã¤ãã¯こちらã
ã³ãã³ãã©ã¤ã³ããã
sudo pip install networkx
以ä¸ãmatplotlibã¨ãpygraphvizã¯ã¤ã³ã¹ãã¼ã«ãã¨ãã¾ããããpygraphvizã¯pip install pygraphvizã§ã¤ã³ã¹ãã¼ã«ã§ããªããããªã®ã§ãこちらãããã¦ã³ãã¼ãããã
ãã¥ã¼ããªã¢ã«
nodeã¨edgeã®ä½æã«networkxãä½æããã°ã©ãã®è¦è¦åã«matplotlibã使ãã
import networkx as nx import matplotlib.pyplot as plt G = nx.Graph()
node(ç¹)ãã¤ãã
G.add_node(1) print G.nodes() >>>[1]
edge()(ç·)ãã¤ãã
G.add_node(2) G.add_edge(3, 4) print G.nodes() print G.edges() >>>[2, 3, 4] >>>[(3, 4)]
matplotlibã§æåãã
nx.draw(G)
plt.show()
#ã°ã©ãã®æå
pygraphvizã使ãã°ãã ã¼ãã¼ã¨ããä½ãã¾ãã