public Varset Add(Varset varset) { Varset cp = new Varset(this); Varset zero = new Varset(0); cp.AlignLength(varset); while (!varset.Equals(zero)) { Varset tmp = cp.And(varset).LeftShift(1); cp = cp.Xor(varset); varset = tmp; } return cp; }
public Varset NextPermutation() { Varset vs = new Varset(this); Varset one = new Varset(0); one.Set(0, true); Varset tmp = vs.Or(vs.Subtract(one)).StaticAdd(one); Varset nextVariables = tmp.Or(tmp.And(tmp.Not().StaticAdd(one)).Divide(vs.And(vs.Not().StaticAdd(one))).RightShift(1).Subtract(one)); return nextVariables; }
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()); } } } }