Graphvizã®éã¬ã¤ã¢ã¦ãç³»ãã¼ã«ã¡ã¢
Graphvizã«ã¯ã°ã©ããã¬ã¤ã¢ã¦ããããã¼ã«ã®ä»ã«ãã°ã©ããç·¨éãå¤æããããææ¨å¤ãè¨ç®ãããã¼ã«ç¾¤ããããã¨ãæè¿ç¥ã£ããç°¡åã«åä½ç¢ºèªããç¯å²ãã¡ã¢ã使ã£ãGraphvizã®ãã¼ã¸ã§ã³ã¯2.20.2-8ubuntu3*1ã
ã¾ããå ¥åç¨ã«ã°ã©ããã¼ã¿ã®ãµã³ãã«input1.dotãç¨æã
digraph DIRECTED { node [shape=circle] A B -> { G } C -> { C D O } E -> { F H K } F -> { E H } G -> { E } I -> { J K L } H -> { B } J -> { N } K -> { I M } L -> { N } N -> { I } }
circoã§ã¬ã¤ã¢ã¦ãããçµæinput1.pngã
以ä¸ããã¼ã«ã®ã³ãã³ãåã®ã¢ã«ãã¡ãããé ã
acyclicï¼ãå ¥åã°ã©ãããéè·¯ããªããªãããã«è¾ºã®æ¹åãå転ããã
ããããDAGã«å¤æããããã ãã辺ã®å転ãªã®ã§èªå·±ã«ã¼ãã¯ãã®ã¾ã¾æ®ãã
å
¥åã°ã©ãã«å¿ãã¦ã³ãã³ãã®çµäºã¹ãã¼ã¿ã¹ãå¤ããã
- 0 å ¥åã°ã©ãã«ãã¨ãã¨éè·¯ããªãã£ã
- 1 å ¥åã°ã©ãã«éè·¯ããã£ã
- 2 å ¥åã°ã©ããç¡åã°ã©ãã ã£ãï¼ãã®å ´åãã³ãã³ãã¯ä½ãåºåããªãï¼
- 255 ã¨ã©ã¼
ä¾ãåºåãcircoã«æ¸¡ãã¦ã¬ã¤ã¢ã¦ãããã
$ acyclic ./input1.dot | circo -Tpng -o ./acyclic.png
çµæã®ç»åacyclic.pngã
bcompsï¼ãå ¥åã°ã©ããäºé£çµæåã«åå²ãã
ããã©ã«ãã§ã¯åå²ãããåæåã¯DOTè¨èªã®subgraphã¨ãã¦å ã®graphã«å å«ãããå½¢ã§åºåããããåæåãå¥ã ã®ã°ã©ãã¨ãã¦åºåãããå ´åã¯-xãªãã·ã§ã³ãä»ããã
ä¾ã
$ bcomps ./input1.dot digraph DIRECTED { node [shape=circle]; subgraph DIRECTED_bcc_1 { I -> J; I -> L; J -> N; L -> N; N -> I; } subgraph DIRECTED_bcc_2 { K -> I; I -> K; } subgraph DIRECTED_bcc_3 { K -> M; } subgraph DIRECTED_bcc_4 { E -> K; } subgraph DIRECTED_bcc_5 { B -> G; G -> E; E -> F; E -> H; F -> E; F -> H; H -> B; } subgraph DIRECTED_bcc_6 { C -> C; C -> D; } subgraph DIRECTED_bcc_7 { C -> C; C -> O; } A; }
ccompsï¼ãå ¥åã°ã©ããé£çµæåã«åå²ãã
bcompsã¨åãããããã©ã«ãã§ã¯åæåã¯subgraphã¨ãã¦åºåããã-xãªãã·ã§ã³ãä»ããã°å¥ã ã®ã°ã©ãã¨ãã¦åºåããããç¹å®ã®é ç¹ãå«ãæåã®ã¿ãã°ã©ãã¨ãã¦åºåãããã«ã¯ã-Xãªãã·ã§ã³ã§é ç¹ãæå®ããã
ä¾ãé ç¹Dãå«ãé£çµæåãåºåã
$ ccomps -X D ./input1.dot digraph DIRECTED_cc { C -> C; C -> D; C -> O; }
å¼·é£çµæåã®åå²ã¯å¾ã«åºã¦ããsccmapã³ãã³ãã§ã
diffimgï¼ãäºã¤ã®ç»åã®å·®åãåºåãã
äºã¤ã®ç»åã®åãã¯ã»ã«ã§å·®åãåã£ãçµæãåºåãããåãç»åãªãçµæã¯é»ä¸è²ã®ç»åã«ãªããã¾ããå ¬å¼ã®ããã¥ã¡ã³ãã«è¨è¿°ãè¦å½ãããªãã£ããã試ããç¯å²ã§ã¯åãç»åãªãçµäºã¹ãã¼ã¿ã¹ã0ãéãç»åãªã1ã«ãªãããã ã
ä¾ãçµäºã¹ãã¼ã¿ã¹ã®ç¢ºèªã¾ã§ã
$ diffimg ./input1.png ./acyclic.png ./diffimg.png $ echo $? 1
çµæã®ç»ådiffimg.pngã
Graphvizã¨ãã¦ã¯ç°è²ãªãã¼ã«ãGraphvizã«ããããã«ã¯ãä¸ã®ä¾ã®ããã«ã°ã©ãã®ã¬ã¤ã¢ã¦ãçµæãæ¯è¼ãã¦äºã¤ã®ã¬ã¤ã¢ã¦ãã®ã©ããéããï¼ã¾ãã¯å ¨ãåããï¼ã調ã¹ãããã®ãã¼ã«ã§ãããã¨æãããäºã¤ã®ç»åã®åãã¯ã»ã«ã®å·®åãåã£ã¦ããã ããªã®ã§ã©ããªç»åã«ã使ããããµã¤ãºãéãç»åå士ã§ãåé¡ãªãã対å¿ãã©ã¼ãããã¯png, jpg, gifã¨ãGhostscriptãããã°psãå¯ãããã
ã¿ã¤ãã³ã°è¯ãï¼ï¼ï¼ã¡ããã©ä»æ¥ãImageMagickã®ã³ãã³ãã§åããã¨ãããã«ã¯ã©ãããã°ããããç´¹ä»ããè¨äºãããã
dijkstraï¼ãå ¥åã°ã©ãã®æå®ããé ç¹ããåé ç¹ã¾ã§ã®è·é¢ãè¨ç®ãã
辺ã®é·ãã¯ããã©ã«ãã§ã¯å
¨ã¦1ã¨ãªãããå
¥åã°ã©ãã«è¾ºã®lenå±æ§ãæå®ãã¦ããã°ãã®å¤ã使ããããè¨ç®ãããè·é¢ã¯ãåé ç¹ã®distå±æ§ã¨ãã¦åºåããããã¾ããæ大è·é¢ï¼å°éä¸å¯è½ãªé ç¹ã¯é¤ãï¼ã¯ã°ã©ãã®maxdistå±æ§ã¨ãã¦åºåãããã
å
¥åã°ã©ããæåã°ã©ãã®å ´åã辺ã®åãã¯ç¡è¦ãããã
ä¾ãé ç¹Kããã®åè·é¢ãè¨ç®ã
$ dijkstra K ./input1.dot digraph DIRECTED { graph [maxdist="3.000"]; node [shape=circle]; A; B [dist="3.000"]; G [dist="2.000"]; B -> G; E [dist="1.000"]; G -> E; C -> C; C -> D; C -> O; F [dist="2.000"]; E -> F; H [dist="2.000"]; E -> H; K [dist="0.000"]; E -> K; F -> E; F -> H; H -> B; I [dist="1.000"]; K -> I; M [dist="1.000"]; K -> M; I -> K; J [dist="2.000"]; I -> J; L [dist="2.000"]; I -> L; N [dist="2.000"]; J -> N; L -> N; N -> I; }
gcï¼ãå ¥åã°ã©ãã®é ç¹æ°ã辺æ°ãé£çµæåæ°ãã¯ã©ã¹ã¿ã¼æ°ãåºåãã
Unixç³»OSã®wcã³ãã³ãã®ã°ã©ããã¼ã¸ã§ã³ãããã§ããã¯ã©ã¹ã¿ã¼ã¨ã¯ãDOTè¨èªã®clusterã®ãã¨*2ã
ä¾ã-aãªãã·ã§ã³ã§é ç¹æ°ã辺æ°ãé£çµæåæ°ãã¯ã©ã¹ã¿ã¼æ°ãå ¨ã¦è¡¨ç¤ºã
$ gc -a ./input1.dot 15 19 3 0 DIRECTED (./input1.dot)
gvcolorï¼ãå ¥åã°ã©ãã®æå®ããé ç¹ã®è²ãä¸æ¹ã®é ç¹ã«æµãè¾¼ãã§è²ãä»ãã
å ¥åã°ã©ãã®ããã¤ãã®é ç¹ã«colorå±æ§ã§è²ãæå®ãã¦ããã°ããã®è²ãrankã®æå³ã§ä¸ã«ãã£ã¦é£çµãã¦ããé ç¹ã¸æµãè¾¼ãã§è²ãä»ãããè¤æ°ã®è²ãæµãè¾¼ãã å ´åã¯ãããã®"å¹³å"ã®è²ã«ãªãã
ãã®ãã¼ã«ã ãã¯ä¸ã®å ¥åã°ã©ãinput2.dotã使ããä¸ã¤ã®é ç¹ã ãè²ãæå®ãã¦ããã
digraph DIRECTED2 { 2 -> 3 -> 4 -> 5 2 -> 1 -> 12 6 -> 3 -> 7 -> 8 9 -> 10 -> 7 -> 11 10 -> 12 2 [color="red"] 6 [color="green"] 9 [color="blue"] }
ä¾ãæåã®dotã§ã¬ã¤ã¢ã¦ãæ å ±ãè¨ç®ãã¦gvcolorã«æ¸¡ãå¿ è¦ãããã
$ dot ./input2.dot | gvcolor | dot -Tpng -o ./gvcolor.png
çµæã®ç»ågvcolor.pngã
nopï¼ãå ¥åã°ã©ãã®DOTãã©ã¼ããããæ¨æºï¼canonicalï¼å½¢å¼ã§è¡¨ç¤ºãã
æ¨æºãã©ããªå½¢å¼ãªã®ã調ã¹ã¦ããªãããçç¥è¨æ³ãã¤ã³ãã³ããæ£è¦åãããã¨æãã°è¯ãããã
ä¾ãã°ã«ã¼ãã³ã°ãã¦ããé ç¹éã®é£çµè¡¨è¨ã解ä½ãããè¡æ«ã«ã¯ã»ãã³ãã³ãä»å ããã¦ããã
$ nop ./input1.dot digraph DIRECTED { node [shape=circle]; A; B -> G; G -> E; C -> C; C -> D; C -> O; E -> F; E -> H; E -> K; F -> E; F -> H; H -> B; K -> I; K -> M; I -> K; I -> J; I -> L; J -> N; L -> N; N -> I; }
pruneï¼ãå ¥åã°ã©ãã®æå®ããé ç¹ãæç©ããã
ããã§ããæç©ãã¨ã¯ãæå®ããé ç¹ãã«ã¼ãã¨ããé¨åã°ã©ããåé¤ããï¼manãã¼ã¸ã«ããåæ㯠"removes subgraphs rooted at nodes specified"ï¼ãã¨ãããã訳ããã ããªã®ã§ãæå®ããé ç¹ãã«ã¼ãã¨ããé¨åã°ã©ããã¯èªåã§ãæå³ãããããããªãããæåéãæã®ããã«ä¼¸ã³åºã¦ããé¨åãåãæ¨ã¦ã¦ããã¤ã¡ã¼ã¸ã§ã
-nãªãã·ã§ã³ã§é ç¹ãæå®ãããåæ㧠"nodes" ã¨è¤æ°å½¢ã«ãªã£ã¦ããéããäºå以ä¸æå®ã§ããã
ä¾ãé ç¹Cã¨é ç¹Kãæç©ãããçµæãcircoã§ã¬ã¤ã¢ã¦ãããã
$ prune -n C -n K ./input1.dot | circo -Tpng -o prune.png
çµæã®ç»åprune.pngã
sccmapï¼ãå ¥åã°ã©ããå¼·é£çµæåã«åå²ãã
åæåã¯ã¯ã©ã¹ã¿ã¼ã¨ãã¦åºåããããã¾ããåæåãé ç¹ã¨ã¿ãªããã¨ãã®ã°ã©ããåºåããããå ¥åã°ã©ããç¡åã°ã©ãã®å ´åã¯è¦åãåºåãããã
ä¾ãæå¾ã«å ¥åã°ã©ãã®é ç¹æ°ã辺æ°ãå¼·é£çµæåæ°ã表示ããã¦ããããããã¯æ¨æºã¨ã©ã¼åºåã
$ sccmap ./input1.dot digraph cluster_0 { K -> I; I -> K; I -> J; I -> L; J -> N; L -> N; N -> I; } digraph cluster_1 { B -> G; G -> E; E -> F; E -> H; F -> E; F -> H; H -> B; } digraph scc_map { cluster_1 -> cluster_0; } 15 nodes, 19 edges, 2 strong components
tredï¼ãå ¥åã°ã©ãã®æ¨ç§»éå ï¼transitive reductionï¼ãåºåãã
ã¨ã£ã¦ããã£ããæ¸ãã¨é ç¹éã®å°éå¯è½æ§ãæãªããã«å¯è½ãªéã辺ãéå¼ãã
ç¨éã¨ãã¦ã¯ãé ç¹ãé£çµãã¾ãã£ã¦ã¦å¯åº¦ãé«ãé¨åãããããããæåã°ã©ããã辺ãéå¼ãã¦è¦ãããã¬ã¤ã¢ã¦ããããã¨ãã«ä½¿ãã¨ãããããããªããå ¥åã°ã©ããç¡åã°ã©ãã®å ´åã¯ä½ãåºåãããªãã
ä¾ãåºåãcircoã«æ¸¡ãã¦ã¬ã¤ã¢ã¦ããããéè·¯ãããå ´åã¯çµæãä¸æã«ãªããªãã®ã§è¦åãåºãã
$ tred ./input1.dot | circo -Tpng -o ./tred.png warning: DIRECTED has cycle(s), transitive reduction not unique cycle involves edge F -> E
çµæã®ç»åtred.pngãå·¦å´ã®é¨åã°ã©ããã辺ãäºæ¬æããã¦ããã
ãã®ä»
ä¸ã§ã¾ã¨ãããã¼ã«ä»¥å¤ã«ããã°ã©ããã¼ã¿ã®ãã©ã¼ãããå¤æãç·¨éãã¼ã«ããããä»å試ãã¦ããªããã®ã§ã¯ããã®ãããã便å©ããã ã
- unflatten:ãã°ã©ãã¬ã¤ã¢ã¦ãã®éã®ã¢ã¹ãã¯ãæ¯ã調æ´ãã
- gvpackï¼ãè¤æ°ã®ã°ã©ãã¬ã¤ã¢ã¦ãããã¼ã¸ãã
- gvprï¼ãawkã®ã°ã©ããã¼ã¸ã§ã³ã®ãããªãã®
ãããããã¼ã«ããããã¨ãããã¨ãé ã®çé
ã«ç½®ãã¦ããã°ãã¤ãå½¹ç«ã¤ããã