Exemple #1
0
 static ZDDNode() // static コンストラクタ。ZDDNode 使用開始直前に呼び出される
 {
     ZeroTerminal     = new ZDDNode();
     OneTerminal      = new ZDDNode();
     ZeroTerminal.id_ = 0;
     OneTerminal.id_  = 1;
 }
Exemple #2
0
        private static void UpdateInfo(ZDDNode n_hat, int i, int x, State state)
        {
            Edge edge = state.graph.GetEdgeList()[i - 1];

            int[] src_dest = new int[] { edge.src, edge.dest };
            foreach (int u in src_dest)
            {
                if (!state.F[i - 1].Contains(u))
                {
                    n_hat.deg[u]  = 0;
                    n_hat.comp[u] = u;
                }
            }
            if (x == 1)
            {
                ++n_hat.deg[edge.src];
                ++n_hat.deg[edge.dest];
                int c_min = Math.Min(n_hat.comp[edge.src], n_hat.comp[edge.dest]);
                int c_max = Math.Max(n_hat.comp[edge.src], n_hat.comp[edge.dest]);
                foreach (int u in state.F[i])
                {
                    if (n_hat.comp[u] == c_max)
                    {
                        n_hat.comp[u] = c_min;
                    }
                }
            }
        }
Exemple #3
0
        public ZDDNode MakeCopy()
        {
            ZDDNode node = new ZDDNode();

            node.deg  = (int[])deg.Clone();  // 配列のコピーを生成
            node.comp = (int[])comp.Clone();
            return(node);
        }
Exemple #4
0
 private static ZDDNode Find(ZDDNode n_prime, List <ZDDNode> N_i, int i, State state)
 {
     foreach (ZDDNode n_primeprime in N_i)
     {
         if (IsEquivalent(n_prime, n_primeprime, i, state))
         {
             return(n_primeprime);
         }
     }
     return(null);
 }
Exemple #5
0
 public void SetChild(ZDDNode node, int child_num)
 {
     if (child_num == 0)
     {
         zero_child = node;
     }
     else
     {
         one_child = node;
     }
 }
Exemple #6
0
        public static ZDDNode CreateRootNode(int number_of_vertices)
        {
            ZDDNode node = new ZDDNode();

            node.SetNextId();
            node.deg  = new int[number_of_vertices + 1];
            node.comp = new int[number_of_vertices + 1];

            for (int i = 1; i <= number_of_vertices; ++i)
            {
                node.deg[i]  = 0;
                node.comp[i] = i;
            }
            return(node);
        }
