Ejemplo n.º 1
0
        public void Prune(DoubleMap cache)
        {
            List<KeyValuePair<ulong, double>> pairs = new List<KeyValuePair<ulong, double>>();
            foreach (KeyValuePair<ulong, double> kvp in cache)
            {
                pairs.Add(kvp);
            }
            pairs.Sort(Comparison);

            // keep track of the ones that have been pruned
            BitArray prunedSet = new BitArray(pairs.Count);
            for (int i = 0; i < pairs.Count; i++)
            {
                if (prunedSet.Get(i))
                {
                    continue;
                }

                Varset pi = new Varset(pairs[i].Key);

                // make sure this variable set is not in an incomplete last layer
                if (pi.Cardinality() > highestCompletedLayer)
                {
                    prunedSet.Set(i, true);
                    continue;
                }

                for (int j = i + 1; j < pairs.Count; j++)
                {
                    if (prunedSet.Get(j))
                    {
                        continue;
                    }

                    // check if parents[i] is a subset of parents[j]
                    Varset pj = new Varset(pairs[j].Key);

                    if (pi.And(pj).Equals(pi)) // 部分集合かどうかの判定
                    {
                        // then we can prune pj
                        prunedSet.Set(j, true);
                        cache.Remove(pj.ToULong());
                    }
                }
            }
        }