public static Inverse ( int interval ) : int[] | ||
interval | int | an integer array represents the interval to be inversed |
Результат | int[] |
/// <summary> /// queries variables for PC /// </summary> private void QueueUpVarsForPC() { IEnumerator v1 = network.Variables.GetEnumerator(); varNetwork = new IList[network.Variables.Count]; PC2Queue = new ArrayList(); int rowC = 0; while (v1.MoveNext()) { IEnumerator v2 = network.Variables.GetEnumerator(); varNetwork[rowC] = new ArrayList(); while (v2.MoveNext()) { if (v1.Current != v2.Current) { var con1 = new object[2]; con1[0] = v1.Current; // first variable con1[1] = v2.Current; // second variable PC2Queue.Add(con1); // Add to queue int[] events = GetEvents((Variable)v1.Current, (Variable)v2.Current); events = AllenEvents.Union(events, AllenEvents.Inverse(GetEvents((Variable)v2.Current, (Variable)v1.Current))); if (events.Length == 0) { events = AllenEvents.I; // assign I interval to events; } var con2 = new object[3]; con2[0] = con1[0]; con2[1] = con1[1]; con2[2] = events; // allen events varNetwork[rowC].Add(con2); } else { varNetwork[rowC].Add(new object[3]); // Add this item just to be consistent with the network } } rowC++; } }
/// <summary> /// Path consistency implementatiopn /// </summary> private void PathConsistency() { if (network.Variables.Count < 3) { return; } QueueUpVarsForPC(); while (PC2Queue.Count > 0) { var obj = (object[])PC2Queue[0]; var x = (AllenVariable)obj[0]; var y = (AllenVariable)obj[1]; int xInd = x.Index; int yInd = y.Index; PC2Queue.RemoveAt(0); IEnumerator kv = network.Variables.GetEnumerator(); while (kv.MoveNext()) { var k = (AllenVariable)kv.Current; if ((k != x) && k != y) { int kInd = k.Index; var objXK = (object[])varNetwork[xInd][kInd]; var cxk = (int[])objXK[2]; var objXY = (object[])varNetwork[xInd][yInd]; var cxy = (int[])objXY[2]; var objYK = (object[])varNetwork[yInd][kInd]; var cyk = (int[])objYK[2]; int[] t = AllenEvents.Composition(cxy, cyk); t = AllenEvents.Intersection(t, cxk); if (AllenEvents.IsEqual(t, cxk) != true) { var con2 = (object[])varNetwork[xInd][kInd]; con2[2] = t; // allen events varNetwork[xInd][kInd] = con2; // Cxk = t con2 = (object[])varNetwork[kInd][xInd]; // con2[0] = k; // con2[1] = x; con2[2] = AllenEvents.Inverse(t); // allen events varNetwork[kInd][xInd] = con2; // Ckx = t var con1 = new object[2]; con1[0] = x; // first variable con1[1] = k; // second variable PC2Queue.Add(con1); } objXY = (object[])varNetwork[xInd][yInd]; cxy = (int[])objXY[2]; var objKY = (object[])varNetwork[kInd][yInd]; var cky = (int[])objKY[2]; var objKX = (object[])varNetwork[kInd][xInd]; var ckx = (int[])objKX[2]; t = AllenEvents.Composition(ckx, cxy); t = AllenEvents.Intersection(t, cky); if (AllenEvents.IsEqual(t, cky) != true) { var con2 = (object[])varNetwork[yInd][kInd]; con2[2] = AllenEvents.Inverse(t); // allen events varNetwork[yInd][kInd] = con2; // Cxk = t var con = new object[2]; con[0] = k; // first variable con[1] = y; // second variable PC2Queue.Add(con); } } } } // Remove the old constraints while (network.Constraints.Count > 0) { network.Constraints.RemoveAt(0); } // Add the new constraints for (int i = 0; i < network.Variables.Count; i++) { for (int j = i + 1; j < network.Variables.Count; j++) { var obj1 = (object[])varNetwork[i][j]; var a = (int[])obj1[2]; if (AllenEvents.IsEqual(a, AllenEvents.I) != true) { for (int k = 0; k < a.Length; k++) { int aa = a[k]; var var1 = (Variable)obj1[0]; var var2 = (Variable)obj1[1]; new AllenConstraint(network, aa, var1, var2); } } } } }