ããããããçµã¿åããççºããæãããã«ãçµè·¯ãBDDã¨ãã¦è¡¨ãã¾ããã
http://d.hatena.ne.jp/nowokay/20121017#1350435805
ã¨ããã§ããFãã«è³ãçµè·¯ã§ããã辺ãéãã¨ããå ´åã«å³ãFãã¨ãªã£ã¦ãããã®ãååããã¾ãã
ãã®ç¯ç¹ã使ãã¨ããã¨ãã«ãçµæãå½ã«ãªãã®ã§ããã°ãããã¯ç¯ç¹ãã¨ä¸è¦ã ã¨è¨ãã¾ããããã§ããã®ãããªç¯ç¹ã¯çç¥ãã¦ãã¾ãã¾ãã
ãã®ãããªå³ããã¼ãæå¶BDD(Zero suppressed BDD)ãç¥ãã¦ZDDã¨å¼ã³ã¾ãã
ãFãããã¹ã¦çç¥ãããã¨ãã§ãã¾ãããã ããBDDã¨ã¯éã£ã¦ãã©ã¡ãã§ãåãçµæã«ãªãå ´åããããããã®æ¥ç¶ã表示ããå¿
è¦ãããã¾ãã
ããããã¨ã2x2ãã¹ã®çµè·¯ã§ãã次ã®ããã«è¡¨ããã¨ãã§ãã¾ããããªãç¯ç¹ã®æ°ãæ¸ã£ã¦ãããã¨ããããã¾ãã
ãTãã«è³ããã¹ã®æ°ããçµè·¯ã®æ°ã§ãã
ãã¾ãã¾ãªçµã¿åãããBDDã§è¡¨ç¤ºããã¨ãããé ç®ã使ãã¨ããå ´åã«Fã«ãªãã¨ãããã¨ãããªãå¤ãããã¾ããZDDã¯ããã®ãããªãçµã¿åãããå¹çããä¿æããå³ã ã¨ããã¾ãã
3x3ãã¹ã®å ´åãã¡ãã£ã¨ãã£ãããã¦ã¾ãã
ã¨ããã§ã1x1ãã¹ã®å ´åã¯ã©ããªã£ããã¨ããã¨ããããªã«åç´ã«ãªã£ã¦ãã¾ããçµè·¯ã®çµã¿åãããä¸ç®çç¶ã§ãã
æåã®äºå決å®æ¨ã¨æ¯ã¹ãã¨ãã¾ã£ãããããããããéãã¾ãã
ã¾ãã§ãå®å®äººè¥²æ¥ã¨ãã£ã¦ãããããã¤ã¡ã¼ã¸ãæã£ã¦å¯¾çãã¦ããã®ãã
å®éã®å®å®äººã¯ãããªæãã ã£ããã¨ããæåæãæã§ãã
ããã§ãããããããçµã¿åããççºããæããã¨ãã§ãããã§ãã
ãã ãZDDãçµè·¯ãã³ã³ãã¯ãã«ä¿æããã¨ã¯ãããZDDã®æ§ç¯ã§ã¯ããããããçµã¿åããççºãèµ·ãã¦ãã¾ã£ã¦ãã¾ããåé¡ã¯ããã®ãããªZDDãããã«å¹çããæ§ç¯ããããã¨ãããã¨ã«ãªãã¾ãã
ZDDã«ã¤ãã¦ã¯ãThe Art of Computer Proguramingã®7.1.4ã§è§£èª¬ããã¦ãã¾ããæ¬ç·¨ã§ã®ãã¼ã¸æ°ã¯å°ãªãã§ãããæ¼ç¿åé¡ã§ããªãã®ãã¼ã¸ãå²ããã¦ãã¾ãã
- ä½è : Donald E. Knuth,åç°è±ä¸
- åºç社/ã¡ã¼ã«ã¼: ã¢ã¹ãã¼ã»ã¡ãã£ã¢ã¯ã¼ã¯ã¹
- çºå£²æ¥: 2011/05/20
- ã¡ãã£ã¢: 大åæ¬
- è³¼å ¥: 2人 ã¯ãªãã¯: 17å
- ãã®ååãå«ãããã° (14件) ãè¦ã
ç®æ¬¡
『フカシギの数え方』 おねえさんといっしょにみんなも25万年数えよう
おねえさんを組み合わせ爆発から救う:格子グラフを生成する
おねえさんを組み合わせ爆発から救う:2分決定木を作る
おねえさんを組み合わせ爆発から救う:無駄を省いてBDDを作る
ããããããçµã¿åããççºããæãï¼ZDDãããããããæã
おねえさんを組み合わせ爆発から救う:完結編おねえさんは星になった
ã½ã¼ã¹ã¯ãã¡ããBDDæ§ç¯ã®å ´åã¨ãã»ã¨ãã©å¤ãã£ã¦ãã¾ãããå®è¡ã«ã¯ãããã¾ã§ã®3ã¤ã®ã½ã¼ã¹ãå¿ è¦ã§ãã
package simpath; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import kis.jgraphsample.CreateBdd.ThroughNode; import kis.jgraphsample.CreateLattice.LatticeEdge; import kis.jgraphsample.CreateTree.DiagramNode; import kis.jgraphsample.CreateTree.EdgeNode; import kis.jgraphsample.CreateTree.LeafNode; public class CreateZdd { public static void main(String[] args){ //æ ¼åã°ã©ãã®çæ ArrayList<CreateLattice.LatticeEdge> edges = new ArrayList<>(); Map<Integer, CreateLattice.LatticeNode> nodeMap = new LinkedHashMap<>(); CreateLattice.generateGraph(3, nodeMap, edges); String param = CreateBdd.solveRoute(edges, nodeMap); //BDDã®çæ //param = "fftftffffftftffffftfttfftftffftt"; List<List<DiagramNode>> layers = createZdd(edges, param); //表示 //CreateTree.paintDiagram(layers, 250, 250, 40, 50); CreateTree.paintDiagram(layers, 400, 640, 40, 50); //CreateTree.paintDiagram(layers, 1150, 800, 35, 30); } /** BDDã®çæ */ static List<List<DiagramNode>> createZdd(ArrayList<LatticeEdge> edges, String param) { List<List<CreateTree.DiagramNode>> layers = new ArrayList<>(); List<DiagramNode> layer = new ArrayList<>(); layers.add(layer); Map<String, CreateTree.EdgeNode> edgeMap = new HashMap<>(); ThroughNode tn = new ThroughNode(); createZdd(layers, edges, edgeMap, 0, param, tn, false); return layers; } /** BDDåãã¼ãã®çæ */ static void createZdd(List<List<CreateTree.DiagramNode>> layers, ArrayList<CreateLattice.LatticeEdge> edges, Map<String, CreateTree.EdgeNode> edgeMap, int height, String param, EdgeNode en, boolean pre) { if(layers.size() <= height){ layers.add(new ArrayList<DiagramNode>()); } List<DiagramNode> layer = layers.get(height); LeafNode ln = null; if(param.equals("t")){ //tã®çµç«¯ ln = new CreateTree.LeafNode(true); }else if(param.indexOf("t") < 0){ //fã ãã®ã¨ãã¯é表示 return; } if(ln != null){ //ï½ã»fã決ã¾ã£ã if(pre){ en.right = ln; }else{ en.left = ln; } layer.add(ln); return; } String left = param.substring(0, param.length() / 2); String right = param.substring(param.length() / 2); if(right.indexOf("t") < 0){ //å³ãf ThroughNode tn = new ThroughNode(); if(pre){ en.right = tn; }else{ en.left = tn; } layer.add(tn); //ããããã createZdd(layers, edges, edgeMap, height+1, left, tn, pre); return; } //åå²ã®çæ EdgeNode nn = edgeMap.get(param); boolean gen = false; if(nn == null){ //æ°ããã§ãçµã¿åãã gen = true; LatticeEdge le = edges.get(height); nn = new EdgeNode(le); layer.add(nn); edgeMap.put(param, nn); } if(pre){ en.right = nn; }else{ en.left = nn; } //ããããã if(gen){ createZdd(layers, edges, edgeMap, height+1, left, nn, false); createZdd(layers, edges, edgeMap, height+1, right, nn, true); } } }