ä»å¹´ã®4æã«ãããããã°ã©ãå¦çã©ã¤ãã©ãªNetworkXã®ä½¿ãæ¹ãã¨ããè¨äºãæ¸ãã¾ãããã¡ã¢ç·¨ã«ãããã¤ãNetworkXé¢ä¿ã®ã¡ã¢ãæ®ã£ã¦ãã¾ãã
NetworkXã¨GraphVizã®çµã¿åããã¯ãã°ã©ãã®æä½ã»è§£æã»æç»ã«ä¾¿å©ãªãã§ãããã°ã©ãã表ç¾ãããã¼ã¿å½¢å¼ãè²ã ãã£ã¦é ãããããããæãããã¾ããå®è£ ã«ä¾åããªãä¸è¬è«ãä¸åæ´çãã¦ãããã»ããããããã§ããã©ã¤ãã©ãªåºæã®ãã¤ãã£ãå½¢å¼ã§ã¯ãªãã¦ãJSONã§è¡¨ç¾ã§ãããã¼ã¿å½¢å¼ã®è©±ããã¾ãã
ä¾é¡ã¯æ¬¡ã®ãããªã°ã©ãã ã¨ãã¾ãã
- é ç¹ï¼ãã¼ãï¼ã¯ãa, b, c, d, e ã®5ã¤ãããã
- 辺ã¯æ¬¡ã®4æ¬ï¼
- a â b
- b â c
- c â a
- c â d
å 容ï¼
åç´ãªæåã°ã©ã
以ä¸ãæåã°ã©ãã ããèãã¾ããã¾ãã¯å¤é辺ãæããªãåç´ãªæåã°ã©ãããã
ã°ã©ãã¯ãé ç¹ã®éåã¨è¾ºã®éåããããªãã¾ãã辺ã¯ã2ã¤ã®é ç¹ã®é åºå¯¾ã§ããé ç¹ã¯æååã®IDã§è¡¨ç¾ããã¨ãã¦ãã°ã©ãã®å®ç¾©ãç´ ç´ã«JSONãã¼ã¿ã«ããã°æ¬¡ã®ããã§ãããã
{ "nodes": ["a", "b", "c", "d", "e"], "edges": [["a", "b"], ["b", "c"], ["c", "a"], ["c", "d"]] }
ã©ã®è¾ºã¨ãæ¥ãã¦ãªãé ç¹ãå¤ç«ç¹ã¨å¼ã¶ãã¨ã«ãã¾ãããããå¤ç«ç¹ããªããªãã辺ã®ãªã¹ãï¼é åï¼ã ãã§ãå®å ¨ã«ã°ã©ãã表ç¾ã§ãã¾ãããããå¤ç«ç¹ãããã¨ã辺ã®ãªã¹ããè¦ãã ãã§ã¯å¤ç«ç¹ã®åå¨ãåãããªãã®ã§ããã¯ãé ç¹éåãå¿ è¦ã¨ãªãã¾ãã
["a", "a"] ã®ããã«ãèªåèªèº«ã«æ»ã辺ãèªå·±ã«ã¼ã辺ã¨å¼ã³ã¾ãããã¹ã¦ã®é ç¹ãèªå·±ã«ã¼ã辺ãæã¤ã°ã©ãã¯åå°çã°ã©ãã¨ããã¾ããåå°çã°ã©ãã«ã¯å¤ç«ç¹ãããã¾ããï¼ èªå·±ã«ã¼ã辺ã¨ããã©ã辺ã ããã§ããä¾é¡ã®ã°ã©ããåå°çã°ã©ãã«ç´ãã¨ã次ã®ããã«ãªãã¾ãã
{ "nodes": ["a", "b", "c", "d", "e"], "edges": [["a", "a"], ["b", "b"], ["c", "c"], ["d", "d"], ["e", "e"], ["a", "b"], ["b", "c"], ["c", "a"], ["c", "d"] ] }
ãã®å ´åã¯ãé ç¹ãèªå·±ã«ã¼ã辺ã¨ãã¦è¾ºéåã«åãè¾¼ã¾ãã¦ããã®ã§ã辺ã®ãªã¹ãã ãã§ã°ã©ããå®å ¨ã«è¡¨ç¾ã§ãã¾ãã
dict-of-listså½¢å¼
NetworkXã§dict-of-listså½¢å¼ã¨å¼ãã§ãããã¼ã¿å½¢å¼ã§ã¯ã1ã¤ã®é ç¹ããåºã辺ã®ã¿ã¼ã²ããéããªã¹ãã¨ãã¦ä¸¦ã¹ã¾ããå®ä¾ãåºããã»ãã話ãæ©ãã§ãããã
{ "a": ["b"], "b": ["c"], "c": ["a", "d"], "d": [], "e": [] }
æåã«åºããå½¢å¼ãããdict-of-listså½¢å¼ã®ã»ããã³ã³ãã¯ãã§ãããèªå·±ã«ã¼ã辺ãå ããåå°çã°ã©ããªã次ã®ããã§ãã
{ "a": ["a", "b"], "b": ["b", "c"], "c": ["c", "a", "d"], "d": ["d"], "e": ["e"] }
é ç¹ï¼è¾ºã«å¤ãä»ããã°ã©ã
é ç¹ã¨è¾ºï¼ã©ã¡ããçæ¹ã®ã¨ããããï¼ã«ãªãããã®å¤ãä»ããã°ã©ããèãã¾ãããã®å¤ã¯ãã©ãã«ãéããè²ãªã©ã¨å¼ã°ãããã¨ãããã¾ããç¾å®ã®ã¢ãã«ã ã¨é»å§ã ã£ããã輸ééã ã£ããããã¾ãã
ä¾é¡ã®ã°ã©ãã®é ç¹ a, b, c, d, e ã«ããããã 10, 20, 30, 40, 50 ã®æ°å¤ãå²ãå½ã¦ã辺ã«ã¯ãã¿ã¼ã²ããã®å¤ - ã½ã¼ã¹ã®å¤ãã¨å¼ãç®ããå¤ãå²ãå½ã¦ããã¨ã«ãã¾ããã¾ãã¯ç´ æ´ã«ãå¤ããªã¹ãè¦ç´ ï¼ãããã¿ãã«è¦ç´ ï¼ã¨ãã¦ä»ãå ãã¦ã¿ã¾ãã
{ "nodes": [["a", 10], ["b", 20], ["c", 30], ["d", 40], ["e", 50]], "edges": [["a", "b", 10], ["b", "c", 10], ["c", "a", -20], ["c", "d", 10]] }
ããã¾ãè¦ããããªãã§ããããªã¹ãï¼é åï¼ããè¾æ¸ï¼ããããJSONãªãã¸ã§ã¯ãï¼å½¢å¼ã®ã»ããå°ãã¹ãããªãã¾ããå¤ä»ãã®é ç¹ã¯æ¬¡ã®ããã«è¡¨ç¾ã§ãã¾ãã
{ "a": 10, "b": 20, "c": 30, "d": 40, "e": 50 }
å¤ä»ãã®è¾ºã¯å ¥ãåã®è¾æ¸ã§è¡¨ç¾ãã¾ããNetworkXã§ã¯ãdict-of-dictså½¢å¼ã¨å¼ãã§ãã¾ãã
{ "a": {"b": 10}, "b": {"c": 10}, "c": {"a": -20, "d": 10}, "d": {}, "e": {} }
ã¡ãã£ã¨åããã«ããã§ããããã®ãã¼ã¿ãJavaScriptã®å¤æ°edgesã«å ¥ããã¨ããã¨ãedges.a.bãããã㯠edges["a"]["b"] ã¨ãã¦ã辺 aâb ã®å¤ãåããã¨ãã§ãã¾ãã
>>> var edges = { "a": {"b": 10}, "b": {"c": 10}, "c": {"a": -20, "d": 10}, "d": {}, "e": {}} undefined >>> edges.a.b 10 >>> edges["a"]["b"] 10
ãã®ä»
ä¾é¡ã§ã¯ãé ç¹ï¼è¾ºã«ä»ããå¤ãåãªãæ°å¤ã§ããããè¤éãªå¤ãå²ãå½ã¦ããã¨ãã§ãã¾ããä¾ãã°ãGraphVizã§ã¯ã{"color": "green", "shape": "circle"} ã®ãããªå¤ã«ããæç»æã®ã¹ã¿ã¤ãªã³ã°ããã¦ãã¾ãã
å¤é辺ãæ±ãããã¨ãã¯ã辺ã®IDãå¤ã¨ãã¦å²ãå½ã¦ã両端ãåãã§ãIDãéãã°ç°ãªã辺ã¨è§£éããã°ããã§ããããå®éã«ã¯ãNetworkXãGraphVizãå¤é辺ã®ãµãã¼ãã¯å¼±ãã®ã§ãè¦å´ããããããã¨ã¯ããã¾ãã
é£æ¥è¡åãæ¥ç¶è¡åã¨ãã¦ã°ã©ãã表ç¾ãããã¨ãã§ãã¾ããNetworkXã¯ãNumPyãSciPyã®è¡åã«ããã°ã©ã表ç¾ããµãã¼ããã¦ãã¾ãã
ã¨ã«ãããããããªè¡¨ç¾æ¹æ³ãããã¾ããã©ããã²ã¨ã¤ã§æ¸ã¾ãããã¨ãåºæ¥ãªãã®ã§ãå ¨ä½ã®é¢é£æ§ãã¤ããã ä¸ã§é©å®ä½¿ãåãããããªãããã§ãã