public override String ToString() { if ((Var1 != null) && (Var2 != null)) { return(Var1 + " " + AllenEvents.GetString(ConstraintIndex) + " " + Var2); } else { return(null); } }
/// <summary> /// checks for the compatibility of variables /// </summary> /// <param name="a"> /// The a.variable /// </param> /// <param name="b"> /// The b.variable /// </param> /// <param name="d1"> /// The d 1.variable /// </param> /// <param name="d2"> /// The d 2.valirable /// </param> /// <param name="relations"> /// The relations. /// </param> /// <returns> /// boolean value /// </returns> private static bool Compatible(int a, int b, int d1, int d2, int[] relations) { for (int i = 0; i < relations.Length; i++) { if (AllenEvents.Satisfy(relations[i], a, b, d1, d2)) { return(true); } } return(false); }
/// <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); } } } } }