å
æ¥、「『ãã«ã·ã®ã®æ°ãæ¹』 ãããããã¨ãã£ãã! ã¿ããªã§æ°ãã¦ã¿ãã!」ã¨ããåç»ãè¦ã。æ ¼åç¶ã®ãã¹ã®å·¦ä¸ããå³ä¸ã¾ã§ã®çµè·¯ãä½éãããã®ãã調ã¹ã¦、æ ¼åãå¤ããªãã°ãªãã»ã©çµã¿åããã®æ°ãççºçã«å¢ãããã¨ãæãã¦ãããåç»ã 。ããã¯èªå·±åé¿æ©è¡(Self-avoiding walk)ã¨å¼ã°ãã¦ããåé¡ããã。
ããã ãèãã¦ãããã»ã©ã¤ã³ãã¯ãã¯ãªãã®ã ã、åç»ã«åºã¦ãããããããã®çµè·¯ã調ã¹ãããå·å¿µããã®åã、ãããä¸ã§ãçµæ§ãªè©±é¡ã«ãªã£ã¦ãã。å·å¿µã¨è¨ããããçæ°ã«è¿ã。ããã、話é¡ã«ãªã£ãå²ã«ã¯åç»å ã§è¨åããã¦ããé«éãªã¢ã«ã´ãªãºã ãå®è£ ããã¨ãã話ãèããªãã£ãã®ã§、èªåã§ç¢ºããããã¨ã«ãã。
åç»ã®ãããããã¯æ·±ãåªå æ¢ç´¢ã«ããããã°ã©ã ã使ã£ã¦ããã¨æãããã、ããã ã¨ã¹ãã³ã³ã使ã£ã¦ã10×10ãã¹ã®æ ¼åã解ãã®ã«25ä¸å¹´ãæãã£ã¦ãã¾ã。ããã§、é«éåã®ããã«ã¼ããµãã¬ã¹åäºå決å®ã°ã©ã(ZDD; Zero-Suppressed Binary Decision Diagram)ã¨å¼ã°ããã¢ã«ã´ãªãºã ãå©ç¨ãããã¨ã«ãã。ãã®ã¢ã«ã´ãªãºã ãéçºããã®ã¯å大ã®æ¹å çã§、ZDDã«ãããã¹ã¦ã®çµè·¯ãè¦ã¤ãåºãã¢ã«ã´ãªãºã ã¨ãã¦ã¯ãã¼ã¹å çã®SIMPATHã使ã£ã。ZDDã«ã¤ãã¦ã¯ã¯ãã¼ã¹å çãå¼·ãé¢å¿ãæã£ã¦ãã¦、 The Art of Computer Programming Volume 4, Fascicle 1(TAOCP 4-1)ã§ã¯BDD/ZDDã®è©³ç´°ãªè§£èª¬ãèªããã¨ãã§ãã。æ¼ç¿åé¡ã®è§£èª¬ã ãã§æ¸ç±ã®ååã使ã£ã¦ãããã¨ãããã¦ãæ°åã®å ¥ãããããããã ãã。
å®éã«èªåã®ãã¼ãPCã§ZDDã¢ã«ã´ãªãºã ã使ã£ãã³ã¼ããèµ°ãããã、ã»ãã®10ç§ç¨åº¦ã§10×10ãã¹ã®åé¡ã解ãã¦ãã¾ã£ã。ããããããã¹ãã³ã³ã§25ä¸å¹´ããã£ãåé¡ããã¼ãPCã§ãã£ã10ç§ã§ãã。ç´8åååã®é«éåã 。ããã ãåçã«å¤ããã¨ãã£ã±ã楽ãã。ããã¦、ã¢ã«ã´ãªãºã ã®éè¦æ§ãåèªèããããã。
ãã¦、以ä¸ã«ããããããå©ç¨ããã§ãããèªä½ã®æ·±ãåªå æ¢ç´¢(DFS)ããã°ã©ã ã¨é«éãªè§£æ³ã§ããZDDã¢ã«ã´ãªãºã ã®ä¸¡æ¹ãè¼ãã¦ãã。ZDDã«ã¤ãã¦ã¯4ã¤ã®ããã°ã©ã ã1ã¤ã®Pythonã¹ã¯ãªããã§çµ±åãã¦ãã。ããã¯、ã¯ãã¼ã¹å çã®SIMPATHããã³SIMPATH-REDUCEãå©ç¨ãã¦ãã、ã¾ã、SGB (Stanford GraphBase)ã©ã¤ãã©ãªã§ã°ã©ããä½æã、çµè·¯ã®æ°ãä¸ãã«GMPã使ã£ãC++ã§èªä½ã³ã¼ããçµãã ããã§ãã。æåã¯SIMPATHãåèã«å®è£ ãã¦ä¸ã¤ã®ã½ã¼ã¹ã³ã¼ãã«çµ±ä¸ããããã¨æã£ãã、解説ãã¡ããã¨æ¸ããã¦ããã¯ãã¼ã¹å çã®ã³ã¼ãããã®ã¾ã¾å©ç¨ãããã¨ã«ãã。ãããã®ããã°ã©ã ã®ç°¡åãªè§£èª¬ã¨ä½¿ãæ¹ãè¼ãã¦ãã。
ã¾ãã¯DFSã«ããå®è£ ã以ä¸ã«ç¤ºã。Nodeæ§é ä½ããçµè·¯ã辿ã£ã¦æ°ãä¸ããã ãã®åç´ãªããã°ã©ã ã§ãã。
å®è¡æ¹æ³ã¯ä»¥ä¸ã®éã。å¼æ°ã®7ã¯7×7ã®ãã¼ãã表ãã¦ãã、ãã¹ã§è¡¨ç¾ããã°6×6ãã¹ã¨ãªã。ããã¦è¨ç®çµæã¨ãã¦、575,780,564éãã®çµè·¯ãæ¢ç´¢ããããã¨ã示ãã¦ãã。å ã¿ã«7×7ãã¼ã(6×6ãã¹)ã§ç´3åã»ã©ã®æéãæãã£ã¦ãã、ãã以ä¸ã®å¤§ããã ã¨ç¾å®çãªæéã§è§£ããã¨ãé£ãããªã£ã¦ãã。
% ./count_lattice_path_dfs 7 Count all paths from (0, 0) to (6, 6) in the 7x7 lattice graph: Count: 575780564
次ã«、ZDDãå©ç¨ããããã°ã©ã ã®ãã«ãæ¹æ³ã示ã。
ãã«ããããåã«SGBããã³GMPãæºåãã¦ãã。ã¾ã、SIMPATHããã³SIMPATH-REDUCEã«ã¤ãã¦ã¯CWEBãå©ç¨ãã¦ããã®ã§、ãããå ¥ãã¦ãã。
æåã«、SGBã©ã¤ãã©ãªãç¨ãã¦æ ¼åç¶ã®ã°ã©ããä½æãã。
% gcc gen_lattice.c -O3 -lgb -o gen_lattice
ã½ã¼ã¹ã³ã¼ãå ã§ã°ã©ããä¸è¨ã®ããã«ä½æãã¦ãã。boardé¢æ°ã¯ãã§ã¹ã®ãããªæ ¼åç¶ã®ã°ã©ããä½æãããã¨ãã§ãã。ä»ã«ãã°ã©ããä½æãã便å©ãªé¢æ°ãå¤æ°ããã®ã§、èå³ã®ããæ¹ã¯SGBã©ã¤ãã©ãªã®gb_basic.wããããåç §ãã¦æ¬²ãã。
Graph* g = board(N, M, 0L, 0L, 1L, 0L, 0L);
次ã«、SIMPATHããã³SIMPATH-REDUCEã以ä¸ã®ããã«ãã«ããã。
% wget http://www-cs-faculty.stanford.edu/~uno/programs/simpath.w % ctangle simpath.w % gcc simpath.c -O3 -lgb -o simpath
% wget http://www-cs-faculty.stanford.edu/~uno/programs/simpath-reduce.w % ctangle simpath-reduce.w % gcc simpath-reduce.c -O3 -lgb -o simpath-reduce
å ã¿ã«、ctangleã§Cè¨èªã¸ã®å¤æ、cweaveã§TeXå½¢å¼ã¸ã®å¤æãè¡ããã¨ãã§ããã®ã§、以ä¸ã®ããã«TeXå½¢å¼ã®ããã¥ã¡ã³ããä¸ç·ã«ä½ã£ã¦ãããã¨ããå§ããã。ã¾ã、ãããã®ã¢ã«ã´ãªãºã ãç解ããããã«åè¿°ã®TAOCP Vol. 4ãèªãã§ãããã¨ãæã¾ãã。
% cweave simpath.w % tex simpath.tex % dvipdf simpath.dvi # PDFãã¡ã¤ã«ãå¿ è¦ãªã. % cweave simpath-reduce.w % tex simpath-reduce.tex % dvipdf simpath-reduce.dvi # PDFãã¡ã¤ã«ãå¿ è¦ãªã.
æå¾ã«、ZDDããçµè·¯ãæ°ãä¸ããããã°ã©ã ãã³ã³ãã¤ã«ãã。
% g++ count_path_mp.cpp -O3 -lgmp -o count_path_mp
çµè·¯ãä¸ã¤ä¸ã¤æ°ãã¦ãã¦ã¯é«éã«æ°ãä¸ããã¨ããç¹ã§æå³ããªããªã£ã¦ãã¾ãã®ã§、ã¡ããã¨ã¡ã¢åå帰ã§æ°ãã。ZDDã¯é«åº¦ã«å§ç¸®ããã¦ããã®ã§ã¡ã¢åå帰ã§ã»ã¨ãã©ç¬æã«æ°ãä¸ãããã¨ãã§ãã。
ããã¦、ä¸è¨ã®ããã°ã©ã ãçµ±æ¬ããPythonã¹ã¯ãªããã以ä¸ã¨ãªã。ã°ã«ã¼è¨èªã¨ãã¦ãPythonã¯åªç§ã 。
å®è¡æ¹æ³ã¯ä»¥ä¸ã®éã。
% ./count_lattice_path.py 8 Count all paths from (0, 0) to (7, 7) in the 8x8 lattice graph: Count: 789360053252
DFSã®ããã°ã©ã åæ§、å¼æ°ã®8ã¯8×8ãã¼ã(7×7ãã¹)ã表ãã¦ãã。ããã¦è¨ç®çµæã¨ãã¦、789,360,053,252éãã®çµè·¯ãæ¢ç´¢ããããã¨ã示ãã¦ãã。ã¾ã、ä¸éãã¡ã¤ã«ã¨ãã¦ä»¥ä¸ãåºåããã。
lattice_08.gb # SGBã«ããã°ã©ããã¼ã¿. lattice_08.out # SIMPATHã®åºå: not-necessarily-reduced BDD lattice_08.out.r # SIMPATH-REDUCEã®åºå: ZDD lattice_08.out.rc # SIMPATH-REDUCEã®åºåãåçªä». lattice_08.log # ä¸é£ã®å®è¡ãã¡ã¤ã«ã®ãã°.
å ã¿ã«、DFSã§7×7ãã¼ã(6×6ãã¹)ã解ãã¨3åã»ã©ããã£ãã、ZDDã§ã¯0.1ç§æªæºã§å®äºãã。ã¾ã、ZDDã§14×14ãã¼ã(13×13ãã¹)ã¯æ°åã§çµãããã¨ã確èªããã、ãã以ä¸ã¯éä¸ã§æè¼ã¡ã¢ãªä»¥ä¸ã«å¿ è¦ãªã¡ã¢ãªã大ãããªãã®ã§å®è¡ãã¦ããªã。
ããã ãèãã¦ãããã»ã©ã¤ã³ãã¯ãã¯ãªãã®ã ã、åç»ã«åºã¦ãããããããã®çµè·¯ã調ã¹ãããå·å¿µããã®åã、ãããä¸ã§ãçµæ§ãªè©±é¡ã«ãªã£ã¦ãã。å·å¿µã¨è¨ããããçæ°ã«è¿ã。ããã、話é¡ã«ãªã£ãå²ã«ã¯åç»å ã§è¨åããã¦ããé«éãªã¢ã«ã´ãªãºã ãå®è£ ããã¨ãã話ãèããªãã£ãã®ã§、èªåã§ç¢ºããããã¨ã«ãã。
åç»ã®ãããããã¯æ·±ãåªå æ¢ç´¢ã«ããããã°ã©ã ã使ã£ã¦ããã¨æãããã、ããã ã¨ã¹ãã³ã³ã使ã£ã¦ã10×10ãã¹ã®æ ¼åã解ãã®ã«25ä¸å¹´ãæãã£ã¦ãã¾ã。ããã§、é«éåã®ããã«ã¼ããµãã¬ã¹åäºå決å®ã°ã©ã(ZDD; Zero-Suppressed Binary Decision Diagram)ã¨å¼ã°ããã¢ã«ã´ãªãºã ãå©ç¨ãããã¨ã«ãã。ãã®ã¢ã«ã´ãªãºã ãéçºããã®ã¯å大ã®æ¹å çã§、ZDDã«ãããã¹ã¦ã®çµè·¯ãè¦ã¤ãåºãã¢ã«ã´ãªãºã ã¨ãã¦ã¯ãã¼ã¹å çã®SIMPATHã使ã£ã。ZDDã«ã¤ãã¦ã¯ã¯ãã¼ã¹å çãå¼·ãé¢å¿ãæã£ã¦ãã¦、 The Art of Computer Programming Volume 4, Fascicle 1(TAOCP 4-1)ã§ã¯BDD/ZDDã®è©³ç´°ãªè§£èª¬ãèªããã¨ãã§ãã。æ¼ç¿åé¡ã®è§£èª¬ã ãã§æ¸ç±ã®ååã使ã£ã¦ãããã¨ãããã¦ãæ°åã®å ¥ãããããããã ãã。
å®éã«èªåã®ãã¼ãPCã§ZDDã¢ã«ã´ãªãºã ã使ã£ãã³ã¼ããèµ°ãããã、ã»ãã®10ç§ç¨åº¦ã§10×10ãã¹ã®åé¡ã解ãã¦ãã¾ã£ã。ããããããã¹ãã³ã³ã§25ä¸å¹´ããã£ãåé¡ããã¼ãPCã§ãã£ã10ç§ã§ãã。ç´8åååã®é«éåã 。ããã ãåçã«å¤ããã¨ãã£ã±ã楽ãã。ããã¦、ã¢ã«ã´ãªãºã ã®éè¦æ§ãåèªèããããã。
ãã¦、以ä¸ã«ããããããå©ç¨ããã§ãããèªä½ã®æ·±ãåªå æ¢ç´¢(DFS)ããã°ã©ã ã¨é«éãªè§£æ³ã§ããZDDã¢ã«ã´ãªãºã ã®ä¸¡æ¹ãè¼ãã¦ãã。ZDDã«ã¤ãã¦ã¯4ã¤ã®ããã°ã©ã ã1ã¤ã®Pythonã¹ã¯ãªããã§çµ±åãã¦ãã。ããã¯、ã¯ãã¼ã¹å çã®SIMPATHããã³SIMPATH-REDUCEãå©ç¨ãã¦ãã、ã¾ã、SGB (Stanford GraphBase)ã©ã¤ãã©ãªã§ã°ã©ããä½æã、çµè·¯ã®æ°ãä¸ãã«GMPã使ã£ãC++ã§èªä½ã³ã¼ããçµãã ããã§ãã。æåã¯SIMPATHãåèã«å®è£ ãã¦ä¸ã¤ã®ã½ã¼ã¹ã³ã¼ãã«çµ±ä¸ããããã¨æã£ãã、解説ãã¡ããã¨æ¸ããã¦ããã¯ãã¼ã¹å çã®ã³ã¼ãããã®ã¾ã¾å©ç¨ãããã¨ã«ãã。ãããã®ããã°ã©ã ã®ç°¡åãªè§£èª¬ã¨ä½¿ãæ¹ãè¼ãã¦ãã。
ã¾ãã¯DFSã«ããå®è£ ã以ä¸ã«ç¤ºã。Nodeæ§é ä½ããçµè·¯ã辿ã£ã¦æ°ãä¸ããã ãã®åç´ãªããã°ã©ã ã§ãã。
å®è¡æ¹æ³ã¯ä»¥ä¸ã®éã。å¼æ°ã®7ã¯7×7ã®ãã¼ãã表ãã¦ãã、ãã¹ã§è¡¨ç¾ããã°6×6ãã¹ã¨ãªã。ããã¦è¨ç®çµæã¨ãã¦、575,780,564éãã®çµè·¯ãæ¢ç´¢ããããã¨ã示ãã¦ãã。å ã¿ã«7×7ãã¼ã(6×6ãã¹)ã§ç´3åã»ã©ã®æéãæãã£ã¦ãã、ãã以ä¸ã®å¤§ããã ã¨ç¾å®çãªæéã§è§£ããã¨ãé£ãããªã£ã¦ãã。
% ./count_lattice_path_dfs 7 Count all paths from (0, 0) to (6, 6) in the 7x7 lattice graph: Count: 575780564
次ã«、ZDDãå©ç¨ããããã°ã©ã ã®ãã«ãæ¹æ³ã示ã。
ãã«ããããåã«SGBããã³GMPãæºåãã¦ãã。ã¾ã、SIMPATHããã³SIMPATH-REDUCEã«ã¤ãã¦ã¯CWEBãå©ç¨ãã¦ããã®ã§、ãããå ¥ãã¦ãã。
æåã«、SGBã©ã¤ãã©ãªãç¨ãã¦æ ¼åç¶ã®ã°ã©ããä½æãã。
% gcc gen_lattice.c -O3 -lgb -o gen_lattice
ã½ã¼ã¹ã³ã¼ãå ã§ã°ã©ããä¸è¨ã®ããã«ä½æãã¦ãã。boardé¢æ°ã¯ãã§ã¹ã®ãããªæ ¼åç¶ã®ã°ã©ããä½æãããã¨ãã§ãã。ä»ã«ãã°ã©ããä½æãã便å©ãªé¢æ°ãå¤æ°ããã®ã§、èå³ã®ããæ¹ã¯SGBã©ã¤ãã©ãªã®gb_basic.wããããåç §ãã¦æ¬²ãã。
Graph* g = board(N, M, 0L, 0L, 1L, 0L, 0L);
次ã«、SIMPATHããã³SIMPATH-REDUCEã以ä¸ã®ããã«ãã«ããã。
% wget http://www-cs-faculty.stanford.edu/~uno/programs/simpath.w % ctangle simpath.w % gcc simpath.c -O3 -lgb -o simpath
% wget http://www-cs-faculty.stanford.edu/~uno/programs/simpath-reduce.w % ctangle simpath-reduce.w % gcc simpath-reduce.c -O3 -lgb -o simpath-reduce
å ã¿ã«、ctangleã§Cè¨èªã¸ã®å¤æ、cweaveã§TeXå½¢å¼ã¸ã®å¤æãè¡ããã¨ãã§ããã®ã§、以ä¸ã®ããã«TeXå½¢å¼ã®ããã¥ã¡ã³ããä¸ç·ã«ä½ã£ã¦ãããã¨ããå§ããã。ã¾ã、ãããã®ã¢ã«ã´ãªãºã ãç解ããããã«åè¿°ã®TAOCP Vol. 4ãèªãã§ãããã¨ãæã¾ãã。
% cweave simpath.w % tex simpath.tex % dvipdf simpath.dvi # PDFãã¡ã¤ã«ãå¿ è¦ãªã. % cweave simpath-reduce.w % tex simpath-reduce.tex % dvipdf simpath-reduce.dvi # PDFãã¡ã¤ã«ãå¿ è¦ãªã.
æå¾ã«、ZDDããçµè·¯ãæ°ãä¸ããããã°ã©ã ãã³ã³ãã¤ã«ãã。
% g++ count_path_mp.cpp -O3 -lgmp -o count_path_mp
çµè·¯ãä¸ã¤ä¸ã¤æ°ãã¦ãã¦ã¯é«éã«æ°ãä¸ããã¨ããç¹ã§æå³ããªããªã£ã¦ãã¾ãã®ã§、ã¡ããã¨ã¡ã¢åå帰ã§æ°ãã。ZDDã¯é«åº¦ã«å§ç¸®ããã¦ããã®ã§ã¡ã¢åå帰ã§ã»ã¨ãã©ç¬æã«æ°ãä¸ãããã¨ãã§ãã。
ããã¦、ä¸è¨ã®ããã°ã©ã ãçµ±æ¬ããPythonã¹ã¯ãªããã以ä¸ã¨ãªã。ã°ã«ã¼è¨èªã¨ãã¦ãPythonã¯åªç§ã 。
å®è¡æ¹æ³ã¯ä»¥ä¸ã®éã。
% ./count_lattice_path.py 8 Count all paths from (0, 0) to (7, 7) in the 8x8 lattice graph: Count: 789360053252
DFSã®ããã°ã©ã åæ§、å¼æ°ã®8ã¯8×8ãã¼ã(7×7ãã¹)ã表ãã¦ãã。ããã¦è¨ç®çµæã¨ãã¦、789,360,053,252éãã®çµè·¯ãæ¢ç´¢ããããã¨ã示ãã¦ãã。ã¾ã、ä¸éãã¡ã¤ã«ã¨ãã¦ä»¥ä¸ãåºåããã。
lattice_08.gb # SGBã«ããã°ã©ããã¼ã¿. lattice_08.out # SIMPATHã®åºå: not-necessarily-reduced BDD lattice_08.out.r # SIMPATH-REDUCEã®åºå: ZDD lattice_08.out.rc # SIMPATH-REDUCEã®åºåãåçªä». lattice_08.log # ä¸é£ã®å®è¡ãã¡ã¤ã«ã®ãã°.
å ã¿ã«、DFSã§7×7ãã¼ã(6×6ãã¹)ã解ãã¨3åã»ã©ããã£ãã、ZDDã§ã¯0.1ç§æªæºã§å®äºãã。ã¾ã、ZDDã§14×14ãã¼ã(13×13ãã¹)ã¯æ°åã§çµãããã¨ã確èªããã、ãã以ä¸ã¯éä¸ã§æè¼ã¡ã¢ãªä»¥ä¸ã«å¿ è¦ãªã¡ã¢ãªã大ãããªãã®ã§å®è¡ãã¦ããªã。
ã³ã¡ã³ã