static private bool Update(IntDomain[] domArray, int index) { int val = domArray[index].Interval.Min; for (int idx = 0; idx < domArray.Length; ++idx) { IntDomain dom = domArray[idx]; if (idx != index && dom.Contains(val)) { dom = dom.Difference(val); if (dom.IsEmpty()) { return(true); } domArray[idx] = dom; if (dom.Interval.IsBound()) { if (Update(domArray, idx)) { return(true); } } } } return(false); }
private void Update1() { int sum_min = 0; int sum_max = 0; for (int idx = 0; idx < VarList.Count; ++idx) { IntDomain dom = VarList[idx].Domain; m_DomArray[idx] = dom; sum_min += dom.Min; sum_max += dom.Max; } if (m_Value < sum_min || m_Value > sum_max) { Violate(); return; } for (int idx = 0; idx < VarList.Count; ++idx) { IntDomain dom = m_DomArray[idx]; int min = m_Value - (sum_max - dom.Max); int max = m_Value - (sum_min - dom.Min); if (min > dom.Min || max < dom.Max) { sum_min -= dom.Min; sum_max -= dom.Max; dom = dom.Intersect(min, max); if (dom.IsEmpty()) { Violate(); return; } sum_min += dom.Min; sum_max += dom.Max; if (m_Value < sum_min || m_Value > sum_max) { Violate(); return; } m_DomArray[idx] = dom; idx = -1; } } for (int idx = 0; idx < VarList.Count; ++idx) { VarList[idx].Update(m_DomArray[idx]); } }