List <NPoint> getDirectUpPoints(NPoint alpha) { if (alpha.upper.Count != 0) { return(alpha.upper); } //将α中的0依次改为1 for (int i = 0; i < alpha.x.Count; i++) { if (alpha.x[i] == 0) { //x[] = 10010 // //NPoint upoint = alpha.DeepClone(); alpha.x[i] = 1; NPoint val; if (allPoints.TryGetValue(alpha.toInt(), out val)) { alpha.upper.Add(val); } alpha.x[i] = 0; } } return(alpha.upper); }
public int Calculate(NPoint points) { NPoint val; mapGValue.TryGetValue(points.toInt(), out val); Debug.Assert(val != null && val.gfuncValue != null); return(val.gfuncValue.Value); }
public static void Test(String input, String output) { const int nDim = 5; int runTimes = 0; int totalCount = 0; int incorrectCount = 0; DateTime startTime = DateTime.Now; List <HanselChain> hcs = GenerateCube.GenerateNdimCubeAndHanselChain(nDim); FunctionInference functionInference = new FunctionInference(); foreach (HanselChain hc in hcs) { foreach (NPoint p in hc.chain) { NPoint dp = p.DeepClone(); dp.gfuncValue = 0; GFunction.getInstance().mapGValue.Add(dp.toInt(), dp); } } XElement xe = XElement.Load(input); IEnumerable <XElement> elements = from ele in xe.Elements("I_f") select ele; foreach (XElement e in elements) { String f = e.Element("f").Value; var gs = e.Elements("g"); foreach (var g in gs) { totalCount++; String gfunc = g.Value; GFunction.getInstance().g_function = gfunc; functionInference.RunAlgorithm(null, nDim, hcs); functionInference.A.Sort(delegate(NPoint p1, NPoint p2) { BigInteger i1 = p1.toInt(); BigInteger i2 = p2.toInt(); return(-i1.CompareTo(i2)); }); String getf = ""; for (int i = 0; i < f.Length; i++) { getf += functionInference.A[i].realValue.Value; functionInference.A[i].Destory(); } if (!f.Equals(getf) || functionInference.asked.Count > 20) { ++incorrectCount; Console.Out.WriteLine("g:{0},getf:{1},pf:{2},count:{3}", gfunc, getf, f, functionInference.asked.Count); } ++runTimes; if (runTimes % 1000 == 0) { Console.Out.WriteLine("{0} times. Time usage:{1}. IncorrectCount:{2}.", runTimes, (DateTime.Now - startTime).ToString(), incorrectCount); } } } Console.Out.WriteLine("Test finished. Total:{0}", totalCount); }
List <NPoint> getDirectDownPoints(NPoint alpha) { if (alpha.lower.Count != 0) { return(alpha.lower); } //将α中的1依次改为0 for (int i = 0; i < alpha.x.Count; i++) { if (alpha.x[i] == 1) { //NPoint dpoint = alpha.DeepClone(); alpha.x[i] = 0; NPoint val; if (allPoints.TryGetValue(alpha.toInt(), out val)) { alpha.lower.Add(val); } alpha.x[i] = 1; } } return(alpha.lower); }
void HandleBeta1AndBeta2(NPoint beta1, NPoint beta2) { if (beta1.realValue == beta2.realValue && beta1.realValue == 1) { //计算γ==β1 or β2,按位或。令f(γ) = 1,γ归到A中 BigInteger b = beta1.toInt() | beta2.toInt(); NPoint gamma; allPoints.TryGetValue(b, out gamma); //gamma中1的数量-β1中1的数量,如果大于1则这个gamma不能用 if (gamma.HasNOne() - beta1.HasNOne() > 1) { return; } gamma.ffuncValue = 1; //AddPointToA(gamma); AddPointsToA(new List <NPoint>() { gamma }, null, null); //另所有大于γ的γ’,f(γ‘)都等于1,所有的γ’归到A中 List <NPoint> gammas = new List <NPoint>(); for (int i = 0; i < B.Count; ++i) { NPoint p = B[i]; bool? greater = p > gamma; if (greater != null && greater == true) { gammas.Add(p); //p.ffuncValue = 1; //AddPointToA(p); } } AddPointsToA(gammas, 1, null); } else { //计算γ==β1 and β2,按位与。令f(γ) = 0,γ归到A中 BigInteger b = beta1.toInt() & beta2.toInt(); NPoint gamma; allPoints.TryGetValue(b, out gamma); //β1中1的数量-gamma中1的数量,如果大于1则这个gamma不能用 if (beta1.HasNOne() - gamma.HasNOne() > 1) { return; } gamma.ffuncValue = 0; //AddPointToA(gamma); AddPointsToA(new List <NPoint>() { gamma }, null, null); //另所有小于γ的γ’,f(γ‘)都等于0,所有的γ’归到A中 List <NPoint> gammas = new List <NPoint>(); for (int i = 0; i < B.Count; ++i) { NPoint p = B[i]; bool? less = p < gamma; if (less != null && less == true) { gammas.Add(p); //p.ffuncValue = 0; //AddPointToA(p); } } AddPointsToA(gammas, 0, null); } }