Exemple #7
0
 private static bool IsEquivalent(ZDDNode node1, ZDDNode node2, int i, State state)
 {
     foreach (int v in state.F[i]) // フロンティア上の頂点についてのみ比較
     {
         if (node1.deg[v] != node2.deg[v])
         {
             return(false);
         }
         if (node1.comp[v] != node2.comp[v])
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #8
0
        public long GetNumberOfSolutions()
        {
            ZDDNode.ZeroTerminal.sol = 0;
            ZDDNode.OneTerminal.sol  = 1;

            for (int i = node_list_array_.Length - 1; i >= 1; --i)
            {
                for (int j = 0; j < node_list_array_[i].Count; ++j)
                {
                    ZDDNode lo_node = node_list_array_[i][j].GetChild(0);
                    ZDDNode hi_node = node_list_array_[i][j].GetChild(1);
                    node_list_array_[i][j].sol = lo_node.sol + hi_node.sol;
                }
            }
            return(node_list_array_[1][0].sol);
        }
Exemple #9
0
        private static ZDDNode CheckTerminal(ZDDNode n_hat, int i, int x, State state)
        {
            Edge edge = state.graph.GetEdgeList()[i - 1];

            if (x == 1)
            {
                if (n_hat.comp[edge.src] == n_hat.comp[edge.dest])
                {
                    return(ZDDNode.ZeroTerminal);
                }
            }
            ZDDNode n_prime = n_hat.MakeCopy();

            UpdateInfo(n_prime, i, x, state);
            int[] src_dest = new int[] { edge.src, edge.dest };
            foreach (int u in src_dest)
            {
                if ((u == state.s || u == state.t) && n_prime.deg[u] > 1)
                {
                    return(ZDDNode.ZeroTerminal);
                }
                else if ((u != state.s && u != state.t) && n_prime.deg[u] > 2)
                {
                    return(ZDDNode.ZeroTerminal);
                }
            }
            foreach (int u in src_dest)
            {
                if (!state.F[i].Contains(u))
                {
                    if ((u == state.s || u == state.t) && n_prime.deg[u] != 1)
                    {
                        return(ZDDNode.ZeroTerminal);
                    }
                    else if ((u != state.s && u != state.t) && n_prime.deg[u] != 0 && n_prime.deg[u] != 2)
                    {
                        return(ZDDNode.ZeroTerminal);
                    }
                }
            }
            if (i == state.graph.GetEdgeList().Count)
            {
                return(ZDDNode.OneTerminal);
            }
            return(null);
        }
Exemple #10
0
        public static ZDD Construct(State state)
        {
            List <Edge> edge_list = state.graph.GetEdgeList();

            int[]            ZeroOne = new int[] { 0, 1 };
            List <ZDDNode>[] N       = new List <ZDDNode> [edge_list.Count + 2];
            N[1] = new List <ZDDNode>();
            N[1].Add(ZDDNode.CreateRootNode(state.graph.GetNumberOfVertices()));

            for (int i = 1; i <= edge_list.Count; ++i)
            {
                N[i + 1] = new List <ZDDNode>();

                foreach (ZDDNode n_hat in N[i])
                {
                    foreach (int x in ZeroOne)
                    {
                        ZDDNode n_prime = CheckTerminal(n_hat, i, x, state);

                        if (n_prime == null)
                        {
                            n_prime = n_hat.MakeCopy();
                            UpdateInfo(n_prime, i, x, state);
                            ZDDNode n_primeprime = Find(n_prime, N[i + 1], i, state);
                            if (n_primeprime != null)
                            {
                                n_prime = n_primeprime;
                            }
                            else
                            {
                                n_prime.SetNextId();
                                N[i + 1].Add(n_prime);
                            }
                        }
                        n_hat.SetChild(n_prime, x);
                    }
                }
            }
            return(new ZDD(N));
        }
Exemple #11
0
 public void SetChild(ZDDNode node, int child_num)
 {
     if (child_num == 0)
     {
         zero_child = node;
     }
     else
     {
         one_child = node;
     }
 }
Exemple #12
0
 public ZDDNode MakeCopy()
 {
     ZDDNode node = new ZDDNode();
     node.deg = (int[])deg.Clone();   // 配列のコピーを生成
     node.comp = (int[])comp.Clone();
     return node;
 }
Exemple #13
0
        public static ZDDNode CreateRootNode(int number_of_vertices)
        {
            ZDDNode node = new ZDDNode();
            node.SetNextId();
            node.deg = new int[number_of_vertices + 1];
            node.comp = new int[number_of_vertices + 1];

            for (int i = 1; i <= number_of_vertices; ++i)
            {
                node.deg[i] = 0;
                node.comp[i] = i;
            }
            return node;
        }
Exemple #14
0
 // static コンストラクタ。ZDDNode 使用開始直前に呼び出される
 static ZDDNode()
 {
     ZeroTerminal = new ZDDNode();
     OneTerminal = new ZDDNode();
     ZeroTerminal.id_ = 0;
     OneTerminal.id_ = 1;
 }
Exemple #15
0
 private static void UpdateInfo(ZDDNode n_hat, int i, int x, State state)
 {
     Edge edge = state.graph.GetEdgeList()[i - 1];
     int[] src_dest = new int[] { edge.src, edge.dest };
     foreach (int u in src_dest)
     {
         if (!state.F[i - 1].Contains(u))
         {
             n_hat.deg[u] = 0;
             n_hat.comp[u] = u;
         }
     }
     if (x == 1)
     {
         ++n_hat.deg[edge.src];
         ++n_hat.deg[edge.dest];
         int c_min = Math.Min(n_hat.comp[edge.src], n_hat.comp[edge.dest]);
         int c_max = Math.Max(n_hat.comp[edge.src], n_hat.comp[edge.dest]);
         foreach (int u in state.F[i])
         {
             if (n_hat.comp[u] == c_max)
             {
                 n_hat.comp[u] = c_min;
             }
         }
     }
 }
Exemple #16
0
 private static bool IsEquivalent(ZDDNode node1, ZDDNode node2, int i, State state)
 {
     foreach (int v in state.F[i]) // フロンティア上の頂点についてのみ比較
     {
         if (node1.deg[v] != node2.deg[v])
         {
             return false;
         }
         if (node1.comp[v] != node2.comp[v])
         {
             return false;
         }
     }
     return true;
 }
Exemple #17
0
 private static ZDDNode Find(ZDDNode n_prime, List<ZDDNode> N_i, int i, State state)
 {
     foreach (ZDDNode n_primeprime in N_i)
     {
         if (IsEquivalent(n_prime, n_primeprime, i, state))
         {
             return n_primeprime;
         }
     }
     return null;
 }
Exemple #18
0
 private static ZDDNode CheckTerminal(ZDDNode n_hat, int i, int x, State state)
 {
     Edge edge = state.graph.GetEdgeList()[i - 1];
     if (x == 1)
     {
         if (n_hat.comp[edge.src] == n_hat.comp[edge.dest])
         {
             return ZDDNode.ZeroTerminal;
         }
     }
     ZDDNode n_prime = n_hat.MakeCopy();
     UpdateInfo(n_prime, i, x, state);
     int[] src_dest = new int[] { edge.src, edge.dest };
     foreach (int u in src_dest)
     {
         if ((u == state.s || u == state.t) && n_prime.deg[u] > 1)
         {
             return ZDDNode.ZeroTerminal;
         }
         else if ((u != state.s && u != state.t) && n_prime.deg[u] > 2)
         {
             return ZDDNode.ZeroTerminal;
         }
     }
     foreach (int u in src_dest)
     {
         if (!state.F[i].Contains(u))
         {
             if ((u == state.s || u == state.t) && n_prime.deg[u] != 1)
             {
                 return ZDDNode.ZeroTerminal;
             }
             else if ((u != state.s && u != state.t) && n_prime.deg[u] != 0 && n_prime.deg[u] != 2)
             {
                 return ZDDNode.ZeroTerminal;
             }
         }
     }
     if (i == state.graph.GetEdgeList().Count)
     {
         return ZDDNode.OneTerminal;
     }
     return null;
 }